import { checkGate } from './gate.js';
import * as http from './http.js';
/** GET /vps/tiers — VPS tiers. */
export const listTiers = (client) => http.get(client, '/vps/tiers');
/** GET /vps/system-images — Bootable system images. */
export const listSystemImages = (client) => http.get(client, '/vps/system-images');
/** GET /vps/ssh-keys — List SSH keys. */
export const listSshKeys = (client) => http.get(client, '/vps/ssh-keys');
/** POST /vps/ssh-keys — Add an SSH key. */
export const addSshKey = (client, body) => http.post(client, '/vps/ssh-keys', { body });
/** DELETE /vps/ssh-keys/{id} — Delete an SSH key. */
export const deleteSshKey = (client, id) => http.del(client, '/vps/ssh-keys/{id}', { params: { id } });
/** GET /vps/availability — Tier availability. */
export const availability = (client) => http.get(client, '/vps/availability');
/** GET /vps/instances — List your servers. */
export const listInstances = (client) => http.get(client, '/vps/instances');
/** POST /vps/instances — Create a server (202, hourly billing starts). */
export const createInstance = (client, body) => http.post(client, '/vps/instances', { body });
/** GET /vps/apps — One-click app catalog. */
export const appCatalog = (client) => http.get(client, '/vps/apps');
/** GET /vps/apps/deployments — List your app deployments. */
export const listAppDeployments = (client) => http.get(client, '/vps/apps/deployments');
/** POST /vps/apps/deployments — Deploy an app (202, hourly billing starts). */
export const deployApp = (client, body) => http.post(client, '/vps/apps/deployments', { body });
/** GET /vps/apps/deployments/{id} — Get an app deployment. */
export const getAppDeployment = (client, id) => http.get(client, '/vps/apps/deployments/{id}', { params: { id } });
/** POST /vps/apps/deployments/{id}/reveal-password — Reveal an app deployment's root password (once). */
export const revealAppPassword = (client, id) => http.post(client, '/vps/apps/deployments/{id}/reveal-password', { params: { id } });
/** GET /vps/instances/{id} — Get a server. */
export const getInstance = (client, id) => http.get(client, '/vps/instances/{id}', { params: { id } });
/** DELETE /vps/instances/{id} — Destroy a server (202; billing stops). */
export const destroyInstance = (client, id) => http.del(client, '/vps/instances/{id}', { params: { id } });
/** GET /vps/instances/{id}/metrics — Server usage metrics. */
export const getMetrics = (client, id, query) => http.get(client, '/vps/instances/{id}/metrics', { params: { id }, query });
/** POST /vps/instances/{id}/queue-notify — Toggle the queued-create outcome email. */
export const setQueueNotify = (client, id, body) => http.post(client, '/vps/instances/{id}/queue-notify', { params: { id }, body });
/** POST /vps/instances/{id}/images — Snapshot a server (202). */
export const createSnapshot = (client, id, body) => http.post(client, '/vps/instances/{id}/images', { params: { id }, body });
/** POST /vps/instances/{id}/restart — Restart a server (graceful, 202). */
export const restart = (client, id) => http.post(client, '/vps/instances/{id}/restart', { params: { id } });
/** POST /vps/instances/{id}/reset — Force reset a server (hard, 202). */
export const reset = (client, id) => http.post(client, '/vps/instances/{id}/reset', { params: { id } });
/** POST /vps/instances/{id}/shutdown — Shut down a server (graceful, 202). */
export const shutdown = (client, id) => http.post(client, '/vps/instances/{id}/shutdown', { params: { id } });
/** POST /vps/instances/{id}/power-off — Force power off a server (hard, 202). */
export const powerOff = (client, id) => http.post(client, '/vps/instances/{id}/power-off', { params: { id } });
/** POST /vps/instances/{id}/power-on — Power on a stopped server (202). */
export const powerOn = (client, id) => http.post(client, '/vps/instances/{id}/power-on', { params: { id } });
/** PUT /vps/instances/{id}/rdns — Set a server's reverse DNS (PTR, 202). */
export const setRdns = (client, id, body) => http.put(client, '/vps/instances/{id}/rdns', { params: { id }, body });
/** GET /vps/instances/{id}/domains — List a server's connected domains. */
export const listInstanceDomains = (client, id) => http.get(client, '/vps/instances/{id}/domains', { params: { id } });
/** POST /vps/instances/{id}/domains — Connect a domain to a server (202). Gated on `zone`. */
export const connectDomain = async (client, id, body) => {
await checkGate(client, 'POST /vps/instances/{id}/domains', { domain: body.zone });
return http.post(client, '/vps/instances/{id}/domains', { params: { id }, body });
};
/**
* DELETE /vps/instances/{id}/domains/{connection-id} — Disconnect a domain
* from a server. Gated on the connection's zone (resolved via
* `listInstanceDomains` when a gate is set).
*/
export const disconnectDomain = async (client, id, connectionId) => {
if (client.gate) {
const { connections } = await listInstanceDomains(client, id);
const zone = connections?.find((c) => String(c.id) === connectionId)?.zone_origin;
await checkGate(client, 'DELETE /vps/instances/{id}/domains/{connection-id}', { domain: zone });
}
return http.del(client, '/vps/instances/{id}/domains/{connection-id}', {
params: { id, 'connection-id': connectionId },
});
};
/** GET /vps/volumes — List your volumes. */
export const listVolumes = (client) => http.get(client, '/vps/volumes');
/** POST /vps/volumes — Create a volume (202, hourly billing starts). */
export const createVolume = (client, body) => http.post(client, '/vps/volumes', { body });
/** DELETE /vps/volumes/{id} — Delete a volume (202; billing stops). */
export const deleteVolume = (client, id) => http.del(client, '/vps/volumes/{id}', { params: { id } });
/** GET /vps/images — List your snapshots. */
export const listImages = (client) => http.get(client, '/vps/images');
/** DELETE /vps/images/{id} — Delete a snapshot (202). */
export const deleteImage = (client, id) => http.del(client, '/vps/images/{id}', { params: { id } });
/** GET /vps/actions/{id} — Poll a VPS action. */
export const getAction = (client, id) => http.get(client, '/vps/actions/{id}', { params: { id } });
/** GET /vps/activity — Infrastructure activity timeline. */
export const listActivity = (client, query) => http.get(client, '/vps/activity', { query });