Skip to content

feat: add routes-f response version wrapper#359

Merged
davedumto merged 1 commit intoStreamFi-x:devfrom
0xVida:dev
Feb 26, 2026
Merged

feat: add routes-f response version wrapper#359
davedumto merged 1 commit intoStreamFi-x:devfrom
0xVida:dev

Conversation

@0xVida
Copy link
Contributor

@0xVida 0xVida commented Feb 26, 2026

Description

Closes #308

Changes proposed

What were you told to do?

Add a Routes-F versioned API response wrapper: single source for API version, include apiVersion in all routes-f JSON responses, keep backward compatibility, and cover response shape in tests.

What did you do?

  • Version module (lib/routes-f/version.ts):

    • Added ROUTES_F_API_VERSION constant (e.g. "1").
    • Added wrapRoutesFJson(data) to add apiVersion to any payload (spread + overwrite so version is always set).
    • Added jsonResponse(data, init) that returns NextResponse.json(wrapRoutesFJson(data), init) for handlers.
  • Handlers and shared helpers:

    • Updated all routes-f route handlers to use jsonResponse() or wrapRoutesFJson() for every JSON response (health, flags, search, items, items/[id], export, validate, deps, account, feedback, register, metrics, maintenance, audit, activity/daily, preferences, webhook, uploads/sign, mock/generate, preview, import, jobs, jobs/[id]).
    • Updated app/api/routes-f/_lib/errors.ts and _lib/schema.ts so error responses are wrapped with wrapRoutesFJson().
    • For search: wrapped 429 body and the main response body with wrapRoutesFJson() (including cached JSON).
    • For export: JSON format now returns { apiVersion, data: records } instead of a raw array; CSV unchanged.
    • Webhook: secret is read at request time via getWebhookSecret() so tests that set env in beforeAll work.
  • Tests:

    • Added lib/routes-f/__tests__/version.test.ts (constant, wrapRoutesFJson behaviour, jsonResponse shape).
    • Added “Routes-F response version” block in app/api/routes-f/__tests__/routes-f.test.ts asserting apiVersion === "1" on health, validate (success/error), and preferences.
    • Extended export test to assert apiVersion and data array on JSON response.
    • Adjusted NextResponse mocks in jobs/__tests__/route.test.ts, items-create.test.ts, and items-get-by-id.test.ts so response headers (e.g. Location, ETag) are preserved.
  • Backward compatibility: Response shape is { apiVersion, ...existingKeys }; existing clients can ignore apiVersion. Export JSON clients should use response.data for the records array.

Check List (Check all the applicable boxes)

🚨Please review the contribution guideline for this repository.

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description of the PR is clear and explains the approach.
  • I am making a pull request against the main branch (left side).
  • My commit messages styles matches our requested structure.
  • My code additions will fail neither code linting checks nor unit test.
  • I am only making changes to files I was requested to.

Screenshots/Videos

N/A — API-only change. Example response shape after change:

GET /api/routes-f/health
{
  "apiVersion": "1",
  "status": "ok",
  "version": "...",
  "timestamp": "..."
}

@vercel
Copy link

vercel bot commented Feb 26, 2026

@0xVida is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

@davedumto davedumto merged commit 717455e into StreamFi-x:dev Feb 26, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend: Add routes-f response version wrapper

2 participants