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,32 @@
|
||||
import type {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
INodeCredentialTestResult,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { getGoogleAccessToken } from '../../../GenericFunctions';
|
||||
|
||||
export async function googleApiCredentialTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
try {
|
||||
const tokenRequest = await getGoogleAccessToken.call(this, credential.data!, 'sheetV2');
|
||||
if (!tokenRequest.access_token) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: 'Could not generate a token from your private key.',
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: `Private key validation failed: ${err.message}`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Connection successful!',
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * as loadOptions from './loadOptions';
|
||||
export * as listSearch from './listSearch';
|
||||
export * as credentialTest from './credentialTest';
|
||||
export * as resourceMapping from './resourceMapping';
|
||||
@@ -0,0 +1,93 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeListSearchItems,
|
||||
INodeListSearchResult,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { ResourceLocator } from '../helpers/GoogleSheets.types';
|
||||
import { getSpreadsheetId } from '../helpers/GoogleSheets.utils';
|
||||
import { apiRequest } from '../transport';
|
||||
|
||||
export async function spreadSheetsSearch(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const query: string[] = [];
|
||||
if (filter) {
|
||||
query.push(`name contains '${filter.replace("'", "\\'")}'`);
|
||||
}
|
||||
query.push("mimeType = 'application/vnd.google-apps.spreadsheet'");
|
||||
|
||||
const qs = {
|
||||
q: query.join(' and '),
|
||||
pageToken: (paginationToken as string) || undefined,
|
||||
fields: 'nextPageToken, files(id, name, webViewLink)',
|
||||
orderBy: 'modifiedByMeTime desc,name_natural',
|
||||
includeItemsFromAllDrives: true,
|
||||
supportsAllDrives: true,
|
||||
};
|
||||
|
||||
const res = await apiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'',
|
||||
{},
|
||||
qs,
|
||||
'https://www.googleapis.com/drive/v3/files',
|
||||
);
|
||||
return {
|
||||
results: res.files.map((sheet: IDataObject) => ({
|
||||
name: sheet.name as string,
|
||||
value: sheet.id as string,
|
||||
url: sheet.webViewLink as string,
|
||||
})),
|
||||
paginationToken: res.nextPageToken,
|
||||
};
|
||||
}
|
||||
|
||||
export async function sheetsSearch(
|
||||
this: ILoadOptionsFunctions,
|
||||
_filter?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const documentId = this.getNodeParameter('documentId', 0) as IDataObject | null;
|
||||
|
||||
if (!documentId) return { results: [] };
|
||||
|
||||
const { mode, value } = documentId;
|
||||
|
||||
const spreadsheetId = getSpreadsheetId(this.getNode(), mode as ResourceLocator, value as string);
|
||||
|
||||
const query = {
|
||||
fields: 'sheets.properties',
|
||||
};
|
||||
|
||||
const responseData = await apiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/v4/spreadsheets/${spreadsheetId}`,
|
||||
{},
|
||||
query,
|
||||
);
|
||||
|
||||
if (responseData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No data got returned');
|
||||
}
|
||||
|
||||
const returnData: INodeListSearchItems[] = [];
|
||||
for (const sheet of responseData.sheets!) {
|
||||
if (sheet.properties!.sheetType !== 'GRID') {
|
||||
continue;
|
||||
}
|
||||
|
||||
returnData.push({
|
||||
name: sheet.properties!.title as string,
|
||||
value: (sheet.properties!.sheetId as number) || 'gid=0',
|
||||
url: `https://docs.google.com/spreadsheets/d/${spreadsheetId}/edit#gid=${sheet.properties!.sheetId}`,
|
||||
});
|
||||
}
|
||||
|
||||
return { results: returnData };
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import type { IDataObject, ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { GoogleSheet } from '../helpers/GoogleSheet';
|
||||
import type { ResourceLocator } from '../helpers/GoogleSheets.types';
|
||||
import { getSpreadsheetId } from '../helpers/GoogleSheets.utils';
|
||||
|
||||
export async function getSheets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const documentId = this.getNodeParameter('documentId', 0) as IDataObject | null;
|
||||
|
||||
if (!documentId) return [];
|
||||
|
||||
const { mode, value } = documentId;
|
||||
|
||||
const spreadsheetId = getSpreadsheetId(this.getNode(), mode as ResourceLocator, value as string);
|
||||
|
||||
const sheet = new GoogleSheet(spreadsheetId, this);
|
||||
const responseData = await sheet.spreadsheetGetSheets();
|
||||
|
||||
if (responseData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No data got returned');
|
||||
}
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
for (const entry of responseData.sheets!) {
|
||||
if (entry.properties!.sheetType !== 'GRID') {
|
||||
continue;
|
||||
}
|
||||
|
||||
returnData.push({
|
||||
name: entry.properties!.title as string,
|
||||
value: entry.properties!.sheetId as unknown as string,
|
||||
});
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export async function getSheetHeaderRow(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const documentId = this.getNodeParameter('documentId', 0) as IDataObject | null;
|
||||
|
||||
if (!documentId) return [];
|
||||
|
||||
const { mode, value } = documentId;
|
||||
|
||||
const spreadsheetId = getSpreadsheetId(this.getNode(), mode as ResourceLocator, value as string);
|
||||
|
||||
const sheet = new GoogleSheet(spreadsheetId, this);
|
||||
const sheetWithinDocument = this.getNodeParameter('sheetName', undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
const { mode: sheetMode } = this.getNodeParameter('sheetName', 0) as {
|
||||
mode: ResourceLocator;
|
||||
};
|
||||
|
||||
const { title: sheetName } = await sheet.spreadsheetGetSheet(
|
||||
this.getNode(),
|
||||
sheetMode,
|
||||
sheetWithinDocument,
|
||||
);
|
||||
const sheetData = await sheet.getData(`${sheetName}!1:1`, 'FORMATTED_VALUE');
|
||||
|
||||
if (sheetData === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No data got returned');
|
||||
}
|
||||
|
||||
const columns = sheet.testFilter(sheetData, 0, 0);
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
|
||||
for (const column of columns) {
|
||||
returnData.push({
|
||||
name: column as unknown as string,
|
||||
value: column as unknown as string,
|
||||
});
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export async function getSheetHeaderRowAndAddColumn(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const returnData = await getSheetHeaderRow.call(this);
|
||||
returnData.push({
|
||||
name: 'New column ...',
|
||||
value: 'newColumn',
|
||||
});
|
||||
const columnToMatchOn = this.getNodeParameter('columnToMatchOn', 0) as string;
|
||||
return returnData.filter((column) => column.value !== columnToMatchOn);
|
||||
}
|
||||
|
||||
export async function getSheetHeaderRowWithGeneratedColumnNames(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const returnData = await getSheetHeaderRow.call(this);
|
||||
return returnData.map((column, i) => {
|
||||
if (column.value !== '') return column;
|
||||
const indexBasedValue = `col_${i + 1}`;
|
||||
return {
|
||||
name: indexBasedValue,
|
||||
value: indexBasedValue,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export async function getSheetHeaderRowAndSkipEmpty(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const returnData = await getSheetHeaderRow.call(this);
|
||||
return returnData.filter((column) => column.value);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
ResourceMapperField,
|
||||
ResourceMapperFields,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { GoogleSheet } from '../helpers/GoogleSheet';
|
||||
import { ROW_NUMBER, type ResourceLocator } from '../helpers/GoogleSheets.types';
|
||||
import { getSpreadsheetId } from '../helpers/GoogleSheets.utils';
|
||||
|
||||
export async function getMappingColumns(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<ResourceMapperFields> {
|
||||
const documentId = this.getNodeParameter('documentId', 0) as IDataObject | null;
|
||||
|
||||
if (!documentId) return { fields: [] };
|
||||
|
||||
const { mode, value } = documentId;
|
||||
|
||||
const spreadsheetId = getSpreadsheetId(this.getNode(), mode as ResourceLocator, value as string);
|
||||
|
||||
const sheet = new GoogleSheet(spreadsheetId, this);
|
||||
const sheetWithinDocument = this.getNodeParameter('sheetName', undefined, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
const { mode: sheetMode } = this.getNodeParameter('sheetName', 0) as { mode: ResourceLocator };
|
||||
|
||||
const { title: sheetName } = await sheet.spreadsheetGetSheet(
|
||||
this.getNode(),
|
||||
sheetMode,
|
||||
sheetWithinDocument,
|
||||
);
|
||||
|
||||
const locationDefine = this.getNodeParameter(
|
||||
'options.locationDefine.values',
|
||||
0,
|
||||
{},
|
||||
) as IDataObject;
|
||||
|
||||
let columnNamesRow = 1;
|
||||
|
||||
if (locationDefine.headerRow) {
|
||||
columnNamesRow = locationDefine.headerRow as number;
|
||||
}
|
||||
|
||||
const sheetData = await sheet.getData(
|
||||
`${sheetName}!${columnNamesRow}:${columnNamesRow}`,
|
||||
'FORMATTED_VALUE',
|
||||
);
|
||||
|
||||
const columns = sheet.testFilter(sheetData || [], 0, 0).filter((col) => col !== '');
|
||||
|
||||
const fields: ResourceMapperField[] = columns.map((col) => ({
|
||||
id: col,
|
||||
displayName: col,
|
||||
required: false,
|
||||
defaultMatch: col === 'id',
|
||||
display: true,
|
||||
type: 'string',
|
||||
canBeUsedToMatch: true,
|
||||
}));
|
||||
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
if (operation === 'update') {
|
||||
fields.push({
|
||||
id: ROW_NUMBER,
|
||||
displayName: ROW_NUMBER,
|
||||
required: false,
|
||||
defaultMatch: false,
|
||||
display: true,
|
||||
type: 'number',
|
||||
canBeUsedToMatch: true,
|
||||
readOnly: true,
|
||||
removed: true,
|
||||
});
|
||||
}
|
||||
|
||||
return { fields };
|
||||
}
|
||||
Reference in New Issue
Block a user