2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IExecuteFunctions,
|
2019-12-13 13:50:59 -08:00
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeExecutionData,
|
2019-12-13 13:50:59 -08:00
|
|
|
INodePropertyOptions,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2023-02-27 19:39:43 -08:00
|
|
|
JsonObject,
|
2019-12-13 13:50:59 -08:00
|
|
|
} from 'n8n-workflow';
|
2023-01-27 03:22:44 -08:00
|
|
|
import { NodeApiError } from 'n8n-workflow';
|
2022-08-01 13:47:55 -07:00
|
|
|
import { codaApiRequest, codaApiRequestAllItems } from './GenericFunctions';
|
|
|
|
import { tableFields, tableOperations } from './TableDescription';
|
|
|
|
import { formulaFields, formulaOperations } from './FormulaDescription';
|
|
|
|
import { controlFields, controlOperations } from './ControlDescription';
|
|
|
|
import { viewFields, viewOperations } from './ViewDescription';
|
2019-12-13 13:50:59 -08:00
|
|
|
|
|
|
|
export class Coda implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Coda',
|
2020-05-12 06:45:41 -07:00
|
|
|
name: 'coda',
|
2021-06-12 12:00:37 -07:00
|
|
|
icon: 'file:coda.svg',
|
2019-12-13 13:50:59 -08:00
|
|
|
group: ['output'],
|
|
|
|
version: 1,
|
2020-02-05 16:47:40 -08:00
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2020-08-03 08:27:34 -07:00
|
|
|
description: 'Consume Coda API',
|
2019-12-13 13:50:59 -08:00
|
|
|
defaults: {
|
|
|
|
name: 'Coda',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'codaApi',
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2019-12-13 13:50:59 -08:00
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2019-12-13 13:50:59 -08:00
|
|
|
options: [
|
|
|
|
{
|
2020-02-05 16:47:40 -08:00
|
|
|
name: 'Control',
|
|
|
|
value: 'control',
|
2022-08-01 13:47:55 -07:00
|
|
|
description:
|
|
|
|
'Controls provide a user-friendly way to input a value that can affect other parts of the doc',
|
2019-12-13 13:50:59 -08:00
|
|
|
},
|
2020-02-03 16:40:03 -08:00
|
|
|
{
|
|
|
|
name: 'Formula',
|
|
|
|
value: 'formula',
|
|
|
|
description: 'Formulas can be great for performing one-off computations',
|
|
|
|
},
|
|
|
|
{
|
2020-02-05 16:47:40 -08:00
|
|
|
name: 'Table',
|
|
|
|
value: 'table',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Access data of tables in documents',
|
2020-02-03 16:40:03 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'View',
|
|
|
|
value: 'view',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Access data of views in documents',
|
2020-02-03 16:40:03 -08:00
|
|
|
},
|
2019-12-13 13:50:59 -08:00
|
|
|
],
|
2019-12-16 15:52:15 -08:00
|
|
|
default: 'table',
|
2019-12-13 13:50:59 -08:00
|
|
|
},
|
2019-12-16 15:52:15 -08:00
|
|
|
...tableOperations,
|
|
|
|
...tableFields,
|
2020-02-03 16:40:03 -08:00
|
|
|
...formulaOperations,
|
|
|
|
...formulaFields,
|
|
|
|
...controlOperations,
|
|
|
|
...controlFields,
|
|
|
|
...viewOperations,
|
|
|
|
...viewFields,
|
2019-12-13 13:50:59 -08:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
2019-12-16 08:40:44 -08:00
|
|
|
// Get all the available docs to display them to user so that he can
|
2019-12-13 13:50:59 -08:00
|
|
|
// select them easily
|
2019-12-16 08:40:44 -08:00
|
|
|
async getDocs(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2019-12-13 13:50:59 -08:00
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const qs = {};
|
2022-12-29 03:20:43 -08:00
|
|
|
const docs = await codaApiRequestAllItems.call(this, 'items', 'GET', '/docs', {}, qs);
|
2019-12-16 08:40:44 -08:00
|
|
|
for (const doc of docs) {
|
|
|
|
const docName = doc.name;
|
|
|
|
const docId = doc.id;
|
2019-12-13 13:50:59 -08:00
|
|
|
returnData.push({
|
2019-12-16 08:40:44 -08:00
|
|
|
name: docName,
|
|
|
|
value: docId,
|
2019-12-13 13:50:59 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2019-12-16 15:52:15 -08:00
|
|
|
// Get all the available tables to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getTables(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
const docId = this.getCurrentNodeParameter('docId');
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
const tables = await codaApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
`/docs/${docId}/tables`,
|
|
|
|
{},
|
|
|
|
);
|
2019-12-16 15:52:15 -08:00
|
|
|
for (const table of tables) {
|
|
|
|
const tableName = table.name;
|
|
|
|
const tableId = table.id;
|
|
|
|
returnData.push({
|
|
|
|
name: tableName,
|
|
|
|
value: tableId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2020-01-30 14:02:09 -08:00
|
|
|
// Get all the available columns to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getColumns(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
const docId = this.getCurrentNodeParameter('docId');
|
|
|
|
const tableId = this.getCurrentNodeParameter('tableId');
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
const columns = await codaApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
`/docs/${docId}/tables/${tableId}/columns`,
|
|
|
|
{},
|
|
|
|
);
|
2020-01-30 14:02:09 -08:00
|
|
|
for (const column of columns) {
|
|
|
|
const columnName = column.name;
|
|
|
|
const columnId = column.id;
|
|
|
|
returnData.push({
|
|
|
|
name: columnName,
|
|
|
|
value: columnId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2020-02-03 16:40:03 -08:00
|
|
|
// Get all the available views to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getViews(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const docId = this.getCurrentNodeParameter('docId');
|
2022-08-01 13:47:55 -07:00
|
|
|
const views = await codaApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
`/docs/${docId}/tables?tableTypes=view`,
|
|
|
|
{},
|
|
|
|
);
|
2020-02-03 16:40:03 -08:00
|
|
|
for (const view of views) {
|
|
|
|
const viewName = view.name;
|
|
|
|
const viewId = view.id;
|
|
|
|
returnData.push({
|
|
|
|
name: viewName,
|
|
|
|
value: viewId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the available formulas to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getFormulas(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const docId = this.getCurrentNodeParameter('docId');
|
2022-08-01 13:47:55 -07:00
|
|
|
const formulas = await codaApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
`/docs/${docId}/formulas`,
|
|
|
|
{},
|
|
|
|
);
|
2020-02-03 16:40:03 -08:00
|
|
|
for (const formula of formulas) {
|
|
|
|
const formulaName = formula.name;
|
|
|
|
const formulaId = formula.id;
|
|
|
|
returnData.push({
|
|
|
|
name: formulaName,
|
|
|
|
value: formulaId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the available view rows to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getViewRows(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const docId = this.getCurrentNodeParameter('docId');
|
|
|
|
const viewId = this.getCurrentNodeParameter('viewId');
|
2022-08-01 13:47:55 -07:00
|
|
|
const viewRows = await codaApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
`/docs/${docId}/tables/${viewId}/rows`,
|
|
|
|
{},
|
|
|
|
);
|
2020-02-03 16:40:03 -08:00
|
|
|
for (const viewRow of viewRows) {
|
|
|
|
const viewRowName = viewRow.name;
|
|
|
|
const viewRowId = viewRow.id;
|
|
|
|
returnData.push({
|
|
|
|
name: viewRowName,
|
|
|
|
value: viewRowId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the available view columns to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getViewColumns(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
const docId = this.getCurrentNodeParameter('docId');
|
|
|
|
const viewId = this.getCurrentNodeParameter('viewId');
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
const viewColumns = await codaApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
`/docs/${docId}/tables/${viewId}/columns`,
|
|
|
|
{},
|
|
|
|
);
|
2020-02-03 16:40:03 -08:00
|
|
|
for (const viewColumn of viewColumns) {
|
|
|
|
const viewColumnName = viewColumn.name;
|
|
|
|
const viewColumnId = viewColumn.id;
|
|
|
|
returnData.push({
|
|
|
|
name: viewColumnName,
|
|
|
|
value: viewColumnId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2019-12-13 13:50:59 -08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
2022-08-30 08:55:33 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
2019-12-14 08:42:32 -08:00
|
|
|
const items = this.getInputData();
|
2019-12-13 13:50:59 -08:00
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
2019-12-16 15:52:15 -08:00
|
|
|
let qs: IDataObject = {};
|
2022-12-02 03:53:59 -08:00
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2019-12-16 15:52:15 -08:00
|
|
|
|
|
|
|
if (resource === 'table') {
|
|
|
|
// https://coda.io/developers/apis/v1beta1#operation/upsertRows
|
|
|
|
if (operation === 'createRow') {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const sendData = {} as IDataObject;
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
qs = {};
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const tableId = this.getNodeParameter('tableId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const endpoint = `/docs/${docId}/tables/${tableId}/rows`;
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.disableParsing) {
|
|
|
|
qs.disableParsing = options.disableParsing as boolean;
|
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const cells = [];
|
|
|
|
cells.length = 0;
|
|
|
|
for (const key of Object.keys(items[i].json)) {
|
|
|
|
cells.push({
|
|
|
|
column: key,
|
|
|
|
value: items[i].json[key],
|
|
|
|
});
|
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
// Collect all the data for the different docs/tables
|
|
|
|
if (sendData[endpoint] === undefined) {
|
|
|
|
sendData[endpoint] = {
|
|
|
|
rows: [],
|
|
|
|
// TODO: This is not perfect as it ignores if qs changes between
|
|
|
|
// different items but should be OK for now
|
|
|
|
qs,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
((sendData[endpoint]! as IDataObject).rows! as IDataObject[]).push({ cells });
|
2020-08-26 12:24:24 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.keyColumns) {
|
|
|
|
// @ts-ignore
|
2022-12-02 12:54:28 -08:00
|
|
|
(sendData[endpoint]! as IDataObject).keyColumns = options.keyColumns.split(
|
2022-08-01 13:47:55 -07:00
|
|
|
',',
|
|
|
|
) as string[];
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-26 12:24:24 -07:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
// Now that all data got collected make all the requests
|
|
|
|
for (const endpoint of Object.keys(sendData)) {
|
2022-08-01 13:47:55 -07:00
|
|
|
await codaApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
endpoint,
|
|
|
|
sendData[endpoint],
|
|
|
|
(sendData[endpoint]! as IDataObject).qs! as IDataObject,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
|
|
|
return [this.helpers.returnJsonArray({ error: error.message })];
|
|
|
|
}
|
|
|
|
throw error;
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
// Return the incoming data
|
|
|
|
return [items];
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
// https://coda.io/developers/apis/v1beta1#operation/getRow
|
|
|
|
if (operation === 'getRow') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const tableId = this.getNodeParameter('tableId', i) as string;
|
|
|
|
const rowId = this.getNodeParameter('rowId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const endpoint = `/docs/${docId}/tables/${tableId}/rows/${rowId}`;
|
|
|
|
if (options.useColumnNames === false) {
|
|
|
|
qs.useColumnNames = options.useColumnNames as boolean;
|
|
|
|
} else {
|
|
|
|
qs.useColumnNames = true;
|
|
|
|
}
|
|
|
|
if (options.valueFormat) {
|
|
|
|
qs.valueFormat = options.valueFormat as string;
|
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
if (options.rawData === true) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray({
|
|
|
|
id: responseData.id as string,
|
|
|
|
...(responseData.values as IDataObject),
|
|
|
|
}),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2019-12-16 15:52:15 -08:00
|
|
|
}
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
// https://coda.io/developers/apis/v1beta1#operation/listRows
|
|
|
|
if (operation === 'getAllRows') {
|
2019-12-16 08:40:44 -08:00
|
|
|
const docId = this.getNodeParameter('docId', 0) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2019-12-14 08:42:32 -08:00
|
|
|
const tableId = this.getNodeParameter('tableId', 0) as string;
|
2022-12-02 12:54:28 -08:00
|
|
|
const options = this.getNodeParameter('options', 0);
|
2019-12-14 08:42:32 -08:00
|
|
|
const endpoint = `/docs/${docId}/tables/${tableId}/rows`;
|
2019-12-16 15:52:15 -08:00
|
|
|
if (options.useColumnNames === false) {
|
|
|
|
qs.useColumnNames = options.useColumnNames as boolean;
|
|
|
|
} else {
|
|
|
|
qs.useColumnNames = true;
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
if (options.valueFormat) {
|
|
|
|
qs.valueFormat = options.valueFormat as string;
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
if (options.sortBy) {
|
|
|
|
qs.sortBy = options.sortBy as string;
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
if (options.visibleOnly) {
|
|
|
|
qs.visibleOnly = options.visibleOnly as boolean;
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2020-01-30 14:02:09 -08:00
|
|
|
if (options.query) {
|
|
|
|
qs.query = options.query as string;
|
|
|
|
}
|
2019-12-14 08:42:32 -08:00
|
|
|
try {
|
2022-12-02 12:54:28 -08:00
|
|
|
if (returnAll) {
|
2022-08-01 13:47:55 -07:00
|
|
|
responseData = await codaApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
endpoint,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2019-12-14 08:42:32 -08:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2019-12-14 08:42:32 -08:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2021-04-16 09:33:36 -07:00
|
|
|
} catch (error) {
|
2021-07-19 23:58:54 -07:00
|
|
|
if (this.continueOnFail()) {
|
|
|
|
return [this.helpers.returnJsonArray({ error: error.message })];
|
|
|
|
}
|
2023-02-27 19:39:43 -08:00
|
|
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
|
|
|
if (options.rawData === true) {
|
2023-02-27 19:39:43 -08:00
|
|
|
return [this.helpers.returnJsonArray(responseData as IDataObject[])];
|
2019-12-16 15:52:15 -08:00
|
|
|
} else {
|
|
|
|
for (const item of responseData) {
|
2023-02-27 19:39:43 -08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
2019-12-16 15:52:15 -08:00
|
|
|
returnData.push({
|
|
|
|
id: item.id,
|
2020-10-22 06:46:03 -07:00
|
|
|
...item.values,
|
2019-12-16 15:52:15 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
// https://coda.io/developers/apis/v1beta1#operation/deleteRows
|
|
|
|
if (operation === 'deleteRow') {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const sendData = {} as IDataObject;
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const tableId = this.getNodeParameter('tableId', i) as string;
|
|
|
|
const rowId = this.getNodeParameter('rowId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/tables/${tableId}/rows`;
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
// Collect all the data for the different docs/tables
|
|
|
|
if (sendData[endpoint] === undefined) {
|
|
|
|
sendData[endpoint] = [];
|
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
(sendData[endpoint] as string[]).push(rowId);
|
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
// Now that all data got collected make all the requests
|
|
|
|
for (const endpoint of Object.keys(sendData)) {
|
2022-08-01 13:47:55 -07:00
|
|
|
await codaApiRequest.call(this, 'DELETE', endpoint, { rowIds: sendData[endpoint] }, qs);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
|
|
|
return [this.helpers.returnJsonArray({ error: error.message })];
|
|
|
|
}
|
|
|
|
throw error;
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
// Return the incoming data
|
|
|
|
return [items];
|
2019-12-14 08:42:32 -08:00
|
|
|
}
|
2020-01-30 14:02:09 -08:00
|
|
|
// https://coda.io/developers/apis/v1beta1#operation/pushButton
|
|
|
|
if (operation === 'pushButton') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const tableId = this.getNodeParameter('tableId', i) as string;
|
|
|
|
const rowId = this.getNodeParameter('rowId', i) as string;
|
|
|
|
const columnId = this.getNodeParameter('columnId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/tables/${tableId}/rows/${rowId}/buttons/${columnId}`;
|
|
|
|
responseData = await codaApiRequest.call(this, 'POST', endpoint, {});
|
2023-02-27 19:39:43 -08:00
|
|
|
returnData.push(responseData as INodeExecutionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2020-01-30 14:02:09 -08:00
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
2020-02-03 16:40:03 -08:00
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/getColumn
|
|
|
|
if (operation === 'getColumn') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const tableId = this.getNodeParameter('tableId', i) as string;
|
|
|
|
const columnId = this.getNodeParameter('columnId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/tables/${tableId}/columns/${columnId}`;
|
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {});
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/listColumns
|
|
|
|
if (operation === 'getAllColumns') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const tableId = this.getNodeParameter('tableId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/tables/${tableId}/columns`;
|
|
|
|
if (returnAll) {
|
|
|
|
responseData = await codaApiRequestAllItems.call(this, 'items', 'GET', endpoint, {});
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'formula') {
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/getFormula
|
|
|
|
if (operation === 'get') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const formulaId = this.getNodeParameter('formulaId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/formulas/${formulaId}`;
|
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {});
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/listFormulas
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/formulas`;
|
|
|
|
if (returnAll) {
|
|
|
|
responseData = await codaApiRequestAllItems.call(this, 'items', 'GET', endpoint, {});
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'control') {
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/getControl
|
|
|
|
if (operation === 'get') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const controlId = this.getNodeParameter('controlId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/controls/${controlId}`;
|
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {});
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/listControls
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/controls`;
|
|
|
|
if (returnAll) {
|
|
|
|
responseData = await codaApiRequestAllItems.call(this, 'items', 'GET', endpoint, {});
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'view') {
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/getView
|
|
|
|
if (operation === 'get') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const viewId = this.getNodeParameter('viewId', i) as string;
|
2020-08-03 08:27:34 -07:00
|
|
|
const endpoint = `/docs/${docId}/tables/${viewId}`;
|
2020-02-03 16:40:03 -08:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {});
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/listViews
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/tables?tableTypes=view`;
|
|
|
|
if (returnAll) {
|
|
|
|
responseData = await codaApiRequestAllItems.call(this, 'items', 'GET', endpoint, {});
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
responseData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...responseData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
if (operation === 'getAllViewRows') {
|
|
|
|
const docId = this.getNodeParameter('docId', 0) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2020-02-03 16:40:03 -08:00
|
|
|
const viewId = this.getNodeParameter('viewId', 0) as string;
|
2022-12-02 12:54:28 -08:00
|
|
|
const options = this.getNodeParameter('options', 0);
|
2020-08-03 08:27:34 -07:00
|
|
|
const endpoint = `/docs/${docId}/tables/${viewId}/rows`;
|
2020-02-03 16:40:03 -08:00
|
|
|
if (options.useColumnNames === false) {
|
|
|
|
qs.useColumnNames = options.useColumnNames as boolean;
|
|
|
|
} else {
|
|
|
|
qs.useColumnNames = true;
|
|
|
|
}
|
|
|
|
if (options.valueFormat) {
|
|
|
|
qs.valueFormat = options.valueFormat as string;
|
|
|
|
}
|
|
|
|
if (options.sortBy) {
|
|
|
|
qs.sortBy = options.sortBy as string;
|
|
|
|
}
|
|
|
|
if (options.query) {
|
|
|
|
qs.query = options.query as string;
|
|
|
|
}
|
|
|
|
try {
|
2022-12-02 12:54:28 -08:00
|
|
|
if (returnAll) {
|
2022-08-01 13:47:55 -07:00
|
|
|
responseData = await codaApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
endpoint,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-02-03 16:40:03 -08:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2020-02-03 16:40:03 -08:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2021-04-16 09:33:36 -07:00
|
|
|
} catch (error) {
|
2021-07-19 23:58:54 -07:00
|
|
|
if (this.continueOnFail()) {
|
|
|
|
return [this.helpers.returnJsonArray({ error: error.message })];
|
|
|
|
}
|
2023-02-27 19:39:43 -08:00
|
|
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
|
2020-02-03 16:40:03 -08:00
|
|
|
if (options.rawData === true) {
|
2023-02-27 19:39:43 -08:00
|
|
|
return [this.helpers.returnJsonArray(responseData as IDataObject[])];
|
2020-02-03 16:40:03 -08:00
|
|
|
} else {
|
|
|
|
for (const item of responseData) {
|
2023-02-27 19:39:43 -08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
2020-02-03 16:40:03 -08:00
|
|
|
returnData.push({
|
|
|
|
id: item.id,
|
2020-02-05 16:47:40 -08:00
|
|
|
...item.values,
|
2020-02-03 16:40:03 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/deleteViewRow
|
|
|
|
if (operation === 'deleteViewRow') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const viewId = this.getNodeParameter('viewId', i) as string;
|
|
|
|
const rowId = this.getNodeParameter('rowId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/tables/${viewId}/rows/${rowId}`;
|
|
|
|
responseData = await codaApiRequest.call(this, 'DELETE', endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/pushViewButton
|
|
|
|
if (operation === 'pushViewButton') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const viewId = this.getNodeParameter('viewId', i) as string;
|
|
|
|
const rowId = this.getNodeParameter('rowId', i) as string;
|
|
|
|
const columnId = this.getNodeParameter('columnId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/tables/${viewId}/rows/${rowId}/buttons/${columnId}`;
|
|
|
|
responseData = await codaApiRequest.call(this, 'POST', endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
if (operation === 'getAllViewColumns') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const viewId = this.getNodeParameter('viewId', i) as string;
|
|
|
|
const endpoint = `/docs/${docId}/tables/${viewId}/columns`;
|
|
|
|
if (returnAll) {
|
|
|
|
responseData = await codaApiRequestAllItems.call(this, 'items', 'GET', endpoint, {});
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await codaApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.messsage }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
//https://coda.io/developers/apis/v1beta1#operation/updateViewRow
|
|
|
|
if (operation === 'updateViewRow') {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
qs = {};
|
|
|
|
const docId = this.getNodeParameter('docId', i) as string;
|
|
|
|
const viewId = this.getNodeParameter('viewId', i) as string;
|
|
|
|
const rowId = this.getNodeParameter('rowId', i) as string;
|
|
|
|
const keyName = this.getNodeParameter('keyName', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {};
|
|
|
|
const endpoint = `/docs/${docId}/tables/${viewId}/rows/${rowId}`;
|
|
|
|
if (options.disableParsing) {
|
|
|
|
qs.disableParsing = options.disableParsing as boolean;
|
|
|
|
}
|
|
|
|
const cells = [];
|
|
|
|
cells.length = 0;
|
2020-08-03 08:27:34 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
//@ts-ignore
|
|
|
|
for (const key of Object.keys(items[i].json[keyName])) {
|
|
|
|
cells.push({
|
|
|
|
column: key,
|
|
|
|
//@ts-ignore
|
|
|
|
value: items[i].json[keyName][key],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
body.row = {
|
|
|
|
cells,
|
|
|
|
};
|
|
|
|
await codaApiRequest.call(this, 'PUT', endpoint, body, qs);
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
|
|
|
items[i].json = { error: error.message };
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-02-03 16:40:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return [items];
|
|
|
|
}
|
2020-01-30 14:02:09 -08:00
|
|
|
}
|
2019-12-16 15:52:15 -08:00
|
|
|
return [];
|
2019-12-13 13:50:59 -08:00
|
|
|
}
|
|
|
|
}
|