Improvements to Webflow Trigger Node

This commit is contained in:
Jan Oberhauser 2021-05-07 23:32:59 -05:00
parent 8b11eb6332
commit 77da5b70bc

View file

@ -97,6 +97,18 @@ export class WebflowTrigger implements INodeType {
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',
@ -117,57 +129,47 @@ export class WebflowTrigger implements INodeType {
name: 'Site Publish',
value: 'site_publish',
},
{
name: 'Collection Item Created',
value: 'collection_item_created',
},
{
name: 'Collection Item Updated',
value: 'collection_item_changed',
},
{
name: 'Collection Item Deleted',
value: 'collection_item_deleted',
},
],
default: 'form_submission',
},
{
displayName: 'All collections',
name: 'allCollections',
type: 'boolean',
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: {
event: [
'collection_item_created',
'collection_item_changed',
'collection_item_deleted',
],
},
hide: {
allCollections: [
true,
],
},
},
},
// {
// 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,
// ],
// },
// },
// },
],
};
@ -188,18 +190,18 @@ export class WebflowTrigger implements INodeType {
}
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;
},
// 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;
// },
},
};
@ -225,8 +227,6 @@ export class WebflowTrigger implements INodeType {
const webhookData = this.getWorkflowStaticData('node');
const siteId = this.getNodeParameter('site') as string;
const event = this.getNodeParameter('event') as string;
const collection = this.getNodeParameter('collection') as string;
const allCollections = this.getNodeParameter('allCollections') as boolean;
const endpoint = `/sites/${siteId}/webhooks`;
const body: IDataObject = {
site_id: siteId,
@ -234,11 +234,17 @@ export class WebflowTrigger implements INodeType {
url: webhookUrl,
};
if(event.startsWith('collection') && !allCollections) {
body.filter = {
'_cid': collection,
};
}
// 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;
@ -250,7 +256,7 @@ export class WebflowTrigger implements INodeType {
const endpoint = `/sites/${siteId}/webhooks/${webhookData.webhookId}`;
try {
responseData = await webflowApiRequest.call(this, 'DELETE', endpoint);
} catch(error) {
} catch (error) {
return false;
}
if (!responseData.deleted) {