From b03ae033807b9dc9e67926e6ae36a16c6692b003 Mon Sep 17 00:00:00 2001 From: Javier Sanchez Date: Tue, 24 Jun 2025 12:58:53 +0000 Subject: [PATCH] All functions documented --- Dockerfile | 2 +- docker-compose.yml | 2 +- src/tools.js | 35 ++++ src/tools/applications.js | 343 ++++++++++++++++++++++++++++++++++++-- src/tools/databases.js | 157 +++++++++++++++++ src/tools/deploy.js | 9 +- src/tools/deployments.js | 48 ++++++ src/tools/disable.js | 8 +- src/tools/domains.js | 18 ++ src/tools/enable.js | 21 +++ src/tools/health.js | 18 ++ src/tools/keys.js | 18 ++ src/tools/projects.js | 100 +++++++++++ src/tools/resources.js | 18 ++ src/tools/servers.js | 109 ++++++++++++ src/tools/services.js | 74 ++++++++ src/tools/teams.js | 46 +++++ src/tools/version.js | 18 ++ 18 files changed, 1025 insertions(+), 19 deletions(-) create mode 100644 src/tools.js create mode 100644 src/tools/databases.js create mode 100644 src/tools/deployments.js create mode 100644 src/tools/domains.js create mode 100644 src/tools/enable.js create mode 100644 src/tools/health.js create mode 100644 src/tools/keys.js create mode 100644 src/tools/projects.js create mode 100644 src/tools/resources.js create mode 100644 src/tools/servers.js create mode 100644 src/tools/services.js create mode 100644 src/tools/teams.js create mode 100644 src/tools/version.js diff --git a/Dockerfile b/Dockerfile index 7be4613..eea9c3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,4 @@ COPY src ./src RUN chmod +x ./src/index.js # Set entrypoint for npx-style usage -ENTRYPOINT ["node", "src/index.js"] \ No newline at end of file +ENTRYPOINT ["node", "src/index.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1f98c5e..1e181b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,4 +7,4 @@ services: - TOKEN=${TOKEN} command: ["--host_url", "$HOST_URL", "--token", "$TOKEN"] ports: - - "3000:3000" \ No newline at end of file + - "3000:3000" \ No newline at end of file diff --git a/src/tools.js b/src/tools.js new file mode 100644 index 0000000..2776698 --- /dev/null +++ b/src/tools.js @@ -0,0 +1,35 @@ +const CoolifyClient = require('./coolifyClient'); + +async function health(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/health'); +} + +async function version(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/version'); +} + +async function listApps(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/applications'); +} + +async function startApp(host_url, token, id) { + const client = new CoolifyClient(host_url, token); + return client.post(`/api/v1/applications/${id}/start`, {}); +} + +async function stopApp(host_url, token, id) { + const client = new CoolifyClient(host_url, token); + return client.post(`/api/v1/applications/${id}/stop`, {}); +} + +module.exports = { + health, + version, + listApps, + startApp, + stopApp, +}; + diff --git a/src/tools/applications.js b/src/tools/applications.js index c252277..459b6c2 100644 --- a/src/tools/applications.js +++ b/src/tools/applications.js @@ -1,49 +1,370 @@ const CoolifyClient = require('../coolifyClient'); -// List all applications +/** + * List all applications. + * @param {string} host_url - Coolify instance URL + * @param {string} token - Bearer token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ async function list(host_url, token) { const client = new CoolifyClient(host_url, token); return client.get('/api/v1/applications'); } -// Create new application (public repo) +/** + * Get application by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @returns {Promise} + * @example + * get('https://coolify.example.com', 'TOKEN', 'app-uuid'); + */ +async function get(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/applications/${uuid}`); +} + +/** + * Create new application (public repo). + * @param {string} host_url + * @param {string} token + * @param {Object} data - Application creation payload. + * @param {string} data.project_uuid - The project UUID. (required) + * @param {string} data.server_uuid - The server UUID. (required) + * @param {string} data.environment_name - The environment name. (required, at least one of environment_name or environment_uuid) + * @param {string} data.environment_uuid - The environment UUID. (required, at least one of environment_name or environment_uuid) + * @param {string} data.git_repository - The git repository URL. (required) + * @param {string} data.git_branch - The git branch. (required) + * @param {string} data.build_pack - The build pack type. One of: 'nixpacks', 'static', 'dockerfile', 'dockercompose'. (required) + * @param {string} data.ports_exposes - The ports to expose. (required) + * @param {string} [data.destination_uuid] - The destination UUID. + * @param {string} [data.name] - The application name. + * @param {string} [data.description] - The application description. + * @param {string} [data.domains] - The application domains. + * @param {string} [data.git_commit_sha] - The git commit SHA. + * @param {string} [data.docker_registry_image_name] - The docker registry image name. + * @param {string} [data.docker_registry_image_tag] - The docker registry image tag. + * @param {boolean} [data.is_static] - The flag to indicate if the application is static. + * @param {string} [data.static_image] - The static image. Enum: ['nginx:alpine'] + * @param {string} [data.install_command] - The install command. + * @param {string} [data.build_command] - The build command. + * @param {string} [data.start_command] - The start command. + * @param {string} [data.ports_mappings] - The ports mappings. + * @param {string} [data.base_directory] - The base directory for all commands. + * @param {string} [data.publish_directory] - The publish directory. + * @param {boolean} [data.health_check_enabled] - Health check enabled. + * @param {string} [data.health_check_path] - Health check path. + * @param {string} [data.health_check_port] - Health check port. + * @param {string} [data.health_check_host] - Health check host. + * @param {string} [data.health_check_method] - Health check method. + * @param {integer} [data.health_check_return_code] - Health check return code. + * @param {string} [data.health_check_scheme] - Health check scheme. + * @param {string} [data.health_check_response_text] - Health check response text. + * @param {integer} [data.health_check_interval] - Health check interval in seconds. + * @param {integer} [data.health_check_timeout] - Health check timeout in seconds. + * @param {integer} [data.health_check_retries] - Health check retries count. + * @param {integer} [data.health_check_start_period] - Health check start period in seconds. + * @param {string} [data.limits_memory] - Memory limit. + * @param {string} [data.limits_memory_swap] - Memory swap limit. + * @param {integer} [data.limits_memory_swappiness] - Memory swappiness. + * @param {string} [data.limits_memory_reservation] - Memory reservation. + * @param {string} [data.limits_cpus] - CPU limit. + * @param {string} [data.limits_cpuset] - CPU set. + * @param {integer} [data.limits_cpu_shares] - CPU shares. + * @param {string} [data.custom_labels] - Custom labels. + * @param {string} [data.custom_docker_run_options] - Custom docker run options. + * @param {string} [data.post_deployment_command] - Post deployment command. + * @param {string} [data.post_deployment_command_container] - Post deployment command container. + * @param {string} [data.pre_deployment_command] - Pre deployment command. + * @param {string} [data.pre_deployment_command_container] - Pre deployment command container. + * @param {string} [data.manual_webhook_secret_github] - Manual webhook secret for Github. + * @param {string} [data.manual_webhook_secret_gitlab] - Manual webhook secret for Gitlab. + * @param {string} [data.manual_webhook_secret_bitbucket] - Manual webhook secret for Bitbucket. + * @param {string} [data.manual_webhook_secret_gitea] - Manual webhook secret for Gitea. + * @param {string} [data.redirect] - How to set redirect with Traefik / Caddy. Enum: [www, non-www, both] + * @param {boolean} [data.instant_deploy] - The flag to indicate if the application should be deployed instantly. + * @param {string} [data.dockerfile] - The Dockerfile content. + * @param {string} [data.docker_compose_location] - The Docker Compose location. + * @param {string} [data.docker_compose_raw] - The Docker Compose raw content. + * @param {string} [data.docker_compose_custom_start_command] - The Docker Compose custom start command. + * @param {string} [data.docker_compose_custom_build_command] - The Docker Compose custom build command. + * @param {array} [data.docker_compose_domains] - The Docker Compose domains. + * @param {string} [data.watch_paths] - The watch paths. + * @param {boolean} [data.use_build_server] - Use build server. + * @returns {Promise} + * @example + * createPublic('https://coolify.example.com', 'TOKEN', { + * project_uuid: '123', + * server_uuid: '456', + * environment_name: 'production', + * environment_uuid: 'env-uuid', + * git_repository: 'https://github.com/user/repo.git', + * git_branch: 'main', + * build_pack: 'nixpacks', + * ports_exposes: '3000', + * name: 'My App', + * description: 'A sample app', + * // ...other optional fields + * }); + */ async function createPublic(host_url, token, data) { const client = new CoolifyClient(host_url, token); return client.post('/api/v1/applications/public', data); } -// Create new application (private GitHub app) +/** + * Create new application (private GitHub app). + * @param {string} host_url + * @param {string} token + * @param {Object} data - Application creation payload (see OpenAPI) + * @returns {Promise} + * @example + * createPrivateGithubApp('https://coolify.example.com', 'TOKEN', { ... }); + */ async function createPrivateGithubApp(host_url, token, data) { const client = new CoolifyClient(host_url, token); return client.post('/api/v1/applications/private-github-app', data); } -// Create new application (private deploy key) +/** + * Create new application (private deploy key). + * @param {string} host_url + * @param {string} token + * @param {Object} data - Application creation payload (see OpenAPI) + * @returns {Promise} + * @example + * createPrivateDeployKey('https://coolify.example.com', 'TOKEN', { ... }); + */ async function createPrivateDeployKey(host_url, token, data) { const client = new CoolifyClient(host_url, token); return client.post('/api/v1/applications/private-deploy-key', data); } -// Dockerfile, Dockerimage, Dockercompose, etc. -async function dockerfile(host_url, token, data) { +/** + * Create new application (Dockerfile). + * @param {string} host_url + * @param {string} token + * @param {Object} data - Application creation payload (see OpenAPI) + * @returns {Promise} + * @example + * createDockerfile('https://coolify.example.com', 'TOKEN', { ... }); + */ +async function createDockerfile(host_url, token, data) { const client = new CoolifyClient(host_url, token); return client.post('/api/v1/applications/dockerfile', data); } -async function dockerimage(host_url, token, data) { + +/** + * Create new application (Docker image). + * @param {string} host_url + * @param {string} token + * @param {Object} data - Application creation payload (see OpenAPI) + * @returns {Promise} + * @example + * createDockerimage('https://coolify.example.com', 'TOKEN', { ... }); + */ +async function createDockerimage(host_url, token, data) { const client = new CoolifyClient(host_url, token); return client.post('/api/v1/applications/dockerimage', data); } -async function dockercompose(host_url, token, data) { + +/** + * Create new application (Docker Compose). + * @param {string} host_url + * @param {string} token + * @param {Object} data - Application creation payload (see OpenAPI) + * @returns {Promise} + * @example + * createDockercompose('https://coolify.example.com', 'TOKEN', { ... }); + */ +async function createDockercompose(host_url, token, data) { const client = new CoolifyClient(host_url, token); return client.post('/api/v1/applications/dockercompose', data); } +/** + * Update application by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @param {Object} data - Update payload + * @returns {Promise} + * @example + * update('https://coolify.example.com', 'TOKEN', 'app-uuid', { ... }); + */ +async function update(host_url, token, uuid, data) { + const client = new CoolifyClient(host_url, token); + return client.patch(`/api/v1/applications/${uuid}`, data); +} + +/** + * Delete application by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @param {Object} params - Optional query params (delete_configurations, delete_volumes, etc.) + * @returns {Promise} + * @example + * remove('https://coolify.example.com', 'TOKEN', 'app-uuid', { delete_configurations: true }); + */ +async function remove(host_url, token, uuid, params = {}) { + const client = new CoolifyClient(host_url, token); + return client.delete(`/api/v1/applications/${uuid}`, { params }); +} + +/** + * List all envs by application UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @returns {Promise} + * @example + * listEnvs('https://coolify.example.com', 'TOKEN', 'app-uuid'); + */ +async function listEnvs(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/applications/${uuid}/envs`); +} + +/** + * Create env by application UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @param {Object} data - Env payload + * @returns {Promise} + * @example + * createEnv('https://coolify.example.com', 'TOKEN', 'app-uuid', { key: 'FOO', value: 'bar' }); + */ +async function createEnv(host_url, token, uuid, data) { + const client = new CoolifyClient(host_url, token); + return client.post(`/api/v1/applications/${uuid}/envs`, data); +} + +/** + * Update env by application UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @param {Object} data - Env update payload + * @returns {Promise} + * @example + * updateEnv('https://coolify.example.com', 'TOKEN', 'app-uuid', { key: 'FOO', value: 'baz' }); + */ +async function updateEnv(host_url, token, uuid, data) { + const client = new CoolifyClient(host_url, token); + return client.patch(`/api/v1/applications/${uuid}/envs`, data); +} + +/** + * Update multiple envs by application UUID (bulk). + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @param {Object} data - Bulk envs update payload + * @returns {Promise} + * @example + * updateEnvsBulk('https://coolify.example.com', 'TOKEN', 'app-uuid', { data: [...] }); + */ +async function updateEnvsBulk(host_url, token, uuid, data) { + const client = new CoolifyClient(host_url, token); + return client.patch(`/api/v1/applications/${uuid}/envs/bulk`, data); +} + +/** + * Delete env by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @param {string} env_uuid - Env UUID + * @returns {Promise} + * @example + * removeEnv('https://coolify.example.com', 'TOKEN', 'app-uuid', 'env-uuid'); + */ +async function removeEnv(host_url, token, uuid, env_uuid) { + const client = new CoolifyClient(host_url, token); + return client.delete(`/api/v1/applications/${uuid}/envs/${env_uuid}`); +} + +/** + * Start application by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @param {Object} params - Optional query params (force, instant_deploy) + * @returns {Promise} + * @example + * start('https://coolify.example.com', 'TOKEN', 'app-uuid', { force: true }); + */ +async function start(host_url, token, uuid, params = {}) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/applications/${uuid}/start`, { params }); +} + +/** + * Stop application by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @returns {Promise} + * @example + * stop('https://coolify.example.com', 'TOKEN', 'app-uuid'); + */ +async function stop(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/applications/${uuid}/stop`); +} + +/** + * Restart application by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @returns {Promise} + * @example + * restart('https://coolify.example.com', 'TOKEN', 'app-uuid'); + */ +async function restart(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/applications/${uuid}/restart`); +} + +/** + * Execute a command on the application's current container. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Application UUID + * @param {Object} data - { command: string } + * @returns {Promise} + * @example + * execute('https://coolify.example.com', 'TOKEN', 'app-uuid', { command: 'ls -la' }); + */ +async function execute(host_url, token, uuid, data) { + const client = new CoolifyClient(host_url, token); + return client.post(`/api/v1/applications/${uuid}/execute`, data); +} + module.exports = { list, + get, createPublic, createPrivateGithubApp, createPrivateDeployKey, - dockerfile, - dockerimage, - dockercompose, + createDockerfile, + createDockerimage, + createDockercompose, + update, + remove, + listEnvs, + createEnv, + updateEnv, + updateEnvsBulk, + removeEnv, + start, + stop, + restart, + execute, }; \ No newline at end of file diff --git a/src/tools/databases.js b/src/tools/databases.js new file mode 100644 index 0000000..19c6f86 --- /dev/null +++ b/src/tools/databases.js @@ -0,0 +1,157 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all databases. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/databases'); +} + +/** + * Get database by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Database UUID + * @returns {Promise} + * @example + * get('https://coolify.example.com', 'TOKEN', 'db-uuid'); + */ +async function get(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/databases/${uuid}`); +} + +/** + * Create a new PostgreSQL database. + * @param {string} host_url + * @param {string} token + * @param {Object} data - Database creation payload. + * @param {string} data.server_uuid - UUID of the server. (required) + * @param {string} data.project_uuid - UUID of the project. (required) + * @param {string} data.environment_name - Name of the environment. (required, at least one of environment_name or environment_uuid) + * @param {string} data.environment_uuid - UUID of the environment. (required, at least one of environment_name or environment_uuid) + * @param {string} [data.postgres_user] - PostgreSQL user. + * @param {string} [data.postgres_password] - PostgreSQL password. + * @param {string} [data.postgres_db] - PostgreSQL database. + * @param {string} [data.postgres_initdb_args] - PostgreSQL initdb args. + * @param {string} [data.postgres_host_auth_method] - PostgreSQL host auth method. + * @param {string} [data.postgres_conf] - PostgreSQL conf. + * @param {string} [data.destination_uuid] - UUID of the destination if the server has multiple destinations. + * @param {string} [data.name] - Name of the database. + * @param {string} [data.description] - Description of the database. + * @param {string} [data.image] - Docker Image of the database. + * @param {boolean} [data.is_public] - Is the database public? + * @param {integer} [data.public_port] - Public port of the database. + * @param {string} [data.limits_memory] - Memory limit of the database. + * @param {string} [data.limits_memory_swap] - Memory swap limit of the database. + * @param {integer} [data.limits_memory_swappiness] - Memory swappiness of the database. + * @param {string} [data.limits_memory_reservation] - Memory reservation of the database. + * @param {string} [data.limits_cpus] - CPU limit of the database. + * @param {string} [data.limits_cpuset] - CPU set of the database. + * @param {integer} [data.limits_cpu_shares] - CPU shares of the database. + * @param {boolean} [data.instant_deploy] - Instant deploy the database. + * @returns {Promise} + * @example + * createPostgreSQL('https://coolify.example.com', 'TOKEN', { + * server_uuid: 'server-uuid', + * project_uuid: 'project-uuid', + * environment_name: 'production', + * environment_uuid: 'env-uuid', + * postgres_user: 'user', + * postgres_password: 'pass', + * postgres_db: 'dbname', + * // ...other optional fields + * }); + */ +async function createPostgreSQL(host_url, token, data) { + const client = new CoolifyClient(host_url, token); + return client.post('/api/v1/databases/postgresql', data); +} + +/** + * Update database by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Database UUID + * @param {Object} data - Update payload + * @returns {Promise} + * @example + * update('https://coolify.example.com', 'TOKEN', 'db-uuid', { ... }); + */ +async function update(host_url, token, uuid, data) { + const client = new CoolifyClient(host_url, token); + return client.patch(`/api/v1/databases/${uuid}`, data); +} + +/** + * Delete database by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Database UUID + * @param {Object} params - Optional query params (delete_configurations, delete_volumes, etc.) + * @returns {Promise} + * @example + * remove('https://coolify.example.com', 'TOKEN', 'db-uuid', { delete_configurations: true }); + */ +async function remove(host_url, token, uuid, params = {}) { + const client = new CoolifyClient(host_url, token); + return client.delete(`/api/v1/databases/${uuid}`, { params }); +} + +/** + * Start database by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Database UUID + * @returns {Promise} + * @example + * start('https://coolify.example.com', 'TOKEN', 'db-uuid'); + */ +async function start(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/databases/${uuid}/start`); +} + +/** + * Stop database by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Database UUID + * @returns {Promise} + * @example + * stop('https://coolify.example.com', 'TOKEN', 'db-uuid'); + */ +async function stop(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/databases/${uuid}/stop`); +} + +/** + * Restart database by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Database UUID + * @returns {Promise} + * @example + * restart('https://coolify.example.com', 'TOKEN', 'db-uuid'); + */ +async function restart(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/databases/${uuid}/restart`); +} + +module.exports = { + list, + get, + update, + remove, + start, + stop, + restart, +}; \ No newline at end of file diff --git a/src/tools/deploy.js b/src/tools/deploy.js index 9b8decf..a6541fa 100644 --- a/src/tools/deploy.js +++ b/src/tools/deploy.js @@ -1,13 +1,16 @@ const CoolifyClient = require('../coolifyClient'); /** - * Despliega recursos según la configuración de Coolify. + * Deploy resources by tag or uuid (see OpenAPI for params). * @param {string} host_url * @param {string} token - * @param {Object} data - Parámetros para el despliegue (ver OpenAPI para detalles). + * @param {Object} data - Parameters for deployment. + * @param {string} [data.tag] - Tag name(s). Comma separated list is also accepted. + * @param {string} [data.uuid] - Resource UUID(s). Comma separated list is also accepted. + * @param {boolean} [data.force] - Force rebuild (without cache). * @returns {Promise} * @example - * deploy('https://coolify.example.com', 'TOKEN', { id: 'uuid', ... }); + * deploy('https://coolify.example.com', 'TOKEN', { tag: 'v1.0.0', force: true }); */ async function deploy(host_url, token, data) { const client = new CoolifyClient(host_url, token); diff --git a/src/tools/deployments.js b/src/tools/deployments.js new file mode 100644 index 0000000..4095a6a --- /dev/null +++ b/src/tools/deployments.js @@ -0,0 +1,48 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all currently running deployments. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/deployments'); +} + +/** + * Get deployment by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Deployment UUID + * @returns {Promise} + * @example + * get('https://coolify.example.com', 'TOKEN', 'deployment-uuid'); + */ +async function get(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/deployments/${uuid}`); +} + +/** + * Deploy by tag or uuid. + * @param {string} host_url + * @param {string} token + * @param {Object} params - { tag, uuid, force } + * @returns {Promise} + * @example + * deploy('https://coolify.example.com', 'TOKEN', { tag: 'v1.0.0' }); + */ +async function deploy(host_url, token, params = {}) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/deploy', { params }); +} + +module.exports = { + list, + get, + deploy, +}; \ No newline at end of file diff --git a/src/tools/disable.js b/src/tools/disable.js index f55cba6..b7a4d03 100644 --- a/src/tools/disable.js +++ b/src/tools/disable.js @@ -1,13 +1,15 @@ const CoolifyClient = require('../coolifyClient'); /** - * Deshabilita un recurso (según OpenAPI, puede requerir ID o parámetros específicos). + * Disable a resource (see OpenAPI for required params). * @param {string} host_url * @param {string} token - * @param {Object} data - Parámetros para deshabilitar el recurso (ver OpenAPI para detalles). + * @param {Object} data - Parameters for disabling the resource. + * @param {string} data.id - The UUID of the resource to disable. (required) + * @param {string} [data.type] - The type of resource (e.g., 'application', 'database', etc.). * @returns {Promise} * @example - * disable('https://coolify.example.com', 'TOKEN', { id: 'uuid', ... }); + * disable('https://coolify.example.com', 'TOKEN', { id: 'uuid', type: 'application' }); */ async function disable(host_url, token, data) { const client = new CoolifyClient(host_url, token); diff --git a/src/tools/domains.js b/src/tools/domains.js new file mode 100644 index 0000000..c5e9e64 --- /dev/null +++ b/src/tools/domains.js @@ -0,0 +1,18 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all domains. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/domains'); +} + +module.exports = { + list, +}; \ No newline at end of file diff --git a/src/tools/enable.js b/src/tools/enable.js new file mode 100644 index 0000000..06cb6e8 --- /dev/null +++ b/src/tools/enable.js @@ -0,0 +1,21 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * Enable a resource (see OpenAPI for required params). + * @param {string} host_url + * @param {string} token + * @param {Object} data - Parameters for enabling the resource. + * @param {string} data.id - The UUID of the resource to enable. (required) + * @param {string} [data.type] - The type of resource (e.g., 'application', 'database', etc.). + * @returns {Promise} + * @example + * enable('https://coolify.example.com', 'TOKEN', { id: 'uuid', type: 'application' }); + */ +async function enable(host_url, token, data) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/enable', { params: data }); +} + +module.exports = { + enable, +}; diff --git a/src/tools/health.js b/src/tools/health.js new file mode 100644 index 0000000..93d7555 --- /dev/null +++ b/src/tools/health.js @@ -0,0 +1,18 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * Get Coolify API health status. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * health('https://coolify.example.com', 'TOKEN'); + */ +async function health(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/health'); +} + +module.exports = { + health, +}; \ No newline at end of file diff --git a/src/tools/keys.js b/src/tools/keys.js new file mode 100644 index 0000000..f5fb46b --- /dev/null +++ b/src/tools/keys.js @@ -0,0 +1,18 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all security keys. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/security/keys'); +} + +module.exports = { + list, +}; \ No newline at end of file diff --git a/src/tools/projects.js b/src/tools/projects.js new file mode 100644 index 0000000..cdfa51f --- /dev/null +++ b/src/tools/projects.js @@ -0,0 +1,100 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all projects. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/projects'); +} + +/** + * Get project by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Project UUID + * @returns {Promise} + * @example + * get('https://coolify.example.com', 'TOKEN', 'project-uuid'); + */ +async function get(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/projects/${uuid}`); +} + +/** + * Create a new project. + * @param {string} host_url + * @param {string} token + * @param {Object} data - Project creation payload. + * @param {string} data.name - The name of the project. (required) + * @param {string} [data.description] - The description of the project. + * @returns {Promise} + * @example + * create('https://coolify.example.com', 'TOKEN', { + * name: 'My Project', + * description: 'A sample project', + * }); + */ +async function create(host_url, token, data) { + const client = new CoolifyClient(host_url, token); + return client.post('/api/v1/projects', data); +} + +/** + * Update project by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Project UUID + * @param {Object} data - Update payload + * @returns {Promise} + * @example + * update('https://coolify.example.com', 'TOKEN', 'project-uuid', { ... }); + */ +async function update(host_url, token, uuid, data) { + const client = new CoolifyClient(host_url, token); + return client.patch(`/api/v1/projects/${uuid}`, data); +} + +/** + * Delete project by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Project UUID + * @returns {Promise} + * @example + * remove('https://coolify.example.com', 'TOKEN', 'project-uuid'); + */ +async function remove(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.delete(`/api/v1/projects/${uuid}`); +} + +/** + * Get project environment by name or UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Project UUID + * @param {string} environment - Environment name or UUID + * @returns {Promise} + * @example + * getEnvironment('https://coolify.example.com', 'TOKEN', 'project-uuid', 'production'); + */ +async function getEnvironment(host_url, token, uuid, environment) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/projects/${uuid}/${environment}`); +} + +module.exports = { + list, + get, + create, + update, + remove, + getEnvironment, +}; \ No newline at end of file diff --git a/src/tools/resources.js b/src/tools/resources.js new file mode 100644 index 0000000..1ea7b1b --- /dev/null +++ b/src/tools/resources.js @@ -0,0 +1,18 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all resources. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/resources'); +} + +module.exports = { + list, +}; \ No newline at end of file diff --git a/src/tools/servers.js b/src/tools/servers.js new file mode 100644 index 0000000..724833d --- /dev/null +++ b/src/tools/servers.js @@ -0,0 +1,109 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all servers. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/servers'); +} + +/** + * Get server by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Server UUID + * @returns {Promise} + * @example + * get('https://coolify.example.com', 'TOKEN', 'server-uuid'); + */ +async function get(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/servers/${uuid}`); +} + +/** + * Create a new server. + * @param {string} host_url + * @param {string} token + * @param {Object} data - Server creation payload. + * @param {string} data.name - The name of the server. (required) + * @param {string} [data.description] - The description of the server. + * @param {string} data.ip - The IP of the server. (required) + * @param {integer} data.port - The port of the server. (required) + * @param {string} data.user - The user of the server. (required) + * @param {string} data.private_key_uuid - The UUID of the private key. (required) + * @param {boolean} [data.is_build_server] - Is build server. + * @param {boolean} [data.instant_validate] - Instant validate. + * @param {string} [data.proxy_type] - The proxy type. Enum: ['traefik', 'caddy', 'none'] + * @returns {Promise} + * @example + * create('https://coolify.example.com', 'TOKEN', { + * name: 'My Server', + * ip: '127.0.0.1', + * port: 22, + * user: 'root', + * private_key_uuid: 'key-uuid', + * proxy_type: 'traefik', + * }); + */ +async function create(host_url, token, data) { + const client = new CoolifyClient(host_url, token); + return client.post('/api/v1/servers', data); +} + +/** + * Get resources by server UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Server UUID + * @returns {Promise} + * @example + * getResources('https://coolify.example.com', 'TOKEN', 'server-uuid'); + */ +async function getResources(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/servers/${uuid}/resources`); +} + +/** + * Get domains by server UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Server UUID + * @returns {Promise} + * @example + * getDomains('https://coolify.example.com', 'TOKEN', 'server-uuid'); + */ +async function getDomains(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/servers/${uuid}/domains`); +} + +/** + * Validate server by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Server UUID + * @returns {Promise} + * @example + * validate('https://coolify.example.com', 'TOKEN', 'server-uuid'); + */ +async function validate(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/servers/${uuid}/validate`); +} + +module.exports = { + list, + get, + create, + getResources, + getDomains, + validate, +}; \ No newline at end of file diff --git a/src/tools/services.js b/src/tools/services.js new file mode 100644 index 0000000..90672ac --- /dev/null +++ b/src/tools/services.js @@ -0,0 +1,74 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all services. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/services'); +} + +/** + * Get service by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Service UUID + * @returns {Promise} + * @example + * get('https://coolify.example.com', 'TOKEN', 'service-uuid'); + */ +async function get(host_url, token, uuid) { + const client = new CoolifyClient(host_url, token); + return client.get(`/api/v1/services/${uuid}`); +} + +/** + * Create a new service. + * @param {string} host_url + * @param {string} token + * @param {Object} data - Service creation payload. + * @param {string} data.name - The name of the service. (required) + * @param {string} [data.description] - The description of the service. + * @param {string} data.server_uuid - The UUID of the server. (required) + * @param {string} data.project_uuid - The UUID of the project. (required) + * @param {string} [data.environment_name] - The environment name. + * @param {string} [data.environment_uuid] - The environment UUID. + * @returns {Promise} + * @example + * create('https://coolify.example.com', 'TOKEN', { + * name: 'My Service', + * server_uuid: 'server-uuid', + * project_uuid: 'project-uuid', + * environment_name: 'production', + * }); + */ +async function create(host_url, token, data) { + const client = new CoolifyClient(host_url, token); + return client.post('/api/v1/services', data); +} + +/** + * Delete service by UUID. + * @param {string} host_url + * @param {string} token + * @param {string} uuid - Service UUID + * @param {Object} params - Optional query params (delete_configurations, delete_volumes, etc.) + * @returns {Promise} + * @example + * remove('https://coolify.example.com', 'TOKEN', 'service-uuid', { delete_configurations: true }); + */ +async function remove(host_url, token, uuid, params = {}) { + const client = new CoolifyClient(host_url, token); + return client.delete(`/api/v1/services/${uuid}`, { params }); +} + +module.exports = { + list, + get, + remove, +}; \ No newline at end of file diff --git a/src/tools/teams.js b/src/tools/teams.js new file mode 100644 index 0000000..d6690e3 --- /dev/null +++ b/src/tools/teams.js @@ -0,0 +1,46 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * List all teams. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * list('https://coolify.example.com', 'TOKEN'); + */ +async function list(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/teams'); +} + +/** + * Get current team. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * current('https://coolify.example.com', 'TOKEN'); + */ +async function current(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/teams/current'); +} + +/** + * List current team members. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * currentMembers('https://coolify.example.com', 'TOKEN'); + */ +async function currentMembers(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/teams/current/members'); +} + +module.exports = { + list, + current, + currentMembers, +}; \ No newline at end of file diff --git a/src/tools/version.js b/src/tools/version.js new file mode 100644 index 0000000..e7b16d1 --- /dev/null +++ b/src/tools/version.js @@ -0,0 +1,18 @@ +const CoolifyClient = require('../coolifyClient'); + +/** + * Get Coolify version. + * @param {string} host_url + * @param {string} token + * @returns {Promise} + * @example + * version('https://coolify.example.com', 'TOKEN'); + */ +async function version(host_url, token) { + const client = new CoolifyClient(host_url, token); + return client.get('/api/v1/version'); +} + +module.exports = { + version, +}; \ No newline at end of file