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,6 +1,4 @@
|
||||
import {
|
||||
OptionsWithUrl,
|
||||
} from 'request';
|
||||
import { OptionsWithUrl } from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
@@ -9,18 +7,25 @@ import {
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject, NodeApiError, NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, qs: IDataObject = {} ,headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function mailchimpApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
endpoint: string,
|
||||
method: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
headers?: object,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;
|
||||
|
||||
const host = 'api.mailchimp.com/3.0';
|
||||
|
||||
const options: OptionsWithUrl = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
method,
|
||||
qs,
|
||||
@@ -45,19 +50,32 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||
} else {
|
||||
const credentials = await this.getCredentials('mailchimpOAuth2Api');
|
||||
|
||||
const { api_endpoint } = await getMetadata.call(this, credentials.oauthTokenData as IDataObject);
|
||||
const { api_endpoint } = await getMetadata.call(
|
||||
this,
|
||||
credentials.oauthTokenData as IDataObject,
|
||||
);
|
||||
|
||||
options.url = `${api_endpoint}/3.0${endpoint}`;
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2!.call(this, 'mailchimpOAuth2Api', options, { tokenType: 'Bearer' });
|
||||
return await this.helpers.requestOAuth2!.call(this, 'mailchimpOAuth2Api', options, {
|
||||
tokenType: 'Bearer',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function mailchimpApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, endpoint: string, method: string, propertyName: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function mailchimpApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
endpoint: string,
|
||||
method: string,
|
||||
propertyName: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
@@ -69,14 +87,13 @@ export async function mailchimpApiRequestAllItems(this: IExecuteFunctions | ILoa
|
||||
responseData = await mailchimpApiRequest.call(this, endpoint, method, body, query);
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
query.offset += query.count;
|
||||
} while (
|
||||
responseData[propertyName] && responseData[propertyName].length !== 0
|
||||
);
|
||||
} while (responseData[propertyName] && responseData[propertyName].length !== 0);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||
// tslint:disable-next-line:no-any
|
||||
export function validateJSON(json: string | undefined): any {
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(json!);
|
||||
@@ -86,12 +103,15 @@ export function validateJSON(json: string | undefined): any { // tslint:disable-
|
||||
return result;
|
||||
}
|
||||
|
||||
async function getMetadata(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, oauthTokenData: IDataObject) {
|
||||
async function getMetadata(
|
||||
this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
oauthTokenData: IDataObject,
|
||||
) {
|
||||
const credentials = await this.getCredentials('mailchimpOAuth2Api');
|
||||
const options: OptionsWithUrl = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': `OAuth ${oauthTokenData.access_token}`,
|
||||
Accept: 'application/json',
|
||||
Authorization: `OAuth ${oauthTokenData.access_token}`,
|
||||
},
|
||||
method: 'GET',
|
||||
url: credentials.metadataUrl as string,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
IHookFunctions,
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IHookFunctions, IWebhookFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
@@ -13,9 +10,7 @@ import {
|
||||
NodeApiError,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
mailchimpApiRequest,
|
||||
} from './GenericFunctions';
|
||||
import { mailchimpApiRequest } from './GenericFunctions';
|
||||
|
||||
export class MailchimpTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -36,9 +31,7 @@ export class MailchimpTrigger implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'apiKey',
|
||||
],
|
||||
authentication: ['apiKey'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -47,9 +40,7 @@ export class MailchimpTrigger implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'oAuth2',
|
||||
],
|
||||
authentication: ['oAuth2'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -91,7 +82,8 @@ export class MailchimpTrigger implements INodeType {
|
||||
type: 'options',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'The list that is gonna fire the event. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'The list that is gonna fire the event. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getLists',
|
||||
},
|
||||
@@ -113,17 +105,19 @@ export class MailchimpTrigger implements INodeType {
|
||||
{
|
||||
name: 'Cleaned',
|
||||
value: 'cleaned',
|
||||
description: 'Whether the webhook is triggered when a subscriber\'s email address is cleaned from the list',
|
||||
description:
|
||||
"Whether the webhook is triggered when a subscriber's email address is cleaned from the list",
|
||||
},
|
||||
{
|
||||
name: 'Email Address Updated',
|
||||
value: 'upemail',
|
||||
description: 'Whether the webhook is triggered when a subscriber\'s email address is changed',
|
||||
description:
|
||||
"Whether the webhook is triggered when a subscriber's email address is changed",
|
||||
},
|
||||
{
|
||||
name: 'Profile Updated',
|
||||
value: 'profile',
|
||||
description: 'Whether the webhook is triggered when a subscriber\'s profile is updated',
|
||||
description: "Whether the webhook is triggered when a subscriber's profile is updated",
|
||||
},
|
||||
{
|
||||
name: 'Subscribe',
|
||||
@@ -143,7 +137,8 @@ export class MailchimpTrigger implements INodeType {
|
||||
type: 'multiOptions',
|
||||
required: true,
|
||||
default: [],
|
||||
description: 'The possible sources of any events that can trigger the webhook and whether they are enabled',
|
||||
description:
|
||||
'The possible sources of any events that can trigger the webhook and whether they are enabled',
|
||||
options: [
|
||||
{
|
||||
name: 'User',
|
||||
@@ -153,7 +148,8 @@ export class MailchimpTrigger implements INodeType {
|
||||
{
|
||||
name: 'Admin',
|
||||
value: 'admin',
|
||||
description: 'Whether the webhook is triggered by admin-initiated actions in the web interface',
|
||||
description:
|
||||
'Whether the webhook is triggered by admin-initiated actions in the web interface',
|
||||
},
|
||||
{
|
||||
name: 'API',
|
||||
@@ -283,16 +279,17 @@ export class MailchimpTrigger implements INodeType {
|
||||
if (req.body.id !== webhookData.id) {
|
||||
return {};
|
||||
}
|
||||
// @ts-ignore
|
||||
if (!webhookData.events.includes(req.body.type)
|
||||
|
||||
if (
|
||||
// @ts-ignore
|
||||
&& !webhookData.sources.includes(req.body.type)) {
|
||||
!webhookData.events.includes(req.body.type) &&
|
||||
// @ts-ignore
|
||||
!webhookData.sources.includes(req.body.type)
|
||||
) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
workflowData: [
|
||||
this.helpers.returnJsonArray(req.body),
|
||||
],
|
||||
workflowData: [this.helpers.returnJsonArray(req.body)],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user