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.
69 lines • 3.08 kB
JavaScript
/**
* `subdomains` namespace — `*.run402.com` subdomain claims pointing at
* deployments or releases (defaulting to the project's live release).
* `add` and `delete` accept an optional `projectId` for ownership
* tracking; `list` requires one.
*/
import { LocalError } from "../errors.js";
import { requireProjectCredentials } from "../project-credentials.js";
export class Subdomains {
client;
constructor(client) {
this.client = client;
}
async #resolveProjectId(opts, context) {
if (opts.projectId)
return opts.projectId;
const getActive = this.client.credentials.getActiveProject;
if (typeof getActive === "function") {
const active = await getActive.call(this.client.credentials);
if (active)
return active;
}
throw new LocalError("Subdomains operation requires opts.projectId or an active project (set with `r.projects.use(id)` or pass it explicitly).", context);
}
/**
* Claim a subdomain and point it at a deployment or release. Omit both
* `deploymentId` and `releaseId` to bind the project's live release —
* the gateway resolves it, and answers 404 only when the project has no
* live release with a site.
*/
async add(input) {
const name = input.name;
const options = { projectId: input.projectId };
const projectId = await this.#resolveProjectId(options, "adding subdomain");
const project = await requireProjectCredentials(this.client, projectId, "adding subdomain");
return this.client.request("/subdomains/v1", {
method: "POST",
headers: { Authorization: `Bearer ${project.service_key}` },
body: {
name,
...(input.deploymentId ? { deployment_id: input.deploymentId } : {}),
...(input.releaseId ? { release_id: input.releaseId } : {}),
},
context: "adding subdomain",
});
}
/** Release a subdomain. */
async delete(name, opts = {}) {
const projectId = await this.#resolveProjectId(opts, "deleting subdomain");
const project = await requireProjectCredentials(this.client, projectId, "deleting subdomain");
return this.client.request(`/subdomains/v1/${encodeURIComponent(name)}`, {
method: "DELETE",
headers: { Authorization: `Bearer ${project.service_key}` },
context: "deleting subdomain",
});
}
/** List a project's subdomains. */
async list(projectId) {
const project = await requireProjectCredentials(this.client, projectId, "listing subdomains");
// Gateway responds `{ subdomains: [...] }`; unwrap so callers get the
// array shape the type promises.
const body = await this.client.request("/subdomains/v1", {
headers: { Authorization: `Bearer ${project.service_key}` },
context: "listing subdomains",
});
return body.subdomains ?? [];
}
}
//# sourceMappingURL=subdomains.js.map