Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

refactor: add API client - #52

Merged
joshsny merged 13 commits into
mainfrom
refactor/api
Jul 22, 2025
Merged

refactor: add API client#52
joshsny merged 13 commits into
mainfrom
refactor/api

Conversation

@joshsny

@joshsny joshsny commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

First step of a refactor. We're utilising various functions to interact with the API. Let's pull this out into an API client we can test better.

Adds

  • An API client
  • Removes the existing posthogApi.ts functions
  • Integration tests you can run locally to test the API client

Copilot AI review requested due to automatic review settings July 22, 2025 08:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces an ApiClient class to refactor the codebase away from individual API functions toward a centralized client pattern. The refactor improves testability by consolidating API interactions into a single client with comprehensive integration tests.

  • Replaces scattered API functions with a structured ApiClient class that provides organized methods for different API endpoints
  • Adds comprehensive test infrastructure with Vitest configuration and integration tests covering all major API operations
  • Updates the main application code to use the new client pattern while maintaining existing functionality

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/api/client.ts Implements the new ApiClient class with methods for organizations, projects, feature flags, insights, dashboards, queries, and users
tests/api/client.test.ts Comprehensive integration tests covering all ApiClient functionality with proper setup and cleanup
src/index.ts Refactors existing code to use the new ApiClient instead of individual API functions
vitest.config.ts Test configuration for the new testing infrastructure
tests/setup.ts Test environment setup loading test-specific environment variables
package.json Adds testing dependencies and scripts
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

tests/api/client.test.ts:367

  • Skipped test reduces coverage for SQL insight functionality. Consider implementing the test or adding a comment explaining why it's skipped.
		it.skip("should execute SQL insight query", async () => {

Comment thread src/index.ts
Comment thread src/index.ts
Comment thread src/api/client.ts Outdated
Comment thread src/api/client.ts
Comment thread src/api/client.ts
Comment thread src/api/client.ts
@joshsny
joshsny requested a review from jonathanlab July 22, 2025 10:34
Comment thread src/lib/constants.ts
Comment thread src/api/client.ts

@jonathanlab jonathanlab left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great stuff 馃殺

Comment thread src/api/client.ts
Comment thread src/api/client.ts
Comment thread src/api/client.ts
Comment thread src/api/client.ts
@joshsny
joshsny merged commit 08ace4a into main Jul 22, 2025
4 checks passed
@joshsny
joshsny deleted the refactor/api branch July 22, 2025 11:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants