UNPKG

n8n-nodes-apitable

Version:
104 lines 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSpaces = getSpaces; exports.getDatasheets = getDatasheets; exports.getViews = getViews; const n8n_workflow_1 = require("n8n-workflow"); async function getSpaces() { const returnData = []; const credentials = await this.getCredentials('aitableApi'); if (!credentials) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "No credentials got returned!"); } const options = { headers: { Authorization: `Bearer ${credentials.apiToken}`, Accept: "application/json", }, method: "GET", url: `${credentials.url}/fusion/v1/spaces`, json: true, }; const response = await this.helpers.request(options); if (response.success && response.code === 200) { for (const space of response.data.spaces) { returnData.push({ name: space.name, value: space.id, }); } } else { throw new n8n_workflow_1.NodeApiError(this.getNode(), response); } return returnData; } async function getDatasheets() { const returnData = []; const credentials = await this.getCredentials('aitableApi'); if (!credentials) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "No credentials got returned!"); } let spaceId = this.getCurrentNodeParameter('spaceId'); if (spaceId === undefined) { spaceId = (await getSpaces.call(this))[0].value; } const options = { headers: { Authorization: `Bearer ${credentials.apiToken}`, Accept: "application/json", }, method: "GET", url: `${credentials.url}/fusion/v1/spaces/${spaceId}/nodes`, json: true, }; const response = await this.helpers.request(options); if (response.success && response.code === 200) { for (const node of response.data.nodes) { if (node.type === 'Datasheet') { returnData.push({ name: node.name, value: node.id, }); } } } else { throw new n8n_workflow_1.NodeApiError(this.getNode(), response); } return returnData; } async function getViews() { const returnData = []; const credentials = await this.getCredentials('aitableApi'); if (!credentials) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "No credentials got returned!"); } const datasheetId = this.getCurrentNodeParameter('datasheetId'); if (!datasheetId) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), "No datasheet got returned!"); } const options = { headers: { Authorization: `Bearer ${credentials.apiToken}`, Accept: "application/json", }, method: "GET", url: `${credentials.url}/fusion/v1/datasheets/${datasheetId}/views`, json: true, }; const response = await this.helpers.request(options); if (response.success && response.code === 200) { for (const view of response.data.views) { returnData.push({ name: view.name, value: view.id, }); } } else { throw new n8n_workflow_1.NodeApiError(this.getNode(), response); } return returnData; } //# sourceMappingURL=LoadOptions.js.map