oauthApps.utils.ts 1.3 KB

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