Description
The application entrypoint src/index.ts does not compile cleanly: { metricsHandler, metricsMiddleware } is imported four times (lines 9, 12, 14, 17), and the file references NextFunction, ErrorRequestHandler, WebhookDeliveryService, and webhookRepository without importing any of them. In addition, the rejectOversizedJsonPayload and httpBodyErrorHandler guards are defined in the file but never registered on the Express app, and metricsMiddleware/metricsHandler are imported but never used. This issue makes src/index.ts a clean, buildable bootstrap.
Requirements and context
- Collapse the four duplicate
./metrics/prometheus imports into a single import.
- Add the missing type imports
NextFunction and ErrorRequestHandler from express.
- Import
WebhookDeliveryService from ./services/webhookDeliveryService and webhookRepository from ./repositories/webhookRepository (both already exported in the repo).
- Register
metricsMiddleware early in the middleware chain and expose metricsHandler at GET /metrics.
- Wire
rejectOversizedJsonPayload before express.json() and register httpBodyErrorHandler as an error handler after the routes so the existing 413/400 responses actually fire.
- Non-functional:
npm run build must succeed with no TypeScript errors; no behavior change to the existing /health, /api/openapi.json, and /api/v1/streams routes.
Acceptance criteria
Suggested execution
1. Fork the repo and create a branch — git checkout -b feature/fix-index-bootstrap.
2. Implement changes — edit src/index.ts: dedupe imports, add the missing imports, register the metrics middleware/route and the body-size guard + error handler.
3. Write/extend tests — this repo uses Jest + Supertest. Add src/__tests__/index.bootstrap.test.ts that imports app and uses Supertest to assert GET /metrics is 200 and that an oversized JSON POST returns 413, alongside the existing src/httpLimits.test.ts patterns.
4. Test and commit —
npm run lint -- --max-warnings 0
npm run build
npm test
Example commit message
fix(server): dedupe metric imports and wire body-size guards in index.ts
Guidelines
Keep coverage for any new module at the repo standard (95% per jest.config.js). Update README.md if you add the GET /metrics route to the documented surface. Do not change unrelated middleware ordering. Timeframe: 96 hours.
Description
The application entrypoint
src/index.tsdoes not compile cleanly:{ metricsHandler, metricsMiddleware }is imported four times (lines 9, 12, 14, 17), and the file referencesNextFunction,ErrorRequestHandler,WebhookDeliveryService, andwebhookRepositorywithout importing any of them. In addition, therejectOversizedJsonPayloadandhttpBodyErrorHandlerguards are defined in the file but never registered on the Express app, andmetricsMiddleware/metricsHandlerare imported but never used. This issue makessrc/index.tsa clean, buildable bootstrap.Requirements and context
./metrics/prometheusimports into a single import.NextFunctionandErrorRequestHandlerfromexpress.WebhookDeliveryServicefrom./services/webhookDeliveryServiceandwebhookRepositoryfrom./repositories/webhookRepository(both already exported in the repo).metricsMiddlewareearly in the middleware chain and exposemetricsHandleratGET /metrics.rejectOversizedJsonPayloadbeforeexpress.json()and registerhttpBodyErrorHandleras an error handler after the routes so the existing 413/400 responses actually fire.npm run buildmust succeed with no TypeScript errors; no behavior change to the existing/health,/api/openapi.json, and/api/v1/streamsroutes.Acceptance criteria
./metrics/prometheusis imported exactly once and both exports are referenced.NextFunction,ErrorRequestHandler,WebhookDeliveryService, andwebhookRepositoryare imported and resolve.metricsMiddlewareis applied andGET /metricsreturns Prometheus text viametricsHandler.rejectOversizedJsonPayloadandhttpBodyErrorHandlerare registered and an oversized JSON body returns HTTP 413.npm run buildexits 0 with no duplicate-import or unresolved-symbol errors.Suggested execution
1. Fork the repo and create a branch —
git checkout -b feature/fix-index-bootstrap.2. Implement changes — edit
src/index.ts: dedupe imports, add the missing imports, register the metrics middleware/route and the body-size guard + error handler.3. Write/extend tests — this repo uses Jest + Supertest. Add
src/__tests__/index.bootstrap.test.tsthat importsappand uses Supertest to assertGET /metricsis 200 and that an oversized JSON POST returns 413, alongside the existingsrc/httpLimits.test.tspatterns.4. Test and commit —
npm run lint -- --max-warnings 0 npm run build npm testExample commit message
Guidelines
Keep coverage for any new module at the repo standard (95% per
jest.config.js). UpdateREADME.mdif you add theGET /metricsroute to the documented surface. Do not change unrelated middleware ordering. Timeframe: 96 hours.