File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,11 +38,30 @@ import { toast } from 'sonner'
3838import { EmptyState , PageHeader , QueryError , ResultsSummary } from '@/components/common'
3939import { useUrlFilters } from '@/hooks'
4040
41+ /**
42+ * Type guard to check if an object is a valid Bouncer.
43+ * This provides runtime validation of the data received from the API.
44+ */
45+ function isBouncer ( obj : unknown ) : obj is Bouncer {
46+ return (
47+ obj !== null &&
48+ typeof obj === 'object' &&
49+ 'name' in obj &&
50+ typeof ( obj as { name : unknown } ) . name === 'string' &&
51+ 'ip_address' in obj &&
52+ typeof ( obj as { ip_address : unknown } ) . ip_address === 'string' &&
53+ 'valid' in obj &&
54+ typeof ( obj as { valid : unknown } ) . valid === 'boolean'
55+ )
56+ }
57+
4158function normalizeBouncers ( raw : unknown ) : Bouncer [ ] {
42- if ( Array . isArray ( raw ) ) return raw as Bouncer [ ]
59+ if ( Array . isArray ( raw ) ) {
60+ return raw . filter ( isBouncer )
61+ }
4362
4463 if ( raw && typeof raw === 'object' && 'bouncers' in raw && Array . isArray ( ( raw as { bouncers : unknown } ) . bouncers ) ) {
45- return ( raw as { bouncers : Bouncer [ ] } ) . bouncers
64+ return ( raw as { bouncers : unknown [ ] } ) . bouncers . filter ( isBouncer )
4665 }
4766
4867 return [ ]
You can’t perform that action at this time.
0 commit comments