mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-12-17 09:43:01 -06:00
Outgrow Trigger V1
This commit is contained in:
parent
e863c55657
commit
24f7ae4a19
14 changed files with 564 additions and 585 deletions
|
|
@ -1,77 +0,0 @@
|
|||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
export class ExampleNode implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Example Node',
|
||||
name: 'exampleNode',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
description: 'Basic Example Node',
|
||||
defaults: {
|
||||
name: 'Example Node',
|
||||
},
|
||||
inputs: [NodeConnectionType.Main],
|
||||
outputs: [NodeConnectionType.Main],
|
||||
usableAsTool: true,
|
||||
properties: [
|
||||
// Node properties which the user gets displayed and
|
||||
// can change on the node.
|
||||
{
|
||||
displayName: 'My String',
|
||||
name: 'myString',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'Placeholder value',
|
||||
description: 'The description text',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// The function below is responsible for actually doing whatever this node
|
||||
// is supposed to do. In this case, we're just appending the `myString` property
|
||||
// with whatever the user has entered.
|
||||
// You can make async calls and use `await`.
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
|
||||
let item: INodeExecutionData;
|
||||
let myString: string;
|
||||
|
||||
// Iterates over all input items and add the key "myString" with the
|
||||
// value the parameter "myString" resolves to.
|
||||
// (This could be a different value for each item in case it contains an expression)
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
try {
|
||||
myString = this.getNodeParameter('myString', itemIndex, '') as string;
|
||||
item = items[itemIndex];
|
||||
|
||||
item.json.myString = myString;
|
||||
} catch (error) {
|
||||
// This node should never fail but we want to showcase how
|
||||
// to handle errors.
|
||||
if (this.continueOnFail()) {
|
||||
items.push({ json: this.getInputData(itemIndex)[0].json, error, pairedItem: itemIndex });
|
||||
} else {
|
||||
// Adding `itemIndex` allows other workflows to handle this error
|
||||
if (error.context) {
|
||||
// If the error thrown already contains the context property,
|
||||
// only append the itemIndex
|
||||
error.context.itemIndex = itemIndex;
|
||||
throw error;
|
||||
}
|
||||
throw new NodeOperationError(this.getNode(), error, {
|
||||
itemIndex,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [items];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"node": "n8n-nodes-base.httpbin",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Development", "Developer Tools"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "http://httpbin.org/#/Auth/get_bearer"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "http://httpbin.org/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
import { INodeType, INodeTypeDescription, NodeConnectionType } from 'n8n-workflow';
|
||||
import { httpVerbFields, httpVerbOperations } from './HttpVerbDescription';
|
||||
|
||||
export class HttpBin implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'HttpBin',
|
||||
name: 'httpBin',
|
||||
icon: { light: 'file:httpbin.svg', dark: 'file:httpbin.svg' },
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Interact with HttpBin API',
|
||||
defaults: {
|
||||
name: 'HttpBin',
|
||||
},
|
||||
inputs: [NodeConnectionType.Main],
|
||||
outputs: [NodeConnectionType.Main],
|
||||
usableAsTool: true,
|
||||
credentials: [
|
||||
{
|
||||
name: 'httpbinApi',
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
requestDefaults: {
|
||||
baseURL: 'https://httpbin.org',
|
||||
url: '',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
},
|
||||
/**
|
||||
* In the properties array we have two mandatory options objects required
|
||||
*
|
||||
* [Resource & Operation]
|
||||
*
|
||||
* https://docs.n8n.io/integrations/creating-nodes/code/create-first-node/#resources-and-operations
|
||||
*
|
||||
* In our example, the operations are separated into their own file (HTTPVerbDescription.ts)
|
||||
* to keep this class easy to read.
|
||||
*
|
||||
*/
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'HTTP Verb',
|
||||
value: 'httpVerb',
|
||||
},
|
||||
],
|
||||
default: 'httpVerb',
|
||||
},
|
||||
|
||||
...httpVerbOperations,
|
||||
...httpVerbFields,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
|
@ -1,250 +0,0 @@
|
|||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
// When the resource `httpVerb` is selected, this `operation` parameter will be shown.
|
||||
export const httpVerbOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['httpVerb'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'GET',
|
||||
value: 'get',
|
||||
description: 'Perform a GET request',
|
||||
action: 'Perform a GET request',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/get',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'DELETE',
|
||||
value: 'delete',
|
||||
description: 'Perform a DELETE request',
|
||||
action: 'Perform a DELETE request',
|
||||
routing: {
|
||||
request: {
|
||||
method: 'DELETE',
|
||||
url: '/delete',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
// Here we define what to show when the `get` operation is selected.
|
||||
// We do that by adding `operation: ["get"]` to `displayOptions.show`
|
||||
const getOperation: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Type of Data',
|
||||
name: 'typeofData',
|
||||
default: 'queryParameter',
|
||||
description: 'Select type of data to send [Query Parameters]',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['httpVerb'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Query',
|
||||
value: 'queryParameter',
|
||||
},
|
||||
],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Query Parameters',
|
||||
name: 'arguments',
|
||||
default: {},
|
||||
description: "The request's query parameters",
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['httpVerb'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'keyvalue',
|
||||
displayName: 'Key:Value',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Key',
|
||||
name: 'key',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'Key of query parameter',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
property: '={{$parent.key}}',
|
||||
type: 'query',
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'Value of query parameter',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Here we define what to show when the DELETE Operation is selected.
|
||||
// We do that by adding `operation: ["delete"]` to `displayOptions.show`
|
||||
const deleteOperation: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Type of Data',
|
||||
name: 'typeofData',
|
||||
default: 'queryParameter',
|
||||
description: 'Select type of data to send [Query Parameter Arguments, JSON-Body]',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['httpVerb'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Query',
|
||||
value: 'queryParameter',
|
||||
},
|
||||
{
|
||||
name: 'JSON',
|
||||
value: 'jsonData',
|
||||
},
|
||||
],
|
||||
required: true,
|
||||
type: 'options',
|
||||
},
|
||||
{
|
||||
displayName: 'Query Parameters',
|
||||
name: 'arguments',
|
||||
default: {},
|
||||
description: "The request's query parameters",
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['httpVerb'],
|
||||
operation: ['delete'],
|
||||
typeofData: ['queryParameter'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'keyvalue',
|
||||
displayName: 'Key:Value',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Key',
|
||||
name: 'key',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'Key of query parameter',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
property: '={{$parent.key}}',
|
||||
type: 'query',
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'Value of query parameter',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'JSON Object',
|
||||
name: 'arguments',
|
||||
default: {},
|
||||
description: "The request's JSON properties",
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['httpVerb'],
|
||||
operation: ['delete'],
|
||||
typeofData: ['jsonData'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'keyvalue',
|
||||
displayName: 'Key:Value',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Key',
|
||||
name: 'key',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'Key of JSON property',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
routing: {
|
||||
send: {
|
||||
property: '={{$parent.key}}',
|
||||
type: 'body',
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'Value of JSON property',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const httpVerbFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* httpVerb:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...getOperation,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* httpVerb:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
...deleteOperation,
|
||||
];
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="32px" height="32px" viewBox="0 0 32 32" enable-background="new 0 0 32 32" xml:space="preserve"> <image id="image0" width="32" height="32" x="0" y="0"
|
||||
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAAABGdBTUEAALGPC/xhBQAAACBjSFJN
|
||||
AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElN
|
||||
RQfmBg4UAC/TqOZZAAACA0lEQVRIx5XVv09TURwF8M+jFHDSyRkGFhPAEfyRdDHi5uriXyDoYgKT
|
||||
MJDWzUT/Ahf/AiOEpajEgCESmpiYmDCxGowDTYE+h76+vte+15Zzk753b7733HNO772PbEw7ECba
|
||||
genswtEcgl0/PHARV72066YrIDSZ6k8KBym4741r0XsB284TdUX8chn1zrzwJUmw4KFXPqjFE0Y0
|
||||
u5YKEhpmfLZuy7f2wLKGI8WhDRYdaVhurdTCidmU5P44N+skaaGQH1IfFFrOYMotT932zNgQExve
|
||||
OfTeT8dtBceO3TFlOyopY7UPxV+/fWyn3Y0xrFhJjZWFXhs12pKdRO9ObGSuyB8Xbd9JjMjDc6HQ
|
||||
IcrKqAiVe8vyCEJPrGBWxZYqqtZt9RbmHabAvAAVdVUlJTvWshbMt0AYn40OmlchSKOePTyYIMQn
|
||||
rb8yI8TsDCrRs4od7Jv3KOoPGWKboBqp2LN3FQvdO7EPshSsRSTXrSop2cSiiUGkG/bj2JqaQiHW
|
||||
4nv50mFcu28j30KQarAnEPhuzvwwGYQ975vx7+JwGXTjTIAzoYlhCArR5d0KkfauqJAVY6+FG5hD
|
||||
OS6veqyCuSiTAQT/jKmlQtyxIBCoZV28HQvN6LuQvJFC4xjvibfYOZUdUXd9taTWJbOubiIVXmjG
|
||||
W/fs9qpZcpr6pOe1U0udSf8BR7ef4yxyOskAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjItMDYtMTRU
|
||||
MTc6MDA6NDcrMDM6MDBfo1sRAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIyLTA2LTE0VDE3OjAwOjQ3
|
||||
KzAzOjAwLv7jrQAAAABJRU5ErkJggg==" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.5 KiB |
20
nodes/outgrow/outgrow.node.json
Normal file
20
nodes/outgrow/outgrow.node.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"node": "n8n-nodes-base.outgrow",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": [
|
||||
"Miscellaneous"
|
||||
],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": ""
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
145
nodes/outgrow/outgrow.node.ts
Normal file
145
nodes/outgrow/outgrow.node.ts
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
import {
|
||||
ITriggerFunctions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
ILoadOptionsFunctions,
|
||||
INodePropertyOptions,
|
||||
ITriggerResponse,
|
||||
NodeApiError,
|
||||
NodeConnectionType,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class outgrow implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Outgrow Trigger',
|
||||
name: 'outgrowTrigger',
|
||||
icon: 'file:outgrow.svg',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["calcId"]}}',
|
||||
description: 'Fetch leads from Outgrow calculators at regular intervals',
|
||||
defaults: {
|
||||
name: 'Outgrow Trigger',
|
||||
},
|
||||
inputs: [],
|
||||
outputs: [NodeConnectionType.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'outgrowApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Calculator',
|
||||
name: 'calcId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCalculators',
|
||||
},
|
||||
default: '',
|
||||
description: 'Which Outgrow calculator to fetch leads from',
|
||||
},
|
||||
{
|
||||
displayName: 'Polling Interval (Minutes)',
|
||||
name: 'pollingInterval',
|
||||
type: 'number',
|
||||
required: false,
|
||||
default: 5,
|
||||
description: 'How often (in minutes) to check for new leads',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getCalculators(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const credentials = await this.getCredentials('outgrowApi');
|
||||
if (!credentials?.apiKey) {
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'API Key is missing or invalid',
|
||||
});
|
||||
}
|
||||
|
||||
const url = `https://api-calc.outgrow.co/api/v1/get_cal/${credentials.apiKey}`;
|
||||
try {
|
||||
const response = await this.helpers.request({ method: 'GET', url });
|
||||
const calculators = JSON.parse(response);
|
||||
|
||||
return calculators.map((calc: { id: string; calculator: string }) => ({
|
||||
name: calc.calculator,
|
||||
value: calc.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error, {
|
||||
message: 'Failed to load calculators',
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
||||
const credentials = await this.getCredentials('outgrowApi');
|
||||
if (!credentials?.apiKey) {
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'API Key is missing or invalid',
|
||||
});
|
||||
}
|
||||
|
||||
const calcId = this.getNodeParameter('calcId', 0) as string;
|
||||
if (!calcId) {
|
||||
throw new NodeApiError(this.getNode(), {
|
||||
message: 'No calculator selected',
|
||||
});
|
||||
}
|
||||
|
||||
const pollingInterval = (this.getNodeParameter('pollingInterval', 0) as number) * 60 * 1000;
|
||||
const url = `https://api-calc.outgrow.co/api/v1/get_leads/${credentials.apiKey}/${calcId}`;
|
||||
|
||||
const poll = async () => {
|
||||
try {
|
||||
const responseData = await this.helpers.request({
|
||||
method: 'GET',
|
||||
url,
|
||||
json: true,
|
||||
});
|
||||
|
||||
if (responseData?.length > 0) {
|
||||
this.emit([this.helpers.returnJsonArray(responseData)]);
|
||||
} else {
|
||||
// UI-friendly "no leads" response
|
||||
this.emit([this.helpers.returnJsonArray([{
|
||||
status: 'no_data',
|
||||
message: 'No new leads in the last 24 hours',
|
||||
calculatorId: calcId,
|
||||
timestamp: new Date().toISOString(),
|
||||
}])]);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error, {
|
||||
message: 'Outgrow API Error',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const mode = this.getMode();
|
||||
if (mode === 'manual') {
|
||||
return {
|
||||
manualTriggerFunction: async () => await poll(),
|
||||
};
|
||||
}
|
||||
|
||||
if (mode === 'trigger') {
|
||||
const interval = setInterval(poll, pollingInterval);
|
||||
await poll(); // Initial call
|
||||
|
||||
return {
|
||||
closeFunction: async () => clearInterval(interval),
|
||||
};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
3
nodes/outgrow/outgrow.svg
Normal file
3
nodes/outgrow/outgrow.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 29 KiB |
Loading…
Add table
Add a link
Reference in a new issue