pull:初次提交
This commit is contained in:
129
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/GenericFunctions.ts
Executable file
129
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/GenericFunctions.ts
Executable file
@@ -0,0 +1,129 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IWebhookFunctions,
|
||||
IHttpRequestMethods,
|
||||
IHttpRequestOptions,
|
||||
INodePropertyOptions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function webflowApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
option: IDataObject = {},
|
||||
) {
|
||||
let credentialsType = 'webflowOAuth2Api';
|
||||
|
||||
let options: IHttpRequestOptions = {
|
||||
method,
|
||||
qs,
|
||||
body,
|
||||
url: uri || `https://api.webflow.com${resource}`,
|
||||
json: true,
|
||||
};
|
||||
options = Object.assign({}, options, option);
|
||||
|
||||
// Keep support for v1 node
|
||||
if (this.getNode().typeVersion === 1) {
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken');
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
credentialsType = 'webflowApi';
|
||||
}
|
||||
options.headers = { 'accept-version': '1.0.0' };
|
||||
} else {
|
||||
options.returnFullResponse = true;
|
||||
options.url = `https://api.webflow.com/v2${resource}`;
|
||||
}
|
||||
|
||||
if (Object.keys(options.qs as IDataObject).length === 0) {
|
||||
delete options.qs;
|
||||
}
|
||||
|
||||
if (Object.keys(options.body as IDataObject).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
return await this.helpers.httpRequestWithAuthentication.call(this, credentialsType, options);
|
||||
}
|
||||
|
||||
export async function webflowApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
query: IDataObject = {},
|
||||
): Promise<IDataObject[]> {
|
||||
const returnData: IDataObject[] = [];
|
||||
let responseData;
|
||||
|
||||
query.limit = 100;
|
||||
query.offset = 0;
|
||||
|
||||
const isTypeVersion1 = this.getNode().typeVersion === 1;
|
||||
|
||||
do {
|
||||
responseData = await webflowApiRequest.call(this, method, endpoint, body, query);
|
||||
const items = isTypeVersion1 ? responseData.items : responseData.body.items;
|
||||
returnData.push(...(items as IDataObject[]));
|
||||
|
||||
if (responseData.offset !== undefined || responseData?.body?.pagination?.offset !== undefined) {
|
||||
query.offset += query.limit;
|
||||
}
|
||||
} while (
|
||||
isTypeVersion1
|
||||
? returnData.length < responseData.total
|
||||
: returnData.length < responseData.body.pagination.total
|
||||
);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
// Load Options
|
||||
export async function getSites(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const response = await webflowApiRequest.call(this, 'GET', '/sites');
|
||||
|
||||
const sites = response.body?.sites || response;
|
||||
|
||||
for (const site of sites) {
|
||||
returnData.push({
|
||||
name: site.displayName || site.name,
|
||||
value: site.id || site._id,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
export async function getCollections(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const siteId = this.getCurrentNodeParameter('siteId');
|
||||
const response = await webflowApiRequest.call(this, 'GET', `/sites/${siteId}/collections`);
|
||||
|
||||
const collections = response.body?.collections || response;
|
||||
|
||||
for (const collection of collections) {
|
||||
returnData.push({
|
||||
name: collection.displayName || collection.name,
|
||||
value: collection.id || collection._id,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
export async function getFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const collectionId = this.getCurrentNodeParameter('collectionId');
|
||||
const response = await webflowApiRequest.call(this, 'GET', `/collections/${collectionId}`);
|
||||
|
||||
const fields = response.body?.fields || response;
|
||||
|
||||
for (const field of fields) {
|
||||
returnData.push({
|
||||
name: `${field.displayName || field.name} (${field.type}) ${field.isRequired || field.required ? ' (required)' : ''}`,
|
||||
value: field.slug,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
380
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V1/ItemDescription.ts
Executable file
380
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V1/ItemDescription.ts
Executable file
@@ -0,0 +1,380 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const itemOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
default: 'get',
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
action: 'Create an item',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
action: 'Delete an item',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
action: 'Get an item',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
action: 'Get many items',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
action: 'Update an item',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const itemFields: INodeProperties[] = [
|
||||
// ----------------------------------
|
||||
// item: create
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the site containing the collection whose items to add to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the collection to add an item to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Live',
|
||||
name: 'live',
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'Whether the item should be published on the live site',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fieldsUi',
|
||||
placeholder: 'Add Field',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'fieldValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name or ID',
|
||||
name: 'fieldId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFields',
|
||||
loadOptionsDependsOn: ['collectionId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Field to set for the item to create. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value to set for the item to create',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// item: get
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['delete', 'get'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the site containing the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['delete', 'get'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Item ID',
|
||||
name: 'itemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['delete', 'get'],
|
||||
},
|
||||
},
|
||||
description: 'ID of the item to operate on',
|
||||
},
|
||||
// ----------------------------------
|
||||
// item: update
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the site containing the collection whose items to update. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the collection whose items to update. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Item ID',
|
||||
name: 'itemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description: 'ID of the item to update',
|
||||
},
|
||||
{
|
||||
displayName: 'Live',
|
||||
name: 'live',
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
description: 'Whether the item should be published on the live site',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fieldsUi',
|
||||
placeholder: 'Add Field',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'fieldValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name or ID',
|
||||
name: 'fieldId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFields',
|
||||
loadOptionsDependsOn: ['collectionId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Field to set for the item to update. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value to set for the item to update',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
// ----------------------------------
|
||||
// item:getAll
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the site containing the collection whose items to retrieve. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
description:
|
||||
'ID of the collection whose items to retrieve. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 100,
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
209
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V1/WebflowTriggerV1.node.ts
Executable file
209
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V1/WebflowTriggerV1.node.ts
Executable file
@@ -0,0 +1,209 @@
|
||||
import {
|
||||
type IHookFunctions,
|
||||
type IWebhookFunctions,
|
||||
type IDataObject,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
type IWebhookResponseData,
|
||||
type INodeTypeBaseDescription,
|
||||
NodeConnectionTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getSites, webflowApiRequest } from '../GenericFunctions';
|
||||
|
||||
export class WebflowTriggerV1 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
constructor(baseDescription: INodeTypeBaseDescription) {
|
||||
this.description = {
|
||||
...baseDescription,
|
||||
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: [NodeConnectionTypes.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/code/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',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
getSites,
|
||||
},
|
||||
};
|
||||
|
||||
webhookMethods = {
|
||||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
const siteId = this.getNodeParameter('site') as string;
|
||||
|
||||
const event = this.getNodeParameter('event') as string;
|
||||
const registeredWebhooks = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/sites/${siteId}/webhooks`,
|
||||
);
|
||||
|
||||
const webhooks = registeredWebhooks.body?.webhooks || registeredWebhooks;
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
if (webhook.url === webhookUrl && webhook.triggerType === event) {
|
||||
webhookData.webhookId = webhook._id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
const response = await webflowApiRequest.call(this, 'POST', endpoint, body);
|
||||
const _id = response.body?._id || response._id;
|
||||
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;
|
||||
}
|
||||
const deleted = responseData.body?.deleted || responseData.deleted;
|
||||
if (!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 as IDataObject[])],
|
||||
};
|
||||
}
|
||||
}
|
||||
258
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V1/WebflowV1.node.ts
Executable file
258
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V1/WebflowV1.node.ts
Executable file
@@ -0,0 +1,258 @@
|
||||
import {
|
||||
type IExecuteFunctions,
|
||||
type IDataObject,
|
||||
type INodeTypeBaseDescription,
|
||||
type INodeExecutionData,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
NodeConnectionTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { itemFields, itemOperations } from './ItemDescription';
|
||||
import {
|
||||
webflowApiRequest,
|
||||
webflowApiRequestAllItems,
|
||||
getSites,
|
||||
getCollections,
|
||||
getFields,
|
||||
} from '../GenericFunctions';
|
||||
|
||||
export class WebflowV1 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
constructor(baseDescription: INodeTypeBaseDescription) {
|
||||
this.description = {
|
||||
...baseDescription,
|
||||
version: 1,
|
||||
description: 'Consume the Webflow API',
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
defaults: {
|
||||
name: 'Webflow',
|
||||
},
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'webflowApi',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: ['accessToken'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'webflowOAuth2Api',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: ['oAuth2'],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Authentication',
|
||||
name: 'authentication',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Access Token',
|
||||
value: 'accessToken',
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2',
|
||||
},
|
||||
],
|
||||
default: 'accessToken',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Item',
|
||||
value: 'item',
|
||||
},
|
||||
],
|
||||
default: 'item',
|
||||
},
|
||||
...itemOperations,
|
||||
...itemFields,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
getSites,
|
||||
getCollections,
|
||||
getFields,
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
let responseData;
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
if (resource === 'item') {
|
||||
// *********************************************************************
|
||||
// item
|
||||
// *********************************************************************
|
||||
|
||||
// https://developers.webflow.com/#item-model
|
||||
|
||||
if (operation === 'create') {
|
||||
// ----------------------------------
|
||||
// item: create
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#create-new-collection-item
|
||||
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
|
||||
const properties = this.getNodeParameter(
|
||||
'fieldsUi.fieldValues',
|
||||
i,
|
||||
[],
|
||||
) as IDataObject[];
|
||||
|
||||
const live = this.getNodeParameter('live', i) as boolean;
|
||||
|
||||
const fields = {} as IDataObject;
|
||||
|
||||
properties.forEach((data) => (fields[data.fieldId as string] = data.fieldValue));
|
||||
|
||||
const body: IDataObject = {
|
||||
fields,
|
||||
};
|
||||
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/collections/${collectionId}/items`,
|
||||
body,
|
||||
{ live },
|
||||
);
|
||||
} else if (operation === 'delete') {
|
||||
// ----------------------------------
|
||||
// item: delete
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#remove-collection-item
|
||||
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/collections/${collectionId}/items/${itemId}`,
|
||||
);
|
||||
} else if (operation === 'get') {
|
||||
// ----------------------------------
|
||||
// item: get
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#get-single-item
|
||||
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items/${itemId}`,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
} else if (operation === 'getAll') {
|
||||
// ----------------------------------
|
||||
// item: getAll
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#get-all-items-for-a-collection
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', 0);
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const qs: IDataObject = {};
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await webflowApiRequestAllItems.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', 0);
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
}
|
||||
} else if (operation === 'update') {
|
||||
// ----------------------------------
|
||||
// item: update
|
||||
// ----------------------------------
|
||||
|
||||
// https://developers.webflow.com/#update-collection-item
|
||||
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
|
||||
const properties = this.getNodeParameter(
|
||||
'fieldsUi.fieldValues',
|
||||
i,
|
||||
[],
|
||||
) as IDataObject[];
|
||||
|
||||
const live = this.getNodeParameter('live', i) as boolean;
|
||||
|
||||
const fields = {} as IDataObject;
|
||||
|
||||
properties.forEach((data) => (fields[data.fieldId as string] = data.fieldValue));
|
||||
|
||||
const body: IDataObject = {
|
||||
fields,
|
||||
};
|
||||
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/collections/${collectionId}/items/${itemId}`,
|
||||
body,
|
||||
{ live },
|
||||
);
|
||||
}
|
||||
}
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ json: { error: error.message } });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
179
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V2/WebflowTriggerV2.node.ts
Executable file
179
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V2/WebflowTriggerV2.node.ts
Executable file
@@ -0,0 +1,179 @@
|
||||
import type {
|
||||
IHookFunctions,
|
||||
IDataObject,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
INodeTypeBaseDescription,
|
||||
IWebhookFunctions,
|
||||
IWebhookResponseData,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import { getSites, webflowApiRequest } from '../GenericFunctions';
|
||||
|
||||
export class WebflowTriggerV2 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
constructor(baseDescription: INodeTypeBaseDescription) {
|
||||
this.description = {
|
||||
...baseDescription,
|
||||
displayName: 'Webflow Trigger',
|
||||
name: 'webflowTrigger',
|
||||
icon: 'file:webflow.svg',
|
||||
group: ['trigger'],
|
||||
version: 2,
|
||||
description: 'Handle Webflow events via webhooks',
|
||||
defaults: {
|
||||
name: 'Webflow Trigger',
|
||||
},
|
||||
|
||||
inputs: [],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'webflowOAuth2Api',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
webhooks: [
|
||||
{
|
||||
name: 'default',
|
||||
httpMethod: 'POST',
|
||||
responseMode: 'onReceived',
|
||||
path: 'webhook',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
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/code/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',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
getSites,
|
||||
},
|
||||
};
|
||||
|
||||
webhookMethods = {
|
||||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
const siteId = this.getNodeParameter('site') as string;
|
||||
|
||||
const event = this.getNodeParameter('event') as string;
|
||||
const registeredWebhooks = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/sites/${siteId}/webhooks`,
|
||||
);
|
||||
|
||||
const webhooks = registeredWebhooks.body?.webhooks || registeredWebhooks;
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
if (webhook.url === webhookUrl && webhook.triggerType === event) {
|
||||
webhookData.webhookId = webhook._id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
const response = await webflowApiRequest.call(this, 'POST', endpoint, body);
|
||||
const _id = response.body?._id || response._id;
|
||||
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;
|
||||
}
|
||||
const deleted = responseData.body?.deleted || responseData.deleted;
|
||||
if (!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 as IDataObject[])],
|
||||
};
|
||||
}
|
||||
}
|
||||
34
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V2/WebflowV2.node.ts
Executable file
34
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V2/WebflowV2.node.ts
Executable file
@@ -0,0 +1,34 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeType,
|
||||
INodeTypeBaseDescription,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getSites, getCollections, getFields } from '../GenericFunctions';
|
||||
import { router } from './actions/router';
|
||||
import { versionDescription } from './actions/versionDescription';
|
||||
|
||||
export class WebflowV2 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
constructor(baseDescription: INodeTypeBaseDescription) {
|
||||
this.description = {
|
||||
...baseDescription,
|
||||
...versionDescription,
|
||||
usableAsTool: true,
|
||||
};
|
||||
}
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
getSites,
|
||||
getCollections,
|
||||
getFields,
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions) {
|
||||
return await router.call(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as create from './create.operation';
|
||||
import * as deleteItem from './delete.operation';
|
||||
import * as get from './get.operation';
|
||||
import * as getAll from './getAll.operation';
|
||||
import * as update from './update.operation';
|
||||
|
||||
export { create, deleteItem, get, getAll, update };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
default: 'get',
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
action: 'Create an item',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'deleteItem',
|
||||
action: 'Delete an item',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
action: 'Get an item',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
action: 'Get many items',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
action: 'Update an item',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
},
|
||||
},
|
||||
},
|
||||
...create.description,
|
||||
...deleteItem.description,
|
||||
...get.description,
|
||||
...getAll.description,
|
||||
...update.description,
|
||||
];
|
||||
@@ -0,0 +1,138 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions, wrapData } from '../../../../../utils/utilities';
|
||||
import { webflowApiRequest } from '../../../GenericFunctions';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the site containing the collection whose items to add to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the collection to add an item to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Live',
|
||||
name: 'live',
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
default: false,
|
||||
description: 'Whether the item should be published on the live site',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fieldsUi',
|
||||
placeholder: 'Add Field',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'fieldValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name or ID',
|
||||
name: 'fieldId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFields',
|
||||
loadOptionsDependsOn: ['collectionId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Field to set for the item to create. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value to set for the item to create',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['create'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let responseData;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
|
||||
const uiFields = this.getNodeParameter('fieldsUi.fieldValues', i, []) as IDataObject[];
|
||||
|
||||
const live = this.getNodeParameter('live', i) as boolean;
|
||||
|
||||
const fieldData = {} as IDataObject;
|
||||
|
||||
uiFields.forEach((data) => (fieldData[data.fieldId as string] = data.fieldValue));
|
||||
|
||||
const body: IDataObject = {
|
||||
fieldData,
|
||||
};
|
||||
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/collections/${collectionId}/items${live ? '/live' : ''}`,
|
||||
body,
|
||||
);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
wrapData(responseData.body as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ json: { message: error.message, error } });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions, wrapData } from '../../../../../utils/utilities';
|
||||
import { webflowApiRequest } from '../../../GenericFunctions';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the site containing the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Item ID',
|
||||
name: 'itemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'ID of the item to operate on',
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['deleteItem'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
let responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/collections/${collectionId}/items/${itemId}`,
|
||||
);
|
||||
|
||||
if (responseData.statusCode === 204) {
|
||||
responseData = { success: true };
|
||||
} else {
|
||||
responseData = { success: false };
|
||||
}
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
wrapData(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ json: { message: error.message, error } });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions, wrapData } from '../../../../../utils/utilities';
|
||||
import { webflowApiRequest } from '../../../GenericFunctions';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the site containing the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Item ID',
|
||||
name: 'itemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'ID of the item to operate on',
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['get'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let responseData;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items/${itemId}`,
|
||||
);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
wrapData(responseData.body as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ json: { message: error.message, error } });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions, wrapData } from '../../../../../utils/utilities';
|
||||
import { webflowApiRequest, webflowApiRequestAllItems } from '../../../GenericFunctions';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the site containing the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the collection whose items to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 100,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let responseData;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const qs: IDataObject = {};
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await webflowApiRequestAllItems.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items`,
|
||||
{},
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i);
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/collections/${collectionId}/items`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.body.items;
|
||||
}
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
wrapData(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ json: { message: error.message, error } });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { updateDisplayOptions, wrapData } from '../../../../../utils/utilities';
|
||||
import { webflowApiRequest } from '../../../GenericFunctions';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Site Name or ID',
|
||||
name: 'siteId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getSites',
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the site containing the collection whose items to add to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Collection Name or ID',
|
||||
name: 'collectionId',
|
||||
type: 'options',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getCollections',
|
||||
loadOptionsDependsOn: ['siteId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'ID of the collection to add an item to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Item ID',
|
||||
name: 'itemId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'ID of the item to update',
|
||||
},
|
||||
{
|
||||
displayName: 'Live',
|
||||
name: 'live',
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
default: false,
|
||||
description: 'Whether the item should be published on the live site',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fieldsUi',
|
||||
placeholder: 'Add Field',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'fieldValues',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Field Name or ID',
|
||||
name: 'fieldId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFields',
|
||||
loadOptionsDependsOn: ['collectionId'],
|
||||
},
|
||||
default: '',
|
||||
description:
|
||||
'Field to set for the item to create. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field Value',
|
||||
name: 'fieldValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value to set for the item to create',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['item'],
|
||||
operation: ['update'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let responseData;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
const collectionId = this.getNodeParameter('collectionId', i) as string;
|
||||
const itemId = this.getNodeParameter('itemId', i) as string;
|
||||
|
||||
const uiFields = this.getNodeParameter('fieldsUi.fieldValues', i, []) as IDataObject[];
|
||||
|
||||
const live = this.getNodeParameter('live', i) as boolean;
|
||||
|
||||
const fieldData = {} as IDataObject;
|
||||
|
||||
uiFields.forEach((data) => (fieldData[data.fieldId as string] = data.fieldValue));
|
||||
|
||||
const body: IDataObject = {
|
||||
fieldData,
|
||||
};
|
||||
|
||||
responseData = await webflowApiRequest.call(
|
||||
this,
|
||||
'PATCH',
|
||||
`/collections/${collectionId}/items/${itemId}${live ? '/live' : ''}`,
|
||||
body,
|
||||
);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
wrapData(responseData.body as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ json: { message: error.message, error } });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { AllEntities } from 'n8n-workflow';
|
||||
|
||||
type NodeMap = {
|
||||
item: 'create' | 'deleteItem' | 'get' | 'getAll' | 'update';
|
||||
};
|
||||
|
||||
export type WebflowType = AllEntities<NodeMap>;
|
||||
31
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V2/actions/router.ts
Executable file
31
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/V2/actions/router.ts
Executable file
@@ -0,0 +1,31 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import * as item from './Item/Item.resource';
|
||||
import type { WebflowType } from './node.type';
|
||||
|
||||
export async function router(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
let returnData: INodeExecutionData[] = [];
|
||||
|
||||
const items = this.getInputData();
|
||||
const resource = this.getNodeParameter<WebflowType>('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
const webflowNodeData = {
|
||||
resource,
|
||||
operation,
|
||||
} as WebflowType;
|
||||
|
||||
switch (webflowNodeData.resource) {
|
||||
case 'item':
|
||||
returnData = await item[webflowNodeData.operation].execute.call(this, items);
|
||||
break;
|
||||
default:
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`The operation "${operation}" is not supported!`,
|
||||
);
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||
import { NodeConnectionTypes, type INodeTypeDescription } from 'n8n-workflow';
|
||||
|
||||
import * as item from './Item/Item.resource';
|
||||
|
||||
export const versionDescription: INodeTypeDescription = {
|
||||
displayName: 'Webflow',
|
||||
name: 'webflow',
|
||||
icon: 'file:webflow.svg',
|
||||
group: ['transform'],
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume the Webflow API',
|
||||
version: [2],
|
||||
defaults: {
|
||||
name: 'Webflow',
|
||||
},
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'webflowOAuth2Api',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Item',
|
||||
value: 'item',
|
||||
},
|
||||
],
|
||||
default: 'item',
|
||||
},
|
||||
...item.description,
|
||||
],
|
||||
};
|
||||
18
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/Webflow.node.json
Executable file
18
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/Webflow.node.json
Executable file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.webflow",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Marketing"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/webflow/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.webflow/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
26
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/Webflow.node.ts
Executable file
26
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/Webflow.node.ts
Executable file
@@ -0,0 +1,26 @@
|
||||
import type { INodeTypeBaseDescription, IVersionedNodeType } from 'n8n-workflow';
|
||||
import { VersionedNodeType } from 'n8n-workflow';
|
||||
|
||||
import { WebflowV1 } from './V1/WebflowV1.node';
|
||||
import { WebflowV2 } from './V2/WebflowV2.node';
|
||||
|
||||
export class Webflow extends VersionedNodeType {
|
||||
constructor() {
|
||||
const baseDescription: INodeTypeBaseDescription = {
|
||||
displayName: 'Webflow',
|
||||
name: 'webflow',
|
||||
icon: 'file:webflow.svg',
|
||||
group: ['transform'],
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume the Webflow API',
|
||||
defaultVersion: 2,
|
||||
};
|
||||
|
||||
const nodeVersions: IVersionedNodeType['nodeVersions'] = {
|
||||
1: new WebflowV1(baseDescription),
|
||||
2: new WebflowV2(baseDescription),
|
||||
};
|
||||
|
||||
super(nodeVersions, baseDescription);
|
||||
}
|
||||
}
|
||||
18
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/WebflowTrigger.node.json
Executable file
18
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/WebflowTrigger.node.json
Executable file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.webflowTrigger",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Marketing"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/webflow/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.webflowtrigger/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
25
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/WebflowTrigger.node.ts
Executable file
25
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/WebflowTrigger.node.ts
Executable file
@@ -0,0 +1,25 @@
|
||||
import type { INodeTypeBaseDescription, IVersionedNodeType } from 'n8n-workflow';
|
||||
import { VersionedNodeType } from 'n8n-workflow';
|
||||
|
||||
import { WebflowTriggerV1 } from './V1/WebflowTriggerV1.node';
|
||||
import { WebflowTriggerV2 } from './V2/WebflowTriggerV2.node';
|
||||
|
||||
export class WebflowTrigger extends VersionedNodeType {
|
||||
constructor() {
|
||||
const baseDescription: INodeTypeBaseDescription = {
|
||||
displayName: 'Webflow Trigger',
|
||||
name: 'webflowTrigger',
|
||||
icon: 'file:webflow.svg',
|
||||
group: ['trigger'],
|
||||
description: 'Handle Webflow events via webhooks',
|
||||
defaultVersion: 2,
|
||||
};
|
||||
|
||||
const nodeVersions: IVersionedNodeType['nodeVersions'] = {
|
||||
1: new WebflowTriggerV1(baseDescription),
|
||||
2: new WebflowTriggerV2(baseDescription),
|
||||
};
|
||||
|
||||
super(nodeVersions, baseDescription);
|
||||
}
|
||||
}
|
||||
32
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/create.json
vendored
Executable file
32
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/create.json
vendored
Executable file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"createdOn": {
|
||||
"type": "string"
|
||||
},
|
||||
"fieldData": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"slug": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"isArchived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"isDraft": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"lastUpdated": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
9
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/deleteItem.json
vendored
Executable file
9
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/deleteItem.json
vendored
Executable file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
29
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/get.json
vendored
Executable file
29
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/get.json
vendored
Executable file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"createdOn": {
|
||||
"type": "string"
|
||||
},
|
||||
"fieldData": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"slug": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"isArchived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"lastUpdated": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
32
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/getAll.json
vendored
Executable file
32
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/getAll.json
vendored
Executable file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"createdOn": {
|
||||
"type": "string"
|
||||
},
|
||||
"fieldData": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"slug": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"isArchived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"isDraft": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"lastUpdated": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
32
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/update.json
vendored
Executable file
32
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/__schema__/v2.0.0/item/update.json
vendored
Executable file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"createdOn": {
|
||||
"type": "string"
|
||||
},
|
||||
"fieldData": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"slug": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"isArchived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"isDraft": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"lastUpdated": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
149
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/test/GenericFunctions.test.ts
Executable file
149
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/test/GenericFunctions.test.ts
Executable file
@@ -0,0 +1,149 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
IHttpRequestMethods,
|
||||
ILoadOptionsFunctions,
|
||||
INode,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { webflowApiRequest, webflowApiRequestAllItems } from '../GenericFunctions';
|
||||
|
||||
describe('Webflow -> webflowApiRequestAllItems', () => {
|
||||
let mockExecuteFunctions: IExecuteFunctions | ILoadOptionsFunctions;
|
||||
|
||||
const v1Response = {
|
||||
items: [
|
||||
{ id: '1', name: 'Item 1' },
|
||||
{ id: '2', name: 'Item 2' },
|
||||
],
|
||||
total: 2,
|
||||
};
|
||||
|
||||
const v2Response = {
|
||||
body: {
|
||||
items: [
|
||||
{ id: '1', name: 'Item 1' },
|
||||
{ id: '2', name: 'Item 2' },
|
||||
],
|
||||
pagination: {
|
||||
total: 2,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const setupMockFunctions = (typeVersion: number) => {
|
||||
mockExecuteFunctions = {
|
||||
getNode: jest.fn().mockReturnValue({ typeVersion }),
|
||||
getNodeParameter: jest.fn(),
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: jest
|
||||
.fn()
|
||||
.mockResolvedValue(typeVersion === 1 ? v1Response : v2Response),
|
||||
},
|
||||
} as unknown as IExecuteFunctions | ILoadOptionsFunctions;
|
||||
jest.clearAllMocks();
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
setupMockFunctions(1);
|
||||
});
|
||||
|
||||
it('should return all items for type version 1', async () => {
|
||||
const result = await webflowApiRequestAllItems.call(
|
||||
mockExecuteFunctions,
|
||||
'GET',
|
||||
'/collections/collection_id/items',
|
||||
);
|
||||
|
||||
expect(result).toEqual(v1Response.items);
|
||||
});
|
||||
|
||||
it('should return all items for type version 2', async () => {
|
||||
setupMockFunctions(2);
|
||||
|
||||
const result = await webflowApiRequestAllItems.call(
|
||||
mockExecuteFunctions,
|
||||
'GET',
|
||||
'/collections/collection_id/items',
|
||||
);
|
||||
|
||||
expect(result).toEqual(v2Response.body.items);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Webflow -> webflowApiRequest', () => {
|
||||
const node: INode = {
|
||||
id: '8e3c489c-4905-4bc4-9fc6-f1912d0766ec',
|
||||
name: 'Webflow',
|
||||
type: 'n8n-nodes-base.webflow',
|
||||
typeVersion: 2,
|
||||
position: [0, 0],
|
||||
credentials: {
|
||||
webflowOAuth2Api: {
|
||||
id: 'xxyyzz',
|
||||
name: 'credential name',
|
||||
},
|
||||
},
|
||||
parameters: {
|
||||
operation: 'update',
|
||||
itemId: 'xxx',
|
||||
siteId: 'yyy',
|
||||
collectionId: 'zzz',
|
||||
live: true,
|
||||
},
|
||||
};
|
||||
it('should use live in the url for v2 when live is true', async () => {
|
||||
const mockThis = {
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: jest.fn().mockResolvedValue({ statusCode: 200, data: 'x' }),
|
||||
},
|
||||
getNode() {
|
||||
return node;
|
||||
},
|
||||
getNodeParameter: jest.fn(),
|
||||
} as unknown as IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions;
|
||||
|
||||
const method: IHttpRequestMethods = 'PATCH';
|
||||
const resource = `/collections/${node.parameters.collectionId}/items/${node.parameters.itemId}${node.parameters.live ? '/live' : ''}`;
|
||||
|
||||
await webflowApiRequest.call(mockThis, method, resource);
|
||||
|
||||
expect(mockThis.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'webflowOAuth2Api',
|
||||
{
|
||||
method: 'PATCH',
|
||||
returnFullResponse: true,
|
||||
url: 'https://api.webflow.com/v2/collections/zzz/items/xxx/live',
|
||||
json: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
it('should skip live in the url for v2 when live is false', async () => {
|
||||
const mockThis = {
|
||||
helpers: {
|
||||
httpRequestWithAuthentication: jest.fn().mockResolvedValue({ statusCode: 200, data: 'x' }),
|
||||
},
|
||||
getNode() {
|
||||
return node;
|
||||
},
|
||||
getNodeParameter: jest.fn(),
|
||||
} as unknown as IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions;
|
||||
|
||||
node.parameters.live = false;
|
||||
|
||||
const method: IHttpRequestMethods = 'PATCH';
|
||||
const resource = `/collections/${node.parameters.collectionId}/items/${node.parameters.itemId}${node.parameters.live ? '/live' : ''}`;
|
||||
|
||||
await webflowApiRequest.call(mockThis, method, resource);
|
||||
|
||||
expect(mockThis.helpers.httpRequestWithAuthentication).toHaveBeenCalledWith(
|
||||
'webflowOAuth2Api',
|
||||
{
|
||||
method: 'PATCH',
|
||||
returnFullResponse: true,
|
||||
url: 'https://api.webflow.com/v2/collections/zzz/items/xxx',
|
||||
json: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
1
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/webflow.svg
Executable file
1
n8n-n8n-1.109.2/packages/nodes-base/nodes/Webflow/webflow.svg
Executable file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="#fff" fill-rule="evenodd" stroke="#000" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 67 66"><use xlink:href="#a" x="1" y="1"/><symbol id="a" overflow="visible"><g fill-rule="nonzero" stroke="none"><path fill="#4353ff" d="M0 32C0 14.272 14.272 0 32 0s32 14.272 32 32-14.272 32-32 32S0 49.728 0 32"/><path d="m41.4 28.2-2.9 9.14c0-.7-2-15.86-2-15.86-4.6 0-7.04 3.26-8.32 6.72l-3.54 9.16c0-.66-.5-9.08-.5-9.08a7.48 7.48 0 0 0-7.26-6.78l3.76 22.96c4.8 0 7.4-3.26 8.74-6.72l3-7.8c0 .32 2 14.52 2 14.52a9.24 9.24 0 0 0 8.8-6.46l6.8-16.52c-4.8 0-7.32 3.26-8.6 6.72z"/></g></symbol></svg>
|
||||
|
After Width: | Height: | Size: 684 B |
Reference in New Issue
Block a user