import { HttpError } from "../errors";
import { handleScratchApi } from "../sites/scratch";
import { getSiteUsage } from "../sites/usage";
import { createEditorSession } from "./editor";
import { apiContext } from "./http";
import type { ApiContext } from "./http";
import { createPull, getPull, listPulls, mergePull, updatePullBranch } from "./pulls";
import { getPullAiFix, startPullAiFix } from "./mergefix";
import {
createRepo,
deleteRepo,
forkRepo,
getCollaborator,
getRepo,
importRepo,
listRepos,
putCollaborator,
updateRepo,
} from "./repos";
import {
approveRunApi,
cancelRunApi,
createRegistrationToken,
deleteRunnerApi,
listRunnersApi,
listRunsApi,
putRunnerPolicy,
} from "./runners";
import { createProtection, listProtections, putContents, setPushProtection } from "./settings";
import { getLfsUsage, getUser, listTokens, revokeToken } from "./user";
export const API_V1_PREFIX = "/api/v1/";
/** Anonymous scratch deploys; listed as token-only in `src/server.ts` because it never reads cookies. */
export const SCRATCH_API_PATH = "/scratch";
type Handler = (ctx: ApiContext, params: string[]) => Response | Promise<Response>;
type Route = { method: string; pattern: RegExp; handler: Handler };
const SEG = "([^/]+)";
const REPO = `/repos/${SEG}/${SEG}`;