mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 22:54:05 -08:00
88dea330b9
* ⚡ Update `lintfix` script * ⚡ Run baseline `lintfix` * 🔥 Remove unneeded exceptions (#3538) * 🔥 Remove exceptions for `node-param-default-wrong-for-simplify` * 🔥 Remove exceptions for `node-param-placeholder-miscased-id` * ⚡ Update version * 👕 Apply `node-param-placeholder-missing` (#3542) * 👕 Apply `filesystem-wrong-cred-filename` (#3543) * 👕 Apply `node-param-description-missing-from-dynamic-options` (#3545) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-class-description-empty-string` (#3546) * 👕 Apply `node-class-description-icon-not-svg` (#3548) * 👕 Apply `filesystem-wrong-node-filename` (#3549) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Expand lintings to credentials (#3550) * 👕 Apply `node-param-multi-options-type-unsorted-items` (#3552) * ⚡ fix * ⚡ Minor fixes Co-authored-by: Michael Kret <michael.k@radency.com> * 👕 Apply `node-param-description-wrong-for-dynamic-multi-options` (#3541) * ⚡ Add new lint rule, node-param-description-wrong-for-dynamic-multi-options * ⚡ Fix with updated linting rules * ⚡ Minor fixes Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-description-boolean-without-whether` (#3553) * ⚡ fix * Update packages/nodes-base/nodes/Clockify/ProjectDescription.ts Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply node-param-display-name-wrong-for-dynamic-multi-options (#3537) * 👕 Add exceptions * 👕 Add exception * ✏️ Alphabetize rules * ⚡ Restore `lintfix` command Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: brianinoa <54530642+brianinoa@users.noreply.github.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com>
185 lines
5.1 KiB
TypeScript
185 lines
5.1 KiB
TypeScript
import {
|
|
IPollFunctions,
|
|
} from 'n8n-core';
|
|
|
|
import {
|
|
IDataObject,
|
|
INodeExecutionData,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
NodeOperationError,
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
apiRequestAllItems,
|
|
downloadRecordAttachments,
|
|
} from './GenericFunctions';
|
|
|
|
import moment from 'moment';
|
|
|
|
export class AirtableTrigger implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Airtable Trigger',
|
|
name: 'airtableTrigger',
|
|
icon: 'file:airtable.svg',
|
|
group: ['trigger'],
|
|
version: 1,
|
|
description: 'Starts the workflow when Airtable events occur',
|
|
subtitle: '={{$parameter["event"]}}',
|
|
defaults: {
|
|
name: 'Airtable Trigger',
|
|
},
|
|
credentials: [
|
|
{
|
|
name: 'airtableApi',
|
|
required: true,
|
|
},
|
|
],
|
|
polling: true,
|
|
inputs: [],
|
|
outputs: ['main'],
|
|
properties: [
|
|
{
|
|
displayName: 'Base ID',
|
|
name: 'baseId',
|
|
type: 'string',
|
|
default: '',
|
|
required: true,
|
|
description: 'The ID of this base',
|
|
},
|
|
{
|
|
displayName: 'Table ID',
|
|
name: 'tableId',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'The ID of the table to access',
|
|
required: true,
|
|
},
|
|
{
|
|
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: 'Download Attachments',
|
|
name: 'downloadAttachments',
|
|
type: 'boolean',
|
|
default: false,
|
|
description: 'Whether the attachment fields define in \'Download Fields\' will be downloaded',
|
|
},
|
|
{
|
|
displayName: 'Download Fields',
|
|
name: 'downloadFieldNames',
|
|
type: 'string',
|
|
required: true,
|
|
displayOptions: {
|
|
show: {
|
|
downloadAttachments: [
|
|
true,
|
|
],
|
|
},
|
|
},
|
|
default: '',
|
|
description: 'Name of the fields of type \'attachment\' that should be downloaded. Multiple ones can be defined separated by comma. Case sensitive.',
|
|
},
|
|
{
|
|
displayName: 'Additional Fields',
|
|
name: 'additionalFields',
|
|
type: 'collection',
|
|
placeholder: 'Add Field',
|
|
default: {},
|
|
options: [
|
|
{
|
|
displayName: 'Fields',
|
|
name: 'fields',
|
|
type: 'string',
|
|
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: <code>name, id</code>. By default just the trigger field will be included.',
|
|
},
|
|
{
|
|
displayName: 'Formula',
|
|
name: 'formula',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'Formulas may involve functions, numeric operations, logical operations, and text operations that operate on fields. More info <a href="https://support.airtable.com/hc/en-us/articles/203255215-Formula-Field-Reference">here</a>.',
|
|
},
|
|
{
|
|
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.',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
|
|
const downloadAttachments = this.getNodeParameter('downloadAttachments', 0) as boolean;
|
|
|
|
const webhookData = this.getWorkflowStaticData('node');
|
|
|
|
const qs: IDataObject = {};
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields') as IDataObject;
|
|
|
|
const base = this.getNodeParameter('baseId') as string;
|
|
|
|
const table = this.getNodeParameter('tableId') as string;
|
|
|
|
const triggerField = this.getNodeParameter('triggerField') as string;
|
|
|
|
const endpoint = `${base}/${table}`;
|
|
|
|
const now = moment().utc().format();
|
|
|
|
const startDate = webhookData.lastTimeChecked as string || now;
|
|
|
|
const endDate = now;
|
|
|
|
if (additionalFields.viewId) {
|
|
qs.view = additionalFields.viewId;
|
|
}
|
|
|
|
if (additionalFields.fields) {
|
|
qs['fields[]'] = (additionalFields.fields as string).split(',');
|
|
}
|
|
|
|
qs.filterByFormula = `IS_AFTER({${triggerField}}, DATETIME_PARSE("${startDate}", "YYYY-MM-DD HH:mm:ss"))`;
|
|
|
|
if (additionalFields.formula) {
|
|
qs.filterByFormula = `AND(${qs.filterByFormula}, ${additionalFields.formula})`;
|
|
}
|
|
|
|
if (this.getMode() === 'manual') {
|
|
delete qs.filterByFormula;
|
|
qs.maxRecords = 1;
|
|
}
|
|
|
|
const { records } = await apiRequestAllItems.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
webhookData.lastTimeChecked = endDate;
|
|
|
|
if (Array.isArray(records) && records.length) {
|
|
if (this.getMode() === 'manual' && records[0].fields[triggerField] === undefined) {
|
|
throw new NodeOperationError(this.getNode(), `The Field "${triggerField}" does not exist.`);
|
|
}
|
|
|
|
if (downloadAttachments === true) {
|
|
const downloadFieldNames = (this.getNodeParameter('downloadFieldNames', 0) as string).split(',');
|
|
const data = await downloadRecordAttachments.call(this, records, downloadFieldNames);
|
|
return [data];
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(records)];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|