MCPcopy Create free account
hub / github.com/vercel/vercel / getWebhookEvents

Function getWebhookEvents

packages/cli/src/util/webhooks/get-webhook-events.ts:10–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8 * Results are cached in memory after the first fetch.
9 */
10export async function getWebhookEvents(): Promise<string[]> {
11 if (cachedEvents) {
12 return cachedEvents;
13 }
14
15 const cache = new OpenApiCache();
16 const loaded = await cache.load();
17
18 if (!loaded) {
19 output.debug('Failed to load OpenAPI spec for webhook events');
20 return [];
21 }
22
23 const endpoints = cache.getEndpoints();
24 const createWebhookEndpoint = endpoints.find(
25 e => e.path === '/v1/webhooks' && e.method === 'POST'
26 );
27
28 if (!createWebhookEndpoint) {
29 output.debug('Could not find POST /v1/webhooks endpoint in OpenAPI spec');
30 return [];
31 }
32
33 const bodyFields = cache.getBodyFields(createWebhookEndpoint);
34 const eventsField = bodyFields.find(f => f.name === 'events');
35
36 if (!eventsField?.enumValues) {
37 output.debug('Could not find events enum in webhook endpoint');
38 return [];
39 }
40
41 cachedEvents = eventsField.enumValues.filter(
42 (v): v is string => typeof v === 'string'
43 );
44 return cachedEvents;
45}
46
47/**
48 * Validates webhook events against the OpenAPI spec.

Callers 2

createFunction · 0.90
validateWebhookEventsFunction · 0.85

Calls 6

loadMethod · 0.95
getEndpointsMethod · 0.95
getBodyFieldsMethod · 0.95
debugMethod · 0.80
filterMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected