🔀 Merge branch 'RicardoE105-feature/microsoft-excel' into oauth-support

This commit is contained in:
Jan Oberhauser 2020-03-28 19:09:39 +01:00
commit c96eb51bb0
11 changed files with 1965 additions and 8 deletions

View file

@ -0,0 +1,21 @@
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';
export class MicrosoftExcelOAuth2Api implements ICredentialType {
name = 'microsoftExcelOAuth2Api';
extends = [
'microsoftOAuth2Api',
];
displayName = 'Microsoft OAuth2 API';
properties = [
//https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent
{
displayName: 'Scope',
name: 'scope',
type: 'hidden' as NodePropertyTypes,
default: 'openid offline_access Files.ReadWrite',
},
];
}

View file

@ -0,0 +1,38 @@
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';
export class MicrosoftOAuth2Api implements ICredentialType {
name = 'microsoftOAuth2Api';
extends = [
'oAuth2Api',
];
displayName = 'Microsoft OAuth2 API';
properties = [
{
displayName: 'Authorization URL',
name: 'authUrl',
type: 'string' as NodePropertyTypes,
default: 'https://login.microsoftonline.com/{yourtenantid}/oauth2/v2.0/authorize',
},
{
displayName: 'Access Token URL',
name: 'accessTokenUrl',
type: 'string' as NodePropertyTypes,
default: 'https://login.microsoftonline.com/{yourtenantid}/oauth2/v2.0/token',
},
{
displayName: 'Auth URI Query Parameters',
name: 'authQueryParameters',
type: 'hidden' as NodePropertyTypes,
default: 'response_mode=query',
},
{
displayName: 'Authentication',
name: 'authentication',
type: 'hidden' as NodePropertyTypes,
default: 'body',
},
];
}

View file

@ -0,0 +1,26 @@
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';
const scopes = [
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.events',
];
export class TestOAuth2Api implements ICredentialType {
name = 'testOAuth2Api';
extends = [
'googleOAuth2Api',
];
displayName = 'Test OAuth2 API';
properties = [
{
displayName: 'Scope',
name: 'scope',
type: 'string' as NodePropertyTypes,
default: '',
placeholder: 'asdf',
},
];
}

View file

@ -0,0 +1,293 @@
// import { google } from 'googleapis';
// import {
// IHookFunctions,
// IWebhookFunctions,
// } from 'n8n-core';
// import {
// IDataObject,
// INodeTypeDescription,
// INodeType,
// IWebhookResponseData,
// } from 'n8n-workflow';
// import { getAuthenticationClient } from './GoogleApi';
// export class GoogleDriveTrigger implements INodeType {
// description: INodeTypeDescription = {
// displayName: 'Google Drive Trigger',
// name: 'googleDriveTrigger',
// icon: 'file:googleDrive.png',
// group: ['trigger'],
// version: 1,
// subtitle: '={{$parameter["owner"] + "/" + $parameter["repository"] + ": " + $parameter["events"].join(", ")}}',
// description: 'Starts the workflow when a file on Google Drive got changed.',
// defaults: {
// name: 'Google Drive Trigger',
// color: '#3f87f2',
// },
// inputs: [],
// outputs: ['main'],
// credentials: [
// {
// name: 'googleApi',
// required: true,
// }
// ],
// webhooks: [
// {
// name: 'default',
// httpMethod: 'POST',
// responseMode: 'onReceived',
// path: 'webhook',
// },
// ],
// properties: [
// {
// displayName: 'Resource Id',
// name: 'resourceId',
// type: 'string',
// default: '',
// required: true,
// placeholder: '',
// description: 'ID of the resource to watch, for example a file ID.',
// },
// ],
// };
// // @ts-ignore (because of request)
// webhookMethods = {
// default: {
// async checkExists(this: IHookFunctions): Promise<boolean> {
// // const webhookData = this.getWorkflowStaticData('node');
// // if (webhookData.webhookId === undefined) {
// // // No webhook id is set so no webhook can exist
// // return false;
// // }
// // // Webhook got created before so check if it still exists
// // const owner = this.getNodeParameter('owner') as string;
// // const repository = this.getNodeParameter('repository') as string;
// // const endpoint = `/repos/${owner}/${repository}/hooks/${webhookData.webhookId}`;
// // try {
// // await githubApiRequest.call(this, 'GET', endpoint, {});
// // } catch (e) {
// // if (e.message.includes('[404]:')) {
// // // Webhook does not exist
// // delete webhookData.webhookId;
// // delete webhookData.webhookEvents;
// // return false;
// // }
// // // Some error occured
// // throw e;
// // }
// // If it did not error then the webhook exists
// // return true;
// return false;
// },
// async create(this: IHookFunctions): Promise<boolean> {
// const webhookUrl = this.getNodeWebhookUrl('default');
// const resourceId = this.getNodeParameter('resourceId') as string;
// const credentials = this.getCredentials('googleApi');
// if (credentials === undefined) {
// throw new Error('No credentials got returned!');
// }
// const scopes = [
// 'https://www.googleapis.com/auth/drive',
// 'https://www.googleapis.com/auth/drive.appdata',
// 'https://www.googleapis.com/auth/drive.photos.readonly',
// ];
// const client = await getAuthenticationClient(credentials.email as string, credentials.privateKey as string, scopes);
// const drive = google.drive({
// version: 'v3',
// auth: client,
// });
// const accessToken = await client.getAccessToken();
// console.log('accessToken: ');
// console.log(accessToken);
// const asdf = await drive.changes.getStartPageToken();
// // console.log('asdf: ');
// // console.log(asdf);
// const response = await drive.changes.watch({
// //
// pageToken: asdf.data.startPageToken,
// requestBody: {
// id: 'asdf-test-2',
// address: webhookUrl,
// resourceId,
// type: 'web_hook',
// // page_token: '',
// }
// });
// console.log('...response...CREATE');
// console.log(JSON.stringify(response, null, 2));
// // const endpoint = `/repos/${owner}/${repository}/hooks`;
// // const body = {
// // name: 'web',
// // config: {
// // url: webhookUrl,
// // content_type: 'json',
// // // secret: '...later...',
// // insecure_ssl: '1', // '0' -> not allow inscure ssl | '1' -> allow insercure SSL
// // },
// // events,
// // active: true,
// // };
// // let responseData;
// // try {
// // responseData = await githubApiRequest.call(this, 'POST', endpoint, body);
// // } catch (e) {
// // if (e.message.includes('[422]:')) {
// // throw new Error('A webhook with the identical URL exists already. Please delete it manually on Github!');
// // }
// // throw e;
// // }
// // if (responseData.id === undefined || responseData.active !== true) {
// // // Required data is missing so was not successful
// // throw new Error('Github webhook creation response did not contain the expected data.');
// // }
// // const webhookData = this.getWorkflowStaticData('node');
// // webhookData.webhookId = responseData.id as string;
// // webhookData.webhookEvents = responseData.events as string[];
// return true;
// },
// async delete(this: IHookFunctions): Promise<boolean> {
// const webhookUrl = this.getNodeWebhookUrl('default');
// const resourceId = this.getNodeParameter('resourceId') as string;
// const credentials = this.getCredentials('googleApi');
// if (credentials === undefined) {
// throw new Error('No credentials got returned!');
// }
// const scopes = [
// 'https://www.googleapis.com/auth/drive',
// 'https://www.googleapis.com/auth/drive.appdata',
// 'https://www.googleapis.com/auth/drive.photos.readonly',
// ];
// const client = await getAuthenticationClient(credentials.email as string, credentials.privateKey as string, scopes);
// const drive = google.drive({
// version: 'v3',
// auth: client,
// });
// // Remove channel
// const response = await drive.channels.stop({
// requestBody: {
// id: 'asdf-test-2',
// address: webhookUrl,
// resourceId,
// type: 'web_hook',
// }
// });
// console.log('...response...DELETE');
// console.log(JSON.stringify(response, null, 2));
// // const webhookData = this.getWorkflowStaticData('node');
// // if (webhookData.webhookId !== undefined) {
// // const owner = this.getNodeParameter('owner') as string;
// // const repository = this.getNodeParameter('repository') as string;
// // const endpoint = `/repos/${owner}/${repository}/hooks/${webhookData.webhookId}`;
// // const body = {};
// // try {
// // await githubApiRequest.call(this, 'DELETE', endpoint, body);
// // } catch (e) {
// // return false;
// // }
// // // Remove from the static workflow data so that it is clear
// // // that no webhooks are registred anymore
// // delete webhookData.webhookId;
// // delete webhookData.webhookEvents;
// // }
// return true;
// },
// },
// };
// async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
// const bodyData = this.getBodyData();
// console.log('');
// console.log('');
// console.log('GOT WEBHOOK CALL');
// console.log(JSON.stringify(bodyData, null, 2));
// // Check if the webhook is only the ping from Github to confirm if it workshook_id
// if (bodyData.hook_id !== undefined && bodyData.action === undefined) {
// // Is only the ping and not an actual webhook call. So return 'OK'
// // but do not start the workflow.
// return {
// webhookResponse: 'OK'
// };
// }
// // Is a regular webhoook call
// // TODO: Add headers & requestPath
// const returnData: IDataObject[] = [];
// returnData.push(
// {
// body: bodyData,
// headers: this.getHeaderData(),
// query: this.getQueryData(),
// }
// );
// return {
// workflowData: [
// this.helpers.returnJsonArray(returnData)
// ],
// };
// }
// }

View file

@ -0,0 +1,73 @@
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import {
IDataObject
} from 'n8n-workflow';
export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
},
method,
body,
qs,
uri: uri || `https://graph.microsoft.com/v1.0/me${resource}`,
json: true
};
try {
if (Object.keys(headers).length !== 0) {
options.headers = Object.assign({}, options.headers, headers);
}
//@ts-ignore
return await this.helpers.requestOAuth.call(this, 'microsoftExcelOAuth2Api', options);
} catch (error) {
if (error.response && error.response.body && error.response.body.error && error.response.body.error.message) {
// Try to return the error prettier
throw new Error(`Microsoft error response [${error.statusCode}]: ${error.response.body.error.message}`);
}
throw error;
}
}
export async function microsoftApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, propertyName: string ,method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = [];
let responseData;
let uri: string | undefined;
query['$top'] = 100;
do {
responseData = await microsoftApiRequest.call(this, method, endpoint, body, query, uri);
uri = responseData['@odata.nextLink'];
returnData.push.apply(returnData, responseData[propertyName]);
} while (
responseData['@odata.nextLink'] !== undefined
);
return returnData;
}
export async function microsoftApiRequestAllItemsSkip(this: IExecuteFunctions | ILoadOptionsFunctions, propertyName: string ,method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = [];
let responseData;
query['$top'] = 100;
query['$skip'] = 0;
do {
responseData = await microsoftApiRequest.call(this, method, endpoint, body, query);
query['$skip'] += query['$top'];
returnData.push.apply(returnData, responseData[propertyName]);
} while (
responseData['value'].length !== 0
);
return returnData;
}

View file

@ -0,0 +1,421 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
INodeTypeDescription,
INodeType,
ILoadOptionsFunctions,
INodePropertyOptions,
} from 'n8n-workflow';
import {
microsoftApiRequest,
microsoftApiRequestAllItems,
microsoftApiRequestAllItemsSkip,
} from './GenericFunctions';
import {
workbookOperations,
workbookFields,
} from './WorkbookDescription';
import {
worksheetOperations,
worksheetFields,
} from './WorksheetDescription';
import {
tableOperations,
tableFields,
} from './TableDescription';
export class MicrosoftExcel implements INodeType {
description: INodeTypeDescription = {
displayName: 'Microsoft Excel',
name: 'microsoftExcel',
icon: 'file:excel.png',
group: ['input'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume Microsoft Excel API.',
defaults: {
name: 'Microsoft Excel',
color: '#1c6d40',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'microsoftExcelOAuth2Api',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
options: [
{
name: 'Table',
value: 'table',
description: 'Represents an Excel table.',
},
{
name: 'Workbook',
value: 'workbook',
description: 'Workbook is the top level object which contains related workbook objects such as worksheets, tables, ranges, etc.',
},
{
name: 'Worksheet',
value: 'worksheet',
description: 'An Excel worksheet is a grid of cells. It can contain data, tables, charts, etc.',
},
],
default: 'workbook',
description: 'The resource to operate on.',
},
...workbookOperations,
...workbookFields,
...worksheetOperations,
...worksheetFields,
...tableOperations,
...tableFields,
],
};
methods = {
loadOptions: {
// Get all the workbooks to display them to user so that he can
// select them easily
async getWorkbooks(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const qs: IDataObject = {
select: 'id,name',
};
const returnData: INodePropertyOptions[] = [];
const workbooks = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/drive/root/search(q='.xlsx')`, {}, qs);
for (const workbook of workbooks) {
const workbookName = workbook.name;
const workbookId = workbook.id;
returnData.push({
name: workbookName,
value: workbookId,
});
}
return returnData;
},
// Get all the worksheets to display them to user so that he can
// select them easily
async getworksheets(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const workbookId = this.getCurrentNodeParameter('workbook');
const qs: IDataObject = {
select: 'id,name',
};
const returnData: INodePropertyOptions[] = [];
const worksheets = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/drive/items/${workbookId}/workbook/worksheets`, {}, qs);
for (const worksheet of worksheets) {
const worksheetName = worksheet.name;
const worksheetId = worksheet.id;
returnData.push({
name: worksheetName,
value: worksheetId,
});
}
return returnData;
},
// Get all the tables to display them to user so that he can
// select them easily
async getTables(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const workbookId = this.getCurrentNodeParameter('workbook');
const worksheetId = this.getCurrentNodeParameter('worksheet');
const qs: IDataObject = {
select: 'id,name',
};
const returnData: INodePropertyOptions[] = [];
const tables = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables`, {}, qs);
for (const table of tables) {
const tableName = table.name;
const tableId = table.id;
returnData.push({
name: tableName,
value: tableId,
});
}
return returnData;
},
}
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
let qs: IDataObject = {};
const result: IDataObject[] = [];
let responseData;
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
if (resource === 'table') {
//https://docs.microsoft.com/en-us/graph/api/table-post-rows?view=graph-rest-1.0&tabs=http
if (operation === 'addRow') {
// TODO: At some point it should be possible to use item dependent parameters.
// Is however important to then not make one separate request each.
const workbookId = this.getNodeParameter('workbook', 0) as string;
const worksheetId = this.getNodeParameter('worksheet', 0) as string;
const tableId = this.getNodeParameter('table', 0) as string;
const additionalFields = this.getNodeParameter('additionalFields', 0) as IDataObject;
const body: IDataObject = {};
if (additionalFields.index) {
body.index = additionalFields.index as number;
}
// Get table columns to eliminate any columns not needed on the input
responseData = await microsoftApiRequest.call(this, 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/columns`, {}, qs);
const columns = responseData.value.map((column: IDataObject) => (column.name));
const rows: any[][] = []; // tslint:disable-line:no-any
// Bring the items into the correct format
for (const item of items) {
const row = [];
for (const column of columns) {
row.push(item.json[column]);
}
rows.push(row);
}
body.values = rows;
const { id } = await microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/createSession`, { persistChanges: true });
responseData = await microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/rows/add`, body, {}, '', { 'workbook-session-id': id });
await microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/closeSession`, {}, {}, '', { 'workbook-session-id': id });
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
}
//https://docs.microsoft.com/en-us/graph/api/table-list-columns?view=graph-rest-1.0&tabs=http
if (operation === 'getColumns') {
for (let i = 0; i < length; i++) {
qs = {};
const workbookId = this.getNodeParameter('workbook', i) as string;
const worksheetId = this.getNodeParameter('worksheet', i) as string;
const tableId = this.getNodeParameter('table', i) as string;
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const rawData = this.getNodeParameter('rawData', i) as boolean;
if (rawData) {
const filters = this.getNodeParameter('filters', i) as IDataObject;
if (filters.fields) {
qs['$select'] = filters.fields;
}
}
if (returnAll === true) {
responseData = await microsoftApiRequestAllItemsSkip.call(this, 'value', 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/columns`, {}, qs);
} else {
qs['$top'] = this.getNodeParameter('limit', i) as number;
responseData = await microsoftApiRequest.call(this, 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/columns`, {}, qs);
responseData = responseData.value;
}
if (!rawData) {
responseData = responseData.map((column: IDataObject) => ({ name: column.name }));
} else {
const dataProperty = this.getNodeParameter('dataProperty', i) as string;
responseData = { [dataProperty] : responseData };
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
}
}
//https://docs.microsoft.com/en-us/graph/api/table-list-rows?view=graph-rest-1.0&tabs=http
if (operation === 'getRows') {
for (let i = 0; i < length; i++) {
qs = {};
const workbookId = this.getNodeParameter('workbook', i) as string;
const worksheetId = this.getNodeParameter('worksheet', i) as string;
const tableId = this.getNodeParameter('table', i) as string;
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const rawData = this.getNodeParameter('rawData', i) as boolean;
if (rawData) {
const filters = this.getNodeParameter('filters', i) as IDataObject;
if (filters.fields) {
qs['$select'] = filters.fields;
}
}
if (returnAll === true) {
responseData = await microsoftApiRequestAllItemsSkip.call(this, 'value', 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/rows`, {}, qs);
} else {
const rowsQs = { ...qs };
rowsQs['$top'] = this.getNodeParameter('limit', i) as number;
responseData = await microsoftApiRequest.call(this, 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/rows`, {}, rowsQs);
responseData = responseData.value;
}
if (!rawData) {
const columnsQs = { ...qs };
columnsQs['$select'] = 'name';
// TODO: That should probably be cached in the future
let columns = await microsoftApiRequestAllItemsSkip.call(this, 'value', 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/columns`, {}, columnsQs);
//@ts-ignore
columns = columns.map(column => column.name);
for (let i = 0; i < responseData.length; i++) {
const object: IDataObject = {};
for (let y = 0; y < columns.length; y++) {
object[columns[y]] = responseData[i].values[0][y];
}
returnData.push({ ...object });
}
} else {
const dataProperty = this.getNodeParameter('dataProperty', i) as string;
returnData.push({ [dataProperty]: responseData });
}
}
}
if (operation === 'lookup') {
for (let i = 0; i < length; i++) {
qs = {};
const workbookId = this.getNodeParameter('workbook', i) as string;
const worksheetId = this.getNodeParameter('worksheet', i) as string;
const tableId = this.getNodeParameter('table', i) as string;
const lookupColumn = this.getNodeParameter('lookupColumn', i) as string;
const lookupValue = this.getNodeParameter('lookupValue', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
responseData = await microsoftApiRequestAllItemsSkip.call(this, 'value', 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/rows`, {}, {});
qs['$select'] = 'name';
// TODO: That should probably be cached in the future
let columns = await microsoftApiRequestAllItemsSkip.call(this, 'value', 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/${tableId}/columns`, {}, qs);
columns = columns.map((column: IDataObject) => column.name);
if (!columns.includes(lookupColumn)) {
throw new Error(`Column ${lookupColumn} does not exist on the table selected`);
}
result.length = 0;
for (let i = 0; i < responseData.length; i++) {
const object: IDataObject = {};
for (let y = 0; y < columns.length; y++) {
object[columns[y]] = responseData[i].values[0][y];
}
result.push({ ...object });
}
if (options.returnAllMatches) {
responseData = result.filter((data: IDataObject) => {
return (data[lookupColumn]?.toString() === lookupValue );
});
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
responseData = result.find((data: IDataObject) => {
return (data[lookupColumn]?.toString() === lookupValue );
});
returnData.push(responseData as IDataObject);
}
}
}
}
if (resource === 'workbook') {
for (let i = 0; i < length; i++) {
qs = {};
//https://docs.microsoft.com/en-us/graph/api/worksheetcollection-add?view=graph-rest-1.0&tabs=http
if (operation === 'addWorksheet') {
const workbookId = this.getNodeParameter('workbook', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const body: IDataObject = {};
if (additionalFields.name) {
body.name = additionalFields.name;
}
const { id } = await microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/createSession`, { persistChanges: true });
responseData = await microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/worksheets/add`, body, {}, '', { 'workbook-session-id': id });
await microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/closeSession`, {}, {}, '', { 'workbook-session-id': id });
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const filters = this.getNodeParameter('filters', i) as IDataObject;
if (filters.fields) {
qs['$select'] = filters.fields;
}
if (returnAll === true) {
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/drive/root/search(q='.xlsx')`, {}, qs);
} else {
qs['$top'] = this.getNodeParameter('limit', i) as number;
responseData = await microsoftApiRequest.call(this, 'GET', `/drive/root/search(q='.xlsx')`, {}, qs);
responseData = responseData.value;
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
}
}
if (resource === 'worksheet') {
for (let i = 0; i < length; i++) {
qs = {};
//https://docs.microsoft.com/en-us/graph/api/workbook-list-worksheets?view=graph-rest-1.0&tabs=http
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const workbookId = this.getNodeParameter('workbook', i) as string;
const filters = this.getNodeParameter('filters', i) as IDataObject;
if (filters.fields) {
qs['$select'] = filters.fields;
}
if (returnAll === true) {
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', `/drive/items/${workbookId}/workbook/worksheets`, {}, qs);
} else {
qs['$top'] = this.getNodeParameter('limit', i) as number;
responseData = await microsoftApiRequest.call(this, 'GET', `/drive/items/${workbookId}/workbook/worksheets`, {}, qs);
responseData = responseData.value;
}
}
//https://docs.microsoft.com/en-us/graph/api/worksheet-range?view=graph-rest-1.0&tabs=http
if (operation === 'getContent') {
const workbookId = this.getNodeParameter('workbook', i) as string;
const worksheetId = this.getNodeParameter('worksheet', i) as string;
const range = this.getNodeParameter('range', i) as string;
const rawData = this.getNodeParameter('rawData', i) as boolean;
if (rawData) {
const filters = this.getNodeParameter('filters', i) as IDataObject;
if (filters.fields) {
qs['$select'] = filters.fields;
}
}
responseData = await microsoftApiRequest.call(this, 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/range(address='${range}')`, {}, qs);
if (!rawData) {
const keyRow = this.getNodeParameter('keyRow', i) as number;
const dataStartRow = this.getNodeParameter('dataStartRow', i) as number;
if (responseData.values === null) {
throw new Error('Range did not return data');
}
const keyValues = responseData.values[keyRow];
for (let i = dataStartRow; i < responseData.values.length; i++) {
const object: IDataObject = {};
for (let y = 0; y < keyValues.length; y++) {
object[keyValues[y]] = responseData.values[i][y];
}
returnData.push({ ...object });
}
} else {
const dataProperty = this.getNodeParameter('dataProperty', i) as string;
returnData.push({ [dataProperty]: responseData });
}
}
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}

View file

@ -0,0 +1,625 @@
import { INodeProperties } from 'n8n-workflow';
export const tableOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'table',
],
},
},
options: [
{
name: 'Add Row',
value: 'addRow',
description: 'Adds rows to the end of the table'
},
{
name: 'Get Columns',
value: 'getColumns',
description: 'Retrieve a list of tablecolumns',
},
{
name: 'Get Rows',
value: 'getRows',
description: 'Retrieve a list of tablerows',
},
{
name: 'Lookup',
value: 'lookup',
description: 'Looks for a specific column value and then returns the matching row'
},
],
default: 'addRow',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const tableFields = [
/* -------------------------------------------------------------------------- */
/* table:addRow */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workbook',
name: 'workbook',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getWorkbooks',
},
displayOptions: {
show: {
operation: [
'addRow',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Worksheet',
name: 'worksheet',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getworksheets',
loadOptionsDependsOn: [
'workbook',
],
},
displayOptions: {
show: {
operation: [
'addRow',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Table',
name: 'table',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getTables',
loadOptionsDependsOn: [
'worksheet',
],
},
displayOptions: {
show: {
operation: [
'addRow',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
operation: [
'addRow',
],
resource: [
'table',
],
},
},
options: [
{
displayName: 'Index',
name: 'index',
type: 'number',
default: 0,
typeOptions: {
minValue: 0,
},
description: `Specifies the relative position of the new row. If not defined,</br>
the addition happens at the end. Any rows below the inserted row are shifted downwards. Zero-indexed`,
},
],
},
/* -------------------------------------------------------------------------- */
/* table:getRows */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workbook',
name: 'workbook',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getWorkbooks',
},
displayOptions: {
show: {
operation: [
'getRows',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Worksheet',
name: 'worksheet',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getworksheets',
loadOptionsDependsOn: [
'workbook',
],
},
displayOptions: {
show: {
operation: [
'getRows',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Table',
name: 'table',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getTables',
loadOptionsDependsOn: [
'worksheet',
],
},
displayOptions: {
show: {
operation: [
'getRows',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getRows',
],
resource: [
'table',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getRows',
],
resource: [
'table',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'RAW Data',
name: 'rawData',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getRows',
],
resource: [
'table',
],
},
},
default: false,
description: 'If the data should be returned RAW instead of parsed into keys according to their header.',
},
{
displayName: 'Data Property',
name: 'dataProperty',
type: 'string',
default: 'data',
displayOptions: {
show: {
operation: [
'getRows'
],
resource: [
'table',
],
rawData: [
true,
],
},
},
description: 'The name of the property into which to write the RAW data.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
operation: [
'getRows',
],
resource: [
'table',
],
rawData: [
true,
],
},
},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: '',
description: `Fields the response will containt. Multiple can be added separated by ,.`,
},
]
},
/* -------------------------------------------------------------------------- */
/* table:getColumns */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workbook',
name: 'workbook',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getWorkbooks',
},
displayOptions: {
show: {
operation: [
'getColumns',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Worksheet',
name: 'worksheet',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getworksheets',
loadOptionsDependsOn: [
'workbook',
],
},
displayOptions: {
show: {
operation: [
'getColumns',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Table',
name: 'table',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getTables',
loadOptionsDependsOn: [
'worksheet',
],
},
displayOptions: {
show: {
operation: [
'getColumns',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getColumns',
],
resource: [
'table',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getColumns',
],
resource: [
'table',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'RAW Data',
name: 'rawData',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getColumns',
],
resource: [
'table',
],
},
},
default: false,
description: 'If the data should be returned RAW instead of parsed into keys according to their header.',
},
{
displayName: 'Data Property',
name: 'dataProperty',
type: 'string',
default: 'data',
displayOptions: {
show: {
operation: [
'getColumns'
],
resource: [
'table',
],
rawData: [
true,
],
},
},
description: 'The name of the property into which to write the RAW data.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
operation: [
'getColumns',
],
resource: [
'table',
],
rawData: [
true
],
},
},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: '',
description: `Fields the response will containt. Multiple can be added separated by ,.`,
},
]
},
/* -------------------------------------------------------------------------- */
/* table:lookup */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workbook',
name: 'workbook',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getWorkbooks',
},
displayOptions: {
show: {
operation: [
'lookup',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Worksheet',
name: 'worksheet',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getworksheets',
loadOptionsDependsOn: [
'workbook',
],
},
displayOptions: {
show: {
operation: [
'lookup',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Table',
name: 'table',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getTables',
loadOptionsDependsOn: [
'worksheet',
],
},
displayOptions: {
show: {
operation: [
'lookup',
],
resource: [
'table',
],
},
},
default: '',
},
{
displayName: 'Lookup Column',
name: 'lookupColumn',
type: 'string',
default: '',
placeholder: 'Email',
required: true,
displayOptions: {
show: {
resource: [
'table',
],
operation: [
'lookup'
],
},
},
description: 'The name of the column in which to look for value.',
},
{
displayName: 'Lookup Value',
name: 'lookupValue',
type: 'string',
default: '',
placeholder: 'frank@example.com',
required: true,
displayOptions: {
show: {
resource: [
'table',
],
operation: [
'lookup'
],
},
},
description: 'The value to look for in column.',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
resource: [
'table',
],
operation: [
'lookup',
],
},
},
options: [
{
displayName: 'Return All Matches',
name: 'returnAllMatches',
type: 'boolean',
default: false,
description: 'By default only the first result gets returned. If options gets set all found matches get returned.',
},
],
}
] as INodeProperties[];

View file

@ -0,0 +1,154 @@
import { INodeProperties } from 'n8n-workflow';
export const workbookOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'workbook',
],
},
},
options: [
{
name: 'Add Worksheet',
value: 'addWorksheet',
description: 'Adds a new worksheet to the workbook.',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get data of all workbooks',
},
],
default: 'create',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const workbookFields = [
/* -------------------------------------------------------------------------- */
/* workbook:addWorksheet */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workbook',
name: 'workbook',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getWorkbooks',
},
displayOptions: {
show: {
operation: [
'addWorksheet',
],
resource: [
'workbook',
],
},
},
default: '',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
operation: [
'addWorksheet',
],
resource: [
'workbook',
],
},
},
options: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: `The name of the worksheet to be added. If specified, name should be unqiue. </BR>
If not specified, Excel determines the name of the new worksheet.`,
},
]
},
/* -------------------------------------------------------------------------- */
/* workbook:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'workbook',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'workbook',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'workbook',
],
},
},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: '',
description: `Fields the response will containt. Multiple can be added separated by ,.`,
},
]
},
] as INodeProperties[];

View file

@ -0,0 +1,303 @@
import { INodeProperties } from 'n8n-workflow';
export const worksheetOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'worksheet',
],
},
},
options: [
{
name: 'Get All',
value: 'getAll',
description: 'Get all worksheets',
},
{
name: 'Get Content',
value: 'getContent',
description: 'Get worksheet content',
},
],
default: 'create',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const worksheetFields = [
/* -------------------------------------------------------------------------- */
/* worksheet:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workbook',
name: 'workbook',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getWorkbooks',
},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'worksheet',
],
},
},
default: '',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'worksheet',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'worksheet',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'worksheet',
],
},
},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: '',
description: `Fields the response will containt. Multiple can be added separated by ,.`,
},
]
},
/* -------------------------------------------------------------------------- */
/* worksheet:getContent */
/* -------------------------------------------------------------------------- */
{
displayName: 'Workbook',
name: 'workbook',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getWorkbooks',
},
displayOptions: {
show: {
operation: [
'getContent',
],
resource: [
'worksheet',
],
},
},
default: '',
},
{
displayName: 'Worksheet',
name: 'worksheet',
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'getworksheets',
loadOptionsDependsOn: [
'workbook',
],
},
displayOptions: {
show: {
operation: [
'getContent',
],
resource: [
'worksheet',
],
},
},
default: '',
},
{
displayName: 'Range',
name: 'range',
type: 'string',
displayOptions: {
show: {
operation: [
'getContent',
],
resource: [
'worksheet',
],
},
},
default: 'A1:C3',
required: true,
description: 'The address or the name of the range. If not specified, the entire worksheet range is returned.',
},
{
displayName: 'RAW Data',
name: 'rawData',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getContent',
],
resource: [
'worksheet',
],
},
},
default: false,
description: 'If the data should be returned RAW instead of parsed into keys according to their header.',
},
{
displayName: 'Data Property',
name: 'dataProperty',
type: 'string',
default: 'data',
displayOptions: {
show: {
operation: [
'getContent'
],
resource: [
'worksheet',
],
rawData: [
true,
],
},
},
description: 'The name of the property into which to write the RAW data.',
},
{
displayName: 'Data Start Row',
name: 'dataStartRow',
type: 'number',
typeOptions: {
minValue: 1,
},
default: 1,
displayOptions: {
show: {
operation: [
'getContent',
],
resource: [
'worksheet',
],
},
hide: {
rawData: [
true
],
},
},
description: 'Index of the first row which contains<br />the actual data and not the keys. Starts with 0.',
},
{
displayName: 'Key Row',
name: 'keyRow',
type: 'number',
typeOptions: {
minValue: 0,
},
displayOptions: {
show: {
operation: [
'getContent',
],
resource: [
'worksheet',
],
},
hide: {
rawData: [
true
],
},
},
default: 0,
description: 'Index of the row which contains the keys. Starts at 0.<br />The incoming node data is matched to the keys for assignment. The matching is case sensitve.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
operation: [
'getContent',
],
resource: [
'worksheet',
],
rawData: [
true,
],
},
},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: '',
description: `Fields the response will containt. Multiple can be added separated by ,.`,
},
]
},
] as INodeProperties[];

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -56,6 +56,8 @@
"dist/credentials/MailgunApi.credentials.js",
"dist/credentials/MandrillApi.credentials.js",
"dist/credentials/MattermostApi.credentials.js",
"dist/credentials/MicrosoftExcelOAuth2Api.credentials.js",
"dist/credentials/MicrosoftOAuth2Api.credentials.js",
"dist/credentials/MongoDb.credentials.js",
"dist/credentials/MySql.credentials.js",
"dist/credentials/NextCloudApi.credentials.js",
@ -136,6 +138,7 @@
"dist/nodes/Mandrill/Mandrill.node.js",
"dist/nodes/Mattermost/Mattermost.node.js",
"dist/nodes/Merge.node.js",
"dist/nodes/Microsoft/Excel/MicrosoftExcel.node.js",
"dist/nodes/MoveBinaryData.node.js",
"dist/nodes/MongoDb/MongoDb.node.js",
"dist/nodes/MySql/MySql.node.js",