SDK de JavaScript

@enzonic/cloud-api es un cliente tipado e isomórfico para Node y el navegador.

Instalar

bash
npm install @enzonic/cloud-api

Inicializar

ts
import { CloudClient } from "@enzonic/cloud-api"; const cloud = new CloudClient({ apiKey: process.env.CLOUD_API_KEY!, baseUrl: "https://cloud.api.enzonic.com", // opcional });

Superficie de la API

ts
// cuenta y facturación await cloud.account(); await cloud.transactions(50); await cloud.billing.config(); await cloud.billing.checkout(2500); await cloud.billing.invoices(); await cloud.budget.get(); await cloud.budget.set({ monthlyBudgetCents: 5000 }); await cloud.logs(100); // descubrimiento await cloud.regions(); await cloud.instances(); await cloud.eggs(); await cloud.egg(instanceId, eggId); // claves await cloud.keys.list(); await cloud.keys.create("name", { expiresInDays: 90, scopes: ["servers:read"] }); await cloud.keys.revoke(id); // servidores await cloud.servers.list(); await cloud.servers.get(id); await cloud.servers.create({ name, eggId, region, ramMb, cpuPercent, diskMb }); await cloud.servers.resize(id, { ramMb, cpuPercent, diskMb }); await cloud.servers.delete(id); await cloud.servers.power(id, "start"); await cloud.servers.resources(id); await cloud.servers.command(id, "say hi"); await cloud.servers.console(id); // archivos await cloud.files.list(id, "/"); await cloud.files.read(id, "/server.properties"); await cloud.files.write(id, "/server.properties", "..."); await cloud.files.downloadUrl(id, "/world.zip"); await cloud.files.delete(id, ["a", "b"], "/"); // administración (solo cuentas admin) await cloud.admin.addInstance({ name, baseUrl, appApiKey }); await cloud.admin.grantCredits(userId, 1000);

Manejo de errores

ts
import { CloudError } from "@enzonic/cloud-api"; try { await cloud.servers.create({ /* ... */ }); } catch (e) { if (e instanceof CloudError) { console.error(e.status, e.code, e.message); // p.ej. 402 payment_required } }
JavaScript SDK | Enzonic Cloud API