mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
70ae90fa3c
* ⚡ Update `lintfix` script * 👕 Remove unneeded lint exceptions * 👕 Run baseline `lintfix` * 👕 Apply `node-param-description-miscased-url` (#3441) * 👕 Apply `rule node-param-placeholder-miscased-id` (#3443) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-option-name-wrong-for-upsert` (#3446) * 👕 Apply `node-param-min-value-wrong-for-limit` (#3442) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * Apply `node-param-display-name-wrong-for-dynamic-options` (#3454) * 🔨 fix * ⚡ Fix `Assigned To` fields Co-authored-by: Michael Kret <michael.k@radency.com> * 👕 Apply `rule node-param-default-wrong-for-number` (#3453) * 👕 Apply `node-param-default-wrong-for-string` (#3452) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * Apply `node-param-display-name-miscased` (#3449) * 🔨 fix * 🔨 exceptions * ⚡ review fixes * 👕 Apply `node-param-description-lowercase-first-char` (#3451) * ⚡ fix * ⚡ review fixes * ⚡ fix Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-description-wrong-for-dynamic-options` (#3456) * Rule working as intended * Add rule * 🔥 Remove repetitions * 👕 Add exceptions Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Small fix for `node-param-description-wrong-for-dynamic-options` * 👕 Apply `node-param-default-wrong-for-fixed-collection` (#3460) * 👕 Apply `node-param-description-line-break-html-tag` (#3462) * 👕 Run baseline `lintfix` * 👕 Apply `node-param-options-type-unsorted-items` (#3459) * ⚡ fix * 🔨 exceptions * Add exception for Salesmate and Zoom Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * ⚡ Restore `lintfix` command Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: brianinoa <54530642+brianinoa@users.noreply.github.com>
278 lines
6.5 KiB
TypeScript
278 lines
6.5 KiB
TypeScript
import {
|
|
IHookFunctions,
|
|
IWebhookFunctions,
|
|
} from 'n8n-core';
|
|
|
|
import {
|
|
IDataObject,
|
|
ILoadOptionsFunctions,
|
|
INodePropertyOptions,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
IWebhookResponseData,
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
webflowApiRequest,
|
|
} from './GenericFunctions';
|
|
|
|
export class WebflowTrigger implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Webflow Trigger',
|
|
name: 'webflowTrigger',
|
|
icon: 'file:webflow.svg',
|
|
group: ['trigger'],
|
|
version: 1,
|
|
description: 'Handle Webflow events via webhooks',
|
|
defaults: {
|
|
name: 'Webflow Trigger',
|
|
},
|
|
inputs: [],
|
|
outputs: ['main'],
|
|
credentials: [
|
|
{
|
|
name: 'webflowApi',
|
|
required: true,
|
|
displayOptions: {
|
|
show: {
|
|
authentication: [
|
|
'accessToken',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: 'webflowOAuth2Api',
|
|
required: true,
|
|
displayOptions: {
|
|
show: {
|
|
authentication: [
|
|
'oAuth2',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
],
|
|
webhooks: [
|
|
{
|
|
name: 'default',
|
|
httpMethod: 'POST',
|
|
responseMode: 'onReceived',
|
|
path: 'webhook',
|
|
},
|
|
],
|
|
properties: [
|
|
{
|
|
displayName: 'Authentication',
|
|
name: 'authentication',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
name: 'Access Token',
|
|
value: 'accessToken',
|
|
},
|
|
{
|
|
name: 'OAuth2',
|
|
value: 'oAuth2',
|
|
},
|
|
],
|
|
default: 'accessToken',
|
|
},
|
|
{
|
|
displayName: 'Site Name or ID',
|
|
name: 'site',
|
|
type: 'options',
|
|
required: true,
|
|
default: '',
|
|
typeOptions: {
|
|
loadOptionsMethod: 'getSites',
|
|
},
|
|
description: 'Site that will trigger the events. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/nodes/expressions.html#expressions">expression</a>.',
|
|
},
|
|
{
|
|
displayName: 'Event',
|
|
name: 'event',
|
|
type: 'options',
|
|
required: true,
|
|
options: [
|
|
{
|
|
name: 'Collection Item Created',
|
|
value: 'collection_item_created',
|
|
},
|
|
{
|
|
name: 'Collection Item Deleted',
|
|
value: 'collection_item_deleted',
|
|
},
|
|
{
|
|
name: 'Collection Item Updated',
|
|
value: 'collection_item_changed',
|
|
},
|
|
{
|
|
name: 'Ecomm Inventory Changed',
|
|
value: 'ecomm_inventory_changed',
|
|
},
|
|
{
|
|
name: 'Ecomm New Order',
|
|
value: 'ecomm_new_order',
|
|
},
|
|
{
|
|
name: 'Ecomm Order Changed',
|
|
value: 'ecomm_order_changed',
|
|
},
|
|
{
|
|
name: 'Form Submission',
|
|
value: 'form_submission',
|
|
},
|
|
{
|
|
name: 'Site Publish',
|
|
value: 'site_publish',
|
|
},
|
|
],
|
|
default: 'form_submission',
|
|
},
|
|
// {
|
|
// displayName: 'All collections',
|
|
// name: 'allCollections',
|
|
// type: 'boolean',
|
|
// displayOptions: {
|
|
// show: {
|
|
// event: [
|
|
// 'collection_item_created',
|
|
// 'collection_item_changed',
|
|
// 'collection_item_deleted',
|
|
// ],
|
|
// },
|
|
// },
|
|
// required: false,
|
|
// default: true,
|
|
// description: 'Receive events from all collections',
|
|
// },
|
|
// {
|
|
// displayName: 'Collection',
|
|
// name: 'collection',
|
|
// type: 'options',
|
|
// required: false,
|
|
// default: '',
|
|
// typeOptions: {
|
|
// loadOptionsMethod: 'getCollections',
|
|
// loadOptionsDependsOn: [
|
|
// 'site',
|
|
// ],
|
|
// },
|
|
// description: 'Collection that will trigger the events',
|
|
// displayOptions: {
|
|
// show: {
|
|
// allCollections: [
|
|
// false,
|
|
// ],
|
|
// },
|
|
// },
|
|
// },
|
|
],
|
|
};
|
|
|
|
methods = {
|
|
loadOptions: {
|
|
// Get all the sites to display them to user so that he can
|
|
// select them easily
|
|
async getSites(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const returnData: INodePropertyOptions[] = [];
|
|
const sites = await webflowApiRequest.call(this, 'GET', '/sites');
|
|
for (const site of sites) {
|
|
const siteName = site.name;
|
|
const siteId = site._id;
|
|
returnData.push({
|
|
name: siteName,
|
|
value: siteId,
|
|
});
|
|
}
|
|
return returnData;
|
|
},
|
|
// async getCollections(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
// const returnData: INodePropertyOptions[] = [];
|
|
// const siteId = this.getCurrentNodeParameter('site');
|
|
// const collections = await webflowApiRequest.call(this, 'GET', `/sites/${siteId}/collections`);
|
|
// for (const collection of collections) {
|
|
// returnData.push({
|
|
// name: collection.name,
|
|
// value: collection._id,
|
|
// });
|
|
// }
|
|
// return returnData;
|
|
// },
|
|
},
|
|
};
|
|
|
|
// @ts-ignore
|
|
webhookMethods = {
|
|
default: {
|
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
|
const webhookData = this.getWorkflowStaticData('node');
|
|
const siteId = this.getNodeParameter('site') as string;
|
|
if (webhookData.webhookId === undefined) {
|
|
return false;
|
|
}
|
|
const endpoint = `/sites/${siteId}/webhooks/${webhookData.webhookId}`;
|
|
try {
|
|
await webflowApiRequest.call(this, 'GET', endpoint);
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
async create(this: IHookFunctions): Promise<boolean> {
|
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
|
const webhookData = this.getWorkflowStaticData('node');
|
|
const siteId = this.getNodeParameter('site') as string;
|
|
const event = this.getNodeParameter('event') as string;
|
|
const endpoint = `/sites/${siteId}/webhooks`;
|
|
const body: IDataObject = {
|
|
site_id: siteId,
|
|
triggerType: event,
|
|
url: webhookUrl,
|
|
|
|
};
|
|
|
|
// if (event.startsWith('collection')) {
|
|
// const allCollections = this.getNodeParameter('allCollections') as boolean;
|
|
|
|
// if (allCollections === false) {
|
|
// body.filter = {
|
|
// 'cid': this.getNodeParameter('collection') as string,
|
|
// };
|
|
// }
|
|
// }
|
|
|
|
const { _id } = await webflowApiRequest.call(this, 'POST', endpoint, body);
|
|
webhookData.webhookId = _id;
|
|
return true;
|
|
},
|
|
async delete(this: IHookFunctions): Promise<boolean> {
|
|
let responseData;
|
|
const webhookData = this.getWorkflowStaticData('node');
|
|
const siteId = this.getNodeParameter('site') as string;
|
|
const endpoint = `/sites/${siteId}/webhooks/${webhookData.webhookId}`;
|
|
try {
|
|
responseData = await webflowApiRequest.call(this, 'DELETE', endpoint);
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
if (!responseData.deleted) {
|
|
return false;
|
|
}
|
|
delete webhookData.webhookId;
|
|
return true;
|
|
},
|
|
},
|
|
};
|
|
|
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
|
const req = this.getRequestObject();
|
|
return {
|
|
workflowData: [
|
|
this.helpers.returnJsonArray(req.body),
|
|
],
|
|
};
|
|
}
|
|
}
|