JavaScript SDK

@enzonic/cloud-api is a typed, isomorphic client for Node and the browser.

Install

bash
npm install @enzonic/cloud-api

Initialise

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

Surface

ts
// account & billing 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); // discovery await cloud.regions(); await cloud.instances(); await cloud.eggs(); await cloud.egg(instanceId, eggId); // keys await cloud.keys.list(); await cloud.keys.create("name", { expiresInDays: 90, scopes: ["servers:read"] }); await cloud.keys.revoke(id); // servers 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); // files 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"], "/"); // admin (admin accounts only) await cloud.admin.addInstance({ name, baseUrl, appApiKey }); await cloud.admin.grantCredits(userId, 1000);

Error handling

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); // e.g. 402 payment_required } }
JavaScript SDK | Enzonic Cloud API