+ added new tools

This commit is contained in:
Miquel Colomer 2021-02-25 10:35:48 +01:00
parent 85703a8bf7
commit 0a0509a4ae
8 changed files with 173 additions and 168 deletions

View file

@ -7,7 +7,7 @@ export class UProcApi implements ICredentialType {
name = 'uprocApi';
displayName = 'uProc API';
properties = [
{
{
displayName: 'Email',
name: 'email',
type: 'string' as NodePropertyTypes,

View file

@ -20,12 +20,15 @@ export async function uprocApiRequest(this: IHookFunctions | IExecuteFunctions |
}
const token = Buffer.from(`${credentials.email}:${credentials.apiKey}`).toString('base64');
const options: OptionsWithUri = {
headers: { Authorization: `Basic ${token}` },
headers: {
Authorization: `Basic ${token}`,
"User-agent": "n8n"
},
method,
qs,
body,
uri: uri || `https://api.uproc.io/api/v2/process`,
json: true,
json: true
};
try {

View file

@ -1,6 +1,6 @@
import {
IDataObject,
INodeProperties,
IDataObject,
} from 'n8n-workflow';
import {
@ -18,7 +18,7 @@ const finalGroups = {
const options = [];
for (const group of (groups as IDataObject).groups as IDataObject[]) {
for(const group of (groups as IDataObject).groups as IDataObject[]){
const item = {
name: group.translated,
value: group.name,

View file

@ -1,36 +1,36 @@
export const groups = {
groups: [{
'translated': 'Audio',
'name': 'audio',
}, {
'translated': 'Communication',
'name': 'communication',
}, {
'translated': 'Company',
'name': 'company',
}, {
'translated': 'Finance',
'name': 'finance',
}, {
'translated': 'Geographical',
'name': 'geographic',
}, {
'translated': 'Image',
'name': 'image',
}, {
'translated': 'Internet',
'name': 'internet',
}, {
'translated': 'Personal',
'name': 'personal',
}, {
'translated': 'Product',
'name': 'product',
}, {
'translated': 'Security',
'name': 'security',
}, {
'translated': 'Text',
'name': 'text',
}],
groups: [{
"translated": "Audio",
"name": "audio"
}, {
"translated": "Communication",
"name": "communication"
}, {
"translated": "Company",
"name": "company"
}, {
"translated": "Finance",
"name": "finance"
}, {
"translated": "Geographical",
"name": "geographic"
}, {
"translated": "Image",
"name": "image"
}, {
"translated": "Internet",
"name": "internet"
}, {
"translated": "Personal",
"name": "personal"
}, {
"translated": "Product",
"name": "product"
}, {
"translated": "Security",
"name": "security"
}, {
"translated": "Text",
"name": "text"
}]
};

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
import {
IDataObject,
INodeProperties,
IDataObject,
} from 'n8n-workflow';
import {
@ -21,7 +21,7 @@ function capitalize(str: string): string {
const operations = [];
for (const group of (groups as IDataObject).groups as IDataObject[]) {
for(const group of (groups as IDataObject).groups as IDataObject[]) {
const item = {
displayName: 'Operation',
name: 'tool',
@ -30,30 +30,30 @@ for (const group of (groups as IDataObject).groups as IDataObject[]) {
displayOptions: {
show: {
group: [
group.name,
group.name
],
},
},
default: '',
options: [],
options: []
};
const options = [];
for (const tool of (tools as IDataObject).processors as IDataObject[]) {
for(const tool of (tools as IDataObject).processors as IDataObject[]){
if (tool.g === group.name) {
const link = 'https://app.uproc.io/#/tools/processor/' + (tool.k as string).replace(/([A-Z]+)/g, '-$1').toLowerCase().replace('-', '/').replace('-', '/');
const link = 'https://app.uproc.io/#/tools/processor/' + (tool.k as string).replace(/([A-Z]+)/g, "-$1").toLowerCase().replace('-', '/').replace('-', '/');
const option = {
name: tool.d as string,
value: tool.k,
description: (tool.ed as string) + ` <a href="${link}" target='_blank'>Info</a>`,
description: (tool.ed as string) + " <a href='" + link + "' target='_blank'>Info</a>"
};
options.push(option);
}
}
//Tool
item.options = (options.sort((a, b) => (a.name > b.name) ? 1 : -1) as any); // tslint:disable-line:no-any
item.default = (options[0].value as string);
item.options = <any>options.sort((a, b) => (a.name > b.name) ? 1 : -1);
item.default = <string>options[0].value;
operations.push(item);
}
@ -61,12 +61,12 @@ export const toolOperations = operations as INodeProperties[];
let parameters = [];
//all tools
for (const tool of (tools as IDataObject).processors as IDataObject[]) {
for(const tool of (tools as IDataObject).processors as IDataObject[]) {
//all parameters in tool
for (const param of (tool as IDataObject).p as IDataObject[]) {
const displayName = param.n as string;
const capitalizedDisplayName = capitalize(displayName.replace(/_/g, ' '));
const description = `The "${capitalizedDisplayName}" value to use as a parameter for this Operation`;
const capitalizedDisplayName = capitalize(displayName.replace(/_/g, " "));
const description = "The '" + capitalizedDisplayName + "' value to use as a parameter for this Operation";
const parameter = {
displayName: capitalizedDisplayName,
name: param.n,
@ -82,7 +82,7 @@ for (const tool of (tools as IDataObject).processors as IDataObject[]) {
tool.g,
],
tool: [
tool.k,
tool.k
],
},
},

View file

@ -1,143 +1,145 @@
import {
IExecuteFunctions,
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import {
uprocApiRequest,
uprocApiRequest,
} from './GenericFunctions';
import {
groupOptions,
groupOptions,
} from './GroupDescription';
import {
toolOperations,
toolParameters,
toolOperations,
toolParameters,
} from './ToolDescription';
export class UProc implements INodeType {
description: INodeTypeDescription = {
displayName: 'uProc',
name: 'uproc',
icon: 'file:uproc.png',
group: ['output'],
version: 1,
subtitle: '={{$parameter["tool"]}}',
description: 'Consume uProc API',
defaults: {
name: 'uProc',
color: '#219ef9',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'uprocApi',
required: true,
},
],
properties: [
...groupOptions,
...toolOperations,
...toolParameters,
{
displayName: 'Additional Options',
name: 'additionalOptions',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
group: [
'audio',
'communication',
'company',
'finance',
'geographic',
'image',
'internet',
'personal',
'product',
'security',
'text',
],
},
},
options: [
{
displayName: 'Data Webhook',
name: 'dataWebhook',
type: 'string',
description: 'URL to send tool response when tool has resolved your request. You can create your own webhook at <a href="https://beeceptor.com" target="_blank">Beeceptor</a>, <a href="https://www.integromat.com/" target="_blank">Integromat</a>, <a href="https://zapier.com/" target="_blank">Zapier</a> or <a href="https://n8n.io/" target="_blank">n8n</a>',
default: '',
},
],
},
],
};
description: INodeTypeDescription = {
displayName: 'uProc',
name: 'uproc',
icon: 'file:uproc.png',
group: ['output'],
version: 1,
subtitle: '={{$parameter["tool"]}}',
description: 'Consume uProc API',
defaults: {
name: 'uProc',
color: '#219ef9',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'uprocApi',
required: true,
},
],
properties: [
...groupOptions,
...toolOperations,
...toolParameters,
{
displayName: 'Additional Options',
name: 'additionalOptions',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
group: [
'audio',
'communication',
'company',
'finance',
'geographic',
'image',
'internet',
'personal',
'product',
'security',
'text',
],
},
},
options: [
{
displayName: 'Data Webhook',
name: 'dataWebhook',
type: 'string',
description: 'URL to send tool response when tool has resolved your request. You can create your own webhook at en <a href="https://beeceptor.com" target="_blank">Beeceptor</a>, <a href="https://www.integromat.com/" target="_blank">Integromat</a>, <a href="https://zapier.com/" target="_blank">Zapier</a> or <a href="https://n8n.io/" target="_blank">n8n</a>',
default: '',
}
]
}
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
let responseData;
const group = this.getNodeParameter('group', 0) as string;
const tool = this.getNodeParameter('tool', 0) as string;
const additionalOptions = this.getNodeParameter('additionalOptions', 0) as IDataObject;
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
let responseData;
const group = this.getNodeParameter('group', 0) as string;
const tool = this.getNodeParameter('tool', 0) as string;
const additionalOptions = this.getNodeParameter('additionalOptions', 0) as IDataObject;
const dataWebhook = additionalOptions.dataWebhook as string;
const dataWebhook = additionalOptions.dataWebhook as string;
interface LooseObject {
[key: string]: any; // tslint:disable-line:no-any
}
interface LooseObject {
[key: string]: any;
}
const fields = toolParameters.filter((field) => {
return field && field.displayOptions && field.displayOptions.show && field.displayOptions.show.group && field.displayOptions.show.tool &&
field.displayOptions.show.group.indexOf(group) !== -1 && field.displayOptions.show.tool.indexOf(tool) !== -1;
}).map((field) => {
return field.name;
});
const fields = toolParameters.filter((field) => {
return field && field.displayOptions && field.displayOptions.show && field.displayOptions.show.group && field.displayOptions.show.tool &&
field.displayOptions.show.group.indexOf(group) !== -1 && field.displayOptions.show.tool.indexOf(tool) !== -1;
}).map((field) => {
return field.name;
});
const requestPromises = [];
for (let i = 0; i < length; i++) {
const toolKey = tool.replace(/([A-Z]+)/g, '-$1').toLowerCase();
const body: LooseObject = {
processor: toolKey,
params: {},
};
const requestPromises = [];
for (let i = 0; i < length; i++) {
const toolKey = tool.replace(/([A-Z]+)/g, "-$1").toLowerCase();
const body: LooseObject = {
processor: toolKey,
params: {}
};
fields.forEach((field) => {
if (field && field.length) {
const data = this.getNodeParameter(field, i) as string;
body.params[field] = data + '';
}
});
//console.log(fields);
fields.forEach((field) => {
if (field && field.length) {
const data = this.getNodeParameter(field, i) as string;
//console.log(field, data);
body.params[field] = data + "";
}
});
if (dataWebhook && dataWebhook.length) {
body.callback = {};
}
if (dataWebhook && dataWebhook.length) {
body.callback = {};
}
if (dataWebhook && dataWebhook.length) {
body.callback.data = dataWebhook;
}
if (dataWebhook && dataWebhook.length) {
body.callback.data = dataWebhook;
}
//Change to multiple requests
responseData = await uprocApiRequest.call(this, 'POST', body);
//Change to multiple requests
responseData = await uprocApiRequest.call(this, 'POST', body);
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
}
}
return [this.helpers.returnJsonArray(returnData)];
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB