n8n/packages/nodes-base/nodes/SendInBlue/AttributeDescription.ts
brianinoa 74cedd94a8
feat(SendInBlue Node): Add SendInBlue Regular + Trigger Node (#3746)
* add sendinblue svg icon

* Add code and required files for new sendinblue node

* Add node to package.json

* Update credentials to display API Key instead of Access Token

* Use new svg found in brandfetch

*  Improvements

* ♻️ Moved descriptions for email to it's own file

*  Added support for contact get

*  moved email descriptions to it's own file

*  Add logic to conditionally remove/format sms,email

*  Improvements

*  Refactor Sender descriptions to it's own file

*  Fix urls

*  Improvements attempt

*  Refactor remove inline descriptions

*  Minor improvement

* 🎨 Learn a nice way to send options as key-value

*  Improvements

* ♻️ Fix Create Operation structure

* ♻️ Refactor create functionality for attribute

♻️ Introduce override for createAttribute selectedCategory

♻️ Add delete functionality

* 🔥 Remove preSend from delete

*  Implement override for body types

*  Cleanup node file

*  Update response for contact update
 Update request url for contact delete

*  Add presend check for optional properties that are empty
 Add Model file and TransactionalEmail interface

*  formatting

* ♻️ Remove requestOperations from Node Description level

* ♻️ Cleanup routing for Get All
♻️ Make Identifier required

*  Formatting

* ♻️ Add Options Collection

* ♻️ Add Filters area

* ♻️ Formatting

* ♻️ Handle empty return

* ♻️ Remove unused code

* ♻️ Fix pagination
♻️ Fix empty return for delete

*  Add pagination

*  Fix Modified Since

* ♻️ Reorder send operation ui

*  Remove no longer needed presend
 Add send html template operation

* ♻️ Make Contact Attribute name and type required

* ♻️ Rename Attribute to Contact Attribute

* ♻️ Rename Identifier to Contact Identifier

* ♻️ Remove SMS from root level because it can exist in Contact Attributes

* ♻️ Fix Array type using 'Array<T>'
♻️ Fix double quotes should be single quotes

* 👕 Lint Fix

*  Add email attachment functionality
 Add attachment data validation

*  Add dynamic loading of Email Template IDs

* ♻️ Cleanup validation method

*  Introduce workaround and use binary data for attachments

* feat: Migrated to npm release of riot-tmpl fork.

* 👕 Lint fix rules

* 👕 Lint fix rules

* fix: Updated imports to use @n8n_io/riot-tmpl

* fix: Fixed Logger.ts types.

*  Fix mixmatch of filename and package.json credentials list

*  fix mixmatch in nodes list

* feat(core): Give access to getBinaryDataBuffer in preSend method

*  clean up mixmatches in node naming

* ♻️ Refactor code to use newly exposed getBinaryDataBuffer method

*  Improvements

* 🔥 Remove unnecessary lines

* 👕 Fix linting issues

*  Fix issues with up to date APIs and improve readability

*  update naming of files

* ♻️ Move sendHtml boolean above subject
♻️ Update naming from Parameters to Fields

* ♻️ Move sendHtml boolean above subject
♻️ Update naming from Parameters to Fields

* ♻️ Add attribute name url encoding
♻️ Change limit's default to 50

*  Fix default for templateId

*  Fix display name for attribute list

* ♻️ Add clarity to attribute value display name

* ♻️ Add tags and attachments for emails

* ♻️ Add use of item's binary data fileName

* 👕 Fix action lint rule

* 👕 Remove deprecated lint rule

* ⬆️ Update eslint-plugin-n8n-nodes-base

* 👕 Fix lint rule for file name

*  Fix update attribute

* ♻️ Add upsert capabilites

* 🔥 Remove create or update operation

* ♻️ Add sendInBlueWebhookApi namespace

* ♻️ Add Webhook API functionality

*  Add SendInBlue Trigger

*  Return correct webhookId data

*  Add placeholder for receiving data

* 👕 Fixing existing linting issues

* 🚨 Enable namespacing in tslint file

* 👕 Fix linting issues

*  Rename exported WebhookApi

* 🔥 Remove unused Model.ts file

* ♻️ Update node to use SendInBlue namespace

*  Revert back to allowing upsert functionality

* ♻️ Fix options to better describe events

* Remove update flag for create operation

* ♻️ Fix discrepancies for contact resource

* remove no-namespace lint rule

* 👕 Fix linting issues

* ♻️ Add sendInBlueWebhookApi namespace

* ♻️ Add Webhook API functionality

*  Add SendInBlue Trigger

*  Return correct webhookId data

*  Add placeholder for receiving data

* 👕 Fix linting issues

*  Rename exported WebhookApi

* ♻️ Fix options to better describe events

* Add optionswithuri import that was lost

*  Fix details from janober's review

*  Fix order of displayName and name properties

*  Fix default value and improve loadOptions

*  Introduce support for comma separated attribute values

*  Introduce support for comma separated attribute values

* 👕 Fix linting issues

* Update defaults and required props

*  Fix copy paste issue Upsert was not using correct endpoint

*  Fix upsert email field display name

*  Last update, upsert email description

*  Add PostReceived type limit

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
Co-authored-by: Alex Grozav <alex@grozav.com>
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
2022-08-03 18:08:51 +02:00

533 lines
10 KiB
TypeScript

import {
IExecuteSingleFunctions,
IHttpRequestOptions,
INodeExecutionData,
INodeProperties,
JsonObject,
} from 'n8n-workflow';
import { SendInBlueNode } from './GenericFunctions';
export const attributeOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['attribute'],
},
},
options: [
{
name: 'Create',
value: 'create',
routing: {
request: {
method: 'POST',
url: '=/v3/contacts/attributes/{{$parameter.attributeCategory}}/{{encodeURI($parameter.attributeName)}}',
},
output: {
postReceive: [
{
type: 'set',
properties: {
value: '={{ { "success": true } }}', // Also possible to use the original response data
},
},
],
},
send: {
preSend: [
async function (
this: IExecuteSingleFunctions,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
const selectedCategory = this.getNodeParameter('attributeCategory') as string;
const override = SendInBlueNode.INTERCEPTORS.get(selectedCategory);
if (override) {
override.call(this, requestOptions.body! as JsonObject);
}
return requestOptions;
},
],
},
},
action: 'Create an attribute',
},
{
name: 'Update',
value: 'update',
routing: {
request: {
method: 'PUT',
url: '=/v3/contacts/attributes/{{$parameter.updateAttributeCategory}}/{{encodeURI($parameter.updateAttributeName)}}',
},
},
action: 'Update an attribute',
},
{
name: 'Delete',
value: 'delete',
routing: {
request: {
method: 'DELETE',
url: '=/v3/contacts/attributes/{{$parameter.deleteAttributeCategory}}/{{encodeURI($parameter.deleteAttributeName)}}',
},
output: {
postReceive: [
{
type: 'set',
properties: {
value: '={{ { "success": true } }}', // Also possible to use the original response data
},
},
],
},
},
action: 'Delete an attribute',
},
{
name: 'Get All',
value: 'getAll',
routing: {
request: {
method: 'GET',
url: 'v3/contacts/attributes',
},
send: {
paginate: false,
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'attributes',
},
},
],
},
},
action: 'Get all attributes',
},
],
default: 'create',
},
];
const createAttributeOperations: INodeProperties[] = [
{
displayName: 'Category',
name: 'attributeCategory',
default: 'normal',
description: 'Category of the attribute',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['create'],
},
},
options: [
{
name: 'Calculated',
value: 'calculated',
},
{
name: 'Category',
value: 'category',
},
{
name: 'Global',
value: 'global',
},
{
name: 'Normal',
value: 'normal',
},
{
name: 'Transactional',
value: 'transactional',
},
],
type: 'options',
required: true,
},
{
displayName: 'Name',
name: 'attributeName',
default: '',
description: 'Name of the attribute',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['create'],
},
},
required: true,
type: 'string',
},
{
displayName: 'Type',
name: 'attributeType',
default: '',
description: 'Attribute Type',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['create'],
attributeCategory: ['normal'],
},
},
options: [
{
name: 'Boolean',
value: 'boolean',
},
{
name: 'Date',
value: 'date',
},
{
name: 'Float',
value: 'float',
},
{
name: 'Text',
value: 'text',
},
],
required: true,
type: 'options',
routing: {
send: {
type: 'body',
property: 'type',
value: '={{$value}}',
},
},
},
{
displayName: 'Value',
name: 'attributeValue',
default: '',
description: 'Value of the attribute',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['create'],
attributeCategory: ['global', 'calculated'],
},
},
type: 'string',
placeholder: '',
required: true,
routing: {
send: {
type: 'body',
property: 'value',
value: '={{$value}}',
},
},
},
{
displayName: 'Contact Attribute List',
name: 'attributeCategoryList',
type: 'collection',
placeholder: 'Add Attributes',
default: {},
displayOptions: {
show: {
resource: ['attribute'],
operation: ['create'],
attributeCategory: ['category'],
},
},
options: [
{
displayName: 'Contact Attributes',
name: 'categoryEnumeration',
placeholder: 'Add Attribute',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
options: [
{
name: 'attributesValues',
displayName: 'Attribute',
values: [
{
displayName: 'Value ID',
name: 'attributeCategoryValue',
type: 'number',
default: 1,
description: 'ID of the value, must be numeric',
routing: {
send: {
value: '={{$value}}',
property: '=enumeration[{{$index}}].value',
type: 'body',
},
},
},
{
displayName: 'Label',
name: 'attributeCategoryLabel',
type: 'string',
default: '',
routing: {
send: {
value: '={{$value}}',
property: '=enumeration[{{$index}}].label',
type: 'body',
},
},
description: 'Label of the value',
},
],
},
],
default: {},
description: 'List of values and labels that the attribute can take',
},
],
},
];
const updateAttributeOperations: INodeProperties[] = [
{
displayName: 'Category',
name: 'updateAttributeCategory',
default: 'calculated',
description: 'Category of the attribute',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['update'],
},
},
options: [
{
name: 'Calculated',
value: 'calculated',
},
{
name: 'Category',
value: 'category',
},
{
name: 'Global',
value: 'global',
},
],
type: 'options',
},
{
displayName: 'Name',
name: 'updateAttributeName',
default: '',
description: 'Name of the existing attribute',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['update'],
},
},
type: 'string',
},
{
displayName: 'Value',
name: 'updateAttributeValue',
default: '',
description: 'Value of the attribute to update',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['update'],
},
hide: {
updateAttributeCategory: ['category'],
},
},
type: 'string',
placeholder: '',
routing: {
send: {
type: 'body',
property: 'value',
value: '={{$value}}',
},
},
},
{
displayName: 'Update Fields',
name: 'updateAttributeCategoryList',
default: {},
description: 'List of the values and labels that the attribute can take',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['update'],
updateAttributeCategory: ['category'],
},
},
options: [
{
displayName: 'Contact Attributes',
name: 'updateCategoryEnumeration',
placeholder: 'Add Attribute',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
options: [
{
name: 'updateAttributesValues',
displayName: 'Attribute',
values: [
{
displayName: 'Value',
name: 'attributeCategoryValue',
type: 'number',
default: 1,
description: 'ID of the value, must be numeric',
routing: {
send: {
value: '={{$value}}',
property: '=enumeration[{{$index}}].value',
type: 'body',
},
},
},
{
displayName: 'Label',
name: 'attributeCategoryLabel',
type: 'string',
default: '',
routing: {
send: {
value: '={{$value}}',
property: '=enumeration[{{$index}}].label',
type: 'body',
},
},
description: 'Label of the value',
},
],
},
],
default: {},
description: 'List of values and labels that the attribute can take',
},
],
},
];
const deleteAttribueOperations: INodeProperties[] = [
{
displayName: 'Category',
name: 'deleteAttributeCategory',
default: 'normal',
description: 'Category of the attribute',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['delete'],
},
},
options: [
{
name: 'Calculated',
value: 'calculated',
},
{
name: 'Category',
value: 'category',
},
{
name: 'Global',
value: 'global',
},
{
name: 'Normal',
value: 'normal',
},
{
name: 'Transactional',
value: 'transactional',
},
],
type: 'options',
},
{
displayName: 'Name',
name: 'deleteAttributeName',
default: '',
description: 'Name of the attribute',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['delete'],
},
},
type: 'string',
},
];
const getAllAttributeOperations: INodeProperties[] = [
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['attribute'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 1000,
},
routing: {
output: {
postReceive: [
{
type: 'limit',
properties: {
maxResults: '={{$value}}',
},
},
],
},
},
default: 50,
description: 'Max number of results to return',
},
];
export const attributeFields: INodeProperties[] = [
...createAttributeOperations,
...updateAttributeOperations,
...deleteAttribueOperations,
...getAllAttributeOperations,
];