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,7 +1,4 @@
import {
IHookFunctions,
IWebhookFunctions,
} from 'n8n-core';
import { IHookFunctions, IWebhookFunctions } from 'n8n-core';
import {
ILoadOptionsFunctions,
@@ -11,9 +8,7 @@ import {
IWebhookResponseData,
} from 'n8n-workflow';
import {
formIoApiRequest,
} from './GenericFunctions';
import { formIoApiRequest } from './GenericFunctions';
export class FormIoTrigger implements INodeType {
description: INodeTypeDescription = {
@@ -53,21 +48,21 @@ export class FormIoTrigger implements INodeType {
},
required: true,
default: '',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
},
{
displayName: 'Form Name or ID',
name: 'formId',
type: 'options',
typeOptions: {
loadOptionsDependsOn: [
'projectId',
],
loadOptionsDependsOn: ['projectId'],
loadOptionsMethod: 'getForms',
},
required: true,
default: '',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
},
{
displayName: 'Trigger Events',
@@ -91,7 +86,8 @@ export class FormIoTrigger implements INodeType {
name: 'simple',
type: 'boolean',
default: true,
description: 'Whether to return a simplified version of the response instead of the raw data',
description:
'Whether to return a simplified version of the response instead of the raw data',
},
],
};
@@ -133,12 +129,19 @@ export class FormIoTrigger implements INodeType {
const formId = this.getNodeParameter('formId') as string;
const projectId = this.getNodeParameter('projectId') as string;
const method = this.getNodeParameter('events') as string[];
const actions = await formIoApiRequest.call(this, 'GET', `/project/${projectId}/form/${formId}/action`);
const actions = await formIoApiRequest.call(
this,
'GET',
`/project/${projectId}/form/${formId}/action`,
);
for (const action of actions) {
if (action.name === 'webhook') {
if (action.settings.url === webhookUrl &&
// tslint:disable-next-line: no-any
(action.method.length === method.length && action.method.every((value: any) => method.includes(value)))) {
if (
action.settings.url === webhookUrl &&
action.method.length === method.length &&
// tslint:disable-next-line:no-any
action.method.every((value: any) => method.includes(value))
) {
webhookData.webhookId = action._id;
return true;
}
@@ -158,9 +161,7 @@ export class FormIoTrigger implements INodeType {
name: `webhook`,
title: `webhook-n8n:${webhookUrl}`,
method,
handler: [
'after',
],
handler: ['after'],
priority: 0,
settings: {
method: 'post',
@@ -172,7 +173,12 @@ export class FormIoTrigger implements INodeType {
},
},
};
const webhook = await formIoApiRequest.call(this, 'POST', `/project/${projectId}/form/${formId}/action`, payload);
const webhook = await formIoApiRequest.call(
this,
'POST',
`/project/${projectId}/form/${formId}/action`,
payload,
);
webhookData.webhookId = webhook._id;
return true;
},
@@ -181,7 +187,11 @@ export class FormIoTrigger implements INodeType {
const webhookData = this.getWorkflowStaticData('node');
const formId = this.getNodeParameter('formId') as string;
const projectId = this.getNodeParameter('projectId') as string;
await formIoApiRequest.call(this, 'DELETE', `/project/${projectId}/form/${formId}/action/${webhookData.webhookId}`);
await formIoApiRequest.call(
this,
'DELETE',
`/project/${projectId}/form/${formId}/action/${webhookData.webhookId}`,
);
delete webhookData.webhookId;
return true;
},
@@ -196,9 +206,7 @@ export class FormIoTrigger implements INodeType {
response = response.data;
}
return {
workflowData: [
this.helpers.returnJsonArray(response),
],
workflowData: [this.helpers.returnJsonArray(response)],
};
}
}

View File

@@ -1,14 +1,6 @@
import {
IExecuteFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import {
IHookFunctions,
IWebhookFunctions,
NodeApiError,
} from 'n8n-workflow';
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
import { IHookFunctions, IWebhookFunctions, NodeApiError } from 'n8n-workflow';
interface IFormIoCredentials {
environment: 'cloudHosted' | ' selfHosted';
@@ -21,7 +13,10 @@ interface IFormIoCredentials {
* Method has the logic to get jwt token from Form.io
* @param this
*/
async function getToken(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, credentials: IFormIoCredentials) {
async function getToken(
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
credentials: IFormIoCredentials,
) {
const base = credentials.domain || 'https://formio.form.io';
const options = {
headers: {
@@ -43,7 +38,9 @@ async function getToken(this: IExecuteFunctions | IWebhookFunctions | IHookFunct
const responseObject = await this.helpers.request!(options);
return responseObject.headers['x-jwt-token'];
} catch (error) {
throw new Error(`Authentication Failed for Form.io. Please provide valid credentails/ endpoint details`);
throw new Error(
`Authentication Failed for Form.io. Please provide valid credentails/ endpoint details`,
);
}
}
@@ -52,9 +49,15 @@ async function getToken(this: IExecuteFunctions | IWebhookFunctions | IHookFunct
* @param this
* @param method
*/
export async function formIoApiRequest(this: IHookFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, endpoint: string, body = {}, qs = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = await this.getCredentials('formIoApi') as unknown as IFormIoCredentials;
export async function formIoApiRequest(
this: IHookFunctions | ILoadOptionsFunctions | IWebhookFunctions,
method: string,
endpoint: string,
body = {},
qs = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const credentials = (await this.getCredentials('formIoApi')) as unknown as IFormIoCredentials;
const token = await getToken.call(this, credentials);