1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-10-06 09:37:36 +03:00

Improvements to Automizy-Node

This commit is contained in:
Jan Oberhauser 2020-10-13 21:39:36 +02:00
parent 719a30350c
commit 97d1f46a14
4 changed files with 322 additions and 339 deletions

View File

@ -16,11 +16,6 @@ import {
automizyApiRequestAllItems,
} from './GenericFunctions';
import {
contactListFields,
contactListOperations,
} from './ContactListDescription';
import {
contactFields,
contactOperations,
@ -62,10 +57,6 @@ export class Automizy implements INodeType {
name: 'Contact',
value: 'contact',
},
{
name: 'Contact List',
value: 'contactList',
},
{
name: 'List',
value: 'list',
@ -74,8 +65,6 @@ export class Automizy implements INodeType {
default: 'contactList',
description: 'The resource to operate on.'
},
...contactListOperations,
...contactListFields,
...contactOperations,
...contactFields,
@ -89,6 +78,24 @@ export class Automizy implements INodeType {
loadOptions: {
// Get all the tags to display them to user so that he can
// select them easily
async getLists(
this: ILoadOptionsFunctions
): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const lists = await automizyApiRequestAllItems.call(
this,
'smartLists',
'GET',
`/smart-lists`,
);
for (const list of lists) {
returnData.push({
name: list.name,
value: list.id
});
}
return returnData;
},
async getTags(
this: ILoadOptionsFunctions
): Promise<INodePropertyOptions[]> {
@ -100,17 +107,13 @@ export class Automizy implements INodeType {
'/contacts/tag-manager'
);
for (const tag of tags) {
const tagName = tag.name;
const tagId = tag.name;
returnData.push({
name: tagName,
value: tagId
name: tag.name,
value: tag.name
});
}
return returnData;
},
// Get all the custom fields to display them to user so that he can
// select them easily
async getCustomFields(
this: ILoadOptionsFunctions
): Promise<INodePropertyOptions[]> {
@ -122,11 +125,9 @@ export class Automizy implements INodeType {
'/custom-fields',
);
for (const customField of customFields) {
const customFieldName = customField.name;
const customFieldId = customField.id;
returnData.push({
name: customFieldName,
value: customFieldId
name: customField.name,
value: customField.id
});
}
return returnData;
@ -144,9 +145,9 @@ export class Automizy implements INodeType {
const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < length; i++) {
if (resource === 'contactList') {
if (resource === 'contact') {
if (operation === 'add') {
if (operation === 'create') {
const listId = this.getNodeParameter('listId', i) as string;
const email = this.getNodeParameter('email', i) as string;
@ -160,7 +161,7 @@ export class Automizy implements INodeType {
Object.assign(body, additionalFields);
if (body.customFieldsUi) {
const customFieldsValues= (body.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
const customFieldsValues = (body.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
body.customFields = {};
@ -181,6 +182,28 @@ export class Automizy implements INodeType {
);
}
if (operation === 'delete') {
const contactId = this.getNodeParameter('contactId', i) as string;
responseData = await automizyApiRequest.call(
this,
'DELETE',
`/contacts/${contactId}`,
);
responseData = { success: true };
}
if (operation === 'get') {
const contactId = this.getNodeParameter('contactId', i) as string;
responseData = await automizyApiRequest.call(
this,
'GET',
`/contacts/${contactId}`,
);
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
@ -189,7 +212,7 @@ export class Automizy implements INodeType {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (additionalFields.direction && additionalFields.sortBy) {
qs.order = `${additionalFields.sortBy}:${additionalFields.direction }`;
qs.order = `${additionalFields.sortBy}:${additionalFields.direction}`;
}
if (additionalFields.fields) {
@ -221,31 +244,6 @@ export class Automizy implements INodeType {
responseData = responseData.contacts;
}
}
}
if (resource === 'contact') {
if (operation === 'delete') {
const contactId = this.getNodeParameter('contactId', i) as string;
responseData = await automizyApiRequest.call(
this,
'DELETE',
`/contacts/${contactId}`,
);
responseData = { success: true };
}
if (operation === 'get') {
const contactId = this.getNodeParameter('contactId', i) as string;
responseData = await automizyApiRequest.call(
this,
'GET',
`/contacts/${contactId}`,
);
}
if (operation === 'update') {
const email = this.getNodeParameter('email', i) as string;
@ -257,7 +255,7 @@ export class Automizy implements INodeType {
Object.assign(body, updateFields);
if (body.customFieldsUi) {
const customFieldsValues= (body.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
const customFieldsValues = (body.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
body.customFields = {};
@ -324,7 +322,7 @@ export class Automizy implements INodeType {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (additionalFields.direction && additionalFields.sortBy) {
qs.order = `${additionalFields.sortBy}:${additionalFields.direction }`;
qs.order = `${additionalFields.sortBy}:${additionalFields.direction}`;
}
if (additionalFields.fields) {

View File

@ -15,6 +15,11 @@ export const contactOperations = [
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a contact',
},
{
name: 'Delete',
value: 'delete',
@ -25,6 +30,11 @@ export const contactOperations = [
value: 'get',
description: 'Get a contact',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get all contacts',
},
{
name: 'Update',
value: 'update',
@ -38,6 +48,143 @@ export const contactOperations = [
export const contactFields = [
/* -------------------------------------------------------------------------- */
/* contact:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Email',
name: 'email',
required: true,
type: 'string',
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'contact',
],
},
},
default: '',
description: 'The email address of the contact.',
},
{
displayName: 'List ID',
name: 'listId',
required: true,
type: 'options',
typeOptions: {
loadOptionsMethod: 'getLists',
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'contact',
],
},
},
default: '',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'contact',
],
},
},
default: {},
placeholder: 'Add Field',
options: [
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
type: 'fixedCollection',
default: '',
placeholder: 'Add Custom Field',
typeOptions: {
multipleValues: true,
loadOptionsMethod: 'getCustomFields',
},
options: [
{
name: 'customFieldsValues',
displayName: 'Custom Field',
values: [
{
displayName: 'Key',
name: 'key',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCustomFields',
},
description: 'The end user specified key of the user defined data.',
default: '',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
description: 'The end user specified value of the user defined data.',
default: '',
},
],
},
],
},
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'Active',
value: 'ACTIVE',
},
{
name: 'Banned',
value: 'BANNED',
},
{
name: 'Bounced',
value: 'BOUNCED',
},
{
name: 'Inactive',
value: 'INACTIVE',
},
{
name: 'Unsubscribed',
value: 'UNSUBSCRIBED',
},
],
default: '',
description: 'The status of the contact. You can only send email to contacts with ACTIVE status.',
},
{
displayName: 'Tags',
name: 'tags',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getTags',
},
default: [],
description: 'The tags you want to set to the contact.',
},
],
},
/* -------------------------------------------------------------------------- */
/* contact:delete */
/* -------------------------------------------------------------------------- */
@ -57,8 +204,9 @@ export const contactFields = [
},
},
default: '',
description: 'Can be id or email'
description: 'Can be ID or email.'
},
/* -------------------------------------------------------------------------- */
/* contact:get */
/* -------------------------------------------------------------------------- */
@ -78,8 +226,123 @@ export const contactFields = [
},
},
default: '',
description: 'Can be id or email'
description: 'Can be ID or email',
},
/* -------------------------------------------------------------------------- */
/* contact:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'List ID',
name: 'listId',
required: true,
type: 'options',
typeOptions: {
loadOptionsMethod: 'getLists',
},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'contact',
],
},
},
default: '',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'contact',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'contact',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'contact',
],
},
},
default: {},
options: [
{
displayName: 'Direction',
name: 'direction',
type: 'options',
options: [
{
name: 'ASC',
value: 'asc',
},
{
name: 'DESC',
value: 'desc',
},
],
default: 'desc',
description: 'Defines the direction in which search results are ordered. Default value is DESC. Note: It has to be using with the Sort By parameter',
},
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: '',
description: 'A comma-separated list of attributes to include in the response.',
},
{
displayName: 'Sort By',
name: 'sortBy',
type: 'string',
default: 'Defines the field in which search results are sort by. Note: It has to be using with the Direcction parameter',
},
],
},
/* -------------------------------------------------------------------------- */
/* contact:update */
/* -------------------------------------------------------------------------- */
@ -163,20 +426,20 @@ export const contactFields = [
value: 'ACTIVE',
},
{
name: 'Inactive',
value: 'INACTIVE',
name: 'Banned',
value: 'BANNED',
},
{
name: 'Bounced',
value: 'BOUNCED',
},
{
name: 'Unsubscribed',
value: 'UNSUBSCRIBED',
name: 'Inactive',
value: 'INACTIVE',
},
{
name: 'Banned',
value: 'BANNED',
name: 'Unsubscribed',
value: 'UNSUBSCRIBED',
},
],
default: '',
@ -190,7 +453,7 @@ export const contactFields = [
loadOptionsMethod: 'getTags',
},
default: [],
description: 'The tags you want to set to the contact.',
description: 'The tags you want to set to the contact. Will replace all existing ones.',
},
],
},

View File

@ -1,278 +0,0 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const contactListOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'contactList',
],
},
},
options: [
{
name: 'Add',
value: 'add',
description: 'Add a contact to a list',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get all contacts on a list',
},
],
default: 'add',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const contactListFields = [
/* -------------------------------------------------------------------------- */
/* contactList:add */
/* -------------------------------------------------------------------------- */
{
displayName: 'Email',
name: 'email',
required: true,
type: 'string',
displayOptions: {
show: {
operation: [
'add',
],
resource: [
'contactList',
],
},
},
default: '',
description: 'The email address of the contactList',
},
{
displayName: 'List ID',
name: 'listId',
required: true,
type: 'string',
displayOptions: {
show: {
operation: [
'add',
],
resource: [
'contactList',
],
},
},
default: '',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
displayOptions: {
show: {
operation: [
'add',
],
resource: [
'contactList',
],
},
},
default: {},
placeholder: 'Add Field',
options: [
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
type: 'fixedCollection',
default: '',
placeholder: 'Add Custom Field',
typeOptions: {
multipleValues: true,
loadOptionsMethod: 'getCustomFields',
},
options: [
{
name: 'customFieldsValues',
displayName: 'Custom Field',
values: [
{
displayName: 'Key',
name: 'key',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCustomFields',
},
description: 'The end user specified key of the user defined data.',
default: '',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
description: 'The end user specified value of the user defined data.',
default: '',
},
],
},
],
},
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'Active',
value: 'ACTIVE',
},
{
name: 'Inactive',
value: 'INACTIVE',
},
{
name: 'Bounced',
value: 'BOUNCED',
},
{
name: 'Unsubscribed',
value: 'UNSUBSCRIBED',
},
{
name: 'Banned',
value: 'BANNED',
},
],
default: '',
description: 'The status of the contact. You can only send email to contacts with ACTIVE status.',
},
{
displayName: 'Tags',
name: 'tags',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getTags',
},
default: [],
description: 'The tags you want to set to the contact.',
},
],
},
/* -------------------------------------------------------------------------- */
/* contactList:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'List ID',
name: 'listId',
required: true,
type: 'string',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'contactList',
],
},
},
default: '',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'contactList',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'contactList',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'contactList',
],
},
},
default: {},
options: [
{
displayName: 'Direction',
name: 'direction',
type: 'options',
options: [
{
name: 'ASC',
value: 'asc',
},
{
name: 'DESC',
value: 'desc',
},
],
default: 'desc',
description: 'Defines the direction in which search results are ordered. Default value is DESC. Note: It has to be using with the Sort By parameter',
},
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: '',
description: 'A comma-separated list of attributes to include in the response.',
},
{
displayName: 'Sort By',
name: 'sortBy',
type: 'string',
default: 'Defines the field in which search results are sort by. Note: It has to be using with the Direcction parameter',
},
],
},
] as INodeProperties[];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB