Skip to content

Conversation

@riderx
Copy link
Member

@riderx riderx commented Jan 19, 2026

Summary (AI generated)

Standardized HTTP response format across all API endpoints in private/ and public/ directories. Replaced inconsistent patterns (c.body(null, 204), custom status messages, {success: true}) with uniform BRES ({ status: 'ok' }) for success without data.

Motivation (AI generated)

Inconsistent response formats make the API harder to maintain and consume. This change ensures all endpoints follow the documented convention for consistency and predictability.

Business Impact (AI generated)

Improves developer experience by providing predictable API responses. No functional changes to business logic or user-facing features.

Test Plan (AI generated)

  • All tests pass: 78 tests verified in apikeys.test.ts, organization-api.test.ts, and bundle.test.ts
  • Response format verified across 11 modified endpoints
  • All modified tests updated to match new response format

Generated with AI

Summary by CodeRabbit

  • Documentation

    • Added HTTP Response Conventions to standardize JSON response patterns (success with data, success without data, and error formats)
  • Refactor

    • Standardized success responses across API endpoints to unified JSON payloads (replacing varied messages/204 responses)
    • Shifted toward id/data-centric responses and lowercase 'ok' where applicable
  • Tests

    • Updated tests to validate the new standardized response shapes and values

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 19, 2026 20:56
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Standardized API response shapes: endpoints now return JSON via c.json(...) using either returned data or a centralized BRES object; docs updated with "HTTP Response Conventions"; tests adjusted to match new shapes and lowercase status conventions.

Changes

Cohort / File(s) Summary
Documentation
AGENTS.md
Added "HTTP Response Conventions" describing: success-with-data c.json(data), success-without-data c.json(BRES) (import from utils/hono.ts), use simpleError()/quickError() for errors, and prohibition of c.body(null, 204).
Private endpoints
supabase/functions/_backend/private/create_device.ts, supabase/functions/_backend/private/delete_failed_version.ts, supabase/functions/_backend/private/invite_new_user_to_org.ts, supabase/functions/_backend/private/set_org_email.ts
Added BRES import and replaced 204 or custom success objects with return c.json(BRES); no other logic changes.
Public endpoints — standard responses
supabase/functions/_backend/public/apikey/delete.ts, supabase/functions/_backend/public/bundle/update_metadata.ts, supabase/functions/_backend/public/organization/members/delete.ts, supabase/functions/_backend/public/organization/members/post.ts
Replaced ad-hoc success payloads ({ success: true }, { status: 'success' }, { status: 'OK' }) with c.json(BRES) and added BRES imports.
Public endpoints — organization flow
supabase/functions/_backend/public/organization/delete.ts, supabase/functions/_backend/public/organization/post.ts, supabase/functions/_backend/public/organization/put.ts
delete.ts now returns BRES; post.ts and put.ts removed verbose status fields and return id/data-focused payloads (e.g., { id, data }); small variable rename in put.ts (data_data).
Tests
tests/apikeys.test.ts, tests/bundle.test.ts, tests/organization-api.test.ts
Updated assertions to expect status: 'ok' where applicable and to validate new id/data-centric response shapes; multiple assertion updates in organization-api.test.ts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code with a tidy request,
Swapped scattered statuses for one little chest.
BRES now hums "ok" in JSON so bright,
Tests and docs follow in morning light.
A tiny rabbit clap — consistent and light! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: standardizing HTTP response formats across API endpoints, which is clearly reflected in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes HTTP response formats across API endpoints by replacing inconsistent success response patterns (c.body(null, 204), custom status messages, {success: true}) with a uniform BRES constant ({ status: 'ok' }) for endpoints that return success without meaningful data. The changes also update documentation to establish this as a convention.

Changes:

  • Introduced BRES constant for standardized success responses without data
  • Updated 6 private endpoints and 5 public endpoints to use consistent response patterns
  • Updated all corresponding test expectations to match new response format
  • Added HTTP response convention documentation to AGENTS.md

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
AGENTS.md Added HTTP response conventions section documenting BRES usage pattern
supabase/functions/_backend/private/set_org_email.ts Replaced c.body(null, 204) with c.json(BRES)
supabase/functions/_backend/private/invite_new_user_to_org.ts Replaced custom status message with BRES
supabase/functions/_backend/private/delete_failed_version.ts Replaced custom status message with BRES
supabase/functions/_backend/private/create_device.ts Replaced c.body(null, 204) with c.json(BRES)
supabase/functions/_backend/public/organization/put.ts Removed status message from data response (not BRES since it returns data)
supabase/functions/_backend/public/organization/post.ts Removed status message from data response (not BRES since it returns data)
supabase/functions/_backend/public/organization/members/post.ts Replaced custom status return with BRES
supabase/functions/_backend/public/organization/members/delete.ts Replaced 'OK' status with BRES
supabase/functions/_backend/public/organization/delete.ts Replaced custom status message with BRES
supabase/functions/_backend/public/bundle/update_metadata.ts Replaced 'success' status with BRES
supabase/functions/_backend/public/apikey/delete.ts Replaced {success: true} with BRES
tests/organization-api.test.ts Updated test expectations to match new response format ('ok' instead of 'OK', removed status field checks for data responses)
tests/bundle.test.ts Updated test expectation from 'success' to 'ok'
tests/apikeys.test.ts Updated test expectation from {success: true} to {status: 'ok'}

throw simpleError('cannot_update_org', 'Cannot update org', { error: errorOrg.message })
}
return c.json({ status: 'Organization updated', id: data.id, data: dataOrg }, 200)
return c.json({ id: data.id, data: dataOrg })
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The response returns the user ID instead of the organization ID. The variable data at line 45 contains user information, so data.id is the user's ID, not the organization's ID. This should be changed to return body.orgId or extract the org ID from dataOrg (which is an array). For example: return c.json({ id: body.orgId, data: dataOrg })

Note: This bug was present in the code before this refactoring, but the change makes it more visible and it should be corrected.

Suggested change
return c.json({ id: data.id, data: dataOrg })
return c.json({ id: body.orgId, data: dataOrg })

Copilot uses AI. Check for mistakes.
const safe = type.safeParse(await response.json())
expect(safe.success).toBe(true)
expect(safe.data?.status).toBe('Organization updated')
expect(safe.data?.id).toBeDefined()
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The test should verify that the returned id matches the expected ORG_ID to catch issues where the wrong ID is being returned. Add an assertion like: expect(safe.data?.id).toBe(ORG_ID)

Copilot uses AI. Check for mistakes.
Replace inconsistent response formats (c.body(null, 204), custom status messages, {success: true}) with uniform pattern using BRES ({ status: 'ok' }) for success without data, and c.json(data) for success with data. Updates 11 endpoint files and their tests.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
riderx and others added 2 commits January 19, 2026 21:09
Fixed bug where organization/put.ts was returning user ID (data.id) instead
of the organization ID (body.orgId). Updated tests to verify the correct ID
is returned.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sonarqubecloud
Copy link

@riderx riderx merged commit 8b47ce8 into main Jan 19, 2026
11 checks passed
@riderx riderx deleted the riderx/bogota-v3 branch January 19, 2026 22:06
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.

2 participants