globalThis.process ??= {};
globalThis.process.env ??= {};
import { E as logAudit } from "./db_DZJ1iBSP.mjs";
//#region src/lib/audit.ts
/**
* Best-effort audit write for the mod-cms admin routes. `logAudit` NEVER throws and is
* DECOUPLED — call this AFTER the mutation has committed; a failed audit write must not
* fail or roll back the mutation. mod-cms is single-tenant → `tenantId` is always null.
*/
async function recordAudit(db, ctx, event) {
	const result = await logAudit(db, {
		actorId: ctx.actorId,
		actorType: "admin",
		actorLabel: null,
		action: event.action,
		entityType: event.entityType,
		entityId: event.entityId,
		metadata: event.metadata ?? null,
		ip: ctx.ip,
		tenantId: null
	});
	if (!result.logged) console.warn("mod-cms audit write failed", {
		action: event.action,
		error: result.error
	});
}
/** Extract the client IP from the Astro/CF request, or null. */
function clientIp(request) {
	return request.headers.get("cf-connecting-ip") ?? null;
}
//#endregion
export { recordAudit as n, clientIp as t };
