Skip to content

Commit 8f5493d

Browse files
committed
feat: enhance event filtering with exclusion capability
- Added a new environment variable, FILTER_EVENTS_EXCLUDE, to specify event types that should be denied notifications. - Updated the filtering logic to prioritize excluded events over allowed events, ensuring more precise control over notifications. - Enhanced documentation to reflect the new exclusion feature and provide usage examples for both allowlist and denylist configurations.
1 parent d2af94a commit 8f5493d

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

apps/fumadocs/content/docs/installation/environment.mdx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,31 @@ Add the variables for at least one provider. See the [Providers](/docs/providers
116116
<TypeTable
117117
type={{
118118
FILTER_EVENTS: {
119-
description: 'Comma-separated list of event types to allow',
119+
description: 'Comma-separated allowlist of event types',
120120
type: 'string',
121121
default: 'all events',
122122
},
123+
FILTER_EVENTS_EXCLUDE: {
124+
description: 'Comma-separated denylist of event types',
125+
type: 'string',
126+
default: 'none',
127+
},
123128
}}
124129
/>
125130

126-
Example: `FILTER_EVENTS=deployment.error,deployment.succeeded,deployment.ready`
131+
**Exclude noisy events:**
132+
```
133+
FILTER_EVENTS_EXCLUDE=deployment.cleanup
134+
```
127135

128-
If set, only the specified events will trigger notifications. If not set, all events pass through.
136+
**Only allow specific events:**
137+
```
138+
FILTER_EVENTS=deployment.error,deployment.succeeded,deployment.ready
139+
```
140+
141+
<Callout type="info">
142+
`FILTER_EVENTS_EXCLUDE` takes priority over `FILTER_EVENTS`. An event in the exclude list is always blocked, even if it's in the allow list.
143+
</Callout>
129144

130145
</Step>
131146
<Step>

apps/web/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const env = createEnv({
1919
UPSTASH_REDIS_REST_TOKEN: string().optional(),
2020
// Filtering
2121
FILTER_EVENTS: string().optional(),
22+
FILTER_EVENTS_EXCLUDE: string().optional(),
2223
FILTER_TARGETS: string().optional(),
2324
},
2425
client: {},
@@ -32,6 +33,7 @@ export const env = createEnv({
3233
UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL,
3334
UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN,
3435
FILTER_EVENTS: process.env.FILTER_EVENTS,
36+
FILTER_EVENTS_EXCLUDE: process.env.FILTER_EVENTS_EXCLUDE,
3537
FILTER_TARGETS: process.env.FILTER_TARGETS,
3638
},
3739
extends: [vercel()],

apps/web/src/lib/filter.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ const allowedEvents: Set<string> | null = env.FILTER_EVENTS
55
? new Set(env.FILTER_EVENTS.split(",").map((e) => e.trim()))
66
: null;
77

8+
const excludedEvents: Set<string> | null = env.FILTER_EVENTS_EXCLUDE
9+
? new Set(env.FILTER_EVENTS_EXCLUDE.split(",").map((e) => e.trim()))
10+
: null;
11+
812
const allowedTargets: Set<string> | null = env.FILTER_TARGETS
913
? new Set(env.FILTER_TARGETS.split(",").map((t) => t.trim().toLowerCase()))
1014
: null;
1115

1216
/**
1317
* Check if an event type should trigger notifications.
14-
* If FILTER_EVENTS is not set, all events are allowed.
15-
* If set, only events in the comma-separated list are allowed.
18+
* - FILTER_EVENTS_EXCLUDE takes priority (denylist)
19+
* - FILTER_EVENTS is checked second (allowlist)
20+
* - If neither is set, all events are allowed
1621
*/
1722
export function isEventAllowed(type: WebhookType): boolean {
23+
if (excludedEvents?.has(type)) {
24+
return false;
25+
}
1826
if (!allowedEvents) {
1927
return true;
2028
}

turbo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"UPSTASH_REDIS_REST_TOKEN",
1616
"UPSTASH_REDIS_REST_URL",
1717
"FILTER_EVENTS",
18+
"FILTER_EVENTS_EXCLUDE",
1819
"FILTER_TARGETS",
1920
"WEBHOOK_INTEGRATION_SECRET"
2021
]

0 commit comments

Comments
 (0)