From e9ea8cf5057d6f616b13e6472d1fc58de1e54260 Mon Sep 17 00:00:00 2001 From: Andrey Sinitsyn Date: Fri, 15 Apr 2022 02:22:11 +0300 Subject: [PATCH 1/7] feat(PagerDuty node): add support for additional details for the incident --- packages/nodes-base/nodes/PagerDuty/IncidentDescription.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/nodes-base/nodes/PagerDuty/IncidentDescription.ts b/packages/nodes-base/nodes/PagerDuty/IncidentDescription.ts index 207bfd08a4804..ea8998ab1000a 100644 --- a/packages/nodes-base/nodes/PagerDuty/IncidentDescription.ts +++ b/packages/nodes-base/nodes/PagerDuty/IncidentDescription.ts @@ -120,6 +120,13 @@ export const incidentFields: INodeProperties[] = [ }, default: {}, options: [ + { + displayName: 'Incident details', + name: 'details', + type: 'string', + default: '', + description: 'Provide additional details about the incident which will go in the body', + }, { displayName: 'Escalation Policy ID', name: 'escalationPolicyId', From 17b0cd8f765ce262241c827a635e64c189acc0f8 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Fri, 15 Apr 2022 08:35:51 +0300 Subject: [PATCH 2/7] fix(editor): Fix breaking Drop-downs after removing expressions (#3094) * :bug: Fixed multiOption parameter input dropdown values after removing expression. * :recycle: Moved array value normalization to removeExpression action. * :bug: Handled scenario where expression contained invalid value. --- .../editor-ui/src/components/ParameterInput.vue | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/editor-ui/src/components/ParameterInput.vue b/packages/editor-ui/src/components/ParameterInput.vue index e3fecf8da6f97..b93fe6658971a 100644 --- a/packages/editor-ui/src/components/ParameterInput.vue +++ b/packages/editor-ui/src/components/ParameterInput.vue @@ -421,7 +421,7 @@ export default mixins( return false; }, - expressionValueComputed (): NodeParameterValue | null { + expressionValueComputed (): NodeParameterValue | string[] | null { if (this.areExpressionsDisabled) { return this.value; } @@ -733,7 +733,7 @@ export default mixins( this.$emit('textInput', parameterData); }, - valueChanged (value: string | number | boolean | Date | null) { + valueChanged (value: string[] | string | number | boolean | Date | null) { if (value instanceof Date) { value = value.toISOString(); } @@ -768,7 +768,14 @@ export default mixins( this.expressionEditDialogVisible = true; this.trackExpressionEditOpen(); } else if (command === 'removeExpression') { - this.valueChanged(this.expressionValueComputed !== undefined ? this.expressionValueComputed : null); + let value = this.expressionValueComputed; + + if (this.parameter.type === 'multiOptions' && typeof value === 'string') { + value = (value || '').split(',') + .filter((value) => (this.parameterOptions || []).find((option) => option.value === value)); + } + + this.valueChanged(typeof value !== 'undefined' ? value : null); } else if (command === 'refreshOptions') { this.loadRemoteParameterOptions(); } From d3fecb9f6d2a3c75052b17055f6ef2852e988713 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Fri, 15 Apr 2022 08:00:47 +0200 Subject: [PATCH 3/7] :art: Centralize error throwing for encryption keys and credentials (#3105) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Centralized error throwing for encryption key * Unifying the error message used by cli and core packages * Improvements to error messages to make it more DRY * Removed unnecessary throw * Throwing error when credential does not exist to simplify node behavior (#3112) Co-authored-by: Iván Ovejero --- packages/cli/commands/export/credentials.ts | 3 -- packages/cli/commands/import/credentials.ts | 3 -- packages/cli/commands/start.ts | 10 +--- packages/cli/src/Server.ts | 52 +++++++------------ .../cli/src/WorkflowExecuteAdditionalData.ts | 4 +- packages/cli/src/api/credentials.api.ts | 37 +++++++------ packages/cli/src/constants.ts | 6 ++- .../test/integration/credentials.api.test.ts | 9 ++-- .../cli/test/integration/shared/testDb.ts | 4 -- packages/core/src/Constants.ts | 5 ++ packages/core/src/NodeExecuteFunctions.ts | 38 ++++++-------- packages/core/src/UserSettings.ts | 13 ++--- .../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 | 2 +- .../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 | 2 +- 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 +- 227 files changed, 348 insertions(+), 848 deletions(-) diff --git a/packages/cli/commands/export/credentials.ts b/packages/cli/commands/export/credentials.ts index ab34c9d96835c..5048efe68bd4b 100644 --- a/packages/cli/commands/export/credentials.ts +++ b/packages/cli/commands/export/credentials.ts @@ -123,9 +123,6 @@ export class ExportCredentialsCommand extends Command { if (flags.decrypted) { const encryptionKey = await UserSettings.getEncryptionKey(); - if (encryptionKey === undefined) { - throw new Error('No encryption key got found to decrypt the credentials!'); - } for (let i = 0; i < credentials.length; i++) { const { name, type, nodesAccess, data } = credentials[i]; diff --git a/packages/cli/commands/import/credentials.ts b/packages/cli/commands/import/credentials.ts index eb08f1a0deafe..8405379c49169 100644 --- a/packages/cli/commands/import/credentials.ts +++ b/packages/cli/commands/import/credentials.ts @@ -85,9 +85,6 @@ export class ImportCredentialsCommand extends Command { await UserSettings.prepareUserSettings(); const encryptionKey = await UserSettings.getEncryptionKey(); - if (encryptionKey === undefined) { - throw new Error('No encryption key found to encrypt the credentials!'); - } if (flags.separate) { const files = await glob( diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index dc9045d830f54..ab9654334686b 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -33,7 +33,6 @@ import { } from '../src'; import { getLogger } from '../src/Logger'; -import { RESPONSE_ERROR_MESSAGES } from '../src/constants'; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires const open = require('open'); @@ -173,9 +172,6 @@ export class Start extends Command { // If we don't have a JWT secret set, generate // one based and save to config. const encryptionKey = await UserSettings.getEncryptionKey(); - if (!encryptionKey) { - throw new Error('Fatal error setting up user management: no encryption key set.'); - } // For a key off every other letter from encryption key // CAREFUL: do not change this or it breaks all existing tokens. @@ -210,11 +206,7 @@ export class Start extends Command { // Wait till the database is ready await startDbInitPromise; - const encryptionKey = await UserSettings.getEncryptionKey(); - - if (!encryptionKey) { - throw new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY); - } + await UserSettings.getEncryptionKey(); // Load settings from database and set them to config. const databaseSettings = await Db.collections.Settings.find({ loadOnStartup: true }); diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 68155d0fd7c33..4233340a8e16f 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -1703,13 +1703,11 @@ class App { ); } - const encryptionKey = await UserSettings.getEncryptionKey(); - if (!encryptionKey) { - throw new ResponseHelper.ResponseError( - RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, - undefined, - 500, - ); + let encryptionKey: string; + try { + encryptionKey = await UserSettings.getEncryptionKey(); + } catch (error) { + throw new ResponseHelper.ResponseError(error.message, undefined, 500); } const mode: WorkflowExecuteMode = 'internal'; @@ -1842,15 +1840,11 @@ class App { return ResponseHelper.sendErrorResponse(res, errorResponse); } - const encryptionKey = await UserSettings.getEncryptionKey(); - - if (!encryptionKey) { - const errorResponse = new ResponseHelper.ResponseError( - RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, - undefined, - 503, - ); - return ResponseHelper.sendErrorResponse(res, errorResponse); + let encryptionKey: string; + try { + encryptionKey = await UserSettings.getEncryptionKey(); + } catch (error) { + throw new ResponseHelper.ResponseError(error.message, undefined, 500); } const mode: WorkflowExecuteMode = 'internal'; @@ -1962,13 +1956,11 @@ class App { ); } - const encryptionKey = await UserSettings.getEncryptionKey(); - if (!encryptionKey) { - throw new ResponseHelper.ResponseError( - RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, - undefined, - 500, - ); + let encryptionKey: string; + try { + encryptionKey = await UserSettings.getEncryptionKey(); + } catch (error) { + throw new ResponseHelper.ResponseError(error.message, undefined, 500); } const mode: WorkflowExecuteMode = 'internal'; @@ -2103,15 +2095,11 @@ class App { return ResponseHelper.sendErrorResponse(res, errorResponse); } - const encryptionKey = await UserSettings.getEncryptionKey(); - - if (!encryptionKey) { - const errorResponse = new ResponseHelper.ResponseError( - RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, - undefined, - 503, - ); - return ResponseHelper.sendErrorResponse(res, errorResponse); + let encryptionKey: string; + try { + encryptionKey = await UserSettings.getEncryptionKey(); + } catch (error) { + throw new ResponseHelper.ResponseError(error.message, undefined, 500); } const mode: WorkflowExecuteMode = 'internal'; diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index 156b324b928be..55f52b583bc32 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -66,6 +66,7 @@ import { getWorkflowOwner, } from './UserManagement/UserManagementHelper'; import { whereClause } from './WorkflowHelpers'; +import { RESPONSE_ERROR_MESSAGES } from './constants'; const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType'); @@ -1030,9 +1031,6 @@ export async function getBase( const webhookTestBaseUrl = urlBaseWebhook + config.getEnv('endpoints.webhookTest'); const encryptionKey = await UserSettings.getEncryptionKey(); - if (encryptionKey === undefined) { - throw new Error('No encryption key got found to decrypt the credentials!'); - } return { credentialsHelper: new CredentialsHelper(encryptionKey), diff --git a/packages/cli/src/api/credentials.api.ts b/packages/cli/src/api/credentials.api.ts index 6880017aa8ce5..e69ed08cd4951 100644 --- a/packages/cli/src/api/credentials.api.ts +++ b/packages/cli/src/api/credentials.api.ts @@ -115,13 +115,15 @@ credentialsController.post( ResponseHelper.send(async (req: CredentialRequest.Test): Promise => { const { credentials, nodeToTestWith } = req.body; - const encryptionKey = await UserSettings.getEncryptionKey(); - - if (!encryptionKey) { - return { - status: 'Error', - message: RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, - }; + let encryptionKey: string; + try { + encryptionKey = await UserSettings.getEncryptionKey(); + } catch (error) { + throw new ResponseHelper.ResponseError( + RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, + undefined, + 500, + ); } const helper = new CredentialsHelper(encryptionKey); @@ -149,9 +151,10 @@ credentialsController.post( nodeAccess.date = new Date(); } - const encryptionKey = await UserSettings.getEncryptionKey(); - - if (!encryptionKey) { + let encryptionKey: string; + try { + encryptionKey = await UserSettings.getEncryptionKey(); + } catch (error) { throw new ResponseHelper.ResponseError( RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, undefined, @@ -285,9 +288,10 @@ credentialsController.patch( } } - const encryptionKey = await UserSettings.getEncryptionKey(); - - if (!encryptionKey) { + let encryptionKey: string; + try { + encryptionKey = await UserSettings.getEncryptionKey(); + } catch (error) { throw new ResponseHelper.ResponseError( RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, undefined, @@ -393,9 +397,10 @@ credentialsController.get( const { data, id, ...rest } = credential; - const encryptionKey = await UserSettings.getEncryptionKey(); - - if (!encryptionKey) { + let encryptionKey: string; + try { + encryptionKey = await UserSettings.getEncryptionKey(); + } catch (error) { throw new ResponseHelper.ResponseError( RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, undefined, diff --git a/packages/cli/src/constants.ts b/packages/cli/src/constants.ts index 3cdfbb00c7fc0..59062c46448c5 100644 --- a/packages/cli/src/constants.ts +++ b/packages/cli/src/constants.ts @@ -1,8 +1,12 @@ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/naming-convention */ +import { RESPONSE_ERROR_MESSAGES as CORE_RESPONSE_ERROR_MESSAGES } from 'n8n-core'; + export const RESPONSE_ERROR_MESSAGES = { NO_CREDENTIAL: 'Credential not found', - NO_ENCRYPTION_KEY: 'Encryption key missing to decrypt credentials', + NO_ENCRYPTION_KEY: CORE_RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY, }; export const AUTH_COOKIE_NAME = 'n8n-auth'; diff --git a/packages/cli/test/integration/credentials.api.test.ts b/packages/cli/test/integration/credentials.api.test.ts index f5fa438cd0a0f..e5a502eccdeae 100644 --- a/packages/cli/test/integration/credentials.api.test.ts +++ b/packages/cli/test/integration/credentials.api.test.ts @@ -7,6 +7,7 @@ import type { CredentialPayload, SaveCredentialFunction } from './shared/types'; import type { Role } from '../../src/databases/entities/Role'; import type { User } from '../../src/databases/entities/User'; import * as testDb from './shared/testDb'; +import { RESPONSE_ERROR_MESSAGES } from '../../src/constants'; import { CredentialsEntity } from '../../src/databases/entities/CredentialsEntity'; jest.mock('../../src/telemetry'); @@ -91,7 +92,7 @@ test('POST /credentials should fail with invalid inputs', async () => { test('POST /credentials should fail with missing encryption key', async () => { const mock = jest.spyOn(UserSettings, 'getEncryptionKey'); - mock.mockResolvedValue(undefined); + mock.mockRejectedValue(new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY)); const ownerShell = await testDb.createUserShell(globalOwnerRole); const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell }); @@ -354,7 +355,8 @@ test('PATCH /credentials/:id should fail if cred not found', async () => { test('PATCH /credentials/:id should fail with missing encryption key', async () => { const mock = jest.spyOn(UserSettings, 'getEncryptionKey'); - mock.mockResolvedValue(undefined); + mock.mockRejectedValue(new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY)); + const ownerShell = await testDb.createUserShell(globalOwnerRole); const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell }); @@ -504,7 +506,8 @@ test('GET /credentials/:id should fail with missing encryption key', async () => const savedCredential = await saveCredential(credentialPayload(), { user: ownerShell }); const mock = jest.spyOn(UserSettings, 'getEncryptionKey'); - mock.mockResolvedValue(undefined); + mock.mockRejectedValue(new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY)); + const response = await authOwnerAgent .get(`/credentials/${savedCredential.id}`) diff --git a/packages/cli/test/integration/shared/testDb.ts b/packages/cli/test/integration/shared/testDb.ts index 3ad2dcfc5657f..c15ba056a0ea8 100644 --- a/packages/cli/test/integration/shared/testDb.ts +++ b/packages/cli/test/integration/shared/testDb.ts @@ -392,10 +392,6 @@ export const getMySqlOptions = ({ name }: { name: string }): ConnectionOptions = async function encryptCredentialData(credential: CredentialsEntity) { const encryptionKey = await UserSettings.getEncryptionKey(); - if (!encryptionKey) { - throw new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY); - } - const coreCredential = new Credentials( { id: null, name: credential.name }, credential.type, diff --git a/packages/core/src/Constants.ts b/packages/core/src/Constants.ts index 43103df5acc1d..fc1103a4935ab 100644 --- a/packages/core/src/Constants.ts +++ b/packages/core/src/Constants.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ export const BINARY_ENCODING = 'base64'; export const CUSTOM_EXTENSION_ENV = 'N8N_CUSTOM_EXTENSIONS'; export const ENCRYPTION_KEY_ENV_OVERWRITE = 'N8N_ENCRYPTION_KEY'; @@ -9,3 +10,7 @@ export const PLACEHOLDER_EMPTY_EXECUTION_ID = '__UNKOWN__'; export const PLACEHOLDER_EMPTY_WORKFLOW_ID = '__EMPTY__'; export const TUNNEL_SUBDOMAIN_ENV = 'N8N_TUNNEL_SUBDOMAIN'; export const WAIT_TIME_UNLIMITED = '3000-01-01T00:00:00.000Z'; + +export const RESPONSE_ERROR_MESSAGES = { + NO_ENCRYPTION_KEY: 'Encryption key is missing or was not set', +}; diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index c742cd08e43fc..6dc23ed38e057 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -874,13 +874,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!'); @@ -997,9 +991,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!'); @@ -1269,7 +1261,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) { @@ -1309,8 +1301,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'); } } @@ -1327,15 +1319,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; @@ -1605,7 +1597,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 => { @@ -1759,7 +1751,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: () => { @@ -1949,7 +1941,7 @@ export function getExecuteFunctions( async getCredentials( type: string, itemIndex?: number, - ): Promise { + ): Promise { return getCredentials( workflow, node, @@ -2193,7 +2185,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, @@ -2389,7 +2381,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: ( @@ -2533,7 +2525,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 => { @@ -2692,7 +2684,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/core/src/UserSettings.ts b/packages/core/src/UserSettings.ts index ca6406b66e5a5..ff3a8d4140c70 100644 --- a/packages/core/src/UserSettings.ts +++ b/packages/core/src/UserSettings.ts @@ -10,6 +10,7 @@ import { ENCRYPTION_KEY_ENV_OVERWRITE, EXTENSIONS_SUBDIRECTORY, IUserSettings, + RESPONSE_ERROR_MESSAGES, USER_FOLDER_ENV_OVERWRITE, USER_SETTINGS_FILE_NAME, USER_SETTINGS_SUBFOLDER, @@ -73,19 +74,15 @@ export async function prepareUserSettings(): Promise { * @returns */ -export async function getEncryptionKey(): Promise { +export async function getEncryptionKey(): Promise { if (process.env[ENCRYPTION_KEY_ENV_OVERWRITE] !== undefined) { - return process.env[ENCRYPTION_KEY_ENV_OVERWRITE]; + return process.env[ENCRYPTION_KEY_ENV_OVERWRITE] as string; } const userSettings = await getUserSettings(); - if (userSettings === undefined) { - return undefined; - } - - if (userSettings.encryptionKey === undefined) { - return undefined; + if (userSettings === undefined || userSettings.encryptionKey === undefined) { + throw new Error(RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY); } return userSettings.encryptionKey; 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 7aa9f9e3cee54..11f7093be4037 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 37e3ba1772211..89509e3218908 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 26b29a3ca2633..aaf9f6fac535d 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 c6f63fe64c374..24842fc8f9617 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 5d459b44ee340..c4645559c20ec 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 b2102824afe99..9e3c50615e864 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}`; return await this.helpers.request!(options); 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 9925581d13162..0454a522c161c 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 7560d8276f21b..9ad1932f33d86 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 12ccbcd9d7407..fa6335afbb81f 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 e78e93c3d5844..bca871a23c401 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 1a193c091ca82..667730fce6ab3 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 48ef48a8c63b7..9f18b7436c745 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 5ea259adb2b45..3a392bc73fcfd 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 5e34987d76e29..93c147a548882 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 66d7a57fa4a0d..1baccd54e47c0 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 940e36c18bf9b..504931be4ee72 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 c37d7a19fe795..13711fadc98b8 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 0fbf61e69767e..07afbadbdba7d 100644 --- a/packages/nodes-base/nodes/KoBoToolbox/GenericFunctions.ts +++ b/packages/nodes-base/nodes/KoBoToolbox/GenericFunctions.ts @@ -15,7 +15,7 @@ import { import _ 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 666299260f2d7..8b8ae6c11c445 100644 --- a/packages/nodes-base/nodes/Linear/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Linear/GenericFunctions.ts @@ -24,7 +24,7 @@ import { } 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 a090532cd04e5..712b712b7514f 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 104f82437e690..5e2f8e1a705f1 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 4a7353a50759a..baede8153acf6 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 = { method, 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 fe7899e5175de..c7555b99b47df 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 25a0d22a883e2..230ae6c3f5963 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 738e24bc16ea6..b3e27a4983090 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 37abc7f63aecd..e71036ef6df79 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 d6a1f568f950a..5c8c2a3543d3a 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}`; 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 de4ec2fde05a6..cd9bc02379519 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 1e8b84b4ebb3b..ce9b7b0e23dd4 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 7a2eb0bad7b2c..a43ebfbe8f511 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 e10d354382f7c..982c27bb073c5 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 e625d2e9a03a5..6c11d33728137 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 4978f90b96c36..ba6f259398b49 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 c6105b3b8f94d..037b399432ddb 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 911fb377a5266..a01355e336247 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 1b8d7c849184c..b5209a8e1b5e1 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 c8b9e0f5c68c9..6e6bdf799a864 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 b9ed363f12305..a6ee58cec6fcd 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 4d9bec97394c0..58398d289b661 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 00c224bb37b05..dbc4146bfb2de 100644 --- a/packages/nodes-base/nodes/TravisCi/GenericFunctions.ts +++ b/packages/nodes-base/nodes/TravisCi/GenericFunctions.ts @@ -21,9 +21,6 @@ import 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 d33a386a64149..8627445e136d3 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 7f79064dfa5bc..ba447c3df6f2a 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 b2e96f71532a7..3ce2e0138e505 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 cf10a5d1497d7..c995c526765d0 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 240a912b71a94..c9b58b5795524 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -483,10 +483,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; @@ -533,7 +530,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; @@ -583,7 +580,7 @@ export interface ICredentialTestFunctions { } export interface ILoadOptionsFunctions { - getCredentials(type: string): Promise; + getCredentials(type: string): Promise; getNode(): INode; getNodeParameter( parameterName: string, @@ -624,7 +621,7 @@ export interface ILoadOptionsFunctions { } export interface IHookFunctions { - getCredentials(type: string): Promise; + getCredentials(type: string): Promise; getMode(): WorkflowExecuteMode; getActivationMode(): WorkflowActivateMode; getNode(): INode; @@ -654,7 +651,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; @@ -686,7 +683,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; @@ -714,7 +711,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 8e66d737d196a..a94be10c989b3 100644 --- a/packages/workflow/test/Helpers.ts +++ b/packages/workflow/test/Helpers.ts @@ -211,7 +211,7 @@ export function getExecuteFunctions( async getCredentials( type: string, itemIndex?: number, - ): Promise { + ): Promise { return { apiKey: '12345', }; @@ -388,7 +388,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', }; From 8532b0030dbdeb85b2f74ce078adb44f43a7c4d3 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com> Date: Fri, 15 Apr 2022 08:11:35 +0200 Subject: [PATCH 4/7] fix(core): Make email for UM case insensitive (#3078) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🚧 lowercasing email * ✅ add tests for case insensitive email * 🐘 add migration to lowercase email * 🚚 rename migration * 🐛 fix package.lock * :bug: fix double import * 📋 add todo --- .../email/UserManagementMailer.ts | 1 + .../cli/src/UserManagement/routes/users.ts | 2 +- packages/cli/src/databases/entities/User.ts | 13 +++- .../1648740597343-LowerCaseUserEmail.ts | 17 +++++ .../src/databases/mysqldb/migrations/index.ts | 2 + .../1648740597343-LowerCaseUserEmail.ts | 21 ++++++ .../databases/postgresdb/migrations/index.ts | 2 + .../1648740597343-LowerCaseUserEmail.ts | 22 ++++++ .../src/databases/sqlite/migrations/index.ts | 2 + .../cli/src/databases/utils/transformers.ts | 9 ++- .../test/integration/auth.endpoints.test.ts | 74 ++++++++++--------- packages/cli/test/integration/me.api.test.ts | 20 ++--- .../cli/test/integration/owner.api.test.ts | 29 ++++++++ .../integration/passwordReset.api.test.ts | 19 +++-- .../cli/test/integration/users.api.test.ts | 52 +++++++------ 15 files changed, 204 insertions(+), 81 deletions(-) create mode 100644 packages/cli/src/databases/mysqldb/migrations/1648740597343-LowerCaseUserEmail.ts create mode 100644 packages/cli/src/databases/postgresdb/migrations/1648740597343-LowerCaseUserEmail.ts create mode 100644 packages/cli/src/databases/sqlite/migrations/1648740597343-LowerCaseUserEmail.ts diff --git a/packages/cli/src/UserManagement/email/UserManagementMailer.ts b/packages/cli/src/UserManagement/email/UserManagementMailer.ts index cda715a7c7ac7..5fa51319b6580 100644 --- a/packages/cli/src/UserManagement/email/UserManagementMailer.ts +++ b/packages/cli/src/UserManagement/email/UserManagementMailer.ts @@ -12,6 +12,7 @@ import { } from './Interfaces'; import { NodeMailer } from './NodeMailer'; +// TODO: make function fully async (remove sync functions) async function getTemplate(configKeyName: string, defaultFilename: string) { const templateOverride = (await GenericHelpers.getConfigValue( `userManagement.emails.templates.${configKeyName}`, diff --git a/packages/cli/src/UserManagement/routes/users.ts b/packages/cli/src/UserManagement/routes/users.ts index 3b196970369bd..d6f1caac7da13 100644 --- a/packages/cli/src/UserManagement/routes/users.ts +++ b/packages/cli/src/UserManagement/routes/users.ts @@ -104,7 +104,7 @@ export function usersNamespace(this: N8nApp): void { 400, ); } - createUsers[invite.email] = null; + createUsers[invite.email.toLowerCase()] = null; }); const role = await Db.collections.Role.findOne({ scope: 'global', name: 'member' }); diff --git a/packages/cli/src/databases/entities/User.ts b/packages/cli/src/databases/entities/User.ts index ee539c4f65310..12f4ec64c1f4e 100644 --- a/packages/cli/src/databases/entities/User.ts +++ b/packages/cli/src/databases/entities/User.ts @@ -12,6 +12,7 @@ import { ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn, + BeforeInsert, } from 'typeorm'; import { IsEmail, IsString, Length } from 'class-validator'; import * as config from '../../../config'; @@ -20,7 +21,7 @@ import { Role } from './Role'; import { SharedWorkflow } from './SharedWorkflow'; import { SharedCredentials } from './SharedCredentials'; import { NoXss } from '../utils/customValidators'; -import { answersFormatter } from '../utils/transformers'; +import { answersFormatter, lowerCaser } from '../utils/transformers'; export const MIN_PASSWORD_LENGTH = 8; @@ -62,7 +63,11 @@ export class User { @PrimaryGeneratedColumn('uuid') id: string; - @Column({ length: 254, nullable: true }) + @Column({ + length: 254, + nullable: true, + transformer: lowerCaser, + }) @Index({ unique: true }) @IsEmail() email: string; @@ -119,8 +124,10 @@ export class User { }) updatedAt: Date; + @BeforeInsert() @BeforeUpdate() - setUpdateDate(): void { + preUpsertHook(): void { + this.email = this.email?.toLowerCase(); this.updatedAt = new Date(); } diff --git a/packages/cli/src/databases/mysqldb/migrations/1648740597343-LowerCaseUserEmail.ts b/packages/cli/src/databases/mysqldb/migrations/1648740597343-LowerCaseUserEmail.ts new file mode 100644 index 0000000000000..a627ed830ae6a --- /dev/null +++ b/packages/cli/src/databases/mysqldb/migrations/1648740597343-LowerCaseUserEmail.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; +import config = require('../../../../config'); + +export class LowerCaseUserEmail1648740597343 implements MigrationInterface { + name = 'LowerCaseUserEmail1648740597343'; + + public async up(queryRunner: QueryRunner): Promise { + const tablePrefix = config.get('database.tablePrefix'); + + await queryRunner.query(` + UPDATE ${tablePrefix}user + SET email = LOWER(email); + `); + } + + public async down(queryRunner: QueryRunner): Promise {} +} diff --git a/packages/cli/src/databases/mysqldb/migrations/index.ts b/packages/cli/src/databases/mysqldb/migrations/index.ts index 16ee37da4666e..6c859556d0ce1 100644 --- a/packages/cli/src/databases/mysqldb/migrations/index.ts +++ b/packages/cli/src/databases/mysqldb/migrations/index.ts @@ -12,6 +12,7 @@ import { AddWaitColumnId1626183952959 } from './1626183952959-AddWaitColumn'; import { UpdateWorkflowCredentials1630451444017 } from './1630451444017-UpdateWorkflowCredentials'; import { AddExecutionEntityIndexes1644424784709 } from './1644424784709-AddExecutionEntityIndexes'; import { CreateUserManagement1646992772331 } from './1646992772331-CreateUserManagement'; +import { LowerCaseUserEmail1648740597343 } from './1648740597343-LowerCaseUserEmail'; export const mysqlMigrations = [ InitialMigration1588157391238, @@ -28,4 +29,5 @@ export const mysqlMigrations = [ UpdateWorkflowCredentials1630451444017, AddExecutionEntityIndexes1644424784709, CreateUserManagement1646992772331, + LowerCaseUserEmail1648740597343, ]; diff --git a/packages/cli/src/databases/postgresdb/migrations/1648740597343-LowerCaseUserEmail.ts b/packages/cli/src/databases/postgresdb/migrations/1648740597343-LowerCaseUserEmail.ts new file mode 100644 index 0000000000000..02a12d047f02e --- /dev/null +++ b/packages/cli/src/databases/postgresdb/migrations/1648740597343-LowerCaseUserEmail.ts @@ -0,0 +1,21 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; +import config = require('../../../../config'); + +export class LowerCaseUserEmail1648740597343 implements MigrationInterface { + name = 'LowerCaseUserEmail1648740597343'; + + public async up(queryRunner: QueryRunner): Promise { + let tablePrefix = config.get('database.tablePrefix'); + const schema = config.get('database.postgresdb.schema'); + if (schema) { + tablePrefix = schema + '.' + tablePrefix; + } + + await queryRunner.query(` + UPDATE ${tablePrefix}user + SET email = LOWER(email); + `); + } + + public async down(queryRunner: QueryRunner): Promise {} +} diff --git a/packages/cli/src/databases/postgresdb/migrations/index.ts b/packages/cli/src/databases/postgresdb/migrations/index.ts index 903b6a7e723b9..3c1fb23d4f63c 100644 --- a/packages/cli/src/databases/postgresdb/migrations/index.ts +++ b/packages/cli/src/databases/postgresdb/migrations/index.ts @@ -10,6 +10,7 @@ import { UpdateWorkflowCredentials1630419189837 } from './1630419189837-UpdateWo import { AddExecutionEntityIndexes1644422880309 } from './1644422880309-AddExecutionEntityIndexes'; import { IncreaseTypeVarcharLimit1646834195327 } from './1646834195327-IncreaseTypeVarcharLimit'; import { CreateUserManagement1646992772331 } from './1646992772331-CreateUserManagement'; +import { LowerCaseUserEmail1648740597343 } from './1648740597343-LowerCaseUserEmail'; export const postgresMigrations = [ InitialMigration1587669153312, @@ -24,4 +25,5 @@ export const postgresMigrations = [ AddExecutionEntityIndexes1644422880309, IncreaseTypeVarcharLimit1646834195327, CreateUserManagement1646992772331, + LowerCaseUserEmail1648740597343, ]; diff --git a/packages/cli/src/databases/sqlite/migrations/1648740597343-LowerCaseUserEmail.ts b/packages/cli/src/databases/sqlite/migrations/1648740597343-LowerCaseUserEmail.ts new file mode 100644 index 0000000000000..2eb789875081b --- /dev/null +++ b/packages/cli/src/databases/sqlite/migrations/1648740597343-LowerCaseUserEmail.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; +import config = require('../../../../config'); +import { logMigrationEnd, logMigrationStart } from '../../utils/migrationHelpers'; + +export class LowerCaseUserEmail1648740597343 implements MigrationInterface { + name = 'LowerCaseUserEmail1648740597343'; + + public async up(queryRunner: QueryRunner): Promise { + logMigrationStart(this.name); + + const tablePrefix = config.get('database.tablePrefix'); + + await queryRunner.query(` + UPDATE "${tablePrefix}user" + SET email = LOWER(email); + `); + + logMigrationEnd(this.name); + } + + public async down(queryRunner: QueryRunner): Promise {} +} diff --git a/packages/cli/src/databases/sqlite/migrations/index.ts b/packages/cli/src/databases/sqlite/migrations/index.ts index 2f938fe0d15bd..347c403aea03c 100644 --- a/packages/cli/src/databases/sqlite/migrations/index.ts +++ b/packages/cli/src/databases/sqlite/migrations/index.ts @@ -11,6 +11,7 @@ import { AddWaitColumn1621707690587 } from './1621707690587-AddWaitColumn'; import { UpdateWorkflowCredentials1630330987096 } from './1630330987096-UpdateWorkflowCredentials'; import { AddExecutionEntityIndexes1644421939510 } from './1644421939510-AddExecutionEntityIndexes'; import { CreateUserManagement1646992772331 } from './1646992772331-CreateUserManagement'; +import { LowerCaseUserEmail1648740597343 } from './1648740597343-LowerCaseUserEmail'; const sqliteMigrations = [ InitialMigration1588102412422, @@ -24,6 +25,7 @@ const sqliteMigrations = [ UpdateWorkflowCredentials1630330987096, AddExecutionEntityIndexes1644421939510, CreateUserManagement1646992772331, + LowerCaseUserEmail1648740597343, ]; export { sqliteMigrations }; diff --git a/packages/cli/src/databases/utils/transformers.ts b/packages/cli/src/databases/utils/transformers.ts index f843c1c2f795e..c2a9d3e0d20ec 100644 --- a/packages/cli/src/databases/utils/transformers.ts +++ b/packages/cli/src/databases/utils/transformers.ts @@ -2,8 +2,13 @@ import { IPersonalizationSurveyAnswers } from '../../Interfaces'; export const idStringifier = { - from: (value: number): string | number => (value ? value.toString() : value), - to: (value: string): number | string => (value ? Number(value) : value), + from: (value: number): string | number => (typeof value === 'number' ? value.toString() : value), + to: (value: string): number | string => (typeof value === 'string' ? Number(value) : value), +}; + +export const lowerCaser = { + from: (value: string): string => value, + to: (value: string): string => (typeof value === 'string' ? value.toLowerCase() : value), }; /** diff --git a/packages/cli/test/integration/auth.endpoints.test.ts b/packages/cli/test/integration/auth.endpoints.test.ts index fd24d49c0e7c1..0bbb5b7e582ed 100644 --- a/packages/cli/test/integration/auth.endpoints.test.ts +++ b/packages/cli/test/integration/auth.endpoints.test.ts @@ -1,4 +1,3 @@ -import { hashSync, genSaltSync } from 'bcryptjs'; import express from 'express'; import validator from 'validator'; import { v4 as uuid } from 'uuid'; @@ -60,38 +59,47 @@ afterAll(async () => { test('POST /login should log user in', async () => { const authlessAgent = utils.createAgent(app); - const response = await authlessAgent.post('/login').send({ - email: TEST_USER.email, - password: TEST_USER.password, - }); - - expect(response.statusCode).toBe(200); - - const { - id, - email, - firstName, - lastName, - password, - personalizationAnswers, - globalRole, - resetPasswordToken, - } = response.body.data; - - expect(validator.isUUID(id)).toBe(true); - expect(email).toBe(TEST_USER.email); - expect(firstName).toBe(TEST_USER.firstName); - expect(lastName).toBe(TEST_USER.lastName); - expect(password).toBeUndefined(); - expect(personalizationAnswers).toBeNull(); - expect(password).toBeUndefined(); - expect(resetPasswordToken).toBeUndefined(); - expect(globalRole).toBeDefined(); - expect(globalRole.name).toBe('owner'); - expect(globalRole.scope).toBe('global'); - - const authToken = utils.getAuthToken(response); - expect(authToken).toBeDefined(); + await Promise.all( + [ + { + email: TEST_USER.email, + password: TEST_USER.password, + }, + { + email: TEST_USER.email.toUpperCase(), + password: TEST_USER.password, + }, + ].map(async (payload) => { + const response = await authlessAgent.post('/login').send(payload); + + expect(response.statusCode).toBe(200); + + const { + id, + email, + firstName, + lastName, + password, + personalizationAnswers, + globalRole, + resetPasswordToken, + } = response.body.data; + + expect(validator.isUUID(id)).toBe(true); + expect(email).toBe(TEST_USER.email); + expect(firstName).toBe(TEST_USER.firstName); + expect(lastName).toBe(TEST_USER.lastName); + expect(password).toBeUndefined(); + expect(personalizationAnswers).toBeNull(); + expect(resetPasswordToken).toBeUndefined(); + expect(globalRole).toBeDefined(); + expect(globalRole.name).toBe('owner'); + expect(globalRole.scope).toBe('global'); + + const authToken = utils.getAuthToken(response); + expect(authToken).toBeDefined(); + }), + ); }); test('GET /login should receive logged in user', async () => { diff --git a/packages/cli/test/integration/me.api.test.ts b/packages/cli/test/integration/me.api.test.ts index 85c435a5b8030..186f09ddea2f6 100644 --- a/packages/cli/test/integration/me.api.test.ts +++ b/packages/cli/test/integration/me.api.test.ts @@ -91,7 +91,7 @@ describe('Owner shell', () => { } = response.body.data; expect(validator.isUUID(id)).toBe(true); - expect(email).toBe(validPayload.email); + expect(email).toBe(validPayload.email.toLowerCase()); expect(firstName).toBe(validPayload.firstName); expect(lastName).toBe(validPayload.lastName); expect(personalizationAnswers).toBeNull(); @@ -103,7 +103,7 @@ describe('Owner shell', () => { const storedOwnerShell = await Db.collections.User!.findOneOrFail(id); - expect(storedOwnerShell.email).toBe(validPayload.email); + expect(storedOwnerShell.email).toBe(validPayload.email.toLowerCase()); expect(storedOwnerShell.firstName).toBe(validPayload.firstName); expect(storedOwnerShell.lastName).toBe(validPayload.lastName); } @@ -245,7 +245,7 @@ describe('Member', () => { } = response.body.data; expect(validator.isUUID(id)).toBe(true); - expect(email).toBe(validPayload.email); + expect(email).toBe(validPayload.email.toLowerCase()); expect(firstName).toBe(validPayload.firstName); expect(lastName).toBe(validPayload.lastName); expect(personalizationAnswers).toBeNull(); @@ -257,7 +257,7 @@ describe('Member', () => { const storedMember = await Db.collections.User!.findOneOrFail(id); - expect(storedMember.email).toBe(validPayload.email); + expect(storedMember.email).toBe(validPayload.email.toLowerCase()); expect(storedMember.firstName).toBe(validPayload.firstName); expect(storedMember.lastName).toBe(validPayload.lastName); } @@ -400,7 +400,7 @@ describe('Owner', () => { } = response.body.data; expect(validator.isUUID(id)).toBe(true); - expect(email).toBe(validPayload.email); + expect(email).toBe(validPayload.email.toLowerCase()); expect(firstName).toBe(validPayload.firstName); expect(lastName).toBe(validPayload.lastName); expect(personalizationAnswers).toBeNull(); @@ -412,19 +412,13 @@ describe('Owner', () => { const storedOwner = await Db.collections.User!.findOneOrFail(id); - expect(storedOwner.email).toBe(validPayload.email); + expect(storedOwner.email).toBe(validPayload.email.toLowerCase()); expect(storedOwner.firstName).toBe(validPayload.firstName); expect(storedOwner.lastName).toBe(validPayload.lastName); } }); }); -const TEST_USER = { - email: randomEmail(), - firstName: randomName(), - lastName: randomName(), -}; - const SURVEY = [ 'codingSkill', 'companyIndustry', @@ -444,7 +438,7 @@ const VALID_PATCH_ME_PAYLOADS = [ password: randomValidPassword(), }, { - email: randomEmail(), + email: randomEmail().toUpperCase(), firstName: randomName(), lastName: randomName(), password: randomValidPassword(), diff --git a/packages/cli/test/integration/owner.api.test.ts b/packages/cli/test/integration/owner.api.test.ts index 3f97f298b38ca..e479196999b75 100644 --- a/packages/cli/test/integration/owner.api.test.ts +++ b/packages/cli/test/integration/owner.api.test.ts @@ -30,6 +30,12 @@ beforeAll(async () => { }); beforeEach(async () => { + jest.mock('../../config'); + + config.set('userManagement.isInstanceOwnerSetUp', false); +}); + +afterEach(async () => { await testDb.truncate(['User'], testDbName); }); @@ -88,6 +94,29 @@ test('POST /owner should create owner and enable isInstanceOwnerSetUp', async () expect(isInstanceOwnerSetUpSetting).toBe(true); }); +test('POST /owner should create owner with lowercased email', async () => { + const ownerShell = await testDb.createUserShell(globalOwnerRole); + const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell }); + + const newOwnerData = { + email: randomEmail().toUpperCase(), + firstName: randomName(), + lastName: randomName(), + password: randomValidPassword(), + }; + + const response = await authOwnerAgent.post('/owner').send(newOwnerData); + + expect(response.statusCode).toBe(200); + + const { id, email } = response.body.data; + + expect(email).toBe(newOwnerData.email.toLowerCase()); + + const storedOwner = await Db.collections.User!.findOneOrFail(id); + expect(storedOwner.email).toBe(newOwnerData.email.toLowerCase()); +}); + test('POST /owner should fail with invalid inputs', async () => { const ownerShell = await testDb.createUserShell(globalOwnerRole); const authOwnerAgent = utils.createAgent(app, { auth: true, user: ownerShell }); diff --git a/packages/cli/test/integration/passwordReset.api.test.ts b/packages/cli/test/integration/passwordReset.api.test.ts index 8b41428862250..ef1ffdbf2f390 100644 --- a/packages/cli/test/integration/passwordReset.api.test.ts +++ b/packages/cli/test/integration/passwordReset.api.test.ts @@ -19,6 +19,7 @@ jest.mock('../../src/telemetry'); let app: express.Application; let testDbName = ''; let globalOwnerRole: Role; +let globalMemberRole: Role; beforeAll(async () => { app = utils.initTestServer({ endpointGroups: ['passwordReset'], applyAuth: true }); @@ -26,6 +27,7 @@ beforeAll(async () => { testDbName = initResult.testDbName; globalOwnerRole = await testDb.getGlobalOwnerRole(); + globalMemberRole = await testDb.getGlobalMemberRole(); utils.initTestTelemetry(); utils.initTestLogger(); @@ -50,17 +52,22 @@ test('POST /forgot-password should send password reset email', async () => { const owner = await testDb.createUser({ globalRole: globalOwnerRole }); const authlessAgent = utils.createAgent(app); + const member = await testDb.createUser({ email: 'test@test.com', globalRole: globalMemberRole }); await utils.configureSmtp(); - const response = await authlessAgent.post('/forgot-password').send({ email: owner.email }); + await Promise.all( + [{ email: owner.email }, { email: member.email.toUpperCase() }].map(async (payload) => { + const response = await authlessAgent.post('/forgot-password').send(payload); - expect(response.statusCode).toBe(200); - expect(response.body).toEqual({}); + expect(response.statusCode).toBe(200); + expect(response.body).toEqual({}); - const storedOwner = await Db.collections.User!.findOneOrFail({ email: owner.email }); - expect(storedOwner.resetPasswordToken).toBeDefined(); - expect(storedOwner.resetPasswordTokenExpiration).toBeGreaterThan(Math.ceil(Date.now() / 1000)); + const user = await Db.collections.User!.findOneOrFail({ email: payload.email }); + expect(user.resetPasswordToken).toBeDefined(); + expect(user.resetPasswordTokenExpiration).toBeGreaterThan(Math.ceil(Date.now() / 1000)); + }), + ); }); test('POST /forgot-password should fail if emailing is not set up', async () => { diff --git a/packages/cli/test/integration/users.api.test.ts b/packages/cli/test/integration/users.api.test.ts index eaee6d4db8ffb..f139cd4351f09 100644 --- a/packages/cli/test/integration/users.api.test.ts +++ b/packages/cli/test/integration/users.api.test.ts @@ -481,13 +481,15 @@ test('POST /users should fail if user management is disabled', async () => { expect(response.statusCode).toBe(500); }); -test('POST /users should email invites and create user shells', async () => { +test('POST /users should email invites and create user shells but ignore existing', async () => { const owner = await testDb.createUser({ globalRole: globalOwnerRole }); + const member = await testDb.createUser({ globalRole: globalMemberRole }); + const memberShell = await testDb.createUserShell(globalMemberRole); const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner }); await utils.configureSmtp(); - const testEmails = [randomEmail(), randomEmail(), randomEmail()]; + const testEmails = [randomEmail(), randomEmail().toUpperCase(), memberShell.email, member.email]; const payload = testEmails.map((e) => ({ email: e })); @@ -495,27 +497,31 @@ test('POST /users should email invites and create user shells', async () => { expect(response.statusCode).toBe(200); - await Promise.all( - response.body.data.map(async ({ user, error }: { user: User; error: Error }) => { - const { id, email: receivedEmail } = user; - - expect(validator.isUUID(id)).toBe(true); - expect(testEmails.some((e) => e === receivedEmail)).toBe(true); - if (error) { - expect(error).toBe('Email could not be sent'); - } - - const storedUser = await Db.collections.User!.findOneOrFail(id); - const { firstName, lastName, personalizationAnswers, password, resetPasswordToken } = - storedUser; - - expect(firstName).toBeNull(); - expect(lastName).toBeNull(); - expect(personalizationAnswers).toBeNull(); - expect(password).toBeNull(); - expect(resetPasswordToken).toBeNull(); - }), - ); + for (const { + user: { id, email: receivedEmail }, + error, + } of response.body.data) { + expect(validator.isUUID(id)).toBe(true); + expect(id).not.toBe(member.id); + + const lowerCasedEmail = receivedEmail.toLowerCase(); + expect(receivedEmail).toBe(lowerCasedEmail); + expect(payload.some(({ email }) => email.toLowerCase() === lowerCasedEmail)).toBe(true); + + if (error) { + expect(error).toBe('Email could not be sent'); + } + + const storedUser = await Db.collections.User!.findOneOrFail(id); + const { firstName, lastName, personalizationAnswers, password, resetPasswordToken } = + storedUser; + + expect(firstName).toBeNull(); + expect(lastName).toBeNull(); + expect(personalizationAnswers).toBeNull(); + expect(password).toBeNull(); + expect(resetPasswordToken).toBeNull(); + } }); test('POST /users should fail with invalid inputs', async () => { From 18dee373d5ebf337e33d1c38e057ed0c24a74f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Fri, 15 Apr 2022 08:22:58 +0200 Subject: [PATCH 5/7] :zap: Add autocompletion for i18n keys in script sections of Vue files (#3133) * :blue_book: Type `baseText()` to i18n keys * :blue_book: Adjust `baseText()` signature * :shirt: Except JSON files from Vue ESLint * :bug: Fix errors surfaced by `baseText()` typing * :zap: Pluralize keys * :blue_book: Add typing for category names * :zap: Mark internal keys * :pencil2: Update docs references * :art: Prettify syntax * :bug: Fix leftover internal key references --- .../src/components/DeleteUserModal.vue | 12 +++-- .../src/components/InviteUsersModal.vue | 5 +- packages/editor-ui/src/components/Node.vue | 7 ++- .../components/NodeCreator/CategoryItem.vue | 7 +-- .../src/components/WorkflowSettings.vue | 2 +- .../src/plugins/i18n/docs/ADDENDUM.md | 12 ++--- packages/editor-ui/src/plugins/i18n/index.ts | 28 +++++++++-- .../src/plugins/i18n/locales/en.json | 46 +++++++++---------- .../editor-ui/src/plugins/i18n/types.d.ts | 7 --- .../editor-ui/src/views/SettingsUsersView.vue | 5 +- packages/editor-ui/src/views/SetupView.vue | 15 +++++- packages/editor-ui/tsconfig.json | 1 + packages/editor-ui/tslint.json | 3 +- 13 files changed, 95 insertions(+), 55 deletions(-) delete mode 100644 packages/editor-ui/src/plugins/i18n/types.d.ts diff --git a/packages/editor-ui/src/components/DeleteUserModal.vue b/packages/editor-ui/src/components/DeleteUserModal.vue index de21bcb4bbefa..1871288aed2b6 100644 --- a/packages/editor-ui/src/components/DeleteUserModal.vue +++ b/packages/editor-ui/src/components/DeleteUserModal.vue @@ -90,8 +90,11 @@ export default mixins(showMessage).extend({ return this.userToDelete && !this.userToDelete.firstName; }, title(): string { - const user = this.userToDelete && (this.userToDelete.fullName || this.userToDelete.email); - return this.$locale.baseText('settings.users.deleteUser', { interpolate: { user }}); + const user = this.userToDelete && (this.userToDelete.fullName || this.userToDelete.email) || ''; + return this.$locale.baseText( + 'settings.users.deleteUser', + { interpolate: { user }}, + ); }, enabled(): boolean { if (this.isPending) { @@ -138,7 +141,10 @@ export default mixins(showMessage).extend({ if (this.transferId) { const getUserById = this.$store.getters['users/getUserById']; const transferUser: IUser = getUserById(this.transferId); - message = this.$locale.baseText('settings.users.transferredToUser', { interpolate: { user: transferUser.fullName }}); + message = this.$locale.baseText( + 'settings.users.transferredToUser', + { interpolate: { user: transferUser.fullName || '' }}, + ); } this.$showMessage({ diff --git a/packages/editor-ui/src/components/InviteUsersModal.vue b/packages/editor-ui/src/components/InviteUsersModal.vue index 18730fe580884..d52ebd1ae59e9 100644 --- a/packages/editor-ui/src/components/InviteUsersModal.vue +++ b/packages/editor-ui/src/components/InviteUsersModal.vue @@ -106,7 +106,10 @@ export default mixins(showMessage).extend({ }, buttonLabel(): string { if (this.emailsCount > 1) { - return this.$locale.baseText('settings.users.inviteXUser', { interpolate: { count: this.emailsCount }}); + return this.$locale.baseText( + 'settings.users.inviteXUser', + { interpolate: { count: this.emailsCount.toString() }}, + ); } return this.$locale.baseText('settings.users.inviteUser'); diff --git a/packages/editor-ui/src/components/Node.vue b/packages/editor-ui/src/components/Node.vue index 2c7e9abfe78fb..1120a05e356c4 100644 --- a/packages/editor-ui/src/components/Node.vue +++ b/packages/editor-ui/src/components/Node.vue @@ -125,13 +125,16 @@ export default mixins(externalHooks, nodeBase, nodeHelpers, workflowHelpers).ext if (this.nodeType !== null && this.nodeType.hasOwnProperty('eventTriggerDescription')) { const nodeName = this.$locale.shortNodeType(this.nodeType.name); const { eventTriggerDescription } = this.nodeType; - return this.$locale.nodeText().eventTriggerDescription(nodeName, eventTriggerDescription); + return this.$locale.nodeText().eventTriggerDescription( + nodeName, + eventTriggerDescription || '', + ); } else { return this.$locale.baseText( 'node.waitingForYouToCreateAnEventIn', { interpolate: { - nodeType: this.nodeType && getTriggerNodeServiceName(this.nodeType.displayName), + nodeType: this.nodeType ? getTriggerNodeServiceName(this.nodeType.displayName) : '', }, }, ); diff --git a/packages/editor-ui/src/components/NodeCreator/CategoryItem.vue b/packages/editor-ui/src/components/NodeCreator/CategoryItem.vue index dcf9bafe1bc5e..a35b4729e6ecb 100644 --- a/packages/editor-ui/src/components/NodeCreator/CategoryItem.vue +++ b/packages/editor-ui/src/components/NodeCreator/CategoryItem.vue @@ -15,6 +15,7 @@