From 426177bf87e05ad46932230c335e2ad9d02ce499 Mon Sep 17 00:00:00 2001 From: Cedric Ziel Date: Tue, 17 Dec 2024 08:55:01 +0100 Subject: [PATCH] fix: remove trigger node --- .../nodes/Baserow/BaserowTrigger.node.json | 18 -- .../nodes/Baserow/BaserowTrigger.node.ts | 228 ------------------ packages/nodes-base/package.json | 1 - 3 files changed, 247 deletions(-) delete mode 100644 packages/nodes-base/nodes/Baserow/BaserowTrigger.node.json delete mode 100644 packages/nodes-base/nodes/Baserow/BaserowTrigger.node.ts diff --git a/packages/nodes-base/nodes/Baserow/BaserowTrigger.node.json b/packages/nodes-base/nodes/Baserow/BaserowTrigger.node.json deleted file mode 100644 index 3ea6f63829..0000000000 --- a/packages/nodes-base/nodes/Baserow/BaserowTrigger.node.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "node": "n8n-nodes-base.baserowTrigger", - "nodeVersion": "1.0", - "codexVersion": "1.0", - "categories": ["Data & Storage"], - "resources": { - "credentialDocumentation": [ - { - "url": "https://docs.n8n.io/integrations/builtin/credentials/baserow/" - } - ], - "primaryDocumentation": [ - { - "url": "https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.baserowtrigger/" - } - ] - } -} diff --git a/packages/nodes-base/nodes/Baserow/BaserowTrigger.node.ts b/packages/nodes-base/nodes/Baserow/BaserowTrigger.node.ts deleted file mode 100644 index 88469a76b5..0000000000 --- a/packages/nodes-base/nodes/Baserow/BaserowTrigger.node.ts +++ /dev/null @@ -1,228 +0,0 @@ -import moment from 'moment-timezone'; -import type { - IPollFunctions, - IDataObject, - INodeExecutionData, - INodeType, - INodeTypeDescription, - ILoadOptionsFunctions, -} from 'n8n-workflow'; -import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; - -import { - baserowApiRequest, - baserowApiRequestAllItems, - getJwtToken, - getTableFields, - TableFieldMapper, - toOptions, -} from './GenericFunctions'; -import type { BaserowCredentials, LoadedResource, Row } from './types'; - -export class BaserowTrigger implements INodeType { - description: INodeTypeDescription = { - displayName: 'Baserow Trigger', - name: 'baserowTrigger', - icon: 'file:baserow.svg', - group: ['trigger'], - version: 1, - description: 'Starts the workflow when Baserow events occur', - subtitle: '={{$parameter["event"]}}', - defaults: { - name: 'Baserow Trigger', - }, - credentials: [ - { - name: 'baserowApi', - required: true, - }, - ], - polling: true, - inputs: [], - outputs: [NodeConnectionType.Main], - properties: [ - { - displayName: 'Database Name or ID', - name: 'databaseId', - type: 'options', - default: '', - required: true, - description: - 'Database to operate on. Choose from the list, or specify an ID using an expression.', - typeOptions: { - loadOptionsMethod: 'getDatabaseIds', - }, - }, - { - displayName: 'Table Name or ID', - name: 'tableId', - type: 'options', - default: '', - required: true, - description: - 'Table to operate on. Choose from the list, or specify an ID using an expression.', - typeOptions: { - loadOptionsDependsOn: ['databaseId'], - loadOptionsMethod: 'getTableIds', - }, - }, - { - displayName: 'Trigger Field', - name: 'triggerField', - type: 'string', - default: '', - description: - 'A Created Time or Last Modified Time field that will be used to sort records. If you do not have a Created Time or Last Modified Time field in your schema, please create one, because without this field trigger will not work correctly.', - required: true, - }, - { - displayName: 'Additional Fields', - name: 'additionalFields', - type: 'collection', - placeholder: 'Add Field', - default: {}, - options: [ - { - displayName: 'Fields', - name: 'fields', - type: 'string', - requiresDataPath: 'multiple', - default: '', - // eslint-disable-next-line n8n-nodes-base/node-param-description-miscased-id - description: - 'Fields to be included in the response. Multiple ones can be set separated by comma. Example: name, id. By default all fields will be included.', - }, - { - displayName: 'View ID', - name: 'viewId', - type: 'string', - default: '', - description: - 'The name or ID of a view in the table. If set, only the records in that view will be returned.', - }, - ], - }, - ], - }; - - methods = { - loadOptions: { - async getDatabaseIds(this: ILoadOptionsFunctions) { - const credentials = await this.getCredentials('baserowApi'); - const jwtToken = await getJwtToken.call(this, credentials); - const endpoint = '/api/applications/'; - const databases = (await baserowApiRequest.call( - this, - 'GET', - endpoint, - jwtToken, - )) as LoadedResource[]; - return toOptions(databases); - }, - - async getTableIds(this: ILoadOptionsFunctions) { - const credentials = await this.getCredentials('baserowApi'); - const jwtToken = await getJwtToken.call(this, credentials); - const databaseId = this.getNodeParameter('databaseId', 0) as string; - const endpoint = `/api/database/tables/database/${databaseId}/`; - const tables = (await baserowApiRequest.call( - this, - 'GET', - endpoint, - jwtToken, - )) as LoadedResource[]; - return toOptions(tables); - }, - - async getTableFields(this: ILoadOptionsFunctions) { - const credentials = await this.getCredentials('baserowApi'); - const jwtToken = await getJwtToken.call(this, credentials); - const tableId = this.getNodeParameter('tableId', 0) as string; - const endpoint = `/api/database/fields/table/${tableId}/`; - const fields = (await baserowApiRequest.call( - this, - 'GET', - endpoint, - jwtToken, - )) as LoadedResource[]; - return toOptions(fields); - }, - }, - }; - - async poll(this: IPollFunctions): Promise { - const credentials = await this.getCredentials('baserowApi'); - const jwtToken = await getJwtToken.call(this, credentials); - const additionalFields = this.getNodeParameter('additionalFields') as IDataObject; - const webhookData = this.getWorkflowStaticData('node'); - const tableId = this.getNodeParameter('tableId') as string; - const triggerField = this.getNodeParameter('triggerField') as string; - - const fields = await getTableFields.call(this, tableId, jwtToken); - const tableMapper = new TableFieldMapper(); - tableMapper.createMappings(fields); - - const qs: IDataObject = {}; - - const endpoint = `/api/database/rows/table/${tableId}/`; - - const now = moment().utc().format(); - - const startDate = (webhookData.lastTimeChecked as string) || now; - - const endDate = now; - - if (additionalFields.viewId) { - qs.view_id = additionalFields.viewId; - } - - if (additionalFields.fields) { - const include_fields = (additionalFields.fields as string) - .split(',') - .map((field) => tableMapper.setField(field)) - .join(','); - qs.include = include_fields; - } - - // Constructing datetime filters is unintuitive.. - // First, the date_after filter is deprecated, but still works. - // Second, the datetime needs to be prefixed with the timezone. - // - // Example: "Europe/Amsterdam?2024-10-11 12:13:14" - // see: https://community.baserow.io/t/filtering-on-datetime-fields-does-not-seem-possible/6515/5 - // Note: the real zone does not matter, as long as it is consistent. - const timezone = moment.tz.guess(); - qs[`filter__${tableMapper.nameToId(triggerField)}__date_after`] = `${timezone}?${startDate}`; - - // unset filters to allow fetching a test event - if (this.getMode() === 'manual') { - delete qs[`filter__${tableMapper.nameToId(triggerField)}__date_after`]; - qs.size = 1; - } - - const rows = (await baserowApiRequestAllItems.call( - this, - 'GET', - endpoint, - jwtToken, - {}, - qs, - this.getMode() === 'manual' ? false : undefined, - this.getMode() === 'manual' ? 1 : undefined, - )) as Row[]; - - webhookData.lastTimeChecked = endDate; - - if (Array.isArray(rows) && rows.length) { - rows.forEach((row) => tableMapper.idsToNames(row)); - - if (this.getMode() === 'manual' && rows[0][triggerField] === undefined) { - throw new NodeOperationError(this.getNode(), `The Field "${triggerField}" does not exist.`); - } - - return [this.helpers.returnJsonArray(rows)]; - } - - return null; - } -} diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 27fb4b65c0..e70bac2fc4 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -427,7 +427,6 @@ "dist/nodes/BambooHr/BambooHr.node.js", "dist/nodes/Bannerbear/Bannerbear.node.js", "dist/nodes/Baserow/Baserow.node.js", - "dist/nodes/Baserow/BaserowTrigger.node.js", "dist/nodes/Beeminder/Beeminder.node.js", "dist/nodes/Bitbucket/BitbucketTrigger.node.js", "dist/nodes/Bitly/Bitly.node.js",