Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

3.8 KB
Raw Blame
import {
  BadgeCheckIcon,
  CableIcon,
  DatabaseIcon,
  Package2Icon,
  PlugIcon,
  UsersIcon,
  type LucideIcon,
} from 'lucide-react'
import type { ReactNode } from 'react'
import { Badge, cn, IconPartners } from 'ui'

import type {
  IntegrationDefinition,
  MarketplaceSource,
} from '@/components/interfaces/Integrations/Landing/Integrations.constants'

export { getCategoryIcon, CATEGORY_ICONS } from 'common/marketplace-categories'

export type { MarketplaceSource } from '@/components/interfaces/Integrations/Landing/Integrations.constants'

// Defines featured integrations and their order in the featured hero
export const FEATURED_INTEGRATION_IDS = [
  'grafana',
  'grafana-cloud',
  'cron',
  'queues',
  'stripe_sync_engine',
  'data_api',
] as const

export type MarketplaceIntegrationType = 'oauth' | 'postgres_extension' | 'template' | 'wrapper'

export const INTEGRATION_TYPES: Array<{
  key: MarketplaceIntegrationType
  label: string
  icon: LucideIcon
}> = [
  { key: 'oauth', label: 'OAuth App', icon: PlugIcon },
  { key: 'postgres_extension', label: 'Postgres Module', icon: DatabaseIcon },
  { key: 'template', label: 'Template', icon: Package2Icon },
  { key: 'wrapper', label: 'Wrapper', icon: CableIcon },
]

export const FEATURED_CATEGORIES: Array<{ slug: string; name: string }> = [
  { slug: 'observability', name: 'Observability' },
  { slug: 'security', name: 'Security' },
  { slug: 'billing', name: 'Billing' },
  { slug: 'devtools', name: 'DevTools' },
  { slug: 'ai_vectors', name: 'AI & Vectors' },
  { slug: 'storage', name: 'Storage' },
]

// Categories excluded from the filter dropdown — they either overlap with
// dedicated filter groups (type/source) or are unused in the current catalogue.
export const EXCLUDED_CATEGORY_SLUGS = new Set([
  'agencies',
  'foreign-data-wrapper',
  'app-templates',
])

export const formatCategoryLabel = (
  slug: string | null | undefined,
  categoryOptions?: Array<{ slug: string; name: string }>
): string => {
  if (!slug) return ''
  const pinned = FEATURED_CATEGORIES.find((c) => c.slug === slug)
  if (pinned) return pinned.name
  const remote = categoryOptions?.find((c) => c.slug === slug)
  if (remote) return remote.name
  return slug
    .split(/[-_]/)
    .filter(Boolean)
    .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
    .join(' ')
}

export const getMarketplaceType = (
  integration: IntegrationDefinition
): MarketplaceIntegrationType => {
  if (integration.type === 'wrapper') return 'wrapper'
  if (integration.type === 'postgres_extension') return 'postgres_extension'
  if (integration.id === 'stripe_sync_engine') return 'template'
  return 'oauth'
}

export const getMarketplaceTypeLabel = (type: MarketplaceIntegrationType): string =>
  INTEGRATION_TYPES.find((t) => t.key === type)?.label ?? type

export const MARKETPLACE_SOURCES: Array<{
  key: MarketplaceSource
  label: string
  icon: LucideIcon | ((props: { className?: string }) => ReactNode)
}> = [
  { key: 'Official', label: 'Official', icon: BadgeCheckIcon },
  { key: 'Partner', label: 'Partner', icon: IconPartners },
  { key: 'Community', label: 'Community', icon: UsersIcon },
]

export const getMarketplaceSource = (integration: IntegrationDefinition): MarketplaceSource => {
  if (integration.source) return integration.source
  return integration.listingId ? 'Partner' : 'Official'
}

export const MarketplaceSourceBadge = ({
  source,
  className,
}: {
  source: MarketplaceSource
  className?: string
}) => {
  switch (source) {
    case 'Partner':
      return (
        <Badge className={cn('border-foreground-lighter/50', className)}>
          <IconPartners size={10} /> Partner
        </Badge>
      )
    case 'Community':
      return <Badge className={className}>Community</Badge>
    case 'Official':
      return <Badge className={className}>Official</Badge>
  }
}