Skip to main content

apps/gateway/src/routes/events.ts

Metadata

Indexed Symbols

No indexed functions/methods detected in this file.

Markdown Headings (if applicable)

No markdown headings detected.

Source Preview

import type { FastifyPluginAsync } from "fastify";
import { telemetryIngestRequestSchema } from "@anchor/contracts";
import { routeTelemetryEvent } from "../services/event-router.js";
import { listRecentOutboxEvents, listRecentTelemetryBatches, persistTelemetryBatch } from "../services/event-pipeline.js";
import { getIdempotencyKey, getIdempotencyRouteScope } from "../utils/idempotency.js";
import { getWorkspaceIdFromHeaders } from "../utils/workspace.js";
import { ensureUuid } from "../utils/uuid.js";
import { ensureRoles } from "../utils/authorization.js";

export const eventRoutes: FastifyPluginAsync = async (app) => {
app.get("/api/v1/events/outbox", async (request, reply) => {
if (!ensureRoles(request, reply, ["msp_admin", "ops_engineer", "viewer"])) {
return { error: "Insufficient role for outbox event visibility" };
}

let workspaceId: string;
try {
workspaceId = getWorkspaceIdFromHeaders(request.headers as Record<string, unknown>);
} catch (error) {
reply.code(400);
return { error: error instanceof Error ? error.message : "Invalid workspace header" };
}

try {
const items = await listRecentOutboxEvents(workspaceId);