mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const activityOperations: INodeProperties[] = [
|
||||
{
|
||||
@@ -11,9 +8,7 @@ export const activityOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
resource: ['activity'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -77,7 +72,6 @@ export const activityOperations: INodeProperties[] = [
|
||||
];
|
||||
|
||||
export const activityFields: INodeProperties[] = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* activity:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -88,12 +82,8 @@ export const activityFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -106,12 +96,8 @@ export const activityFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -125,12 +111,8 @@ export const activityFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'ISO 8601 formatted date time',
|
||||
@@ -142,12 +124,8 @@ export const activityFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -164,12 +142,8 @@ export const activityFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -217,12 +191,8 @@ export const activityFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -236,12 +206,8 @@ export const activityFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -264,7 +230,8 @@ export const activityFields: INodeProperties[] = [
|
||||
name: 'gear_id',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Identifier for the gear associated with the activity. ‘none’ clears gear from activity.',
|
||||
description:
|
||||
'Identifier for the gear associated with the activity. ‘none’ clears gear from activity.',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
@@ -300,12 +267,8 @@ export const activityFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -322,16 +285,8 @@ export const activityFields: INodeProperties[] = [
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'getComments',
|
||||
'getLaps',
|
||||
'getKudos',
|
||||
'getZones',
|
||||
'getStreams',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['getComments', 'getLaps', 'getKudos', 'getZones', 'getStreams'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -343,15 +298,8 @@ export const activityFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'getComments',
|
||||
'getLaps',
|
||||
'getKudos',
|
||||
'getZones',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['getComments', 'getLaps', 'getKudos', 'getZones'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
@@ -363,18 +311,9 @@ export const activityFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'getComments',
|
||||
'getLaps',
|
||||
'getKudos',
|
||||
'getZones',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['getComments', 'getLaps', 'getKudos', 'getZones'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -436,12 +375,8 @@ export const activityFields: INodeProperties[] = [
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'getStreams',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['getStreams'],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
@@ -457,12 +392,8 @@ export const activityFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
@@ -474,15 +405,9 @@ export const activityFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'activity',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
resource: ['activity'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
@@ -10,12 +8,24 @@ import {
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function stravaApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
import { IDataObject, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function stravaApiRequest(
|
||||
this:
|
||||
| IExecuteFunctions
|
||||
| IExecuteSingleFunctions
|
||||
| ILoadOptionsFunctions
|
||||
| IHookFunctions
|
||||
| IWebhookFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
headers: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const options: OptionsWithUri = {
|
||||
method,
|
||||
form: body,
|
||||
@@ -42,18 +52,26 @@ export async function stravaApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
}
|
||||
//@ts-ignore
|
||||
return this.helpers?.request(options);
|
||||
|
||||
} else {
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'stravaOAuth2Api', options, { includeCredentialsOnRefreshOnBody: true });
|
||||
return await this.helpers.requestOAuth2.call(this, 'stravaOAuth2Api', options, {
|
||||
includeCredentialsOnRefreshOnBody: true,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function stravaApiRequestAllItems(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function stravaApiRequestAllItems(
|
||||
this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
@@ -66,9 +84,7 @@ export async function stravaApiRequestAllItems(this: IHookFunctions | ILoadOptio
|
||||
responseData = await stravaApiRequest.call(this, method, resource, body, query);
|
||||
query.page++;
|
||||
returnData.push.apply(returnData, responseData);
|
||||
} while (
|
||||
responseData.length !== 0
|
||||
);
|
||||
} while (responseData.length !== 0);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,10 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
stravaApiRequest,
|
||||
stravaApiRequestAllItems,
|
||||
} from './GenericFunctions';
|
||||
import { stravaApiRequest, stravaApiRequestAllItems } from './GenericFunctions';
|
||||
|
||||
import {
|
||||
activityFields,
|
||||
activityOperations,
|
||||
} from './ActivityDescription';
|
||||
import { activityFields, activityOperations } from './ActivityDescription';
|
||||
|
||||
import moment from 'moment';
|
||||
|
||||
@@ -69,7 +56,6 @@ export class Strava implements INodeType {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
for (let i = 0; i < length; i++) {
|
||||
|
||||
try {
|
||||
if (resource === 'activity') {
|
||||
//https://developers.strava.com/docs/reference/#api-Activities-createActivity
|
||||
@@ -110,19 +96,22 @@ export class Strava implements INodeType {
|
||||
responseData = await stravaApiRequest.call(this, 'GET', `/activities/${activityId}`);
|
||||
}
|
||||
if (['getLaps', 'getZones', 'getKudos', 'getComments'].includes(operation)) {
|
||||
|
||||
const path: IDataObject = {
|
||||
'getComments': 'comments',
|
||||
'getZones': 'zones',
|
||||
'getKudos': 'kudos',
|
||||
'getLaps': 'laps',
|
||||
getComments: 'comments',
|
||||
getZones: 'zones',
|
||||
getKudos: 'kudos',
|
||||
getLaps: 'laps',
|
||||
};
|
||||
|
||||
const activityId = this.getNodeParameter('activityId', i) as string;
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
responseData = await stravaApiRequest.call(this, 'GET', `/activities/${activityId}/${path[operation]}`);
|
||||
responseData = await stravaApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/activities/${activityId}/${path[operation]}`,
|
||||
);
|
||||
|
||||
if (returnAll === false) {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
@@ -136,15 +125,26 @@ export class Strava implements INodeType {
|
||||
qs.keys = keys.toString();
|
||||
qs.key_by_type = true;
|
||||
|
||||
responseData = await stravaApiRequest.call(this, 'GET', `/activities/${activityId}/streams`, {}, qs);
|
||||
responseData = await stravaApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/activities/${activityId}/streams`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
}
|
||||
//https://developers.mailerlite.com/reference#subscribers
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
if (returnAll) {
|
||||
|
||||
responseData = await stravaApiRequestAllItems.call(this, 'GET', `/activities`, {}, qs);
|
||||
responseData = await stravaApiRequestAllItems.call(
|
||||
this,
|
||||
'GET',
|
||||
`/activities`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.per_page = this.getNodeParameter('limit', i) as number;
|
||||
|
||||
@@ -169,7 +169,12 @@ export class Strava implements INodeType {
|
||||
|
||||
Object.assign(body, updateFields);
|
||||
|
||||
responseData = await stravaApiRequest.call(this, 'PUT', `/activities/${activityId}`, body);
|
||||
responseData = await stravaApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/activities/${activityId}`,
|
||||
body,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
IHookFunctions,
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IHookFunctions, IWebhookFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
@@ -11,13 +8,9 @@ import {
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
stravaApiRequest,
|
||||
} from './GenericFunctions';
|
||||
import { stravaApiRequest } from './GenericFunctions';
|
||||
|
||||
import {
|
||||
randomBytes,
|
||||
} from 'crypto';
|
||||
import { randomBytes } from 'crypto';
|
||||
|
||||
export class StravaTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -103,7 +96,8 @@ export class StravaTrigger implements INodeType {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
||||
description: 'By default the webhook-data only contain the Object ID. If this option gets activated, it will resolve the data automatically.',
|
||||
description:
|
||||
'By default the webhook-data only contain the Object ID. If this option gets activated, it will resolve the data automatically.',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
@@ -118,7 +112,8 @@ export class StravaTrigger implements INodeType {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
||||
description: 'Strava allows just one subscription at all times. If you want to delete the current subscription to make room for a new subcription with the current parameters, set this parameter to true. Keep in mind this is a destructive operation.',
|
||||
description:
|
||||
'Strava allows just one subscription at all times. If you want to delete the current subscription to make room for a new subcription with the current parameters, set this parameter to true. Keep in mind this is a destructive operation.',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -170,18 +165,32 @@ export class StravaTrigger implements INodeType {
|
||||
if (error.resource === 'PushSubscription' && error.code === 'already exists') {
|
||||
const options = this.getNodeParameter('options') as IDataObject;
|
||||
//get the current subscription
|
||||
const webhooks = await stravaApiRequest.call(this, 'GET', `/push_subscriptions`, {});
|
||||
const webhooks = await stravaApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/push_subscriptions`,
|
||||
{},
|
||||
);
|
||||
|
||||
if (options.deleteIfExist) {
|
||||
// delete the subscription
|
||||
await stravaApiRequest.call(this, 'DELETE', `/push_subscriptions/${webhooks[0].id}`);
|
||||
await stravaApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/push_subscriptions/${webhooks[0].id}`,
|
||||
);
|
||||
// now there is room create a subscription with the n8n data
|
||||
const body = {
|
||||
callback_url: webhookUrl,
|
||||
verify_token: randomBytes(20).toString('hex') as string,
|
||||
};
|
||||
|
||||
responseData = await stravaApiRequest.call(this, 'POST', `/push_subscriptions`, body);
|
||||
responseData = await stravaApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/push_subscriptions`,
|
||||
body,
|
||||
);
|
||||
} else {
|
||||
error.message = `A subscription already exists [${webhooks[0].callback_url}]. If you want to delete this subcription and create a new one with the current parameters please go to options and set delete if exist to true`;
|
||||
throw error;
|
||||
@@ -206,7 +215,6 @@ export class StravaTrigger implements INodeType {
|
||||
async delete(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
if (webhookData.webhookId !== undefined) {
|
||||
|
||||
const endpoint = `/push_subscriptions/${webhookData.webhookId}`;
|
||||
|
||||
try {
|
||||
@@ -273,9 +281,7 @@ export class StravaTrigger implements INodeType {
|
||||
}
|
||||
|
||||
return {
|
||||
workflowData: [
|
||||
this.helpers.returnJsonArray(body),
|
||||
],
|
||||
workflowData: [this.helpers.returnJsonArray(body)],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user