export.ts26 lines · main
| 1 | import { Hono } from 'hono'; |
| 2 | |
| 3 | import { projectRateLimit } from '../middleware/rate-limit.js'; |
| 4 | import { requireProjectAuth, requireProjectRole } from '../middleware/project-auth.js'; |
| 5 | import { buildProjectExport } from '../services/export-import.js'; |
| 6 | import type { ProjectAppEnv as AppEnv } from '../types/app-env.js'; |
| 7 | |
| 8 | /** |
| 9 | * Project export — returns the schema + functions of the project's |
| 10 | * current deployment as a single JSON document. Admin-tier (the export |
| 11 | * includes function source code, which can contain inline secrets if the |
| 12 | * project author hasn't been disciplined). Rate-limited under `mutate`. |
| 13 | */ |
| 14 | export const exportRouter = new Hono<AppEnv>(); |
| 15 | |
| 16 | exportRouter.use('/v1/projects/:id/export', requireProjectAuth()); |
| 17 | |
| 18 | exportRouter.get( |
| 19 | '/v1/projects/:id/export', |
| 20 | projectRateLimit('mutate'), |
| 21 | requireProjectRole('admin'), |
| 22 | async (c) => { |
| 23 | const out = await buildProjectExport(c.req.param('id')); |
| 24 | return c.json(out); |
| 25 | }, |
| 26 | ); |