apps/gateway/src/routes/import-export.ts
Metadata
- Purpose: Gateway HTTP route handlers and request/response behavior.
- Domain:
applications - Language:
ts - Bytes: 4791
- Lines: 139
- Content hash (short):
e8548942 - Source (start): apps/gateway/src/routes/import-export.ts:1
- Source (end): apps/gateway/src/routes/import-export.ts:139
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 { getIdempotencyKey, getIdempotencyRouteScope } from "../utils/idempotency.js";
import { getWorkspaceIdFromHeaders } from "../utils/workspace.js";
import { ensureRoles } from "../utils/authorization.js";
import { createBackgroundJob, listBackgroundJobs } from "../services/job-repository.js";
export const importExportRoutes: FastifyPluginAsync = async (app) => {
app.get<{ Querystring: { limit?: string } }>("/api/v1/jobs", async (request, reply) => {
if (!ensureRoles(request, reply, ["msp_admin", "data_admin", "ops_engineer", "viewer"])) {
return { error: "Insufficient role for background job 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 limitRaw = Number(request.query?.limit ?? 100);
const limit = Number.isFinite(limitRaw) && limitRaw > 0 ? Math.min(Math.floor(limitRaw), 500) : 100;
const data = await listBackgroundJobs(workspaceId, limit);
return {