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.
94 lines • 3.67 kB
JavaScript
import { gateSecret } from "../secret-gate.js";
import { LocalError } from "../errors.js";
export class Branches {
client;
constructor(client) {
this.client = client;
}
async create(projectId, opts = {}) {
gateSecret(this.client, "branches.create", projectId, opts);
assertProjectId(projectId, "creating project branch");
const body = {};
if (opts.fromSnapshotId !== undefined)
body.from_snapshot_id = opts.fromSnapshotId;
if (opts.name !== undefined)
body.name = opts.name;
if (opts.emailMode !== undefined)
body.email_mode = opts.emailMode;
if (opts.enableCron !== undefined)
body.enable_cron = opts.enableCron;
if (opts.ttlDays !== undefined)
body.ttl_days = opts.ttlDays;
const result = await this.client.request(branchCollectionPath(projectId), {
method: "POST",
body,
authMeta: {
method: "branches.create",
capability: "project.branches.manage",
target: { project_id: projectId },
},
context: "creating project branch",
});
if (this.client.credentials.saveProject) {
await this.client.credentials.saveProject(result.branch_project_id, {
anon_key: result.anon_key,
service_key: result.service_key,
...(result.branch_url ? { site_url: result.branch_url } : {}),
});
}
return result;
}
async list(projectId) {
assertProjectId(projectId, "listing project branches");
return this.client.request(branchCollectionPath(projectId), {
authMeta: {
method: "branches.list",
capability: "project.branches.manage",
target: { project_id: projectId },
},
context: "listing project branches",
});
}
async renew(projectId, branchProjectId, opts = {}) {
assertProjectId(projectId, "renewing project branch");
assertProjectId(branchProjectId, "renewing project branch");
const body = {};
if (opts.ttlDays !== undefined)
body.ttl_days = opts.ttlDays;
return this.client.request(`${branchPath(projectId, branchProjectId)}/renew`, {
method: "POST",
body,
authMeta: {
method: "branches.renew",
capability: "project.branches.manage",
target: { project_id: projectId },
},
context: "renewing project branch",
});
}
async delete(projectId, branchProjectId) {
assertProjectId(projectId, "deleting project branch");
assertProjectId(branchProjectId, "deleting project branch");
await this.client.request(branchPath(projectId, branchProjectId), {
method: "DELETE",
authMeta: {
method: "branches.delete",
capability: "project.branches.manage",
target: { project_id: projectId },
},
context: "deleting project branch",
});
}
}
function branchCollectionPath(projectId) {
return `/projects/v1/${encodeURIComponent(projectId)}/branches`;
}
function branchPath(projectId, branchProjectId) {
return `${branchCollectionPath(projectId)}/${encodeURIComponent(branchProjectId)}`;
}
function assertProjectId(value, context) {
if (!value || typeof value !== "string") {
throw new LocalError("branches helper requires a projectId", context);
}
}
//# sourceMappingURL=branches.js.map