first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export * as listSearch from './listSearch';
|
||||
export * as loadOptions from './loadOptions';
|
||||
export * as resourceMapping from './resourceMapping';
|
||||
@@ -0,0 +1,152 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeListSearchItems,
|
||||
INodeListSearchResult,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { apiRequest } from '../transport';
|
||||
|
||||
export async function baseSearch(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
let qs;
|
||||
if (paginationToken) {
|
||||
qs = {
|
||||
offset: paginationToken,
|
||||
};
|
||||
}
|
||||
|
||||
const response = await apiRequest.call(this, 'GET', 'meta/bases', undefined, qs);
|
||||
|
||||
if (filter) {
|
||||
const results: INodeListSearchItems[] = [];
|
||||
|
||||
for (const base of response.bases || []) {
|
||||
if ((base.name as string)?.toLowerCase().includes(filter.toLowerCase())) {
|
||||
results.push({
|
||||
name: base.name as string,
|
||||
value: base.id as string,
|
||||
url: `https://airtable.com/${base.id}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
results,
|
||||
paginationToken: response.offset,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
results: (response.bases || []).map((base: IDataObject) => ({
|
||||
name: base.name as string,
|
||||
value: base.id as string,
|
||||
url: `https://airtable.com/${base.id}`,
|
||||
})),
|
||||
paginationToken: response.offset,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function tableSearch(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const baseId = this.getNodeParameter('base', undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
let qs;
|
||||
if (paginationToken) {
|
||||
qs = {
|
||||
offset: paginationToken,
|
||||
};
|
||||
}
|
||||
|
||||
const response = await apiRequest.call(this, 'GET', `meta/bases/${baseId}/tables`, undefined, qs);
|
||||
|
||||
if (filter) {
|
||||
const results: INodeListSearchItems[] = [];
|
||||
|
||||
for (const table of response.tables || []) {
|
||||
if ((table.name as string)?.toLowerCase().includes(filter.toLowerCase())) {
|
||||
results.push({
|
||||
name: table.name as string,
|
||||
value: table.id as string,
|
||||
url: `https://airtable.com/${baseId}/${table.id}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
results,
|
||||
paginationToken: response.offset,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
results: (response.tables || []).map((table: IDataObject) => ({
|
||||
name: table.name as string,
|
||||
value: table.id as string,
|
||||
url: `https://airtable.com/${baseId}/${table.id}`,
|
||||
})),
|
||||
paginationToken: response.offset,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function viewSearch(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const baseId = this.getNodeParameter('base', undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
const tableId = encodeURI(
|
||||
this.getNodeParameter('table', undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
const response = await apiRequest.call(this, 'GET', `meta/bases/${baseId}/tables`);
|
||||
|
||||
const tableData = ((response.tables as IDataObject[]) || []).find((table: IDataObject) => {
|
||||
return table.id === tableId;
|
||||
});
|
||||
|
||||
if (!tableData) {
|
||||
throw new NodeOperationError(this.getNode(), 'Table information could not be found!', {
|
||||
level: 'warning',
|
||||
});
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
const results: INodeListSearchItems[] = [];
|
||||
|
||||
for (const view of (tableData.views as IDataObject[]) || []) {
|
||||
if ((view.name as string)?.toLowerCase().includes(filter.toLowerCase())) {
|
||||
results.push({
|
||||
name: view.name as string,
|
||||
value: view.id as string,
|
||||
url: `https://airtable.com/${baseId}/${tableId}/${view.id}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
results,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
results: ((tableData.views as IDataObject[]) || []).map((view) => ({
|
||||
name: view.name as string,
|
||||
value: view.id as string,
|
||||
url: `https://airtable.com/${baseId}/${tableId}/${view.id}`,
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import type { IDataObject, ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { apiRequest } from '../transport';
|
||||
|
||||
export async function getColumns(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const base = this.getNodeParameter('base', undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
const tableId = encodeURI(
|
||||
this.getNodeParameter('table', undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
const response = await apiRequest.call(this, 'GET', `meta/bases/${base}/tables`);
|
||||
|
||||
const tableData = ((response.tables as IDataObject[]) || []).find((table: IDataObject) => {
|
||||
return table.id === tableId;
|
||||
});
|
||||
|
||||
if (!tableData) {
|
||||
throw new NodeOperationError(this.getNode(), 'Table information could not be found!', {
|
||||
level: 'warning',
|
||||
});
|
||||
}
|
||||
|
||||
const result: INodePropertyOptions[] = [];
|
||||
|
||||
for (const field of tableData.fields as IDataObject[]) {
|
||||
result.push({
|
||||
name: field.name as string,
|
||||
value: field.name as string,
|
||||
description: `Type: ${field.type}`,
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getColumnsWithRecordId(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const returnData = await getColumns.call(this);
|
||||
return [
|
||||
{
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased-id, n8n-nodes-base/node-param-display-name-miscased
|
||||
name: 'id',
|
||||
value: 'id' as string,
|
||||
description: 'Type: primaryFieldId',
|
||||
},
|
||||
...returnData,
|
||||
];
|
||||
}
|
||||
|
||||
export async function getColumnsWithoutColumnToMatchOn(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const columnToMatchOn = this.getNodeParameter('columnToMatchOn') as string;
|
||||
const returnData = await getColumns.call(this);
|
||||
return returnData.filter((column) => column.value !== columnToMatchOn);
|
||||
}
|
||||
|
||||
export async function getAttachmentColumns(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const base = this.getNodeParameter('base', undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
const tableId = encodeURI(
|
||||
this.getNodeParameter('table', undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
const response = await apiRequest.call(this, 'GET', `meta/bases/${base}/tables`);
|
||||
|
||||
const tableData = ((response.tables as IDataObject[]) || []).find((table: IDataObject) => {
|
||||
return table.id === tableId;
|
||||
});
|
||||
|
||||
if (!tableData) {
|
||||
throw new NodeOperationError(this.getNode(), 'Table information could not be found!', {
|
||||
level: 'warning',
|
||||
});
|
||||
}
|
||||
|
||||
const result: INodePropertyOptions[] = [];
|
||||
|
||||
for (const field of tableData.fields as IDataObject[]) {
|
||||
if (!(field.type as string)?.toLowerCase()?.includes('attachment')) {
|
||||
continue;
|
||||
}
|
||||
result.push({
|
||||
name: field.name as string,
|
||||
value: field.name as string,
|
||||
description: `Type: ${field.type}`,
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import type {
|
||||
FieldType,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodePropertyOptions,
|
||||
ResourceMapperField,
|
||||
ResourceMapperFields,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { apiRequest } from '../transport';
|
||||
|
||||
type AirtableSchema = {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
options?: IDataObject;
|
||||
};
|
||||
|
||||
type TypesMap = Partial<Record<FieldType, string[]>>;
|
||||
|
||||
const airtableReadOnlyFields = [
|
||||
'autoNumber',
|
||||
'button',
|
||||
'count',
|
||||
'createdBy',
|
||||
'createdTime',
|
||||
'formula',
|
||||
'lastModifiedBy',
|
||||
'lastModifiedTime',
|
||||
'lookup',
|
||||
'rollup',
|
||||
'externalSyncSource',
|
||||
'multipleLookupValues',
|
||||
];
|
||||
|
||||
const airtableTypesMap: TypesMap = {
|
||||
string: ['singleLineText', 'multilineText', 'richText', 'email', 'phoneNumber', 'url'],
|
||||
number: ['rating', 'percent', 'number', 'duration', 'currency'],
|
||||
boolean: ['checkbox'],
|
||||
dateTime: ['dateTime', 'date'],
|
||||
time: [],
|
||||
object: [],
|
||||
options: ['singleSelect'],
|
||||
array: ['multipleSelects', 'multipleRecordLinks', 'multipleAttachments'],
|
||||
};
|
||||
|
||||
function mapForeignType(foreignType: string, typesMap: TypesMap): FieldType {
|
||||
let type: FieldType = 'string';
|
||||
|
||||
for (const nativeType of Object.keys(typesMap)) {
|
||||
const mappedForeignTypes = typesMap[nativeType as FieldType];
|
||||
|
||||
if (mappedForeignTypes?.includes(foreignType)) {
|
||||
type = nativeType as FieldType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
export async function getColumns(this: ILoadOptionsFunctions): Promise<ResourceMapperFields> {
|
||||
const base = this.getNodeParameter('base', undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
const tableId = encodeURI(
|
||||
this.getNodeParameter('table', undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
const response = await apiRequest.call(this, 'GET', `meta/bases/${base}/tables`);
|
||||
|
||||
const tableData = ((response.tables as IDataObject[]) || []).find((table: IDataObject) => {
|
||||
return table.id === tableId;
|
||||
});
|
||||
|
||||
if (!tableData) {
|
||||
throw new NodeOperationError(this.getNode(), 'Table information could not be found!', {
|
||||
level: 'warning',
|
||||
});
|
||||
}
|
||||
|
||||
const fields: ResourceMapperField[] = [];
|
||||
|
||||
const constructOptions = (field: AirtableSchema) => {
|
||||
if (field?.options?.choices) {
|
||||
return (field.options.choices as IDataObject[]).map((choice) => ({
|
||||
name: choice.name,
|
||||
value: choice.name,
|
||||
})) as INodePropertyOptions[];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
for (const field of tableData.fields as AirtableSchema[]) {
|
||||
const type = mapForeignType(field.type, airtableTypesMap);
|
||||
const isReadOnly = airtableReadOnlyFields.includes(field.type);
|
||||
const options = constructOptions(field);
|
||||
fields.push({
|
||||
id: field.name,
|
||||
displayName: field.name,
|
||||
required: false,
|
||||
defaultMatch: false,
|
||||
canBeUsedToMatch: true,
|
||||
display: true,
|
||||
type,
|
||||
options,
|
||||
readOnly: isReadOnly,
|
||||
removed: isReadOnly,
|
||||
});
|
||||
}
|
||||
|
||||
return { fields };
|
||||
}
|
||||
|
||||
export async function getColumnsWithRecordId(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<ResourceMapperFields> {
|
||||
const returnData = await getColumns.call(this);
|
||||
return {
|
||||
fields: [
|
||||
{
|
||||
id: 'id',
|
||||
displayName: 'id',
|
||||
required: false,
|
||||
defaultMatch: true,
|
||||
display: true,
|
||||
type: 'string',
|
||||
readOnly: true,
|
||||
},
|
||||
...returnData.fields,
|
||||
],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user