mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Test deliveries in the webhook deliveries table look the same as real ones. Test events are sent with `is_test: true` in the event payload, but the UI doesn't surface it, so there's no way to tell them apart at a glance. Closes FE-4710. ## Solution - Added an `isTestDelivery` helper that checks `eventPayload.is_test === true`. It uses a strict comparison, so values like the string `"true"` don't count. - Show a green "Test" badge next to the event name in the deliveries table. - Show the same badge in the header of the delivery details sheet, next to the status badge. - Added unit tests for the helper and component tests for the table and the sheet, each covering a test delivery and a real one. ## Review instructions 1. Open a project's webhooks page and select an endpoint. 2. Click the button to send a test event and wait for its delivery to appear in the Deliveries table. 3. Check that the new row has a green "Test" badge next to its event name, and that existing rows without it have no badge. 4. Click the test row and check that the delivery details sheet shows the "Test" badge next to the status badge in the header. 5. Click a non-test row and check that its sheet has no "Test" badge.
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import type { WebhookDelivery, WebhookEndpoint } from './PlatformWebhooks.types'
|
|
|
|
const secureRandomHex = (length: number) => {
|
|
if (length <= 0) return ''
|
|
|
|
const cryptoApi = globalThis.crypto
|
|
if (!cryptoApi?.getRandomValues) {
|
|
throw new Error('Web Crypto API is not available')
|
|
}
|
|
|
|
const byteCount = Math.ceil(length / 2)
|
|
const bytes = new Uint8Array(byteCount)
|
|
cryptoApi.getRandomValues(bytes)
|
|
|
|
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0'))
|
|
.join('')
|
|
.slice(0, length)
|
|
}
|
|
|
|
export const generateSigningSecret = () => `whsec_${secureRandomHex(16)}`
|
|
|
|
export const getWebhookEndpointDisplayName = (
|
|
endpoint: Pick<WebhookEndpoint, 'url' | 'eventTypes'>
|
|
) => {
|
|
const eventTypesLabel = endpoint.eventTypes.includes('*')
|
|
? 'all events'
|
|
: endpoint.eventTypes.join(', ')
|
|
return `${endpoint.url} (${eventTypesLabel})`
|
|
}
|
|
|
|
export const getTestWebhookEventType = (
|
|
subscribedEventTypes: string[],
|
|
fallbackEventTypes: string[]
|
|
) => subscribedEventTypes.find((eventType) => eventType !== '*') ?? fallbackEventTypes[0]
|
|
|
|
export const isTestDelivery = (delivery: Pick<WebhookDelivery, 'eventPayload'>) =>
|
|
delivery.eventPayload.is_test === true
|
|
|
|
const normalizeSearch = (value: string) => value.trim().toLowerCase()
|
|
|
|
export const filterWebhookEndpoints = (endpoints: WebhookEndpoint[], search: string) => {
|
|
const normalizedSearch = normalizeSearch(search)
|
|
if (normalizedSearch.length === 0) return endpoints
|
|
|
|
return endpoints.filter((endpoint) => {
|
|
const haystack =
|
|
`${getWebhookEndpointDisplayName(endpoint)} ${endpoint.url} ${endpoint.description}`.toLowerCase()
|
|
return haystack.includes(normalizedSearch)
|
|
})
|
|
}
|