refactor: Format nodes-base package (A-F) (#3800)

* 🔨 prettier formated nodes - A

* 🔨 prettier formated nodes - B

*  prettier formated nodes - C

*  prettier formated nodes - D

*  prettier formated nodes - E-F

* 🎨 Adjust nodes-base formatting command (#3805)

* Format additional files in nodes A-F (#3811)

*  fixes

* 🎨 Add Mindee to ignored dirs

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Michael Kret
2022-08-01 23:47:55 +03:00
committed by GitHub
parent 2c17e6f3ca
commit 0ecbb4a19d
411 changed files with 12906 additions and 20148 deletions

View File

@@ -1,19 +1,8 @@
import {
IHookFunctions,
IWebhookFunctions,
} from 'n8n-core';
import { IHookFunctions, IWebhookFunctions } from 'n8n-core';
import {
IDataObject,
INodeType,
INodeTypeDescription,
IWebhookResponseData,
} from 'n8n-workflow';
import { IDataObject, INodeType, INodeTypeDescription, IWebhookResponseData } from 'n8n-workflow';
import {
calendlyApiRequest,
getAuthenticationType,
} from './GenericFunctions';
import { calendlyApiRequest, getAuthenticationType } from './GenericFunctions';
export class CalendlyTrigger implements INodeType {
description: INodeTypeDescription = {
@@ -59,7 +48,8 @@ export class CalendlyTrigger implements INodeType {
{
name: 'User',
value: 'user',
description: 'Triggers the webhook for subscribed events that belong to the current user',
description:
'Triggers the webhook for subscribed events that belong to the current user',
},
],
},
@@ -83,7 +73,6 @@ export class CalendlyTrigger implements INodeType {
required: true,
},
],
};
// @ts-ignore (because of request)
@@ -93,7 +82,7 @@ export class CalendlyTrigger implements INodeType {
const webhookUrl = this.getNodeWebhookUrl('default');
const webhookData = this.getWorkflowStaticData('node');
const events = this.getNodeParameter('events') as string;
const { apiKey } = await this.getCredentials('calendlyApi') as { apiKey: string };
const { apiKey } = (await this.getCredentials('calendlyApi')) as { apiKey: string };
const authenticationType = getAuthenticationType(apiKey);
@@ -156,7 +145,7 @@ export class CalendlyTrigger implements INodeType {
const webhookData = this.getWorkflowStaticData('node');
const webhookUrl = this.getNodeWebhookUrl('default');
const events = this.getNodeParameter('events') as string;
const { apiKey } = await this.getCredentials('calendlyApi') as { apiKey: string };
const { apiKey } = (await this.getCredentials('calendlyApi')) as { apiKey: string };
const authenticationType = getAuthenticationType(apiKey);
@@ -190,7 +179,7 @@ export class CalendlyTrigger implements INodeType {
scope,
};
if ( scope === 'user') {
if (scope === 'user') {
body.user = resource.uri;
}
@@ -208,13 +197,12 @@ export class CalendlyTrigger implements INodeType {
},
async delete(this: IHookFunctions): Promise<boolean> {
const webhookData = this.getWorkflowStaticData('node');
const { apiKey } = await this.getCredentials('calendlyApi') as { apiKey: string };
const { apiKey } = (await this.getCredentials('calendlyApi')) as { apiKey: string };
const authenticationType = getAuthenticationType(apiKey);
// remove condition once API Keys are deprecated
if (authenticationType === 'apiKey') {
if (webhookData.webhookId !== undefined) {
const endpoint = `/hooks/${webhookData.webhookId}`;
try {
@@ -232,7 +220,14 @@ export class CalendlyTrigger implements INodeType {
if (authenticationType === 'accessToken') {
if (webhookData.webhookURI !== undefined) {
try {
await calendlyApiRequest.call(this, 'DELETE', '', {}, {}, webhookData.webhookURI as string);
await calendlyApiRequest.call(
this,
'DELETE',
'',
{},
{},
webhookData.webhookURI as string,
);
} catch (error) {
return false;
}
@@ -249,9 +244,7 @@ export class CalendlyTrigger implements INodeType {
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const bodyData = this.getBodyData();
return {
workflowData: [
this.helpers.returnJsonArray(bodyData),
],
workflowData: [this.helpers.returnJsonArray(bodyData)],
};
}
}

View File

@@ -1,9 +1,6 @@
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
import {
ICredentialDataDecryptedObject,
@@ -14,9 +11,18 @@ import {
NodeApiError,
} from 'n8n-workflow';
export async function calendlyApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const { apiKey } = await this.getCredentials('calendlyApi') as { apiKey: string };
export async function calendlyApiRequest(
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
method: string,
resource: string,
// tslint:disable-next-line:no-any
body: any = {},
query: IDataObject = {},
uri?: string,
option: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const { apiKey } = (await this.getCredentials('calendlyApi')) as { apiKey: string };
const authenticationType = getAuthenticationType(apiKey);
@@ -60,11 +66,15 @@ export function getAuthenticationType(data: string): 'accessToken' | 'apiKey' {
return data.includes('.') ? 'accessToken' : 'apiKey';
}
export async function validateCredentials(this: ICredentialTestFunctions, decryptedCredentials: ICredentialDataDecryptedObject): Promise<any> { // tslint:disable-line:no-any
export async function validateCredentials(
this: ICredentialTestFunctions,
decryptedCredentials: ICredentialDataDecryptedObject,
// tslint:disable-next-line:no-any
): Promise<any> {
const credentials = decryptedCredentials;
const { apiKey } = credentials as {
apiKey: string,
apiKey: string;
};
const authenticationType = getAuthenticationType(apiKey);
@@ -76,9 +86,15 @@ export async function validateCredentials(this: ICredentialTestFunctions, decryp
};
if (authenticationType === 'accessToken') {
Object.assign(options, { headers: { 'Authorization': `Bearer ${apiKey}` }, uri: 'https://api.calendly.com/users/me' });
Object.assign(options, {
headers: { Authorization: `Bearer ${apiKey}` },
uri: 'https://api.calendly.com/users/me',
});
} else {
Object.assign(options, { headers: { 'X-TOKEN': apiKey }, uri: 'https://calendly.com/api/v1/users/me' });
Object.assign(options, {
headers: { 'X-TOKEN': apiKey },
uri: 'https://calendly.com/api/v1/users/me',
});
}
return this.helpers.request!(options);
}