mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 07:09:07 +03:00
## What
Wires the existing (mocked) Platform Webhooks UI to the real Management
API backend, per FE-3749.
- New `data/platform-webhooks/` query/mutation hooks, calling the real
`/v2/organizations/{slug}/webhooks/...` and
`/v2/projects/{ref}/webhooks/...` endpoints
- Updated `PlatformWebhooks.types.ts` to match the real API contract
(field names, shapes)
- Added a signing secret field to the create-endpoint form (API requires
a user-provided secret, not server-generated like the mock assumed)
- Removed the event-type column from the deliveries table (the real
list-deliveries endpoint doesn't return event type, only the
single-delivery endpoint does)
- Removed `PlatformWebhooks.mock.ts` / `.store.ts` and their tests
## Why
UI was built ~80% against mock data months ago; this closes the gap to a
real, working feature.
## Known open items (not blocking, tracked separately)
- `name` field has no backend storage yet — client-only for now, open
question with Ali/Paweł
- Deliveries table only fetches the backend's default single page — real
server-side pagination not yet wired (see FE-3750)
## Follow-up PR (stacked)
Tests for the new `data/platform-webhooks/` hooks (MSW-based), per the
ticket's own scope split.
## Testing
Manually tested end-to-end against local backend: created/edited/deleted
an endpoint, verified the real signature using webhook.site,
independently recomputed the HMAC and confirmed it matches the
`webhook-signature` header.
Linear: FE-3749
---------
Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { platformWebhooksKeys } from './keys'
|
|
import { listWebhookEndpoints, type WebhookScopeParams } from './platform-webhooks-fetchers'
|
|
import { toWebhookEndpoint } from './platform-webhooks-mappers'
|
|
import type { WebhookEndpoint } from '@/components/interfaces/Platform/Webhooks/PlatformWebhooks.types'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
interface WebhookEndpointsVariables {
|
|
scope: WebhookScopeParams
|
|
limit?: number
|
|
offset?: number
|
|
}
|
|
|
|
async function getWebhookEndpoints(
|
|
{ scope, limit, offset }: WebhookEndpointsVariables,
|
|
signal?: AbortSignal
|
|
): Promise<WebhookEndpoint[]> {
|
|
const result = await listWebhookEndpoints(scope, { limit, offset }, signal)
|
|
return (result?.data ?? []).map(toWebhookEndpoint)
|
|
}
|
|
|
|
export type WebhookEndpointsData = Awaited<ReturnType<typeof getWebhookEndpoints>>
|
|
|
|
export const useWebhookEndpointsQuery = <TData = WebhookEndpointsData>(
|
|
variables: WebhookEndpointsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<WebhookEndpointsData, ResponseError, TData> = {}
|
|
) => {
|
|
const { scope, limit, offset } = variables
|
|
|
|
return useQuery<WebhookEndpointsData, ResponseError, TData>({
|
|
queryKey: platformWebhooksKeys.endpoints(scope, limit, offset),
|
|
queryFn: ({ signal }) => getWebhookEndpoints({ scope, limit, offset }, signal),
|
|
enabled,
|
|
...options,
|
|
})
|
|
}
|