oauthApps.utils.ts53 lines · main
| 1 | import type { OAuthClient } from '@supabase/supabase-js' |
| 2 | |
| 3 | export const OAUTH_APP_REGISTRATION_TYPE_OPTIONS = [ |
| 4 | { name: 'Manual', value: 'manual' }, |
| 5 | { name: 'Dynamic', value: 'dynamic' }, |
| 6 | ] |
| 7 | |
| 8 | export const OAUTH_APP_CLIENT_TYPE_OPTIONS = [ |
| 9 | { name: 'Public', value: 'public' }, |
| 10 | { name: 'Confidential', value: 'confidential' }, |
| 11 | ] |
| 12 | |
| 13 | interface FilterOAuthAppsParams { |
| 14 | apps: OAuthClient[] |
| 15 | searchString?: string |
| 16 | registrationTypes?: string[] |
| 17 | clientTypes?: string[] |
| 18 | } |
| 19 | |
| 20 | export function filterOAuthApps({ |
| 21 | apps, |
| 22 | searchString, |
| 23 | registrationTypes = [], |
| 24 | clientTypes = [], |
| 25 | }: FilterOAuthAppsParams): OAuthClient[] { |
| 26 | return apps.filter((app) => { |
| 27 | // Filter by search string |
| 28 | if (searchString) { |
| 29 | const searchLower = searchString.toLowerCase() |
| 30 | const matchesName = app.client_name.toLowerCase().includes(searchLower) |
| 31 | const matchesClientId = app.client_id.toLowerCase().includes(searchLower) |
| 32 | if (!matchesName && !matchesClientId) { |
| 33 | return false |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // Filter by registration type |
| 38 | if (registrationTypes.length > 0) { |
| 39 | if (!registrationTypes.includes(app.registration_type)) { |
| 40 | return false |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // Filter by client type |
| 45 | if (clientTypes.length > 0) { |
| 46 | if (!clientTypes.includes(app.client_type)) { |
| 47 | return false |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return true |
| 52 | }) |
| 53 | } |