UNPKG

run402-mcp

Version:

MCP server for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.

115 lines • 4.63 kB
import { LocalError } from "../errors.js"; export class Snapshots { client; constructor(client) { this.client = client; } async create(projectId) { assertProjectId(projectId, "creating project snapshot"); return this.client.request(snapshotCollectionPath(projectId), { method: "POST", body: {}, authMeta: { method: "snapshots.create", capability: "project.snapshots.manage", target: { project_id: projectId }, }, context: "creating project snapshot", }); } async list(projectId, opts = {}) { assertProjectId(projectId, "listing project snapshots"); const qs = new URLSearchParams(); if (opts.limit !== undefined) qs.set("limit", String(opts.limit)); if (opts.after !== undefined) qs.set("after", opts.after); if (opts.kind !== undefined) qs.set("kind", opts.kind); const query = qs.toString(); return this.client.request(`${snapshotCollectionPath(projectId)}${query ? `?${query}` : ""}`, { authMeta: { method: "snapshots.list", capability: "project.snapshots.manage", target: { project_id: projectId }, }, context: "listing project snapshots", }); } async get(projectId, snapshotId) { assertProjectId(projectId, "getting project snapshot"); assertSnapshotId(snapshotId, "getting project snapshot"); return this.client.request(snapshotPath(projectId, snapshotId), { authMeta: { method: "snapshots.get", capability: "project.snapshots.manage", target: { project_id: projectId }, }, context: "getting project snapshot", }); } async delete(projectId, snapshotId) { assertProjectId(projectId, "deleting project snapshot"); assertSnapshotId(snapshotId, "deleting project snapshot"); await this.client.request(snapshotPath(projectId, snapshotId), { method: "DELETE", authMeta: { method: "snapshots.delete", capability: "project.snapshots.manage", target: { project_id: projectId }, }, context: "deleting project snapshot", }); } async restorePlan(projectId, snapshotId, opts = {}) { assertProjectId(projectId, "planning project snapshot restore"); assertSnapshotId(snapshotId, "planning project snapshot restore"); return this.client.request(`${snapshotPath(projectId, snapshotId)}/restore`, { method: "POST", body: restoreBody(opts), authMeta: { method: "snapshots.restorePlan", capability: "project.snapshots.manage", target: { project_id: projectId }, }, context: "planning project snapshot restore", }); } async restore(projectId, snapshotId, confirm, opts = {}) { assertProjectId(projectId, "restoring project snapshot"); assertSnapshotId(snapshotId, "restoring project snapshot"); if (!confirm || typeof confirm !== "string") { throw new LocalError("snapshots.restore requires a confirm token from snapshots.restorePlan", "restoring project snapshot"); } return this.client.request(`${snapshotPath(projectId, snapshotId)}/restore`, { method: "POST", body: { ...restoreBody(opts), confirm }, authMeta: { method: "snapshots.restore", capability: "project.snapshots.manage", target: { project_id: projectId }, }, context: "restoring project snapshot", }); } } function snapshotCollectionPath(projectId) { return `/projects/v1/${encodeURIComponent(projectId)}/snapshots`; } function snapshotPath(projectId, snapshotId) { return `${snapshotCollectionPath(projectId)}/${encodeURIComponent(snapshotId)}`; } function restoreBody(opts) { return opts.includeAuth ? { include: ["auth"] } : {}; } function assertProjectId(value, context) { if (!value || typeof value !== "string") { throw new LocalError("snapshots helper requires a projectId", context); } } function assertSnapshotId(value, context) { if (!value || typeof value !== "string") { throw new LocalError("snapshots helper requires a snapshotId", context); } } //# sourceMappingURL=snapshots.js.map