UNPKG

@traien/n8n-nodes-espocrm

Version:
135 lines 5.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetadataService = void 0; const GenericFunctions_1 = require("../GenericFunctions"); class MetadataService { static async getEntityMetadata(execFunctions, entityType) { var _a; const endpoint = `/Metadata`; const responseData = await GenericFunctions_1.espoApiRequest.call(execFunctions, 'GET', endpoint); return ((_a = responseData === null || responseData === void 0 ? void 0 : responseData.entityDefs) === null || _a === void 0 ? void 0 : _a[entityType]) || {}; } static async getFieldDefs(execFunctions, entityType) { var _a, _b; const endpoint = `/Metadata`; const responseData = await GenericFunctions_1.espoApiRequest.call(execFunctions, 'GET', endpoint); return ((_b = (_a = responseData === null || responseData === void 0 ? void 0 : responseData.entityDefs) === null || _a === void 0 ? void 0 : _a[entityType]) === null || _b === void 0 ? void 0 : _b.fields) || {}; } static async getEntityList(execFunctions) { const endpoint = '/Metadata'; const responseData = await GenericFunctions_1.espoApiRequest.call(execFunctions, 'GET', endpoint); return Object.keys((responseData === null || responseData === void 0 ? void 0 : responseData.entityDefs) || {}); } static async getEntityDefinition(execFunctions, entityType) { var _a; const endpoint = `/Metadata`; const responseData = await GenericFunctions_1.espoApiRequest.call(execFunctions, 'GET', endpoint); return ((_a = responseData === null || responseData === void 0 ? void 0 : responseData.entityDefs) === null || _a === void 0 ? void 0 : _a[entityType]) || {}; } static async getEntityLinks(execFunctions, entityType) { var _a, _b; const endpoint = `/Metadata`; const responseData = await GenericFunctions_1.espoApiRequest.call(execFunctions, 'GET', endpoint); return ((_b = (_a = responseData === null || responseData === void 0 ? void 0 : responseData.entityDefs) === null || _a === void 0 ? void 0 : _a[entityType]) === null || _b === void 0 ? void 0 : _b.links) || {}; } static async getEntityIndexes(execFunctions, entityType) { var _a, _b; const endpoint = `/Metadata`; const responseData = await GenericFunctions_1.espoApiRequest.call(execFunctions, 'GET', endpoint); return ((_b = (_a = responseData === null || responseData === void 0 ? void 0 : responseData.entityDefs) === null || _a === void 0 ? void 0 : _a[entityType]) === null || _b === void 0 ? void 0 : _b.indexes) || {}; } static async getEntityCollection(execFunctions, entityType) { var _a, _b; const endpoint = `/Metadata`; const responseData = await GenericFunctions_1.espoApiRequest.call(execFunctions, 'GET', endpoint); return ((_b = (_a = responseData === null || responseData === void 0 ? void 0 : responseData.entityDefs) === null || _a === void 0 ? void 0 : _a[entityType]) === null || _b === void 0 ? void 0 : _b.collection) || {}; } static mapFieldTypeToN8n(espoFieldType, fieldParams = {}) { switch (espoFieldType) { case 'varchar': case 'text': case 'url': case 'email': case 'phone': case 'personName': case 'foreign': return 'string'; case 'int': case 'integer': case 'float': case 'currency': case 'currencyConverted': return 'number'; case 'bool': case 'boolean': return 'boolean'; case 'date': return 'string'; case 'datetime': case 'datetimeOptional': return 'dateTime'; case 'enum': case 'multiEnum': case 'array': case 'checklist': return 'options'; case 'jsonArray': case 'jsonObject': return 'json'; case 'wysiwyg': return 'string'; case 'file': case 'image': case 'attachment': case 'attachmentMultiple': return 'string'; case 'link': case 'linkParent': case 'linkOne': case 'linkMultiple': return 'string'; case 'password': return 'string'; case 'autoincrement': return 'number'; case 'barcode': return 'string'; case 'map': return 'json'; case 'rangeCurrency': case 'rangeFloat': case 'rangeInt': return 'json'; default: return 'string'; } } static generateFieldOptions(fieldDefs, fieldName) { const fieldDef = fieldDefs[fieldName]; if (fieldDef) { if (fieldDef.type === 'enum' && fieldDef.options) { const options = fieldDef.options; return options.map((option) => ({ name: option, value: option, })); } if (fieldDef.type === 'multiEnum' && fieldDef.options) { const options = fieldDef.options; return options.map((option) => ({ name: option, value: option, })); } if ((fieldDef.type === 'link' || fieldDef.type === 'linkMultiple') && fieldDef.entity) { return []; } } return []; } static isRelationshipField(fieldType) { return ['link', 'linkOne', 'linkMultiple', 'linkParent'].includes(fieldType); } } exports.MetadataService = MetadataService; //# sourceMappingURL=MetadataService.js.map