File tree Expand file tree Collapse file tree 5 files changed +46
-0
lines changed
fumadocs/content/docs/installation Expand file tree Collapse file tree 5 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,25 @@ Add the variables for at least one provider. See the [Providers](/docs/providers
100100</Step >
101101<Step >
102102
103+ ### Add Event Filtering (Optional)
104+
105+ <TypeTable
106+ type = { {
107+ FILTER_EVENTS: {
108+ description: ' Comma-separated list of event types to allow' ,
109+ type: ' string' ,
110+ default: ' all events' ,
111+ },
112+ }}
113+ />
114+
115+ Example: ` FILTER_EVENTS=deployment.error,deployment.succeeded,deployment.ready `
116+
117+ If set, only the specified events will trigger notifications. If not set, all events pass through.
118+
119+ </Step >
120+ <Step >
121+
103122### Redeploy
104123
105124Go to ** Deployments** and click the three dots on the latest deployment →
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { after } from "next/server";
22import { ZodError } from "zod/v4" ;
33
44import HttpStatusCode from "@/enums/http-status-codes" ;
5+ import { isEventAllowed } from "@/lib/filter" ;
56import { sendNotifications } from "@/lib/notify" ;
67import { checkRateLimit , getClientIp } from "@/lib/ratelimit" ;
78import { verifySignature } from "@/lib/verify" ;
@@ -33,6 +34,10 @@ export async function POST(req: Request) {
3334 const payload = JSON . parse ( rawBody ) as unknown ;
3435 const webhook = webhookSchema . parse ( payload ) ;
3536
37+ if ( ! isEventAllowed ( webhook . type ) ) {
38+ return Response . json ( { success : true , message : "Event filtered" } ) ;
39+ }
40+
3641 after ( ( ) => sendNotifications ( webhook ) ) ;
3742
3843 return Response . json ( { success : true , message : "Webhook processed" } ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ export const env = createEnv({
1515 // Rate limiting
1616 UPSTASH_REDIS_REST_URL : string ( ) . url ( ) . optional ( ) ,
1717 UPSTASH_REDIS_REST_TOKEN : string ( ) . optional ( ) ,
18+ // Filtering
19+ FILTER_EVENTS : string ( ) . optional ( ) ,
1820 } ,
1921 client : { } ,
2022 runtimeEnv : {
@@ -25,6 +27,7 @@ export const env = createEnv({
2527 SLACK_WEBHOOK_URL : process . env . SLACK_WEBHOOK_URL ,
2628 UPSTASH_REDIS_REST_URL : process . env . UPSTASH_REDIS_REST_URL ,
2729 UPSTASH_REDIS_REST_TOKEN : process . env . UPSTASH_REDIS_REST_TOKEN ,
30+ FILTER_EVENTS : process . env . FILTER_EVENTS ,
2831 } ,
2932 extends : [ vercel ( ) ] ,
3033} ) ;
Original file line number Diff line number Diff line change 1+ import { env } from "@/env" ;
2+ import type { WebhookType } from "@/schemas/vercel" ;
3+
4+ const allowedEvents : Set < string > | null = env . FILTER_EVENTS
5+ ? new Set ( env . FILTER_EVENTS . split ( "," ) . map ( ( e ) => e . trim ( ) ) )
6+ : null ;
7+
8+ /**
9+ * Check if an event type should trigger notifications.
10+ * If FILTER_EVENTS is not set, all events are allowed.
11+ * If set, only events in the comma-separated list are allowed.
12+ */
13+ export function isEventAllowed ( type : WebhookType ) : boolean {
14+ if ( ! allowedEvents ) {
15+ return true ;
16+ }
17+ return allowedEvents . has ( type ) ;
18+ }
Original file line number Diff line number Diff line change 1313 " SLACK_WEBHOOK_URL" ,
1414 " UPSTASH_REDIS_REST_TOKEN" ,
1515 " UPSTASH_REDIS_REST_URL" ,
16+ " FILTER_EVENTS" ,
1617 " WEBHOOK_INTEGRATION_SECRET"
1718 ]
1819 },
You can’t perform that action at this time.
0 commit comments