2022-10-21 08:24:58 -07:00
|
|
|
import { deepCopy, IDataObject, INodeProperties } from 'n8n-workflow';
|
2020-12-19 09:22:41 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { groups } from './Json/Groups';
|
2020-12-19 09:22:41 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { tools } from './Json/Tools';
|
2020-12-19 09:22:41 -08:00
|
|
|
|
|
|
|
function capitalize(str: string): string {
|
|
|
|
if (!str) {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const operations = [];
|
|
|
|
|
2021-02-25 01:47:36 -08:00
|
|
|
for (const group of (groups as IDataObject).groups as IDataObject[]) {
|
2020-12-19 09:22:41 -08:00
|
|
|
const item = {
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'tool',
|
|
|
|
type: 'options',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The Operation to consume',
|
2020-12-19 09:22:41 -08:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
group: [group.name],
|
2020-12-19 09:22:41 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
2021-03-25 15:45:16 -07:00
|
|
|
options: [],
|
2020-12-19 09:22:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
const options = [];
|
2021-02-25 01:47:36 -08:00
|
|
|
for (const tool of (tools as IDataObject).processors as IDataObject[]) {
|
2020-12-19 09:22:41 -08:00
|
|
|
if (tool.g === group.name) {
|
2022-08-17 08:50:24 -07:00
|
|
|
const link =
|
|
|
|
'https://app.uproc.io/#/tools/processor/' +
|
|
|
|
(tool.k as string)
|
|
|
|
.replace(/([A-Z]+)/g, '-$1')
|
|
|
|
.toLowerCase()
|
|
|
|
.replace('-', '/')
|
|
|
|
.replace('-', '/');
|
2020-12-19 09:22:41 -08:00
|
|
|
const option = {
|
|
|
|
name: tool.d as string,
|
|
|
|
value: tool.k,
|
2021-03-25 15:45:16 -07:00
|
|
|
description: (tool.ed as string) + ` <a href="${link}" target='_blank'>Info</a>`,
|
2020-12-19 09:22:41 -08:00
|
|
|
};
|
|
|
|
options.push(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Tool
|
2022-12-02 06:25:21 -08:00
|
|
|
item.options = options.sort((a, b) => (a.name > b.name ? 1 : -1)) as any;
|
2022-08-17 08:50:24 -07:00
|
|
|
item.default = options[0].value as string;
|
2020-12-19 09:22:41 -08:00
|
|
|
operations.push(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const toolOperations = operations as INodeProperties[];
|
|
|
|
|
|
|
|
let parameters = [];
|
|
|
|
//all tools
|
2021-02-25 01:47:36 -08:00
|
|
|
for (const tool of (tools as IDataObject).processors as IDataObject[]) {
|
2020-12-19 09:22:41 -08:00
|
|
|
//all parameters in tool
|
2022-12-02 12:54:28 -08:00
|
|
|
for (const param of tool.p as IDataObject[]) {
|
2020-12-19 09:22:41 -08:00
|
|
|
const displayName = param.n as string;
|
2021-02-25 01:47:36 -08:00
|
|
|
const capitalizedDisplayName = capitalize(displayName.replace(/_/g, ' '));
|
|
|
|
const description = `The "${capitalizedDisplayName}" value to use as a parameter for this Operation`;
|
2020-12-19 09:22:41 -08:00
|
|
|
const parameter = {
|
|
|
|
displayName: capitalizedDisplayName,
|
|
|
|
name: param.n,
|
|
|
|
type: param.t,
|
|
|
|
default: '',
|
|
|
|
placeholder: param.p,
|
|
|
|
required: param.r,
|
|
|
|
options: param.o,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
group: [
|
|
|
|
//@ts-ignore
|
|
|
|
tool.g,
|
|
|
|
],
|
2022-08-17 08:50:24 -07:00
|
|
|
tool: [tool.k],
|
2020-12-19 09:22:41 -08:00
|
|
|
},
|
|
|
|
},
|
2022-10-21 08:24:58 -07:00
|
|
|
description: deepCopy(description),
|
2020-12-19 09:22:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
let modifiedParam = null;
|
|
|
|
//Check if param exists previously
|
|
|
|
for (const currentParam of parameters) {
|
|
|
|
//Get old param in parameters array
|
|
|
|
if (currentParam.name === param.n) {
|
|
|
|
modifiedParam = currentParam;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//if exists, other wise
|
|
|
|
if (modifiedParam) {
|
|
|
|
//Assign new group and tool
|
|
|
|
//@ts-ignore
|
|
|
|
modifiedParam.displayOptions.show.group.push(tool.g);
|
|
|
|
modifiedParam.displayOptions.show.tool.push(tool.k);
|
|
|
|
|
|
|
|
//build new array
|
|
|
|
const newParameters = [];
|
|
|
|
for (const currentParam of parameters) {
|
|
|
|
//Get old param in parameters array
|
|
|
|
if (currentParam.name === modifiedParam.name) {
|
|
|
|
newParameters.push(modifiedParam);
|
|
|
|
} else {
|
|
|
|
newParameters.push(currentParam);
|
|
|
|
}
|
|
|
|
}
|
2022-10-21 08:24:58 -07:00
|
|
|
// eslint-disable-next-line n8n-local-rules/no-json-parse-json-stringify
|
2020-12-19 09:22:41 -08:00
|
|
|
parameters = JSON.parse(JSON.stringify(newParameters));
|
|
|
|
} else {
|
|
|
|
parameters.push(parameter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const toolParameters = parameters as INodeProperties[];
|