Files
supabase/apps/studio/data/config/github-config-query.ts
T
Jordi Enric fa7c223209 fix(studio): use Compute management endpoints FUNC-896 (#50393)
## Problem

Studio still called the legacy `/workers` Management API routes and used
the old `project_worker` response contract, so Compute instances could
not be listed or retrieved after the API rename. The production API type
check also detected drift in the v1 and platform declarations.

## Fix

- Regenerate the v1, v2, and platform API declarations from the deployed
schemas.
- Update Studio list and detail queries to `/compute`.
- Align typed fixtures with the Compute response schemas and
`project_compute_instance` resource type.
- Update platform response type references to the generated `_Output`
schema names.

## How to test

- Run `pnpm api:verify-types`.
- Run `pnpm --filter api-types test`.
- Run `pnpm --filter studio test data/compute/compute.utils.test.ts
"tests/pages/project/[ref]/compute/index.test.tsx"`.
- Run `pnpm --filter studio typecheck`.
- Run `pnpm --filter common typecheck`.
- Run `pnpm --filter studio lint:ratchet`.

Expected result: production API declarations are synchronized, and
Studio requests the `/compute` list and detail endpoints and renders
`project_compute_instance` responses successfully.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Improvements**
* Updated API response handling across profiles, backups, notifications,
integrations, warehouses, access tokens, payments, and other Studio
workflows for more accurate serialized data.
* Compute instance pages and queries now use the compute-specific API
endpoints and response data.
* Improved feature-flag type handling when disabled feature data is
unavailable.

* **Tests**
* Updated automated coverage and fixtures to reflect current compute and
API response formats.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-15 12:50:56 +02:00

71 lines
2.0 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import type { components } from 'api-types'
import { z } from 'zod'
import { gitHubConfigTomlSchema } from '@/components/interfaces/ConfigDrift/github-config.types'
import { get, handleError } from '@/data/fetchers'
import type { UseCustomQueryOptions } from '@/types'
export type GitHubConfigVariables = {
connectionId?: number
branch?: string
}
type GithubConfigQueryResponse =
components['schemas']['GetGitHubConnectionConfigResponse_Output'] & {
config: z.infer<typeof gitHubConfigTomlSchema>
}
export const githubConfigKeys = {
all: ['github-config'] as const,
connection: (connectionId?: number, branch?: string) =>
[...githubConfigKeys.all, connectionId, branch] as const,
}
export async function getGitHubConfig(
{ connectionId, branch }: GitHubConfigVariables,
signal?: AbortSignal
) {
if (!connectionId) throw new Error('connectionId is required')
const { data, error } = await get(
'/platform/integrations/github/connections/{connection_id}/config',
{
params: {
path: { connection_id: connectionId },
query: { ref: branch },
},
signal,
}
)
if (error) return handleError(error)
const parsed = gitHubConfigTomlSchema.safeParse(data.config)
if (parsed.error) {
return handleError(
new Error(`Invalid response from Github config API: ${parsed.error.message}`)
)
}
return {
...data,
config: parsed.data,
}
}
export const useGitHubConfigQuery = <TData = GithubConfigQueryResponse>(
variables: GitHubConfigVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<GithubConfigQueryResponse, Error, TData> = {}
) =>
useQuery<GithubConfigQueryResponse, Error, TData>({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: githubConfigKeys.connection(variables.connectionId, variables.branch),
queryFn: ({ signal }) => getGitHubConfig(variables, signal),
enabled: enabled && typeof variables.connectionId !== 'undefined',
staleTime: 30_000,
...options,
})