Skip to content

feat: add GET /api/admins/agent-signups endpoint#428

Open
recoup-coding-agent wants to merge 1 commit intotestfrom
feature/agent-signups-endpoint
Open

feat: add GET /api/admins/agent-signups endpoint#428
recoup-coding-agent wants to merge 1 commit intotestfrom
feature/agent-signups-endpoint

Conversation

@recoup-coding-agent
Copy link
Copy Markdown
Collaborator

@recoup-coding-agent recoup-coding-agent commented Apr 12, 2026

Summary

  • Adds GET /api/admins/agent-signups endpoint for tracking agent API key signups
  • Queries account_api_keys joined with account_emails filtering by agent+ email prefix
  • Supports period-based filtering (all, daily, weekly, monthly)
  • Admin-only authentication required

Test plan

  • Verify endpoint returns agent signups with correct schema
  • Test period query parameter filtering
  • Confirm admin auth is enforced (401/403 for non-admins)
  • Run unit tests

🤖 Generated with Claude Code


Summary by cubic

Adds an admin endpoint to list agent-created API key signups, with period filtering to analyze trends. Helps admins track agent adoption and enforce access control.

  • New Features
    • GET /api/admins/agent-signups: returns { status, total, signups }.
    • Supports ?period=all|daily|weekly|monthly (UTC midnight cutoffs).
    • Admin-only; OPTIONS with CORS headers included.
    • Supabase join filters emails by agent+%.
    • Tests cover success, auth failures, invalid period, and server errors.

Written for commit 767ee81. Summary will update on new commits.

New admin endpoint that returns API key sign-up records created by AI
agents, identified by the agent+ email prefix. Supports period filtering
(all, daily, weekly, monthly) for time-series analysis.

Includes handler, validation, Supabase query, and tests.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 12, 2026

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

Project Deployment Actions Updated (UTC)
recoup-api Ready Ready Preview Apr 12, 2026 7:05pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

Warning

Rate limit exceeded

@recoup-coding-agent has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 54 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 29 minutes and 54 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: eefa1640-f705-4aa8-9156-5ccccc3800aa

📥 Commits

Reviewing files that changed from the base of the PR and between 84e2208 and 767ee81.

⛔ Files ignored due to path filters (1)
  • lib/admins/agent-signups/__tests__/getAgentSignupsHandler.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (5)
  • app/api/admins/agent-signups/route.ts
  • lib/admins/agent-signups/getAgentSignupsHandler.ts
  • lib/admins/agent-signups/getCutoffDate.ts
  • lib/admins/agent-signups/validateGetAgentSignupsQuery.ts
  • lib/supabase/account_api_keys/getAgentSignups.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/agent-signups-endpoint

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
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 6 files

Confidence score: 3/5

  • There is some merge risk because lib/supabase/account_api_keys/getAgentSignups.ts has a concrete behavior mismatch (returning [] instead of null on error) with high confidence, which can hide database failures as valid empty results.
  • The test maintainability note in lib/admins/agent-signups/__tests__/getAgentSignupsHandler.test.ts is lower severity and non-blocking, but it adds minor cleanup debt rather than runtime risk.
  • Pay close attention to lib/supabase/account_api_keys/getAgentSignups.ts and lib/admins/agent-signups/__tests__/getAgentSignupsHandler.test.ts - align error-return semantics with the project pattern and consider splitting the oversized test file.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/admins/agent-signups/__tests__/getAgentSignupsHandler.test.ts">

<violation number="1" location="lib/admins/agent-signups/__tests__/getAgentSignupsHandler.test.ts:1">
P2: Custom agent: **Enforce Clear Code Style and Maintainability Practices**

Split this test file into smaller specs; it exceeds the 100-line file limit.</violation>
</file>

<file name="lib/supabase/account_api_keys/getAgentSignups.ts">

<violation number="1" location="lib/supabase/account_api_keys/getAgentSignups.ts:32">
P2: Function returns `[]` on error, deviating from the project's documented Supabase query pattern which returns `null` on error. This prevents callers from distinguishing a database failure from an empty result set — an admin monitoring endpoint should surface errors, not hide them.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Client as Admin Client
    participant Route as Next.js API Route
    participant Auth as Admin Auth Service
    participant Logic as Request Handler
    participant DB as Supabase Client

    Note over Client, DB: NEW: Agent Signup Tracking Flow

    Client->>Route: GET /api/admins/agent-signups?period=daily
    Route->>Logic: getAgentSignupsHandler(request)
    
    Logic->>Auth: NEW: validateAdminAuth(request)
    alt Unauthorized or Not Admin
        Auth-->>Client: 401 / 403 Error
    else Authorized Admin
        Auth-->>Logic: Auth Context
        
        Logic->>Logic: NEW: validateGetAgentSignupsQuery()
        opt Invalid period param
            Logic-->>Client: 400 Bad Request
        end

        Logic->>Logic: NEW: getCutoffDate(period)
        Note right of Logic: Calculates UTC midnight boundaries

        Logic->>DB: NEW: getAgentSignups(cutoffDate)
        
        DB->>DB: Build Query
        Note right of DB: JOIN account_api_keys -> accounts -> account_emails<br/>FILTER email LIKE 'agent+%'
        
        alt Database Success
            DB-->>Logic: AgentSignupRow[]
            Logic-->>Client: 200 OK + JSON { status, total, signups }
        else Database/Server Error
            DB-->>Logic: Error
            Logic-->>Client: 500 Internal Server Error
        end
    end

    Note over Client, Route: OPTIONS request returns CORS headers via getCorsHeaders()
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@@ -0,0 +1,153 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 12, 2026

Choose a reason for hiding this comment

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

P2: Custom agent: Enforce Clear Code Style and Maintainability Practices

Split this test file into smaller specs; it exceeds the 100-line file limit.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/admins/agent-signups/__tests__/getAgentSignupsHandler.test.ts, line 1:

<comment>Split this test file into smaller specs; it exceeds the 100-line file limit.</comment>

<file context>
@@ -0,0 +1,153 @@
+import { describe, it, expect, vi, beforeEach } from "vitest";
+import { NextRequest } from "next/server";
+
</file context>
Fix with Cubic


if (error) {
console.error("Error fetching agent signups:", error);
return [];
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 12, 2026

Choose a reason for hiding this comment

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

P2: Function returns [] on error, deviating from the project's documented Supabase query pattern which returns null on error. This prevents callers from distinguishing a database failure from an empty result set — an admin monitoring endpoint should surface errors, not hide them.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/supabase/account_api_keys/getAgentSignups.ts, line 32:

<comment>Function returns `[]` on error, deviating from the project's documented Supabase query pattern which returns `null` on error. This prevents callers from distinguishing a database failure from an empty result set — an admin monitoring endpoint should surface errors, not hide them.</comment>

<file context>
@@ -0,0 +1,47 @@
+
+  if (error) {
+    console.error("Error fetching agent signups:", error);
+    return [];
+  }
+
</file context>
Fix with Cubic

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