n8n-nodes-apitable
Version:
Apitable integration for n8n
119 lines • 5.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApitableOperationsCollector = void 0;
const n8n_openapi_node_1 = require("@devlikeapro/n8n-openapi-node");
class ApitableOperationsCollector extends n8n_openapi_node_1.OperationsCollector {
parseOperation(operation, context) {
var _a, _b, _c;
(_a = operation.parameters) === null || _a === void 0 ? void 0 : _a.forEach(_param => {
const param = _param;
if (!param["schema"]) {
param["schema"] = {};
}
if (param["type"]) {
if (param["type"] == "file") {
param["schema"]["type"] = "string";
param["schema"]["format"] = "binary";
}
else {
param["schema"]["type"] = param["type"];
}
if (param["enum"]) {
param["schema"]["enum"] = param["enum"];
}
}
});
if (!operation.requestBody) {
let bodyParams = (_b = operation.parameters) === null || _b === void 0 ? void 0 : _b.filter(param => param.in == "body" || param.in == "formData");
if (bodyParams && bodyParams.length > 0) {
operation.requestBody = {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": bodyParams.reduce((acc, item) => {
acc[item["name"]] = item;
return acc;
}, {}),
"required": bodyParams.filter((item) => item["required"] == true).map((item) => item["name"])
}
}
}
};
operation.parameters = (_c = operation.parameters) === null || _c === void 0 ? void 0 : _c.filter(param => param.in != "body" && param.in != "formData");
}
}
let operation1 = super.parseOperation(operation, context);
let output = 'data';
if (operation1.option.routing.request.method != "DELETE") {
if (operation1.option.routing.request.url.endsWith("/spaces")) {
output = 'data.spaces';
}
else if (operation1.option.routing.request.url.endsWith("/records")) {
output = 'data.records';
}
else if (operation1.option.routing.request.url.endsWith("/fields")) {
output = 'data.fields';
}
else if (operation1.option.routing.request.url.endsWith("/views")) {
output = 'data.views';
}
else if (operation1.option.routing.request.url.endsWith("/nodes")) {
output = 'data.nodes';
}
}
operation1.option.routing.output = {
postReceive: [
{
type: 'rootProperty',
properties: {
property: output,
},
},
],
};
operation1.fields.forEach(field => {
if (field.name === "spaceId") {
field.type = "options";
field.typeOptions = {
loadOptionsMethod: 'getSpaces',
};
}
else if (field.name === "datasheetId") {
field.type = "options";
field.typeOptions = {
loadOptionsMethod: 'getDatasheets',
};
}
else if (field.name === "viewId") {
field.type = "options";
field.typeOptions = {
loadOptionsMethod: 'getViews',
loadOptionsDependsOn: ['datasheetId'],
};
}
});
const additionalFields = operation1.fields.filter(field => { var _a, _b; return field.required != true && ((_b = (_a = field.routing) === null || _a === void 0 ? void 0 : _a.send) === null || _b === void 0 ? void 0 : _b.type) != "body" && field.name != 'operation'; }).map(field => {
field.displayOptions = undefined;
return field;
});
if (additionalFields.length > 0) {
let additionalFieldsProp = {
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
options: [
...additionalFields
]
};
operation1.fields = operation1.fields.filter(field => { var _a, _b; return field.required || ((_b = (_a = field.routing) === null || _a === void 0 ? void 0 : _a.send) === null || _b === void 0 ? void 0 : _b.type) == "body" || field.name == 'operation'; });
operation1.fields.push(additionalFieldsProp);
}
return operation1;
}
}
exports.ApitableOperationsCollector = ApitableOperationsCollector;
//# sourceMappingURL=utils.js.map