mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
sync upstream master
This commit is contained in:
75
packages/nodes-base/nodes/ExecuteWorkflow.node.ts
Normal file
75
packages/nodes-base/nodes/ExecuteWorkflow.node.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
|
||||
export class ExecuteWorkflow implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Execute Workflow',
|
||||
name: 'executeWorkflow',
|
||||
icon: 'fa:network-wired',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
subtitle: '={{"Workflow: " + $parameter["workflowId"]}}',
|
||||
description: 'Execute another workflow',
|
||||
defaults: {
|
||||
name: 'Execute Workflow',
|
||||
color: '#ff6d5a',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Workflow',
|
||||
name: 'workflowId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getWorkflows',
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'The workflow to execute.',
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getWorkflows(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const options: OptionsWithUri = {
|
||||
method: 'GET',
|
||||
uri: this.getRestApiUrl() + '/workflows',
|
||||
json: true
|
||||
};
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
|
||||
const responseData = await this.helpers.request!(options);
|
||||
for (const workflowData of responseData.data) {
|
||||
returnData.push({
|
||||
name: workflowData.name,
|
||||
value: workflowData.id,
|
||||
});
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const workflowId = this.getNodeParameter('workflowId', 0) as string;
|
||||
const receivedData = await this.executeWorkflow(workflowId, items);
|
||||
|
||||
return receivedData;
|
||||
}
|
||||
}
|
||||
@@ -221,10 +221,14 @@ export class GraphQL implements INodeType {
|
||||
});
|
||||
} else {
|
||||
if (typeof response === 'string') {
|
||||
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
|
||||
try {
|
||||
returnItems.push({ json: JSON.parse(response) });
|
||||
} catch (e) {
|
||||
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
|
||||
}
|
||||
} else {
|
||||
returnItems.push({ json: response });
|
||||
}
|
||||
|
||||
returnItems.push({ json: response });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ export class MoveBinaryData implements INodeType {
|
||||
}
|
||||
|
||||
const encoding = (options.encoding as string) || 'utf8';
|
||||
let convertedValue = new Buffer(value.data, 'base64').toString(encoding);
|
||||
let convertedValue = Buffer.from(value.data, 'base64').toString(encoding);
|
||||
|
||||
if (setAllData === true) {
|
||||
// Set the full data
|
||||
@@ -321,7 +321,7 @@ export class MoveBinaryData implements INodeType {
|
||||
}
|
||||
|
||||
const convertedValue = {
|
||||
data: new Buffer(value as string).toString('base64'),
|
||||
data: Buffer.from(value as string).toString('base64'),
|
||||
mimeType: options.mimeType || 'application/json',
|
||||
};
|
||||
set(newItem.binary!, destinationKey, convertedValue);
|
||||
|
||||
245
packages/nodes-base/nodes/Vero/EventDescripion.ts
Normal file
245
packages/nodes-base/nodes/Vero/EventDescripion.ts
Normal file
@@ -0,0 +1,245 @@
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const eventOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Track',
|
||||
value: 'track',
|
||||
description: `This endpoint tracks an event for a specific customer.
|
||||
If the customer profile doesn’t exist, Vero will create it.`,
|
||||
},
|
||||
],
|
||||
default: 'track',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
||||
export const eventFields = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* event:track */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
operation: [
|
||||
'track',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The unique identifier of the customer',
|
||||
},
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
operation: [
|
||||
'track',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'Email',
|
||||
},
|
||||
{
|
||||
displayName: 'Event Name',
|
||||
name: 'eventName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
operation: [
|
||||
'track',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The name of the event tracked.',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
operation: [
|
||||
'track',
|
||||
]
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
displayName: 'Data',
|
||||
name: 'dataAttributesUi',
|
||||
placeholder: 'Add Data',
|
||||
description: 'key value pairs that represent any properties you want to track with this event',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
operation: [
|
||||
'track',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'dataAttributesValues',
|
||||
displayName: 'Data',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Key',
|
||||
name: 'key',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of the property to set.',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the property to set.',
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Extra',
|
||||
name: 'extraAttributesUi',
|
||||
placeholder: 'Add Extra',
|
||||
description: 'Key value pairs that represent reserved, Vero-specific operators. Refer to the note on “deduplication” below.',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
operation: [
|
||||
'track',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'extraAttributesValues',
|
||||
displayName: 'Extra',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Key',
|
||||
name: 'key',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of the property to set.',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the property to set.',
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Data',
|
||||
name: 'dataAttributesJson',
|
||||
type: 'json',
|
||||
default: '',
|
||||
required: false,
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
description: 'key value pairs that represent the custom user properties you want to update',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
operation: [
|
||||
'track',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Extra',
|
||||
name: 'extraAttributesJson',
|
||||
type: 'json',
|
||||
default: '',
|
||||
required: false,
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
description: 'Key value pairs that represent reserved, Vero-specific operators. Refer to the note on “deduplication” below.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'event',
|
||||
],
|
||||
operation: [
|
||||
'track',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
] as INodeProperties[];
|
||||
50
packages/nodes-base/nodes/Vero/GenericFunctions.ts
Normal file
50
packages/nodes-base/nodes/Vero/GenericFunctions.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { OptionsWithUri } from 'request';
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IDataObject } from 'n8n-workflow';
|
||||
|
||||
export async function veroApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('veroApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
let options: OptionsWithUri = {
|
||||
method,
|
||||
qs,
|
||||
body,
|
||||
form: {
|
||||
auth_token: credentials.authToken,
|
||||
...body,
|
||||
},
|
||||
uri: uri ||`https://api.getvero.com/api/v2${resource}`,
|
||||
json: true
|
||||
};
|
||||
options = Object.assign({}, options, option);
|
||||
if (Object.keys(options.body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
let errorMessage = error.message;
|
||||
if (error.response.body) {
|
||||
errorMessage = error.response.body.message || error.response.body.Message || error.message;
|
||||
}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(json!);
|
||||
} catch (exception) {
|
||||
result = undefined;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
376
packages/nodes-base/nodes/Vero/UserDescription.ts
Normal file
376
packages/nodes-base/nodes/Vero/UserDescription.ts
Normal file
@@ -0,0 +1,376 @@
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const userOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create/Update',
|
||||
value: 'create',
|
||||
description: `Creates a new user profile if the user doesn’t exist yet.
|
||||
Otherwise, the user profile is updated based on the properties provided.`,
|
||||
},
|
||||
{
|
||||
name: 'Alias',
|
||||
value: 'alias',
|
||||
description: 'Changes a user’s identifier.',
|
||||
},
|
||||
{
|
||||
name: 'Unsubscribe',
|
||||
value: 'unsubscribe',
|
||||
description: 'Unsubscribes a single user.',
|
||||
},
|
||||
{
|
||||
name: 'Re-subscribe',
|
||||
value: 'resubscribe',
|
||||
description: 'Resubscribe a single user.',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a single user.',
|
||||
},
|
||||
{
|
||||
name: 'Add Tags',
|
||||
value: 'addTags',
|
||||
description: 'Adds a tag to a user’s profile.',
|
||||
},
|
||||
{
|
||||
name: 'Remove Tags',
|
||||
value: 'removeTags',
|
||||
description: 'Removes a tag from a user’s profile.',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
||||
export const userFields = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The unique identifier of the customer',
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
]
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Email',
|
||||
name: 'email',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The table to create the row in.',
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Data',
|
||||
name: 'dataAttributesUi',
|
||||
placeholder: 'Add Data',
|
||||
description: 'key value pairs that represent the custom user properties you want to update',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'dataAttributesValues',
|
||||
displayName: 'Data',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Key',
|
||||
name: 'key',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of the property to set.',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the property to set.',
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Data',
|
||||
name: 'dataAttributesJson',
|
||||
type: 'json',
|
||||
default: '',
|
||||
required: false,
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
description: 'key value pairs that represent the custom user properties you want to update',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:alias */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'alias',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The old unique identifier of the user',
|
||||
},
|
||||
{
|
||||
displayName: 'New ID',
|
||||
name: 'newId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'alias',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The new unique identifier of the user',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:unsubscribe */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'unsubscribe',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The unique identifier of the user',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:resubscribe */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'resubscribe',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The unique identifier of the user',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The unique identifier of the user',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:addTags */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'addTags',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The unique identifier of the user',
|
||||
},
|
||||
{
|
||||
displayName: 'Tags',
|
||||
name: 'tags',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'addTags',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'Tags to add separated by ","',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* user:removeTags */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'removeTags',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'The unique identifier of the user',
|
||||
},
|
||||
{
|
||||
displayName: 'Tags',
|
||||
name: 'tags',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'user',
|
||||
],
|
||||
operation: [
|
||||
'removeTags',
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'Tags to remove separated by ","',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
232
packages/nodes-base/nodes/Vero/Vero.node.ts
Normal file
232
packages/nodes-base/nodes/Vero/Vero.node.ts
Normal file
@@ -0,0 +1,232 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import {
|
||||
IDataObject,
|
||||
INodeTypeDescription,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
veroApiRequest,
|
||||
validateJSON,
|
||||
} from './GenericFunctions';
|
||||
import {
|
||||
userOperations,
|
||||
userFields,
|
||||
} from './UserDescription';
|
||||
import {
|
||||
eventOperations,
|
||||
eventFields
|
||||
} from './EventDescripion';
|
||||
|
||||
export class Vero implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Vero',
|
||||
name: 'vero',
|
||||
icon: 'file:vero.png',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Vero API',
|
||||
defaults: {
|
||||
name: 'Vero',
|
||||
color: '#c02428',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'veroApi',
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'User',
|
||||
value: 'user',
|
||||
description: `Lets you create, update and manage the subscription status of your users.`,
|
||||
},
|
||||
{
|
||||
name: 'Event',
|
||||
value: 'event',
|
||||
description: `Lets you track events based on actions your customers take in real time.`,
|
||||
},
|
||||
],
|
||||
default: 'user',
|
||||
description: 'Resource to consume.',
|
||||
},
|
||||
...userOperations,
|
||||
...eventOperations,
|
||||
...userFields,
|
||||
...eventFields,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length as unknown as number;
|
||||
let responseData;
|
||||
for (let i = 0; i < length; i++) {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
//https://developers.getvero.com/?bash#users
|
||||
if (resource === 'user') {
|
||||
//https://developers.getvero.com/?bash#users-identify
|
||||
if (operation === 'create') {
|
||||
const id = this.getNodeParameter('id', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
const jsonActive = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
const body = {
|
||||
id,
|
||||
};
|
||||
if (additionalFields.email) {
|
||||
// @ts-ignore
|
||||
body.email = additionalFields.email as string;
|
||||
}
|
||||
if (!jsonActive) {
|
||||
const dataAttributesValues = (this.getNodeParameter('dataAttributesUi', i) as IDataObject).dataAttributesValues as IDataObject[];
|
||||
if (dataAttributesValues) {
|
||||
const dataAttributes = {};
|
||||
for (let i = 0; i < dataAttributesValues.length; i++) {
|
||||
// @ts-ignore
|
||||
dataAttributes[dataAttributesValues[i].key] = dataAttributesValues[i].value;
|
||||
// @ts-ignore
|
||||
body.data = dataAttributes;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const dataAttributesJson = validateJSON(this.getNodeParameter('dataAttributesJson', i) as string);
|
||||
if (dataAttributesJson) {
|
||||
// @ts-ignore
|
||||
body.data = dataAttributesJson;
|
||||
}
|
||||
}
|
||||
try {
|
||||
responseData = await veroApiRequest.call(this, 'POST', '/users/track', body);
|
||||
} catch (err) {
|
||||
throw new Error(`Vero Error: ${err}`);
|
||||
}
|
||||
}
|
||||
//https://developers.getvero.com/?bash#users-alias
|
||||
if (operation === 'alias') {
|
||||
const id = this.getNodeParameter('id', i) as string;
|
||||
const newId = this.getNodeParameter('newId', i) as string;
|
||||
const body = {
|
||||
id,
|
||||
new_id: newId,
|
||||
};
|
||||
try {
|
||||
responseData = await veroApiRequest.call(this, 'PUT', '/users/reidentify', body);
|
||||
} catch (err) {
|
||||
throw new Error(`Vero Error: ${err}`);
|
||||
}
|
||||
}
|
||||
//https://developers.getvero.com/?bash#users-unsubscribe
|
||||
//https://developers.getvero.com/?bash#users-resubscribe
|
||||
//https://developers.getvero.com/?bash#users-delete
|
||||
if (operation === 'unsubscribe' ||
|
||||
operation === 'resubscribe' ||
|
||||
operation === 'delete') {
|
||||
const id = this.getNodeParameter('id', i) as string;
|
||||
const body = {
|
||||
id,
|
||||
};
|
||||
try {
|
||||
responseData = await veroApiRequest.call(this, 'POST', `/users/${operation}`, body);
|
||||
} catch (err) {
|
||||
throw new Error(`Vero Error: ${err}`);
|
||||
}
|
||||
}
|
||||
//https://developers.getvero.com/?bash#tags-add
|
||||
//https://developers.getvero.com/?bash#tags-remove
|
||||
if (operation === 'addTags' ||
|
||||
operation === 'removeTags') {
|
||||
const id = this.getNodeParameter('id', i) as string;
|
||||
const tags = (this.getNodeParameter('tags', i) as string).split(',') as string[];
|
||||
const body = {
|
||||
id,
|
||||
};
|
||||
if (operation === 'addTags') {
|
||||
// @ts-ignore
|
||||
body.add = JSON.stringify(tags);
|
||||
}
|
||||
if (operation === 'removeTags') {
|
||||
// @ts-ignore
|
||||
body.remove = JSON.stringify(tags);
|
||||
}
|
||||
try {
|
||||
responseData = await veroApiRequest.call(this, 'PUT', '/users/tags/edit', body);
|
||||
} catch (err) {
|
||||
throw new Error(`Vero Error: ${err}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//https://developers.getvero.com/?bash#events
|
||||
if (resource === 'event') {
|
||||
//https://developers.getvero.com/?bash#events-track
|
||||
if (operation === 'track') {
|
||||
const id = this.getNodeParameter('id', i) as string;
|
||||
const email = this.getNodeParameter('email', i) as string;
|
||||
const eventName = this.getNodeParameter('eventName', i) as string;
|
||||
const jsonActive = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
const body = {
|
||||
identity: { id, email },
|
||||
event_name: eventName,
|
||||
email,
|
||||
};
|
||||
if (!jsonActive) {
|
||||
const dataAttributesValues = (this.getNodeParameter('dataAttributesUi', i) as IDataObject).dataAttributesValues as IDataObject[];
|
||||
if (dataAttributesValues) {
|
||||
const dataAttributes = {};
|
||||
for (let i = 0; i < dataAttributesValues.length; i++) {
|
||||
// @ts-ignore
|
||||
dataAttributes[dataAttributesValues[i].key] = dataAttributesValues[i].value;
|
||||
// @ts-ignore
|
||||
body.data = JSON.stringify(dataAttributes);
|
||||
}
|
||||
}
|
||||
const extraAttributesValues = (this.getNodeParameter('extraAttributesUi', i) as IDataObject).extraAttributesValues as IDataObject[];
|
||||
if (extraAttributesValues) {
|
||||
const extraAttributes = {};
|
||||
for (let i = 0; i < extraAttributesValues.length; i++) {
|
||||
// @ts-ignore
|
||||
extraAttributes[extraAttributesValues[i].key] = extraAttributesValues[i].value;
|
||||
// @ts-ignore
|
||||
body.extras = JSON.stringify(extraAttributes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const dataAttributesJson = validateJSON(this.getNodeParameter('dataAttributesJson', i) as string);
|
||||
if (dataAttributesJson) {
|
||||
// @ts-ignore
|
||||
body.data = JSON.stringify(dataAttributesJson);
|
||||
}
|
||||
const extraAttributesJson = validateJSON(this.getNodeParameter('extraAttributesJson', i) as string);
|
||||
if (extraAttributesJson) {
|
||||
// @ts-ignore
|
||||
body.extras = JSON.stringify(extraAttributesJson);
|
||||
}
|
||||
}
|
||||
try {
|
||||
responseData = await veroApiRequest.call(this, 'POST', '/events/track', body);
|
||||
} catch (err) {
|
||||
throw new Error(`Vero Error: ${err}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
}
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
BIN
packages/nodes-base/nodes/Vero/vero.png
Normal file
BIN
packages/nodes-base/nodes/Vero/vero.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
@@ -4,6 +4,7 @@ import {
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeTypeDescription,
|
||||
INodeType,
|
||||
IWebhookResponseData,
|
||||
@@ -119,7 +120,6 @@ export class Webhook implements INodeType {
|
||||
default: 'GET',
|
||||
description: 'The HTTP method to liste to.',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'Path',
|
||||
name: 'path',
|
||||
@@ -205,21 +205,10 @@ export class Webhook implements INodeType {
|
||||
},
|
||||
description: 'Name of the binary property to return',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
responseData: [
|
||||
'firstEntryJson',
|
||||
],
|
||||
responseMode: [
|
||||
'lastNode',
|
||||
],
|
||||
},
|
||||
},
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
@@ -227,6 +216,16 @@ export class Webhook implements INodeType {
|
||||
displayName: 'Response Content-Type',
|
||||
name: 'responseContentType',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/responseData': [
|
||||
'firstEntryJson',
|
||||
],
|
||||
'/responseMode': [
|
||||
'lastNode',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
placeholder: 'application/xml',
|
||||
description: 'Set a custom content-type to return if another one as the "application/json" should be returned.',
|
||||
@@ -235,18 +234,35 @@ export class Webhook implements INodeType {
|
||||
displayName: 'Property Name',
|
||||
name: 'responsePropertyName',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/responseData': [
|
||||
'firstEntryJson',
|
||||
],
|
||||
'/responseMode': [
|
||||
'lastNode',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 'data',
|
||||
description: 'Name of the property to return the data of instead of the whole JSON.',
|
||||
},
|
||||
{
|
||||
displayName: 'Raw Body',
|
||||
name: 'rawBody',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Raw body (binary)',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||
const authentication = this.getNodeParameter('authentication', 0) as string;
|
||||
const options = this.getNodeParameter('options', 0) as IDataObject;
|
||||
const req = this.getRequestObject();
|
||||
const resp = this.getResponseObject();
|
||||
const headers = this.getHeaderData();
|
||||
@@ -289,19 +305,31 @@ export class Webhook implements INodeType {
|
||||
}
|
||||
}
|
||||
|
||||
const returnData: IDataObject[] = [];
|
||||
// @ts-ignore
|
||||
const mimeType = headers['content-type'] || 'application/json';
|
||||
|
||||
returnData.push(
|
||||
{
|
||||
const response: INodeExecutionData = {
|
||||
json: {
|
||||
body: this.getBodyData(),
|
||||
headers,
|
||||
query: this.getQueryData(),
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
if (options.rawBody) {
|
||||
response.binary = {
|
||||
data: {
|
||||
// @ts-ignore
|
||||
data: req.rawBody.toString('base64'),
|
||||
mimeType,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
workflowData: [
|
||||
this.helpers.returnJsonArray(returnData)
|
||||
[
|
||||
response,
|
||||
],
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ export class WriteBinaryFile implements INodeType {
|
||||
const fileName = this.getNodeParameter('fileName') as string;
|
||||
|
||||
if (item.binary === undefined) {
|
||||
return item;
|
||||
throw new Error('No binary data set. So file can not be written!');
|
||||
}
|
||||
|
||||
if (item.binary[dataPropertyName] === undefined) {
|
||||
return item;
|
||||
throw new Error(`The binary property "${dataPropertyName}" does not exist. So no file can be written!`);
|
||||
}
|
||||
|
||||
// Write the file to disk
|
||||
|
||||
Reference in New Issue
Block a user