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,103 +8,101 @@ import {
IWebhookResponseData,
} from 'n8n-workflow';
import {
calApiRequest,
sortOptionParameters,
} from './GenericFunctions';
import { calApiRequest, sortOptionParameters } from './GenericFunctions';
export class CalTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'Cal Trigger',
name: 'calTrigger',
icon: 'file:cal.svg',
group: ['trigger'],
version: 1,
subtitle: '=Events: {{$parameter["events"].join(", ")}}',
description: 'Handle Cal events via webhooks',
defaults: {
name: 'Cal Trigger',
color: '#888',
displayName: 'Cal Trigger',
name: 'calTrigger',
icon: 'file:cal.svg',
group: ['trigger'],
version: 1,
subtitle: '=Events: {{$parameter["events"].join(", ")}}',
description: 'Handle Cal events via webhooks',
defaults: {
name: 'Cal Trigger',
color: '#888',
},
inputs: [],
outputs: ['main'],
credentials: [
{
name: 'calApi',
required: true,
},
inputs: [],
outputs: ['main'],
credentials: [
{
name: 'calApi',
required: true,
},
],
webhooks: [
],
webhooks: [
{
name: 'default',
httpMethod: 'POST',
responseMode: 'onReceived',
path: 'webhook',
},
],
properties: [
{
displayName: 'Events',
name: 'events',
type: 'multiOptions',
options: [
{
name: 'default',
httpMethod: 'POST',
responseMode: 'onReceived',
path: 'webhook',
name: 'Booking Cancelled',
value: 'BOOKING_CANCELLED',
description: 'Receive notifications when a Cal event is canceled',
},
],
properties: [
{
displayName: 'Events',
name: 'events',
type: 'multiOptions',
options: [
{
name: 'Booking Cancelled',
value: 'BOOKING_CANCELLED',
description: 'Receive notifications when a Cal event is canceled',
{
name: 'Booking Created',
value: 'BOOKING_CREATED',
description: 'Receive notifications when a new Cal event is created',
},
{
name: 'Booking Rescheduled',
value: 'BOOKING_RESCHEDULED',
description: 'Receive notifications when a Cal event is rescheduled',
},
],
default: [],
required: true,
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Field',
default: {},
options: [
{
displayName: 'App ID',
name: 'appId',
type: 'string',
description: 'The ID of the App to monitor',
default: '',
},
{
displayName: 'EventType Name or ID',
name: 'eventTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getEventTypes',
},
{
name: 'Booking Created',
value: 'BOOKING_CREATED',
description: 'Receive notifications when a new Cal event is created',
description:
'The EventType to monitor. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
default: '',
},
{
displayName: 'Payload Template',
name: 'payloadTemplate',
type: 'string',
description: 'Template to customize the webhook payload',
default: '',
typeOptions: {
alwaysOpenEditWindow: true,
rows: 4,
},
{
name: 'Booking Rescheduled',
value: 'BOOKING_RESCHEDULED',
description: 'Receive notifications when a Cal event is rescheduled',
},
],
default: [],
required: true,
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Field',
default: {},
options: [
{
displayName: 'App ID',
name: 'appId',
type: 'string',
description: 'The ID of the App to monitor',
default: '',
},
{
displayName: 'EventType Name or ID',
name: 'eventTypeId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getEventTypes',
},
description: 'The EventType to monitor. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
default: '',
},
{
displayName: 'Payload Template',
name: 'payloadTemplate',
type: 'string',
description: 'Template to customize the webhook payload',
default: '',
typeOptions: {
alwaysOpenEditWindow: true,
rows: 4,
},
},
],
},
],
},
],
},
],
};
methods = {
@@ -165,7 +160,7 @@ export class CalTrigger implements INodeType {
subscriberUrl,
eventTriggers,
active,
...options as object,
...(options as object),
};
const responseData = await calApiRequest.call(this, 'POST', '/hooks', body);
@@ -181,7 +176,6 @@ export class CalTrigger implements INodeType {
async delete(this: IHookFunctions): Promise<boolean> {
const webhookData = this.getWorkflowStaticData('node');
if (webhookData.webhookId !== undefined) {
const endpoint = `/hooks/${webhookData.webhookId}`;
try {
@@ -202,13 +196,13 @@ export class CalTrigger implements INodeType {
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const req = this.getRequestObject();
return {
workflowData: [
this.helpers.returnJsonArray({
triggerEvent: req.body.triggerEvent,
createdAt: req.body.createdAt,
...req.body.payload,
}),
],
workflowData: [
this.helpers.returnJsonArray({
triggerEvent: req.body.triggerEvent,
createdAt: req.body.createdAt,
...req.body.payload,
}),
],
};
}
}

View File

@@ -1,7 +1,4 @@
import {
IExecuteFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
import {
IDataObject,
@@ -13,8 +10,16 @@ import {
NodeApiError,
} from 'n8n-workflow';
export async function calApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, method: IHttpRequestMethods, resource: string, body: any = {}, query: IDataObject = {}, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function calApiRequest(
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods,
resource: string,
// tslint:disable-next-line:no-any
body: any = {},
query: IDataObject = {},
option: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const credentials = await this.getCredentials('calApi');
let options: IHttpRequestOptions = {
@@ -36,12 +41,18 @@ export async function calApiRequest(this: IExecuteFunctions | IWebhookFunctions
}
}
export function sortOptionParameters(optionParameters: INodePropertyOptions[]): INodePropertyOptions[] {
export function sortOptionParameters(
optionParameters: INodePropertyOptions[],
): INodePropertyOptions[] {
optionParameters.sort((a, b) => {
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
if (aName < bName) {
return -1;
}
if (aName > bName) {
return 1;
}
return 0;
});