Skip to content

refactor: split api-client.ts into focused domain modules#405

Merged
BYK merged 2 commits intomainfrom
refactor/split-api-client
Mar 12, 2026
Merged

refactor: split api-client.ts into focused domain modules#405
BYK merged 2 commits intomainfrom
refactor/split-api-client

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 12, 2026

Split the 1,977-line src/lib/api-client.ts into 12 focused domain modules under src/lib/api/:

Module Purpose
infrastructure.ts Shared helpers, types, constants, raw request functions
organizations.ts Org CRUD and region discovery
projects.ts Project CRUD, search by slug/pattern/DSN key
teams.ts Team CRUD, project teams
repositories.ts Repository listing
issues.ts Issue listing, lookup, status updates
events.ts Event retrieval and resolution
traces.ts Trace details and transactions
logs.ts Log listing, detailed fetch, trace-logs
seer.ts Seer AI root cause analysis and planning
trials.ts Product trial management
users.ts Current user info

The original api-client.ts is now a 100-line barrel re-export, preserving all existing import paths (import { ... } from "./api-client.js" and import * as apiClient for spyOn mocking). No consumer changes required.

Pure refactor — no functional changes.

Split the 1977-line src/lib/api-client.ts monolith into 11 domain
modules under src/lib/api/:

- infrastructure.ts: shared helpers, types, constants, raw request fns
- organizations.ts: org CRUD and region discovery
- projects.ts: project CRUD, search, DSN keys
- teams.ts: team CRUD, project teams
- repositories.ts: repository listing
- issues.ts: issue listing, lookup, status updates
- events.ts: event retrieval and resolution
- traces.ts: trace details and transactions
- logs.ts: log listing, detailed fetch, trace-logs
- seer.ts: Seer AI root cause analysis and planning
- trials.ts: product trial management
- users.ts: current user info

The original api-client.ts becomes a pure barrel re-export (~100 lines)
so all 52+ existing imports remain unchanged. Zero test files modified.

No functional changes — this is a pure structural refactor.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Init

  • Add --team flag to relay team selection to project creation by MathurAditya724 in #403
  • Enforce canonical feature display order by betegon in #388
  • Accept multiple delimiter formats for --features flag by betegon in #386
  • Add git safety checks before wizard modifies files by betegon in #379
  • Add experimental warning before wizard runs by betegon in #378
  • Add init command for guided Sentry project setup by betegon in #283

Issue List

  • Auto-compact when table exceeds terminal height by BYK in #395
  • Redesign table to match Sentry web UI by BYK in #372

Other

  • (trial) Auto-prompt for Seer trial + sentry trial list/start commands by BYK in #399
  • Add --dry-run flag to mutating commands by BYK in #387
  • Return-based output with OutputConfig on buildCommand by BYK in #380
  • Add --fields flag for context-window-friendly JSON output by BYK in #373
  • Magic @ selectors (@latest, @most_frequent) for issue commands by BYK in #371
  • Input hardening against agent hallucinations by BYK in #370
  • Add response caching for read-only API calls by BYK in #330

Bug Fixes 🐛

Init

  • Remove implementation detail from help text by betegon in #385
  • Truncate uncommitted file list to first 5 entries by MathurAditya724 in #381

Other

  • (api) Convert --data to query params for GET requests by BYK in #383
  • (docs) Remove double borders and fix column alignment on landing page tables by betegon in #369
  • Add trace ID validation to trace view + UUID dash-stripping by BYK in #375

Internal Changes 🔧

Init

  • Remove --force flag by betegon in #377
  • Remove dead determine-pm step label by betegon in #374

Other

  • Split api-client.ts into focused domain modules by BYK in #405
  • Migrate non-streaming commands to CommandOutput with markdown rendering by BYK in #398
  • Convert Tier 2-3 commands to return-based output and consola by BYK in #394
  • Convert remaining Tier 1 commands to return-based output by BYK in #382
  • Converge Tier 1 commands to writeOutput helper by BYK in #376

Other

  • Minify JSON on read and pretty-print on write in init local ops by MathurAditya724 in #396

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

Codecov Results 📊

104 passed | Total: 104 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 99.41%. Project has 697 uncovered lines.
✅ Project coverage is 96.65%. Comparing base (base) to head (head).

Files with missing lines (4)
File Patch % Lines
projects.ts 98.35% ⚠️ 3 Missing
events.ts 98.67% ⚠️ 1 Missing
infrastructure.ts 99.50% ⚠️ 1 Missing
issues.ts 99.08% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.58%    96.65%    +1.07%
==========================================
  Files          147       159       +12
  Lines        20755     20784       +29
  Branches         0         0         —
==========================================
+ Hits         19838     20087      +249
- Misses         917       697      -220
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK marked this pull request as ready for review March 12, 2026 16:03
Add comprehensive tests for the uncovered functions across all 12 domain
modules in src/lib/api/. Brings line coverage to 80%+ on every module:

- issues.ts: 25% → 99% (listIssuesAllPages, getIssue, getIssueInOrg, etc.)
- teams.ts: 28% → 100% (listTeams, createTeam, addMemberToTeam, etc.)
- projects.ts: 42% → 87% (listProjects, createProject, getProjectKeys, etc.)
- users.ts: 33% → 100% (getCurrentUser)
- events.ts: 56% → 99% (getLatestEvent, getEvent, resolveEventInOrg)
- traces.ts: 71% → 100% (getDetailedTrace)
- repositories.ts: 65% → 100% (listRepositories)
- logs.ts: 73% → 100% (listLogs)
- infrastructure.ts: 89% → 99% (apiRequest, error paths, Zod validation)

86 new tests, all passing.
@BYK BYK merged commit 5bba832 into main Mar 12, 2026
22 checks passed
@BYK BYK deleted the refactor/split-api-client branch March 12, 2026 18:06
betegon added a commit that referenced this pull request Mar 13, 2026
Dashboard API functions now live in src/lib/api/dashboards.ts following
the domain module pattern from #405.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
betegon added a commit that referenced this pull request Mar 13, 2026
Resolve conflict from api-client split (#405). Move normalizeTraceSpan
and the getDetailedTrace normalization call into src/lib/api/traces.ts.
Rename test file to kebab-case to satisfy lint.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
BYK pushed a commit that referenced this pull request Mar 17, 2026
Dashboard API functions now live in src/lib/api/dashboards.ts following
the domain module pattern from #405.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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