import "../../../../../base64-CmWvODNW.mjs";
import "../../../../../types-CuW0zWDA.mjs";
import { a as unwrapResult, r as handleError, t as apiError } from "../../../../../error-CkAseSqZ.mjs";
import "../../../../../api-tokens-DsvvCtdh.mjs";
import { i as handleApiTokenRevoke } from "../../../../../api-tokens-DvqeZmVq.mjs";
import { Role } from "@emdash-cms/auth";

//#region src/astro/routes/api/admin/api-tokens/[id].ts
/**
* Single API token endpoint
*
* DELETE /_emdash/api/admin/api-tokens/:id — Revoke a token
*/
const prerender = false;
/**
* Revoke (delete) an API token.
*/
const DELETE = async ({ params, locals }) => {
	const { emdash, user } = locals;
	if (!emdash?.db) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500);
	if (!user || user.role < Role.ADMIN) return apiError("FORBIDDEN", "Admin privileges required", 403);
	const tokenId = params.id;
	if (!tokenId) return apiError("VALIDATION_ERROR", "Token ID is required", 400);
	try {
		return unwrapResult(await handleApiTokenRevoke(emdash.db, tokenId, user.id));
	} catch (error) {
		return handleError(error, "Failed to revoke API token", "TOKEN_REVOKE_ERROR");
	}
};

//#endregion
export { DELETE, prerender };
//# sourceMappingURL=_id_.mjs.map