Small adjustments on Mailchimp node

This commit is contained in:
Jan Oberhauser 2019-11-15 21:44:46 +01:00
parent 325fff318e
commit b5544cba94
4 changed files with 40 additions and 41 deletions

View file

@ -13,11 +13,5 @@ export class MailchimpApi implements ICredentialType {
type: 'string' as NodePropertyTypes,
default: '',
},
{
displayName: 'Datacenter',
name: 'datacenter',
type: 'string' as NodePropertyTypes,
default: '',
},
];
}

View file

@ -7,9 +7,8 @@ import {
IExecuteSingleFunctions
} from 'n8n-core';
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('mailchimpApi');
const datacenter = credentials!.datacenter as string;
if (credentials === undefined) {
throw new Error('No credentials got returned!');
@ -17,13 +16,19 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
const headerWithAuthentication = Object.assign({}, headers, { Authorization: `apikey ${credentials.apiKey}` });
const endpoint = 'api.mailchimp.com/3.0';
if (!(credentials.apiKey as string).includes('-')) {
throw new Error('The API key is not valid!');
}
const datacenter = (credentials.apiKey as string).split('-').pop();
const host = 'api.mailchimp.com/3.0';
const options: OptionsWithUri = {
headers: headerWithAuthentication,
method,
uri: `https://${datacenter}.${endpoint}${resource}`,
json: true
uri: `https://${datacenter}.${host}${endpoint}`,
json: true,
};
if (Object.keys(body).length !== 0) {

View file

@ -1,26 +1,27 @@
import * as moment from 'moment';
import {
IExecuteSingleFunctions,
} from 'n8n-core';
import {
IDataObject,
ILoadOptionsFunctions,
INodeTypeDescription,
INodeExecutionData,
INodeType,
ILoadOptionsFunctions,
INodePropertyOptions,
} from 'n8n-workflow';
import {
mailchimpApiRequest,
validateJSON
validateJSON,
} from './GenericFunctions';
import * as moment from 'moment';
enum Status {
subscribe = 'subscribe',
unsubscribed = 'unsubscribe',
cleaned = 'cleaned',
pending = 'pending',
transactional = 'transactional'
transactional = 'transactional',
}
interface ILocation {
@ -78,7 +79,7 @@ export class Mailchimp implements INodeType {
description: 'Add member to list',
},
],
default: '',
default: 'member',
required: true,
description: 'Resource to consume.',
},
@ -101,7 +102,7 @@ export class Mailchimp implements INodeType {
description: 'Create a new member on list',
},
],
default: '',
default: 'create',
description: 'The operation to perform.',
},
{
@ -114,7 +115,7 @@ export class Mailchimp implements INodeType {
displayOptions: {
show: {
resource: [
'member'
'member',
],
operation: [
'create',
@ -124,7 +125,7 @@ export class Mailchimp implements INodeType {
default: '',
options: [],
required: true,
description: 'List of lists'
description: 'List of lists',
},
{
displayName: 'Email',
@ -215,7 +216,7 @@ export class Mailchimp implements INodeType {
displayOptions: {
show: {
resource:[
'member'
'member',
],
operation: [
'create',
@ -298,12 +299,12 @@ export class Mailchimp implements INodeType {
name: 'locationFieldsUi',
type: 'fixedCollection',
placeholder: 'Add Location',
default: false,
default: {},
description: `Subscriber location information.n`,
displayOptions: {
show: {
resource:[
'member'
'member',
],
operation: [
'create',
@ -324,7 +325,7 @@ export class Mailchimp implements INodeType {
type: 'string',
required: true,
description: 'The location latitude.',
default: ''
default: '',
},
{
displayName: 'Longitude',
@ -332,7 +333,7 @@ export class Mailchimp implements INodeType {
type: 'string',
required: true,
description: 'The location longitude.',
default: ''
default: '',
},
],
}
@ -343,7 +344,7 @@ export class Mailchimp implements INodeType {
name: 'mergeFieldsUi',
placeholder: 'Add Merge Fields',
type: 'fixedCollection',
default: '',
default: {},
typeOptions: {
multipleValues: true,
},
@ -366,19 +367,19 @@ export class Mailchimp implements INodeType {
name: 'mergeFieldsValues',
displayName: 'Field',
typeOptions: {
multipleValueButtonText: 'Add Field'
multipleValueButtonText: 'Add Field',
},
values: [
{
displayName: 'Merge Field Name',
displayName: 'Field Name',
name: 'name',
type: 'string',
required: true,
description: 'Merge Field name',
default: ''
default: '',
},
{
displayName: 'Merge Field Value',
displayName: 'Field Value',
name: 'value',
required: true,
type: 'string',
@ -394,20 +395,20 @@ export class Mailchimp implements INodeType {
name: 'mergeFieldsJson',
type: 'json',
typeOptions: {
alwaysOpenEditWindow: true
alwaysOpenEditWindow: true,
},
default: '',
description: '',
displayOptions: {
show: {
resource:[
'member'
'member',
],
operation: [
'create',
],
jsonParameters: [
true
true,
],
},
},
@ -417,20 +418,20 @@ export class Mailchimp implements INodeType {
name: 'locationJson',
type: 'json',
typeOptions: {
alwaysOpenEditWindow: true
alwaysOpenEditWindow: true,
},
default: '',
description: '',
displayOptions: {
show: {
resource:[
'member'
'member',
],
operation: [
'create',
],
jsonParameters: [
true
true,
],
},
},
@ -442,7 +443,6 @@ export class Mailchimp implements INodeType {
methods = {
loadOptions: {
// Get all the available lists to display them to user so that he can
// select them easily
async getLists(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
@ -552,7 +552,7 @@ export class Mailchimp implements INodeType {
}
}
return {
json: response
json: response,
};
}
}

View file

@ -42,8 +42,8 @@
"dist/credentials/HttpHeaderAuth.credentials.js",
"dist/credentials/Imap.credentials.js",
"dist/credentials/LinkFishApi.credentials.js",
"dist/credentials/MailgunApi.credentials.js",
"dist/credentials/MailchimpApi.credentials.js",
"dist/credentials/MailgunApi.credentials.js",
"dist/credentials/MandrillApi.credentials.js",
"dist/credentials/MattermostApi.credentials.js",
"dist/credentials/MongoDb.credentials.js",
@ -98,8 +98,8 @@
"dist/nodes/If.node.js",
"dist/nodes/Interval.node.js",
"dist/nodes/LinkFish/LinkFish.node.js",
"dist/nodes/Mailgun/Mailgun.node.js",
"dist/nodes/Mailchimp/Mailchimp.node.js",
"dist/nodes/Mailgun/Mailgun.node.js",
"dist/nodes/Mandrill/Mandrill.node.js",
"dist/nodes/Mattermost/Mattermost.node.js",
"dist/nodes/Merge.node.js",