mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
⚡ Improvements to Mailchimp-Node
This commit is contained in:
@@ -11,20 +11,6 @@ export class MailchimpOAuth2Api implements ICredentialType {
|
||||
];
|
||||
displayName = 'Mailchimp OAuth2 API';
|
||||
properties = [
|
||||
{
|
||||
displayName: 'Mailchimp Server',
|
||||
name: 'server',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: 'https://login.mailchimp.com/',
|
||||
description: 'The server to connect to.',
|
||||
},
|
||||
{
|
||||
displayName: 'Datacenter',
|
||||
name: 'dataCenter',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: 'us10',
|
||||
description: 'Datacenter that your Mailchimp application is hosted on. Found in the URL of your Mailchimp dashboard.',
|
||||
},
|
||||
{
|
||||
displayName: 'Authorization URL',
|
||||
name: 'authUrl',
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||
}
|
||||
|
||||
try {
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
if (authenticationMethod === 'apiKey') {
|
||||
const credentials = this.getCredentials('mailchimpApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
@@ -52,15 +52,16 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||
|
||||
return await this.helpers.request!(options);
|
||||
} else {
|
||||
const credentials = this.getCredentials('mailchimpOAuth2Api');
|
||||
const datacenter = credentials!.dataCenter;
|
||||
const credentials = this.getCredentials('mailchimpOAuth2Api') as IDataObject;
|
||||
|
||||
options.url = `https://${datacenter}.${host}${endpoint}`;
|
||||
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, 'bearer');
|
||||
return await this.helpers.requestOAuth2!.call(this, 'mailchimpOAuth2Api', options, 'Bearer');
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.response.body && error.response.body.detail) {
|
||||
if (error.respose && error.response.body && error.response.body.detail) {
|
||||
throw new Error(`Mailchimp Error response [${error.statusCode}]: ${error.response.body.detail}`);
|
||||
}
|
||||
throw error;
|
||||
@@ -96,3 +97,17 @@ export function validateJSON(json: string | undefined): any { // tslint:disable-
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getMetadata(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, oauthTokenData: IDataObject) {
|
||||
const credentials = this.getCredentials('mailchimpOAuth2Api') as IDataObject;
|
||||
const options: OptionsWithUrl = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': `OAuth ${oauthTokenData.access_token}`,
|
||||
},
|
||||
method: 'GET',
|
||||
url: credentials.metadataUrl as string,
|
||||
json: true,
|
||||
};
|
||||
return this.helpers.request!(options);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ export class Mailchimp implements INodeType {
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'accessToken',
|
||||
'apiKey',
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -96,15 +96,15 @@ export class Mailchimp implements INodeType {
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Access Token',
|
||||
value: 'accessToken',
|
||||
name: 'API Key',
|
||||
value: 'apiKey',
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2',
|
||||
},
|
||||
],
|
||||
default: 'accessToken',
|
||||
default: 'apiKey',
|
||||
description: 'Method of authentication.',
|
||||
},
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ export class MailchimpTrigger implements INodeType {
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'accessToken',
|
||||
'apiKey',
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -74,15 +74,15 @@ export class MailchimpTrigger implements INodeType {
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Access Token',
|
||||
value: 'accessToken',
|
||||
name: 'API Key',
|
||||
value: 'apiKey',
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2',
|
||||
},
|
||||
],
|
||||
default: 'accessToken',
|
||||
default: 'apiKey',
|
||||
description: 'Method of authentication.',
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user