diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts index 49942b786ac74..920263a893878 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.ts @@ -94,11 +94,11 @@ export class EmbeddingsAzureOpenAi implements INodeType { async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { this.logger.verbose('Supply data for embeddings'); - const credentials = (await this.getCredentials('azureOpenAiApi')) as { + const credentials = await this.getCredentials<{ apiKey: string; resourceName: string; apiVersion: string; - }; + }>('azureOpenAiApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; const options = this.getNodeParameter('options', itemIndex, {}) as { diff --git a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts index 43f9fc5c943be..aa6d6ab3c3598 100644 --- a/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.ts @@ -102,7 +102,7 @@ export class EmbeddingsCohere implements INodeType { async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { this.logger.verbose('Supply data for embeddings Cohere'); const modelName = this.getNodeParameter('modelName', itemIndex, 'embed-english-v2.0') as string; - const credentials = (await this.getCredentials('cohereApi')) as { apiKey: string }; + const credentials = await this.getCredentials<{ apiKey: string }>('cohereApi'); const embeddings = new CohereEmbeddings({ apiKey: credentials.apiKey, model: modelName, diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts index 5770387158b1e..96f5b8e6d80c4 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.ts @@ -133,11 +133,11 @@ export class LmChatAzureOpenAi implements INodeType { }; async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { - const credentials = (await this.getCredentials('azureOpenAiApi')) as { + const credentials = await this.getCredentials<{ apiKey: string; resourceName: string; apiVersion: string; - }; + }>('azureOpenAiApi'); const modelName = this.getNodeParameter('model', itemIndex) as string; const options = this.getNodeParameter('options', itemIndex, {}) as { diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts index b1a9cd7aeaec5..f42cb93fe1757 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts @@ -74,7 +74,7 @@ export class MemoryPostgresChat implements INodeType { }; async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { - const credentials = (await this.getCredentials('postgres')) as PostgresNodeCredentials; + const credentials = await this.getCredentials('postgres'); const tableName = this.getNodeParameter('tableName', itemIndex, 'n8n_chat_histories') as string; const sessionId = getSessionId(this, itemIndex); diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts index dd568ae210d07..7cbf1da574d5b 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryZep/MemoryZep.node.ts @@ -104,11 +104,11 @@ export class MemoryZep implements INodeType { }; async supplyData(this: IExecuteFunctions, itemIndex: number): Promise { - const credentials = (await this.getCredentials('zepApi')) as { + const credentials = await this.getCredentials<{ apiKey?: string; apiUrl?: string; cloud?: boolean; - }; + }>('zepApi'); const nodeVersion = this.getNode().typeVersion; diff --git a/packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/GenericFunctions.ts b/packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/GenericFunctions.ts index bd89c6595da3d..02620ab797cf6 100644 --- a/packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/GenericFunctions.ts +++ b/packages/@n8n/nodes-langchain/nodes/trigger/ChatTrigger/GenericFunctions.ts @@ -14,7 +14,7 @@ export async function validateAuth(context: IWebhookFunctions) { // Basic authorization is needed to call webhook let expectedAuth: ICredentialDataDecryptedObject | undefined; try { - expectedAuth = await context.getCredentials('httpBasicAuth'); + expectedAuth = await context.getCredentials('httpBasicAuth'); } catch {} if (expectedAuth === undefined || !expectedAuth.user || !expectedAuth.password) { diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.ts index 4f999bb16fc55..d041b43d6bf97 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZep/VectorStoreZep.node.ts @@ -79,10 +79,10 @@ export const VectorStoreZep = createVectorStoreNode({ embeddingDimensions?: number; }) || {}; - const credentials = (await context.getCredentials('zepApi')) as { + const credentials = await context.getCredentials<{ apiKey?: string; apiUrl: string; - }; + }>('zepApi'); const zepConfig: IZepConfig = { apiUrl: credentials.apiUrl, @@ -102,10 +102,10 @@ export const VectorStoreZep = createVectorStoreNode({ embeddingDimensions?: number; }) || {}; - const credentials = (await context.getCredentials('zepApi')) as { + const credentials = await context.getCredentials<{ apiKey?: string; apiUrl: string; - }; + }>('zepApi'); const zepConfig = { apiUrl: credentials.apiUrl, diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.ts index 6b2581970840f..71349b586be6a 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepInsert/VectorStoreZepInsert.node.ts @@ -110,10 +110,10 @@ export class VectorStoreZepInsert implements INodeType { embeddingDimensions?: number; }) || {}; - const credentials = (await this.getCredentials('zepApi')) as { + const credentials = await this.getCredentials<{ apiKey?: string; apiUrl: string; - }; + }>('zepApi'); const documentInput = (await this.getInputConnectionData(NodeConnectionType.AiDocument, 0)) as | N8nJsonLoader diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.ts index 56313e1634da6..ca5a743c15ace 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreZepLoad/VectorStoreZepLoad.node.ts @@ -93,10 +93,10 @@ export class VectorStoreZepLoad implements INodeType { embeddingDimensions?: number; }) || {}; - const credentials = (await this.getCredentials('zepApi')) as { + const credentials = await this.getCredentials<{ apiKey?: string; apiUrl: string; - }; + }>('zepApi'); const embeddings = (await this.getInputConnectionData( NodeConnectionType.AiEmbedding, 0, diff --git a/packages/core/src/Credentials.ts b/packages/core/src/Credentials.ts index 1a54d96cd2760..3210703a27ae0 100644 --- a/packages/core/src/Credentials.ts +++ b/packages/core/src/Credentials.ts @@ -3,20 +3,22 @@ import type { ICredentialDataDecryptedObject, ICredentialsEncrypted } from 'n8n- import { ApplicationError, ICredentials, jsonParse } from 'n8n-workflow'; import { Cipher } from './Cipher'; -export class Credentials extends ICredentials { +export class Credentials< + T extends object = ICredentialDataDecryptedObject, +> extends ICredentials { private readonly cipher = Container.get(Cipher); /** * Sets new credential object */ - setData(data: ICredentialDataDecryptedObject): void { + setData(data: T): void { this.data = this.cipher.encrypt(data); } /** * Returns the decrypted credential object */ - getData(): ICredentialDataDecryptedObject { + getData(): T { if (this.data === undefined) { throw new ApplicationError('No data is set so nothing can be returned.'); } diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index f97d86805911f..81d5a09f5f468 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -1656,7 +1656,8 @@ export async function httpRequestWithAuthentication( if (additionalCredentialOptions?.credentialsDecrypted) { credentialsDecrypted = additionalCredentialOptions.credentialsDecrypted.data; } else { - credentialsDecrypted = await this.getCredentials(credentialsType); + credentialsDecrypted = + await this.getCredentials(credentialsType); } if (credentialsDecrypted === undefined) { @@ -1853,7 +1854,10 @@ export async function requestWithAuthentication( if (additionalCredentialOptions?.credentialsDecrypted) { credentialsDecrypted = additionalCredentialOptions.credentialsDecrypted.data; } else { - credentialsDecrypted = await this.getCredentials(credentialsType, itemIndex); + credentialsDecrypted = await this.getCredentials( + credentialsType, + itemIndex, + ); } if (credentialsDecrypted === undefined) { @@ -1988,7 +1992,7 @@ export function getAdditionalKeys( * @param {INode} node Node which request the data * @param {string} type The credential type to return */ -export async function getCredentials( +export async function getCredentials( workflow: Workflow, node: INode, type: string, @@ -1999,7 +2003,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) { @@ -2117,7 +2121,7 @@ export async function getCredentials( expressionResolveValues, ); - return decryptedDataObject; + return decryptedDataObject as T; } /** diff --git a/packages/nodes-base/nodes/Automizy/GenericFunctions.ts b/packages/nodes-base/nodes/Automizy/GenericFunctions.ts index 0e92d09333fc0..94e73e0388a27 100644 --- a/packages/nodes-base/nodes/Automizy/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Automizy/GenericFunctions.ts @@ -17,7 +17,7 @@ export async function automizyApiRequest( qs: IDataObject = {}, option = {}, ): Promise { - const credentials = (await this.getCredentials('automizyApi')) as IDataObject; + const credentials = await this.getCredentials<{ apiToken: string }>('automizyApi'); const options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/Autopilot/GenericFunctions.ts b/packages/nodes-base/nodes/Autopilot/GenericFunctions.ts index f6387d27e9fa5..094d74b0299fe 100644 --- a/packages/nodes-base/nodes/Autopilot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Autopilot/GenericFunctions.ts @@ -19,16 +19,14 @@ export async function autopilotApiRequest( uri?: string, _option: IDataObject = {}, ): Promise { - const credentials = (await this.getCredentials('autopilotApi')) as IDataObject; - - const apiKey = `${credentials.apiKey}`; + const credentials = await this.getCredentials<{ apiKey: string }>('autopilotApi'); const endpoint = 'https://api2.autopilothq.com/v1'; const options: IRequestOptions = { headers: { 'Content-Type': 'application/json', - autopilotapikey: apiKey, + autopilotapikey: credentials.apiKey, }, method, body, diff --git a/packages/nodes-base/nodes/Baserow/Baserow.node.ts b/packages/nodes-base/nodes/Baserow/Baserow.node.ts index 4760e96a13dc8..2753f40f562e8 100644 --- a/packages/nodes-base/nodes/Baserow/Baserow.node.ts +++ b/packages/nodes-base/nodes/Baserow/Baserow.node.ts @@ -111,7 +111,7 @@ export class Baserow implements INodeType { methods = { loadOptions: { async getDatabaseIds(this: ILoadOptionsFunctions) { - const credentials = (await this.getCredentials('baserowApi')) as BaserowCredentials; + const credentials = await this.getCredentials('baserowApi'); const jwtToken = await getJwtToken.call(this, credentials); const endpoint = '/api/applications/'; const databases = (await baserowApiRequest.call( @@ -124,7 +124,7 @@ export class Baserow implements INodeType { }, async getTableIds(this: ILoadOptionsFunctions) { - const credentials = (await this.getCredentials('baserowApi')) as BaserowCredentials; + const credentials = await this.getCredentials('baserowApi'); const jwtToken = await getJwtToken.call(this, credentials); const databaseId = this.getNodeParameter('databaseId', 0) as string; const endpoint = `/api/database/tables/database/${databaseId}/`; @@ -138,7 +138,7 @@ export class Baserow implements INodeType { }, async getTableFields(this: ILoadOptionsFunctions) { - const credentials = (await this.getCredentials('baserowApi')) as BaserowCredentials; + const credentials = await this.getCredentials('baserowApi'); const jwtToken = await getJwtToken.call(this, credentials); const tableId = this.getNodeParameter('tableId', 0) as string; const endpoint = `/api/database/fields/table/${tableId}/`; @@ -160,7 +160,7 @@ export class Baserow implements INodeType { const operation = this.getNodeParameter('operation', 0) as Operation; const tableId = this.getNodeParameter('tableId', 0) as string; - const credentials = (await this.getCredentials('baserowApi')) as BaserowCredentials; + const credentials = await this.getCredentials('baserowApi'); const jwtToken = await getJwtToken.call(this, credentials); const fields = await mapper.getTableFields.call(this, tableId, jwtToken); mapper.createMappings(fields); diff --git a/packages/nodes-base/nodes/Baserow/GenericFunctions.ts b/packages/nodes-base/nodes/Baserow/GenericFunctions.ts index 8e30c5c1482b6..d08d0c2f5ed4a 100644 --- a/packages/nodes-base/nodes/Baserow/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Baserow/GenericFunctions.ts @@ -21,7 +21,7 @@ export async function baserowApiRequest( body: IDataObject = {}, qs: IDataObject = {}, ) { - const credentials = (await this.getCredentials('baserowApi')) as BaserowCredentials; + const credentials = await this.getCredentials('baserowApi'); const options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/Calendly/GenericFunctions.ts b/packages/nodes-base/nodes/Calendly/GenericFunctions.ts index f39aa877618b2..70cf55c1f23f1 100644 --- a/packages/nodes-base/nodes/Calendly/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Calendly/GenericFunctions.ts @@ -19,7 +19,7 @@ export async function getAuthenticationType( ): Promise<'accessToken' | 'apiKey'> { const authentication = this.getNodeParameter('authentication', 0) as string; if (authentication === 'apiKey') { - const { apiKey } = (await this.getCredentials('calendlyApi')) as { apiKey: string }; + const { apiKey } = await this.getCredentials<{ apiKey: string }>('calendlyApi'); return getAuthenticationTypeFromApiKey(apiKey); } else { return 'accessToken'; diff --git a/packages/nodes-base/nodes/Dhl/GenericFunctions.ts b/packages/nodes-base/nodes/Dhl/GenericFunctions.ts index 1a062fb12a3c4..572b637da23ac 100644 --- a/packages/nodes-base/nodes/Dhl/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Dhl/GenericFunctions.ts @@ -21,7 +21,7 @@ export async function dhlApiRequest( uri?: string, option: IDataObject = {}, ): Promise { - const credentials = (await this.getCredentials('dhlApi')) as { apiKey: string }; + const credentials = await this.getCredentials<{ apiKey: string }>('dhlApi'); let options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/Discourse/GenericFunctions.ts b/packages/nodes-base/nodes/Discourse/GenericFunctions.ts index 8a66a6296debf..e363ca59155e6 100644 --- a/packages/nodes-base/nodes/Discourse/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Discourse/GenericFunctions.ts @@ -17,7 +17,7 @@ export async function discourseApiRequest( qs: IDataObject = {}, _option = {}, ): Promise { - const credentials = (await this.getCredentials('discourseApi')) as { url: string }; + const credentials = await this.getCredentials<{ url: string }>('discourseApi'); const options: IRequestOptions = { method, diff --git a/packages/nodes-base/nodes/Disqus/GenericFunctions.ts b/packages/nodes-base/nodes/Disqus/GenericFunctions.ts index 8d03fe04075ef..d9c541144ff64 100644 --- a/packages/nodes-base/nodes/Disqus/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Disqus/GenericFunctions.ts @@ -17,7 +17,7 @@ export async function disqusApiRequest( body: IDataObject = {}, option: IDataObject = {}, ): Promise { - const credentials = (await this.getCredentials('disqusApi')) as IDataObject; + const credentials = await this.getCredentials<{ accessToken: string }>('disqusApi'); qs.api_key = credentials.accessToken; // Convert to query string into a format the API can read diff --git a/packages/nodes-base/nodes/Dropbox/GenericFunctions.ts b/packages/nodes-base/nodes/Dropbox/GenericFunctions.ts index 86e9d655699d8..918d5eefe6f37 100644 --- a/packages/nodes-base/nodes/Dropbox/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Dropbox/GenericFunctions.ts @@ -116,8 +116,8 @@ export function simplify(data: IDataObject[]) { export async function getCredentials(this: IExecuteFunctions) { const authenticationMethod = this.getNodeParameter('authentication', 0) as string; if (authenticationMethod === 'accessToken') { - return (await this.getCredentials('dropboxApi')) as IDataObject; + return await this.getCredentials('dropboxApi'); } else { - return (await this.getCredentials('dropboxOAuth2Api')) as IDataObject; + return await this.getCredentials('dropboxOAuth2Api'); } } diff --git a/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts b/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts index 427ac764b2326..a9286d18f8724 100644 --- a/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts @@ -24,7 +24,7 @@ export async function erpNextApiRequest( uri?: string, option: IDataObject = {}, ) { - const credentials = (await this.getCredentials('erpNextApi')) as ERPNextApiCredentials; + const credentials = await this.getCredentials('erpNextApi'); const baseUrl = getBaseUrl(credentials); let options: IRequestOptions = { diff --git a/packages/nodes-base/nodes/Emelia/GenericFunctions.ts b/packages/nodes-base/nodes/Emelia/GenericFunctions.ts index 6ac76d3561fc4..f6f3cedb4a13c 100644 --- a/packages/nodes-base/nodes/Emelia/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Emelia/GenericFunctions.ts @@ -23,7 +23,7 @@ export async function emeliaApiRequest( body: object = {}, qs: IDataObject = {}, ) { - const { apiKey } = (await this.getCredentials('emeliaApi')) as { apiKey: string }; + const { apiKey } = await this.getCredentials<{ apiKey: string }>('emeliaApi'); const options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/FormIo/GenericFunctions.ts b/packages/nodes-base/nodes/FormIo/GenericFunctions.ts index 52dfbf944e323..9b782dac76575 100644 --- a/packages/nodes-base/nodes/FormIo/GenericFunctions.ts +++ b/packages/nodes-base/nodes/FormIo/GenericFunctions.ts @@ -61,7 +61,7 @@ export async function formIoApiRequest( body = {}, qs = {}, ): Promise { - const credentials = (await this.getCredentials('formIoApi')) as unknown as IFormIoCredentials; + const credentials = await this.getCredentials('formIoApi'); const token = await getToken.call(this, credentials); diff --git a/packages/nodes-base/nodes/Formstack/GenericFunctions.ts b/packages/nodes-base/nodes/Formstack/GenericFunctions.ts index fe53058349a22..2637cedecfa47 100644 --- a/packages/nodes-base/nodes/Formstack/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Formstack/GenericFunctions.ts @@ -73,7 +73,7 @@ export async function apiRequest( try { if (authenticationMethod === 'accessToken') { - const credentials = (await this.getCredentials('formstackApi')) as IDataObject; + const credentials = await this.getCredentials<{ accessToken: string }>('formstackApi'); options.headers!.Authorization = `Bearer ${credentials.accessToken}`; return await this.helpers.request(options); diff --git a/packages/nodes-base/nodes/FreshworksCrm/GenericFunctions.ts b/packages/nodes-base/nodes/FreshworksCrm/GenericFunctions.ts index 5bcdafc5aeccb..0d9e7fad2c029 100644 --- a/packages/nodes-base/nodes/FreshworksCrm/GenericFunctions.ts +++ b/packages/nodes-base/nodes/FreshworksCrm/GenericFunctions.ts @@ -23,7 +23,7 @@ export async function freshworksCrmApiRequest( body: IDataObject = {}, qs: IDataObject = {}, ) { - const { domain } = (await this.getCredentials('freshworksCrmApi')) as FreshworksCrmApiCredentials; + const { domain } = await this.getCredentials('freshworksCrmApi'); const options: IRequestOptions = { method, diff --git a/packages/nodes-base/nodes/Ftp/Ftp.node.ts b/packages/nodes-base/nodes/Ftp/Ftp.node.ts index bce2208ba69d3..d8b77f7d35f08 100644 --- a/packages/nodes-base/nodes/Ftp/Ftp.node.ts +++ b/packages/nodes-base/nodes/Ftp/Ftp.node.ts @@ -510,9 +510,9 @@ export class Ftp implements INodeType { const protocol = this.getNodeParameter('protocol', 0) as string; if (protocol === 'sftp') { - credentials = await this.getCredentials('sftp'); + credentials = await this.getCredentials('sftp'); } else { - credentials = await this.getCredentials('ftp'); + credentials = await this.getCredentials('ftp'); } let ftp: ftpClient; let sftp: sftpClient; diff --git a/packages/nodes-base/nodes/GoToWebinar/GenericFunctions.ts b/packages/nodes-base/nodes/GoToWebinar/GenericFunctions.ts index 4d85e51375b4c..6748ad78d8a39 100644 --- a/packages/nodes-base/nodes/GoToWebinar/GenericFunctions.ts +++ b/packages/nodes-base/nodes/GoToWebinar/GenericFunctions.ts @@ -143,9 +143,9 @@ export async function handleGetAll( } export async function loadWebinars(this: ILoadOptionsFunctions) { - const { oauthTokenData } = (await this.getCredentials('goToWebinarOAuth2Api')) as { + const { oauthTokenData } = await this.getCredentials<{ oauthTokenData: { account_key: string }; - }; + }>('goToWebinarOAuth2Api'); const endpoint = `accounts/${oauthTokenData.account_key}/webinars`; @@ -176,9 +176,9 @@ export async function loadWebinars(this: ILoadOptionsFunctions) { } export async function loadWebinarSessions(this: ILoadOptionsFunctions) { - const { oauthTokenData } = (await this.getCredentials('goToWebinarOAuth2Api')) as { + const { oauthTokenData } = await this.getCredentials<{ oauthTokenData: { organizer_key: string }; - }; + }>('goToWebinarOAuth2Api'); const webinarKey = this.getCurrentNodeParameter('webinarKey') as string; @@ -208,9 +208,9 @@ export async function loadWebinarSessions(this: ILoadOptionsFunctions) { } export async function loadRegistranSimpleQuestions(this: ILoadOptionsFunctions) { - const { oauthTokenData } = (await this.getCredentials('goToWebinarOAuth2Api')) as { + const { oauthTokenData } = await this.getCredentials<{ oauthTokenData: { organizer_key: string }; - }; + }>('goToWebinarOAuth2Api'); const webinarkey = this.getNodeParameter('webinarKey') as string; @@ -233,9 +233,9 @@ export async function loadRegistranSimpleQuestions(this: ILoadOptionsFunctions) } export async function loadAnswers(this: ILoadOptionsFunctions) { - const { oauthTokenData } = (await this.getCredentials('goToWebinarOAuth2Api')) as { + const { oauthTokenData } = await this.getCredentials<{ oauthTokenData: { organizer_key: string }; - }; + }>('goToWebinarOAuth2Api'); const webinarKey = this.getCurrentNodeParameter('webinarKey') as string; @@ -262,9 +262,9 @@ export async function loadAnswers(this: ILoadOptionsFunctions) { } export async function loadRegistranMultiChoiceQuestions(this: ILoadOptionsFunctions) { - const { oauthTokenData } = (await this.getCredentials('goToWebinarOAuth2Api')) as { + const { oauthTokenData } = await this.getCredentials<{ oauthTokenData: { organizer_key: string }; - }; + }>('goToWebinarOAuth2Api'); const webinarkey = this.getNodeParameter('webinarKey') as string; diff --git a/packages/nodes-base/nodes/GoToWebinar/GoToWebinar.node.ts b/packages/nodes-base/nodes/GoToWebinar/GoToWebinar.node.ts index c53ae788bd856..c76785e4c21b9 100644 --- a/packages/nodes-base/nodes/GoToWebinar/GoToWebinar.node.ts +++ b/packages/nodes-base/nodes/GoToWebinar/GoToWebinar.node.ts @@ -154,9 +154,9 @@ export class GoToWebinar implements INodeType { let responseData; const returnData: INodeExecutionData[] = []; - const { oauthTokenData } = (await this.getCredentials('goToWebinarOAuth2Api')) as { + const { oauthTokenData } = await this.getCredentials<{ oauthTokenData: { account_key: string; organizer_key: string }; - }; + }>('goToWebinarOAuth2Api'); const accountKey = oauthTokenData.account_key; const organizerKey = oauthTokenData.organizer_key; diff --git a/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts index ab8d73f58e576..7b64332747398 100644 --- a/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts @@ -42,10 +42,10 @@ export async function googleApiRequest( } if (authenticationMethod === 'serviceAccount') { - const credentials = (await this.getCredentials('googleApi')) as { + const credentials = await this.getCredentials<{ email: string; privateKey: string; - }; + }>('googleApi'); const { access_token } = await getGoogleAccessToken.call(this, credentials, 'books'); diff --git a/packages/nodes-base/nodes/Grafana/GenericFunctions.ts b/packages/nodes-base/nodes/Grafana/GenericFunctions.ts index 9fb11f7c0ec72..03476fc8c62d5 100644 --- a/packages/nodes-base/nodes/Grafana/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Grafana/GenericFunctions.ts @@ -21,7 +21,7 @@ export async function grafanaApiRequest( body: IDataObject = {}, qs: IDataObject = {}, ) { - const { baseUrl: rawBaseUrl } = (await this.getCredentials('grafanaApi')) as GrafanaCredentials; + const { baseUrl: rawBaseUrl } = await this.getCredentials('grafanaApi'); const baseUrl = tolerateTrailingSlash(rawBaseUrl); diff --git a/packages/nodes-base/nodes/Jira/JiraTrigger.node.ts b/packages/nodes-base/nodes/Jira/JiraTrigger.node.ts index cf16b62e15505..36a69994e592a 100644 --- a/packages/nodes-base/nodes/Jira/JiraTrigger.node.ts +++ b/packages/nodes-base/nodes/Jira/JiraTrigger.node.ts @@ -534,7 +534,7 @@ export class JiraTrigger implements INodeType { let httpQueryAuth: ICredentialDataDecryptedObject | undefined; try { - httpQueryAuth = await this.getCredentials('httpQueryAuth'); + httpQueryAuth = await this.getCredentials('httpQueryAuth'); } catch (error) {} if (httpQueryAuth === undefined || !httpQueryAuth.name || !httpQueryAuth.value) { diff --git a/packages/nodes-base/nodes/Jwt/Jwt.node.ts b/packages/nodes-base/nodes/Jwt/Jwt.node.ts index e8d6300ebf707..fa39645180e70 100644 --- a/packages/nodes-base/nodes/Jwt/Jwt.node.ts +++ b/packages/nodes-base/nodes/Jwt/Jwt.node.ts @@ -348,13 +348,13 @@ export class Jwt implements INodeType { const operation = this.getNodeParameter('operation', 0); - const credentials = (await this.getCredentials('jwtAuth')) as { + const credentials = await this.getCredentials<{ keyType: 'passphrase' | 'pemKey'; publicKey: string; privateKey: string; secret: string; algorithm: jwt.Algorithm; - }; + }>('jwtAuth'); for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { const options = this.getNodeParameter('options', itemIndex, {}) as { diff --git a/packages/nodes-base/nodes/Kitemaker/GenericFunctions.ts b/packages/nodes-base/nodes/Kitemaker/GenericFunctions.ts index b1ee217308436..ebadcbaabadd5 100644 --- a/packages/nodes-base/nodes/Kitemaker/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Kitemaker/GenericFunctions.ts @@ -12,9 +12,9 @@ export async function kitemakerRequest( this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, body: IDataObject = {}, ) { - const { personalAccessToken } = (await this.getCredentials('kitemakerApi')) as { + const { personalAccessToken } = await this.getCredentials<{ personalAccessToken: string; - }; + }>('kitemakerApi'); const options = { headers: { diff --git a/packages/nodes-base/nodes/MQTT/Mqtt.node.ts b/packages/nodes-base/nodes/MQTT/Mqtt.node.ts index c4caad68c0923..76d36eb6b79f8 100644 --- a/packages/nodes-base/nodes/MQTT/Mqtt.node.ts +++ b/packages/nodes-base/nodes/MQTT/Mqtt.node.ts @@ -130,7 +130,7 @@ export class Mqtt implements INodeType { }; async execute(this: IExecuteFunctions): Promise { - const credentials = (await this.getCredentials('mqtt')) as unknown as MqttCredential; + const credentials = await this.getCredentials('mqtt'); const client = await createClient(credentials); const publishPromises = []; diff --git a/packages/nodes-base/nodes/MQTT/MqttTrigger.node.ts b/packages/nodes-base/nodes/MQTT/MqttTrigger.node.ts index 864c2cd912e78..e0a8f51ad13ce 100644 --- a/packages/nodes-base/nodes/MQTT/MqttTrigger.node.ts +++ b/packages/nodes-base/nodes/MQTT/MqttTrigger.node.ts @@ -107,7 +107,7 @@ export class MqttTrigger implements INodeType { } const options = this.getNodeParameter('options') as Options; - const credentials = (await this.getCredentials('mqtt')) as unknown as MqttCredential; + const credentials = await this.getCredentials('mqtt'); const client = await createClient(credentials); const parsePayload = (topic: string, payload: Buffer) => { diff --git a/packages/nodes-base/nodes/Mailjet/GenericFunctions.ts b/packages/nodes-base/nodes/Mailjet/GenericFunctions.ts index d25b301b2b3b6..1276d5931cba3 100644 --- a/packages/nodes-base/nodes/Mailjet/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mailjet/GenericFunctions.ts @@ -23,9 +23,9 @@ export async function mailjetApiRequest( if (resource === 'email' || this.getNode().type.includes('Trigger')) { credentialType = 'mailjetEmailApi'; - const { sandboxMode } = (await this.getCredentials('mailjetEmailApi')) as { + const { sandboxMode } = await this.getCredentials<{ sandboxMode: boolean; - }; + }>('mailjetEmailApi'); if (!this.getNode().type.includes('Trigger')) { Object.assign(body, { SandboxMode: sandboxMode }); diff --git a/packages/nodes-base/nodes/Microsoft/Dynamics/GenericFunctions.ts b/packages/nodes-base/nodes/Microsoft/Dynamics/GenericFunctions.ts index c4ec69687855f..f5e7c0d5d3b17 100644 --- a/packages/nodes-base/nodes/Microsoft/Dynamics/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Microsoft/Dynamics/GenericFunctions.ts @@ -20,10 +20,10 @@ export async function microsoftApiRequest( uri?: string, option: IDataObject = {}, ): Promise { - const credentials = (await this.getCredentials('microsoftDynamicsOAuth2Api')) as { + const credentials = await this.getCredentials<{ subdomain: string; region: string; - }; + }>('microsoftDynamicsOAuth2Api'); let options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/Microsoft/GraphSecurity/GenericFunctions.ts b/packages/nodes-base/nodes/Microsoft/GraphSecurity/GenericFunctions.ts index dbc1c40661f6b..0b10e02b3d2ff 100644 --- a/packages/nodes-base/nodes/Microsoft/GraphSecurity/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Microsoft/GraphSecurity/GenericFunctions.ts @@ -17,11 +17,11 @@ export async function msGraphSecurityApiRequest( ) { const { oauthTokenData: { access_token }, - } = (await this.getCredentials('microsoftGraphSecurityOAuth2Api')) as { + } = await this.getCredentials<{ oauthTokenData: { access_token: string; }; - }; + }>('microsoftGraphSecurityOAuth2Api'); const options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/MonicaCrm/GenericFunctions.ts b/packages/nodes-base/nodes/MonicaCrm/GenericFunctions.ts index e8f9e66778a91..24c143a30bac0 100644 --- a/packages/nodes-base/nodes/MonicaCrm/GenericFunctions.ts +++ b/packages/nodes-base/nodes/MonicaCrm/GenericFunctions.ts @@ -17,11 +17,11 @@ export async function monicaCrmApiRequest( body: IDataObject = {}, qs: IDataObject = {}, ) { - const credentials = (await this.getCredentials('monicaCrmApi')) as { + const credentials = await this.getCredentials<{ apiToken: string; environment: string; domain: string; - }; + }>('monicaCrmApi'); if (credentials === undefined) { throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); diff --git a/packages/nodes-base/nodes/MySql/v2/actions/router.ts b/packages/nodes-base/nodes/MySql/v2/actions/router.ts index 0e9b49fa41a9e..e9ef6a8591460 100644 --- a/packages/nodes-base/nodes/MySql/v2/actions/router.ts +++ b/packages/nodes-base/nodes/MySql/v2/actions/router.ts @@ -16,7 +16,7 @@ export async function router(this: IExecuteFunctions): Promise('mySql'); const pool = await createPool.call(this, credentials, nodeOptions); diff --git a/packages/nodes-base/nodes/MySql/v2/methods/listSearch.ts b/packages/nodes-base/nodes/MySql/v2/methods/listSearch.ts index b2bad41908807..feca606392f3b 100644 --- a/packages/nodes-base/nodes/MySql/v2/methods/listSearch.ts +++ b/packages/nodes-base/nodes/MySql/v2/methods/listSearch.ts @@ -3,7 +3,7 @@ import { createPool } from '../transport'; import type { MysqlNodeCredentials } from '../helpers/interfaces'; export async function searchTables(this: ILoadOptionsFunctions): Promise { - const credentials = (await this.getCredentials('mySql')) as MysqlNodeCredentials; + const credentials = await this.getCredentials('mySql'); const nodeOptions = this.getNodeParameter('options', 0) as IDataObject; diff --git a/packages/nodes-base/nodes/MySql/v2/methods/loadOptions.ts b/packages/nodes-base/nodes/MySql/v2/methods/loadOptions.ts index 55c2ba58d771b..c4b4c6b5b30c1 100644 --- a/packages/nodes-base/nodes/MySql/v2/methods/loadOptions.ts +++ b/packages/nodes-base/nodes/MySql/v2/methods/loadOptions.ts @@ -4,7 +4,7 @@ import { escapeSqlIdentifier } from '../helpers/utils'; import type { MysqlNodeCredentials } from '../helpers/interfaces'; export async function getColumns(this: ILoadOptionsFunctions): Promise { - const credentials = (await this.getCredentials('mySql')) as MysqlNodeCredentials; + const credentials = await this.getCredentials('mySql'); const nodeOptions = this.getNodeParameter('options', 0) as IDataObject; const pool = await createPool.call(this, credentials, nodeOptions); diff --git a/packages/nodes-base/nodes/N8n/GenericFunctions.ts b/packages/nodes-base/nodes/N8n/GenericFunctions.ts index e190d8abb0406..cf814bc345082 100644 --- a/packages/nodes-base/nodes/N8n/GenericFunctions.ts +++ b/packages/nodes-base/nodes/N8n/GenericFunctions.ts @@ -32,7 +32,7 @@ export async function apiRequest( baseUrl: string; }; - const credentials = (await this.getCredentials('n8nApi')) as N8nApiCredentials; + const credentials = await this.getCredentials('n8nApi'); const baseUrl = credentials.baseUrl; const options: IRequestOptions = { diff --git a/packages/nodes-base/nodes/Netscaler/ADC/GenericFunctions.ts b/packages/nodes-base/nodes/Netscaler/ADC/GenericFunctions.ts index e941776636d6e..d57f8213964d7 100644 --- a/packages/nodes-base/nodes/Netscaler/ADC/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Netscaler/ADC/GenericFunctions.ts @@ -19,7 +19,7 @@ export async function netscalerADCApiRequest( uri?: string, option: IDataObject = {}, ): Promise { - const { url } = (await this.getCredentials('citrixAdcApi')) as { url: string }; + const { url } = await this.getCredentials<{ url: string }>('citrixAdcApi'); let options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/NextCloud/GenericFunctions.ts b/packages/nodes-base/nodes/NextCloud/GenericFunctions.ts index 882df0d6581ac..9506f015fb8cf 100644 --- a/packages/nodes-base/nodes/NextCloud/GenericFunctions.ts +++ b/packages/nodes-base/nodes/NextCloud/GenericFunctions.ts @@ -27,9 +27,9 @@ export async function nextCloudApiRequest( let credentials; if (authenticationMethod === 'accessToken') { - credentials = (await this.getCredentials('nextCloudApi')) as { webDavUrl: string }; + credentials = await this.getCredentials<{ webDavUrl: string }>('nextCloudApi'); } else { - credentials = (await this.getCredentials('nextCloudOAuth2Api')) as { webDavUrl: string }; + credentials = await this.getCredentials<{ webDavUrl: string }>('nextCloudOAuth2Api'); } const options: IRequestOptions = { diff --git a/packages/nodes-base/nodes/PayPal/PayPalTrigger.node.ts b/packages/nodes-base/nodes/PayPal/PayPalTrigger.node.ts index 309c6d519340c..e4804c7946f51 100644 --- a/packages/nodes-base/nodes/PayPal/PayPalTrigger.node.ts +++ b/packages/nodes-base/nodes/PayPal/PayPalTrigger.node.ts @@ -162,7 +162,7 @@ export class PayPalTrigger implements INodeType { const headerData = this.getHeaderData() as IDataObject; const endpoint = '/notifications/verify-webhook-signature'; - const { env } = (await this.getCredentials('payPalApi')) as { env: string }; + const { env } = await this.getCredentials<{ env: string }>('payPalApi'); // if sanbox omit verification if (env === 'sanbox') { diff --git a/packages/nodes-base/nodes/Pipedrive/PipedriveTrigger.node.ts b/packages/nodes-base/nodes/Pipedrive/PipedriveTrigger.node.ts index fa523ac9c5756..deef1c2c688fb 100644 --- a/packages/nodes-base/nodes/Pipedrive/PipedriveTrigger.node.ts +++ b/packages/nodes-base/nodes/Pipedrive/PipedriveTrigger.node.ts @@ -325,7 +325,7 @@ export class PipedriveTrigger implements INodeType { let httpBasicAuth: ICredentialDataDecryptedObject | undefined; try { - httpBasicAuth = await this.getCredentials('httpBasicAuth'); + httpBasicAuth = await this.getCredentials('httpBasicAuth'); } catch (error) { // Do nothing } diff --git a/packages/nodes-base/nodes/Plivo/GenericFunctions.ts b/packages/nodes-base/nodes/Plivo/GenericFunctions.ts index 6ac63db30f10e..5120a24dbcce2 100644 --- a/packages/nodes-base/nodes/Plivo/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Plivo/GenericFunctions.ts @@ -19,10 +19,10 @@ export async function plivoApiRequest( body: IDataObject = {}, qs: IDataObject = {}, ) { - const credentials = (await this.getCredentials('plivoApi')) as { + const credentials = await this.getCredentials<{ authId: string; authToken: string; - }; + }>('plivoApi'); const options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts b/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts index 14b94b5ea6d4f..f46eba14813b5 100644 --- a/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts +++ b/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts @@ -87,7 +87,7 @@ export async function pgTriggerFunction( } export async function initDB(this: ITriggerFunctions | ILoadOptionsFunctions) { - const credentials = (await this.getCredentials('postgres')) as PostgresNodeCredentials; + const credentials = await this.getCredentials('postgres'); const options = this.getNodeParameter('options', {}) as { connectionTimeout?: number; delayClosingIdleConnection?: number; diff --git a/packages/nodes-base/nodes/Postgres/v2/actions/router.ts b/packages/nodes-base/nodes/Postgres/v2/actions/router.ts index ccdcad70a0cfe..f48060ec3b668 100644 --- a/packages/nodes-base/nodes/Postgres/v2/actions/router.ts +++ b/packages/nodes-base/nodes/Postgres/v2/actions/router.ts @@ -15,7 +15,7 @@ export async function router(this: IExecuteFunctions): Promise('resource', 0); const operation = this.getNodeParameter('operation', 0); - const credentials = (await this.getCredentials('postgres')) as PostgresNodeCredentials; + const credentials = await this.getCredentials('postgres'); const options = this.getNodeParameter('options', 0, {}) as PostgresNodeOptions; const node = this.getNode(); options.nodeVersion = node.typeVersion; diff --git a/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts b/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts index f8612f4df6f74..f81a66700f0c0 100644 --- a/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts +++ b/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts @@ -4,7 +4,7 @@ import { configurePostgres } from '../transport'; import type { PostgresNodeCredentials } from '../helpers/interfaces'; export async function schemaSearch(this: ILoadOptionsFunctions): Promise { - const credentials = (await this.getCredentials('postgres')) as PostgresNodeCredentials; + const credentials = await this.getCredentials('postgres'); const options = { nodeVersion: this.getNode().typeVersion }; const { db } = await configurePostgres.call(this, credentials, options); @@ -23,7 +23,7 @@ export async function schemaSearch(this: ILoadOptionsFunctions): Promise { - const credentials = (await this.getCredentials('postgres')) as PostgresNodeCredentials; + const credentials = await this.getCredentials('postgres'); const options = { nodeVersion: this.getNode().typeVersion }; const { db } = await configurePostgres.call(this, credentials, options); diff --git a/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts b/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts index 3a16870b78dde..ac4f783541dba 100644 --- a/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts +++ b/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts @@ -5,7 +5,7 @@ import { configurePostgres } from '../transport'; import type { PostgresNodeCredentials } from '../helpers/interfaces'; export async function getColumns(this: ILoadOptionsFunctions): Promise { - const credentials = (await this.getCredentials('postgres')) as PostgresNodeCredentials; + const credentials = await this.getCredentials('postgres'); const options = { nodeVersion: this.getNode().typeVersion }; const { db } = await configurePostgres.call(this, credentials, options); diff --git a/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts b/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts index 1dee9a42b6136..dac7dc678dc0d 100644 --- a/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts +++ b/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts @@ -46,7 +46,7 @@ function mapPostgresType(postgresType: string): FieldType { export async function getMappingColumns( this: ILoadOptionsFunctions, ): Promise { - const credentials = (await this.getCredentials('postgres')) as PostgresNodeCredentials; + const credentials = await this.getCredentials('postgres'); const { db } = await configurePostgres.call(this, credentials); diff --git a/packages/nodes-base/nodes/QuickBooks/GenericFunctions.ts b/packages/nodes-base/nodes/QuickBooks/GenericFunctions.ts index ebf727c3661f9..16ef41b80e2e1 100644 --- a/packages/nodes-base/nodes/QuickBooks/GenericFunctions.ts +++ b/packages/nodes-base/nodes/QuickBooks/GenericFunctions.ts @@ -254,9 +254,9 @@ export async function loadResource(this: ILoadOptionsFunctions, resource: string oauthTokenData: { callbackQueryString: { realmId }, }, - } = (await this.getCredentials('quickBooksOAuth2Api')) as { + } = await this.getCredentials<{ oauthTokenData: { callbackQueryString: { realmId: string } }; - }; + }>('quickBooksOAuth2Api'); const endpoint = `/v3/company/${realmId}/query`; const resourceItems = await quickBooksApiRequestAllItems.call( diff --git a/packages/nodes-base/nodes/Supabase/GenericFunctions.ts b/packages/nodes-base/nodes/Supabase/GenericFunctions.ts index b66248f9f5e6e..902bf0ae98d9b 100644 --- a/packages/nodes-base/nodes/Supabase/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Supabase/GenericFunctions.ts @@ -23,10 +23,10 @@ export async function supabaseApiRequest( uri?: string, headers: IDataObject = {}, ) { - const credentials = (await this.getCredentials('supabaseApi')) as { + const credentials = await this.getCredentials<{ host: string; serviceRole: string; - }; + }>('supabaseApi'); const options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/Totp/Totp.node.ts b/packages/nodes-base/nodes/Totp/Totp.node.ts index 92c02393ffb9e..ed5a3a5b7aa64 100644 --- a/packages/nodes-base/nodes/Totp/Totp.node.ts +++ b/packages/nodes-base/nodes/Totp/Totp.node.ts @@ -126,7 +126,7 @@ export class Totp implements INodeType { const returnData: INodeExecutionData[] = []; const operation = this.getNodeParameter('operation', 0); - const credentials = (await this.getCredentials('totpApi')) as { label: string; secret: string }; + const credentials = await this.getCredentials<{ label: string; secret: string }>('totpApi'); if (!credentials.label.includes(':')) { throw new NodeOperationError(this.getNode(), 'Malformed label - expected `issuer:username`'); diff --git a/packages/nodes-base/nodes/Twilio/GenericFunctions.ts b/packages/nodes-base/nodes/Twilio/GenericFunctions.ts index 4f18bbccf5ff0..2b093ba8cc0ff 100644 --- a/packages/nodes-base/nodes/Twilio/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Twilio/GenericFunctions.ts @@ -19,13 +19,13 @@ export async function twilioApiRequest( body: IDataObject, query?: IDataObject, ): Promise { - const credentials = (await this.getCredentials('twilioApi')) as { + const credentials = await this.getCredentials<{ accountSid: string; authType: 'authToken' | 'apiKey'; authToken: string; apiKeySid: string; apiKeySecret: string; - }; + }>('twilioApi'); if (query === undefined) { query = {}; diff --git a/packages/nodes-base/nodes/Venafi/Datacenter/GenericFunctions.ts b/packages/nodes-base/nodes/Venafi/Datacenter/GenericFunctions.ts index 6887a0cf78386..8db5cc2f7f5ac 100644 --- a/packages/nodes-base/nodes/Venafi/Datacenter/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Venafi/Datacenter/GenericFunctions.ts @@ -19,7 +19,7 @@ export async function venafiApiRequest( uri?: string, headers: IDataObject = {}, ): Promise { - const credentials = (await this.getCredentials('venafiTlsProtectDatacenterApi')) as IDataObject; + const credentials = await this.getCredentials('venafiTlsProtectDatacenterApi'); const options: IRequestOptions = { headers: { diff --git a/packages/nodes-base/nodes/Webhook/utils.ts b/packages/nodes-base/nodes/Webhook/utils.ts index 2f3c25d660d8c..ba86f49caab7f 100644 --- a/packages/nodes-base/nodes/Webhook/utils.ts +++ b/packages/nodes-base/nodes/Webhook/utils.ts @@ -191,7 +191,7 @@ export async function validateWebhookAuthentication( // Basic authorization is needed to call webhook let expectedAuth: ICredentialDataDecryptedObject | undefined; try { - expectedAuth = await ctx.getCredentials('httpBasicAuth'); + expectedAuth = await ctx.getCredentials('httpBasicAuth'); } catch {} if (expectedAuth === undefined || !expectedAuth.user || !expectedAuth.password) { @@ -211,7 +211,7 @@ export async function validateWebhookAuthentication( // Special header with value is needed to call webhook let expectedAuth: ICredentialDataDecryptedObject | undefined; try { - expectedAuth = await ctx.getCredentials('httpHeaderAuth'); + expectedAuth = await ctx.getCredentials('httpHeaderAuth'); } catch {} if (expectedAuth === undefined || !expectedAuth.name || !expectedAuth.value) { @@ -232,12 +232,12 @@ export async function validateWebhookAuthentication( let expectedAuth; try { - expectedAuth = (await ctx.getCredentials('jwtAuth')) as { + expectedAuth = await ctx.getCredentials<{ keyType: 'passphrase' | 'pemKey'; publicKey: string; secret: string; algorithm: jwt.Algorithm; - }; + }>('jwtAuth'); } catch {} if (expectedAuth === undefined) { diff --git a/packages/nodes-base/nodes/Wise/GenericFunctions.ts b/packages/nodes-base/nodes/Wise/GenericFunctions.ts index 8742dccd0125a..a5fe5538033ba 100644 --- a/packages/nodes-base/nodes/Wise/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Wise/GenericFunctions.ts @@ -21,11 +21,11 @@ export async function wiseApiRequest( qs: IDataObject = {}, option: IDataObject = {}, ) { - const { apiToken, environment, privateKey } = (await this.getCredentials('wiseApi')) as { + const { apiToken, environment, privateKey } = await this.getCredentials<{ apiToken: string; environment: 'live' | 'test'; privateKey?: string; - }; + }>('wiseApi'); const rootUrl = environment === 'live' diff --git a/packages/nodes-base/nodes/Workable/GenericFunctions.ts b/packages/nodes-base/nodes/Workable/GenericFunctions.ts index 8b6dbc7eaeb71..c9d32403c276b 100644 --- a/packages/nodes-base/nodes/Workable/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Workable/GenericFunctions.ts @@ -19,10 +19,10 @@ export async function workableApiRequest( uri?: string, option: IDataObject = {}, ): Promise { - const credentials = (await this.getCredentials('workableApi')) as { + const credentials = await this.getCredentials<{ accessToken: string; subdomain: string; - }; + }>('workableApi'); let options: IRequestOptions = { headers: { Authorization: `Bearer ${credentials.accessToken}` }, diff --git a/packages/nodes-base/nodes/Workable/WorkableTrigger.node.ts b/packages/nodes-base/nodes/Workable/WorkableTrigger.node.ts index d942f697e86f6..6c7c13bf89441 100644 --- a/packages/nodes-base/nodes/Workable/WorkableTrigger.node.ts +++ b/packages/nodes-base/nodes/Workable/WorkableTrigger.node.ts @@ -137,10 +137,10 @@ export class WorkableTrigger implements INodeType { return false; }, async create(this: IHookFunctions): Promise { - const credentials = (await this.getCredentials('workableApi')) as { + const credentials = await this.getCredentials<{ accessToken: string; subdomain: string; - }; + }>('workableApi'); const webhookData = this.getWorkflowStaticData('node'); const webhookUrl = this.getNodeWebhookUrl('default'); const triggerOn = this.getNodeParameter('triggerOn') as string; diff --git a/packages/nodes-base/nodes/Zendesk/GenericFunctions.ts b/packages/nodes-base/nodes/Zendesk/GenericFunctions.ts index d38f741e4eb6c..d099493554fd4 100644 --- a/packages/nodes-base/nodes/Zendesk/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zendesk/GenericFunctions.ts @@ -30,9 +30,9 @@ export async function zendeskApiRequest( let credentials; if (authenticationMethod === 'apiToken') { - credentials = (await this.getCredentials('zendeskApi')) as { subdomain: string }; + credentials = await this.getCredentials<{ subdomain: string }>('zendeskApi'); } else { - credentials = (await this.getCredentials('zendeskOAuth2Api')) as { subdomain: string }; + credentials = await this.getCredentials<{ subdomain: string }>('zendeskOAuth2Api'); } let options: IRequestOptions = { diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index cab0c6d0e13ee..d17408293ffe1 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -90,7 +90,7 @@ export interface IGetCredentials { get(type: string, id: string | null): Promise; } -export abstract class ICredentials { +export abstract class ICredentials { id?: string; name: string; @@ -106,11 +106,11 @@ export abstract class ICredentials { this.data = data; } - abstract getData(nodeType?: string): ICredentialDataDecryptedObject; + abstract getData(nodeType?: string): T; abstract getDataToSave(): ICredentialsEncrypted; - abstract setData(data: ICredentialDataDecryptedObject): void; + abstract setData(data: T): void; } export interface IUser { @@ -128,11 +128,11 @@ export type ProjectSharingData = { updatedAt: string; }; -export interface ICredentialsDecrypted { +export interface ICredentialsDecrypted { id: string; name: string; type: string; - data?: ICredentialDataDecryptedObject; + data?: T; homeProject?: ProjectSharingData; sharedWithProjects?: ProjectSharingData[]; } @@ -718,7 +718,7 @@ export interface IExecuteWorkflowInfo { export type ICredentialTestFunction = ( this: ICredentialTestFunctions, - credential: ICredentialsDecrypted, + credential: ICredentialsDecrypted, ) => Promise; export interface ICredentialTestFunctions { @@ -860,7 +860,10 @@ export type NodeTypeAndVersion = { export interface FunctionsBase { logger: Logger; - getCredentials(type: string, itemIndex?: number): Promise; + getCredentials( + type: string, + itemIndex?: number, + ): Promise; getCredentialsProperties(type: string): INodeProperties[]; getExecutionId(): string; getNode(): INode; diff --git a/packages/workflow/src/RoutingNode.ts b/packages/workflow/src/RoutingNode.ts index 3ddd29a69e3f3..8824f9c516c28 100644 --- a/packages/workflow/src/RoutingNode.ts +++ b/packages/workflow/src/RoutingNode.ts @@ -116,7 +116,9 @@ export class RoutingNode { credentials = credentialsDecrypted.data; } else if (credentialType) { try { - credentials = (await executeFunctions.getCredentials(credentialType)) || {}; + credentials = + (await executeFunctions.getCredentials(credentialType)) || + {}; } catch (error) { if ( nodeType.description.credentials?.length &&