UNPKG

n8n-nodes-community-coolify

Version:

n8n node to interact with Coolify API - an open-source & self-hostable Heroku / Netlify alternative

393 lines 17.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Coolify = void 0; const n8n_workflow_1 = require("n8n-workflow"); const CoolifyDescription_1 = require("./CoolifyDescription"); class Coolify { constructor() { this.description = { displayName: 'Coolify', name: 'coolify', icon: { light: 'file:coolify.svg', dark: 'file:coolify.svg' }, group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Interact with Coolify API for server, project, application, and deployment management', defaults: { name: 'Coolify', }, inputs: ["main"], outputs: ["main"], usableAsTool: true, credentials: [ { name: 'coolifyApi', required: true, }, ], requestDefaults: { baseURL: '={{$credentials?.baseUrl}}', url: '', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }, properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Application', value: 'application', description: 'Manage applications', }, { name: 'Database', value: 'database', description: 'Manage databases', }, { name: 'Deployment', value: 'deployment', description: 'Manage deployments', }, { name: 'Project', value: 'project', description: 'Manage Coolify projects', }, { name: 'Server', value: 'server', description: 'Manage Coolify servers', }, { name: 'Service', value: 'service', description: 'Manage services', }, ], default: 'server', }, ...CoolifyDescription_1.coolifyOperations, ...CoolifyDescription_1.coolifyFields, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const handleServerOperations = async (operation, itemIndex) => { if (operation === 'list') { return await this.helpers.httpRequest({ method: 'GET', url: '/api/v1/servers', }); } else { const serverUuid = this.getNodeParameter('serverUuid', itemIndex); switch (operation) { case 'getStatus': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/servers/${serverUuid}/status`, }); case 'getResources': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/servers/${serverUuid}/resources`, }); case 'getDomains': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/servers/${serverUuid}/domains`, }); case 'validateConnection': return await this.helpers.httpRequest({ method: 'POST', url: `/api/v1/servers/${serverUuid}/validate`, }); case 'getMetrics': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/servers/${serverUuid}/metrics`, }); default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown server operation: ${operation}`); } } }; const handleProjectOperations = async (operation, itemIndex) => { if (operation === 'list') { return await this.helpers.httpRequest({ method: 'GET', url: '/api/v1/projects', }); } else if (operation === 'create') { const projectName = this.getNodeParameter('projectName', itemIndex); const projectDescription = this.getNodeParameter('projectDescription', itemIndex); return await this.helpers.httpRequest({ method: 'POST', url: '/api/v1/projects', body: { name: projectName, description: projectDescription, }, }); } else { const projectUuid = this.getNodeParameter('projectUuid', itemIndex); switch (operation) { case 'get': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/projects/${projectUuid}`, }); case 'update': const projectName = this.getNodeParameter('projectName', itemIndex); const projectDescription = this.getNodeParameter('projectDescription', itemIndex); return await this.helpers.httpRequest({ method: 'PUT', url: `/api/v1/projects/${projectUuid}`, body: { name: projectName, description: projectDescription, }, }); case 'delete': return await this.helpers.httpRequest({ method: 'DELETE', url: `/api/v1/projects/${projectUuid}`, }); case 'getEnvironments': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/projects/${projectUuid}/environments`, }); case 'getEnvironmentVariables': const environment = this.getNodeParameter('environment', itemIndex); return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/projects/${projectUuid}/environments/${environment}/variables`, }); default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown project operation: ${operation}`); } } }; const handleApplicationOperations = async (operation, itemIndex) => { if (operation === 'list') { return await this.helpers.httpRequest({ method: 'GET', url: '/api/v1/applications', }); } else if (operation === 'create') { const applicationName = this.getNodeParameter('applicationName', itemIndex); return await this.helpers.httpRequest({ method: 'POST', url: '/api/v1/applications', body: { name: applicationName, }, }); } else { const applicationUuid = this.getNodeParameter('applicationUuid', itemIndex); switch (operation) { case 'get': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/applications/${applicationUuid}`, }); case 'delete': return await this.helpers.httpRequest({ method: 'DELETE', url: `/api/v1/applications/${applicationUuid}`, }); default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown application operation: ${operation}`); } } }; const handleServiceOperations = async (operation, itemIndex) => { if (operation === 'list') { return await this.helpers.httpRequest({ method: 'GET', url: '/api/v1/services', }); } else if (operation === 'create') { const serviceName = this.getNodeParameter('serviceName', itemIndex); const serviceType = this.getNodeParameter('serviceType', itemIndex); const projectUuid = this.getNodeParameter('serviceProjectUuid', itemIndex); const serverUuid = this.getNodeParameter('serviceServerUuid', itemIndex); return await this.helpers.httpRequest({ method: 'POST', url: '/api/v1/services', body: { name: serviceName, type: serviceType, projectUuid, serverUuid, }, }); } else { const serviceUuid = this.getNodeParameter('serviceUuid', itemIndex); switch (operation) { case 'getStatus': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/services/${serviceUuid}/status`, }); case 'delete': return await this.helpers.httpRequest({ method: 'DELETE', url: `/api/v1/services/${serviceUuid}`, }); default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown service operation: ${operation}`); } } }; const handleDatabaseOperations = async (operation, itemIndex) => { if (operation === 'list') { return await this.helpers.httpRequest({ method: 'GET', url: '/api/v1/databases', }); } else if (operation === 'create') { const databaseType = this.getNodeParameter('databaseType', itemIndex); const memoryLimit = this.getNodeParameter('memoryLimit', itemIndex); const publicPort = this.getNodeParameter('publicPort', itemIndex); const password = this.getNodeParameter('password', itemIndex); return await this.helpers.httpRequest({ method: 'POST', url: '/api/v1/databases', body: { type: databaseType, memoryLimit, publicPort, password, }, }); } else { const databaseUuid = this.getNodeParameter('databaseUuid', itemIndex); switch (operation) { case 'get': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/databases/${databaseUuid}`, }); case 'update': const memoryLimit = this.getNodeParameter('memoryLimit', itemIndex); const publicPort = this.getNodeParameter('publicPort', itemIndex); const password = this.getNodeParameter('password', itemIndex); return await this.helpers.httpRequest({ method: 'PUT', url: `/api/v1/databases/${databaseUuid}`, body: { memoryLimit, publicPort, password, }, }); case 'delete': return await this.helpers.httpRequest({ method: 'DELETE', url: `/api/v1/databases/${databaseUuid}`, }); default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown database operation: ${operation}`); } } }; const handleDeploymentOperations = async (operation, itemIndex) => { if (operation === 'list') { return await this.helpers.httpRequest({ method: 'GET', url: '/api/v1/deployments', }); } else if (operation === 'getStatus') { const deploymentUuid = this.getNodeParameter('deploymentUuid', itemIndex); return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/deployments/${deploymentUuid}`, }); } else { const applicationUuid = this.getNodeParameter('deploymentApplicationUuid', itemIndex); switch (operation) { case 'deploy': return await this.helpers.httpRequest({ method: 'POST', url: `/api/v1/applications/${applicationUuid}/deploy`, }); case 'forceRebuild': return await this.helpers.httpRequest({ method: 'POST', url: `/api/v1/applications/${applicationUuid}/deploy?force=true`, }); case 'listRecent': return await this.helpers.httpRequest({ method: 'GET', url: `/api/v1/applications/${applicationUuid}/deployments`, }); default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown deployment operation: ${operation}`); } } }; for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { try { const resource = this.getNodeParameter('resource', itemIndex); const operation = this.getNodeParameter('operation', itemIndex); let responseData; if (resource === 'server') { responseData = await handleServerOperations(operation, itemIndex); } else if (resource === 'project') { responseData = await handleProjectOperations(operation, itemIndex); } else if (resource === 'application') { responseData = await handleApplicationOperations(operation, itemIndex); } else if (resource === 'service') { responseData = await handleServiceOperations(operation, itemIndex); } else if (resource === 'database') { responseData = await handleDatabaseOperations(operation, itemIndex); } else if (resource === 'deployment') { responseData = await handleDeploymentOperations(operation, itemIndex); } const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: itemIndex } }); returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: this.getInputData(itemIndex)[0].json, error, pairedItem: itemIndex, }); } else { throw error; } } } return [returnData]; } } exports.Coolify = Coolify; //# sourceMappingURL=Coolify.node.js.map