Skip to content

improvement(api): consolidate public v2 route handling - #6370

Merged
TheodoreSpeaks merged 1 commit into
improvement/v2-platformsfrom
improvement/v2-route-handler-consolidation
Aug 7, 2026
Merged

improvement(api): consolidate public v2 route handling#6370
TheodoreSpeaks merged 1 commit into
improvement/v2-platformsfrom
improvement/v2-route-handler-consolidation

Conversation

@TheodoreSpeaks

@TheodoreSpeaks TheodoreSpeaks commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add an API-key-only route wrapper that centralizes rate limiting, v2 rollout gating, authentication, contract parsing, and canonical v2 rendering of unhandled 500s
  • migrate all standard v2 handlers, including the latest workspace metadata/member endpoints, while preserving endpoint-specific authorization and response behavior
  • remove duplicated route-local error logging/fallback responses so unexpected errors bubble to one shared logger and response mapper
  • leave hybrid workflow execution and signed-upload data-plane handlers on their specialized auth paths
  • fail fast on invalid authenticated state and keep API validation aware of the shared wrapper

Type of Change

  • Improvement

Testing

  • bun run lint
  • bun run --cwd apps/sim type-check
  • bun run check:api-validation:strict
  • bun run check:openapi
  • wrapper, middleware, and workspace Vitest coverage: 28/28
  • complete v2 Vitest suite: 522/525; the three failures are inherited target-branch expectation/schema mismatches in workflow-folder recursive delete and table query

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing for this change
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Aug 7, 2026 6:41am

Request Review

@cursor

cursor Bot commented Aug 7, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Wide refactor of the public API request pipeline (auth, rate limits, parsing order) across many v2 endpoints; behavior is intended to be equivalent but any ordering or envelope regression would affect all migrated routes.

Overview
Introduces withPublicApiRouteHandler, a shared wrapper for API-key v2 routes that runs rate limiting → v2 rollout gate → contract parsing before the route handler, and maps unexpected failures to the canonical v2 500 envelope via withRouteHandler. Auth and rate-limit denials (401/429) and the rollout gate run before the request body is read or parsed.

requireRateLimitUserId replaces unsafe userId! usage when building AuthorizedRequest after an allowed rate-limit result.

Dozens of v2 route modules (audit logs, billing, credentials, custom tools, files, knowledge, logs, MCP servers, etc.) are refactored to register only their contract, rate-limit endpoint, optional parseOptions, and business logic—removing per-route duplicate logging and try/catch. Endpoint-specific authorization (workspace access, personal-key rules, orchestration errors) stays in handlers; some routes now rethrow after mapping known errors so the wrapper handles logging.

Adds public-api-route-handler.test.ts covering short-circuit ordering, body-size options, and error envelopes.

Reviewed by Cursor Bugbot for commit 79177e9. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR consolidates standard public v2 route handling without leaving an eligible follow-up defect.

  • Adds a shared API-key route wrapper for rate limiting, rollout gating, authentication, contract parsing, request context, and canonical unhandled-error responses.
  • Migrates standard v2 endpoints while retaining endpoint-specific authorization and known-error mapping.
  • Updates validation tooling and tests to recognize and exercise wrapper-based routes.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/api/public-api-route-handler.ts Introduces the shared API-key route lifecycle while preserving canonical v2 validation and unhandled-error responses.
apps/sim/lib/core/utils/with-route-handler.ts Extends shared route handling to consistently apply request context, response headers, logging, and configurable unhandled-error rendering.
apps/sim/app/api/v1/middleware.ts Replaces the authenticated user-ID assertion with an explicit invariant check.
apps/sim/lib/api/server/validation.ts Adds customizable oversized-payload handling used by migrated public v2 routes.
scripts/check-api-validation-contracts.ts Recognizes shared-wrapper routes as contract-validated during strict API validation checks.

Sequence Diagram

sequenceDiagram
  participant Client
  participant Wrapper as withPublicApiRouteHandler
  participant RateLimit as API-key / rate limit
  participant Gate as v2 rollout gate
  participant Parser as Contract parser
  participant Route as Endpoint handler
  Client->>Wrapper: v2 request
  Wrapper->>RateLimit: authenticate and check limit
  RateLimit-->>Wrapper: user and rate-limit context
  Wrapper->>Gate: verify v2 access
  Gate-->>Wrapper: allowed
  Wrapper->>Parser: parse params, query, headers, and body
  Parser-->>Wrapper: typed input
  Wrapper->>Route: input and auth context
  Route-->>Wrapper: endpoint response
  Wrapper-->>Client: response with request/rate-limit headers
Loading

Reviews (4): Last reviewed commit: "improvement(api): consolidate public v2 ..." | Re-trigger Greptile

@TheodoreSpeaks
TheodoreSpeaks force-pushed the improvement/v2-route-handler-consolidation branch from ebdbeb0 to 6ba7fd8 Compare August 7, 2026 05:58
@TheodoreSpeaks
TheodoreSpeaks requested a review from a team as a code owner August 7, 2026 05:58
@TheodoreSpeaks
TheodoreSpeaks changed the base branch from staging to improvement/v2-endpoints August 7, 2026 05:58
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks
TheodoreSpeaks force-pushed the improvement/v2-route-handler-consolidation branch from 6ba7fd8 to 445ac76 Compare August 7, 2026 06:03
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6ba7fd8. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 445ac76. Configure here.

@TheodoreSpeaks
TheodoreSpeaks force-pushed the improvement/v2-route-handler-consolidation branch from 445ac76 to 79177e9 Compare August 7, 2026 06:36
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks
TheodoreSpeaks changed the base branch from improvement/v2-endpoints to improvement/v2-platforms August 7, 2026 06:42
@TheodoreSpeaks
TheodoreSpeaks merged commit 804fcc4 into improvement/v2-platforms Aug 7, 2026
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.

1 participant