Add n8n training nodes (#1898)

*  n8n training node

*  Improvements

*  cosmetic changes

*  Improvements

*  Formatting fix

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza 2021-06-27 02:55:33 -04:00 committed by GitHub
parent 7dea5d8a4b
commit ce885e5071
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 246 additions and 0 deletions

View file

@ -0,0 +1,162 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
const data = [
{
id: '23423532',
name: 'Jay Gatsby',
email: 'gatsby@west-egg.com',
notes: 'Keeps asking about a green light??',
country: 'US',
created: '1925-04-10',
},
{
id: '23423533',
name: 'José Arcadio Buendía',
email: 'jab@macondo.co',
notes: 'Lots of people named after him. Very confusing',
country: 'CO',
created: '1967-05-05',
},
{
id: '23423534',
name: 'Max Sendak',
email: 'info@in-and-out-of-weeks.org',
notes: 'Keeps rolling his terrible eyes',
country: 'US',
created: '1963-04-09',
},
{
id: '23423535',
name: 'Zaphod Beeblebrox',
email: 'captain@heartofgold.com',
notes: 'Felt like I was talking to more than one person',
country: null,
created: '1979-10-12',
},
{
id: '23423536',
name: 'Edmund Pevensie',
email: 'edmund@narnia.gov',
notes: 'Passionate sailor',
country: 'UK',
created: '1950-10-16',
},
];
export class N8nTrainingCustomerDatastore implements INodeType {
description: INodeTypeDescription = {
displayName: 'Customer Datastore (n8n training)',
name: 'n8nTrainingCustomerDatastore',
icon: 'file:n8nTrainingCustomerDatastore.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"]}}',
description: 'Dummy node used for n8n training',
defaults: {
name: 'Customer Datastore',
color: '#ff6d5a',
},
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
options: [
{
name: 'Get One Person',
value: 'getOnePerson',
description: 'Get one person',
},
{
name: 'Get All People',
value: 'getAllPeople',
description: 'Get all people',
},
],
default: 'getOnePerson',
description: 'The operation to perform.',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAllPeople',
],
},
},
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: [
'getAllPeople',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 10,
},
default: 5,
description: 'How many results to return.',
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = (items.length as unknown) as number;
const operation = this.getNodeParameter('operation', 0) as string;
let responseData;
for (let i = 0; i < length; i++) {
if (operation === 'getOnePerson') {
responseData = data[0];
}
if (operation === 'getAllPeople') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll === true) {
responseData = data;
} else {
const limit = this.getNodeParameter('limit', i) as number;
responseData = data.splice(0, limit);
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}

View file

@ -0,0 +1,65 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
export class N8nTrainingCustomerMessenger implements INodeType {
description: INodeTypeDescription = {
displayName: 'Customer Messenger (n8n training)',
name: 'n8nTrainingCustomeMessenger',
icon: 'file:n8nTrainingCustomerMessenger.svg',
group: ['transform'],
version: 1,
description: 'Dummy node used for n8n training',
defaults: {
name: 'Customer Messenger',
color: '#ff6d5a',
},
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Customer ID',
name: 'customerId',
type: 'string',
required: true,
default: '',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
required: true,
typeOptions: {
rows: 4,
},
default: '',
},
],
};
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 customerId = this.getNodeParameter('customerId', i) as string;
const message = this.getNodeParameter('message', i) as string;
responseData = { output: `Sent message to customer ${customerId}: ${message}` };
returnData.push(responseData);
}
return [this.helpers.returnJsonArray(returnData)];
}
}

View file

@ -0,0 +1,13 @@
<svg width="200" height="200" viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0)">
<path d="M39.44 104.77C38.6 104.26 37.53 104.85 37.53 105.83V132.23C37.53 143.47 65.52 152.64 100.03 152.64C134.54 152.64 162.53 143.47 162.53 132.23V105.83C162.53 104.85 161.46 104.26 160.62 104.77C146.86 113.17 123.41 117.09 100.03 117.09C76.65 117.09 53.2 113.16 39.44 104.77Z" fill="#717172"/>
<path d="M39.44 149.41C38.6 148.9 37.53 149.49 37.53 150.47V176.87C37.53 188.11 65.52 197.28 100.03 197.28C134.54 197.28 162.53 188.11 162.53 176.87V150.47C162.53 149.49 161.46 148.9 160.62 149.41C146.86 157.81 123.41 161.73 100.03 161.73C76.65 161.73 53.2 157.81 39.44 149.41Z" fill="#717172"/>
<path d="M109.51 82.54C106.43 83.49 103.24 83.97 100.03 83.97C96.78 83.97 93.57 83.49 90.49 82.55L39.65 66.93C39.05 66.75 38.39 67.03 38.14 67.6C37.73 68.54 37.52 69.49 37.52 70.46V87.59C37.52 98.83 65.51 108 100.02 108C134.53 108 162.52 98.83 162.52 87.59V70.46C162.52 69.48 162.31 68.52 161.9 67.58C161.65 67.01 160.99 66.73 160.39 66.91L109.51 82.54Z" fill="#717172"/>
<path d="M194.48 30.59L107.31 3.81C102.56 2.35 97.43 2.35 92.69 3.81L5.52 30.59C-1.84 32.85 -1.84 42.58 5.52 44.84L20.72 49.51C17.39 53.63 15.34 58.66 15.13 64.17C12.12 65.89 10 69 10 72.72C10 76.09 11.78 78.92 14.33 80.74L6.35 116.64C5.66 119.76 8.03 122.72 11.23 122.72H28.76C31.96 122.72 34.34 119.76 33.64 116.64L25.66 80.74C28.22 78.93 29.99 76.09 29.99 72.72C29.99 69.1 27.97 66.08 25.1 64.32C25.34 59.63 27.74 55.48 31.57 52.84L92.69 71.62C95.52 72.49 100.95 73.57 107.31 71.62L194.48 44.84C201.84 42.58 201.84 32.86 194.48 30.59Z" fill="#FF6D5A"/>
</g>
<defs>
<clipPath id="clip0">
<rect width="200" height="200" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -0,0 +1,4 @@
<svg width="200" height="200" viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.13001 36.125C-1.23999 38.085 -1.23999 46.495 5.13001 48.455L80.56 71.625C86.06 73.315 90.76 72.375 93.21 71.625L146.09 55.375C149.4 57.655 154.08 63.545 156.81 66.555C155.85 69.305 156.16 72.435 158.15 74.855C160 77.105 162.74 78.025 165.45 77.835L179.83 106.225C181.08 108.695 184.3 109.375 186.44 107.615L198.17 97.985C200.31 96.225 200.27 92.945 198.09 91.235L173.04 71.625C173.75 69.005 173.39 66.135 171.54 63.885C169.5 61.405 166.37 60.485 163.41 60.985C160.25 57.415 158.38 56.065 155.5 52.495L168.65 48.455C175.02 46.495 175.02 38.085 168.65 36.125L93.21 12.945C89.1 11.685 84.67 11.685 80.56 12.945L5.13001 36.125Z" fill="#FF6D5A"/>
<path d="M134.621 70.931C133.536 70.6428 132.381 70.6515 131.278 70.9921L94.6157 82.2414C91.9644 83.0536 89.2081 83.4641 86.4431 83.4641C83.6431 83.4641 80.8781 83.0536 78.2268 82.2414L41.8703 71.0969C40.1815 70.5816 38.3615 70.8262 36.8827 71.7607C36.0077 72.3721 35.1502 73.0009 34.3189 73.6472C34.2052 73.7346 34.1002 73.8219 33.9864 73.9005C33.8202 74.0315 33.6627 74.1538 33.4964 74.2848C19.6101 85.403 11 100.853 11 117.937C11 132.566 17.3263 145.955 27.8439 156.488C24.1514 171.345 11.805 184.594 11.6563 184.742C11.0088 185.424 10.825 186.419 11.21 187.31C11.595 188.192 12.4175 188.725 13.3713 188.725C32.9627 188.725 47.6453 179.345 54.9166 173.563C64.5767 177.188 75.3043 179.284 86.6531 179.284C107.452 179.284 126.291 172.471 139.967 161.458C153.582 150.366 162 135.073 162 118.173C162 99.1677 151.351 82.189 134.621 70.931Z" fill="#717172"/>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -463,6 +463,8 @@
"dist/nodes/NoOp.node.js", "dist/nodes/NoOp.node.js",
"dist/nodes/Notion/Notion.node.js", "dist/nodes/Notion/Notion.node.js",
"dist/nodes/Notion/NotionTrigger.node.js", "dist/nodes/Notion/NotionTrigger.node.js",
"dist/nodes/N8nTrainingCustomerDatastore.node.js",
"dist/nodes/N8nTrainingCustomerMessenger.node.js",
"dist/nodes/OpenThesaurus/OpenThesaurus.node.js", "dist/nodes/OpenThesaurus/OpenThesaurus.node.js",
"dist/nodes/OpenWeatherMap.node.js", "dist/nodes/OpenWeatherMap.node.js",
"dist/nodes/Orbit/Orbit.node.js", "dist/nodes/Orbit/Orbit.node.js",