marketplace-client.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { createClient } from '@supabase/supabase-js'
  2. import { MergeDeep } from 'type-fest'
  3. import type { Database as DatabaseGenerated } from './marketplace.types'
  4. export type Category = {
  5. id: string
  6. name: string
  7. slug: string
  8. description: string
  9. }
  10. export type Database = MergeDeep<
  11. DatabaseGenerated,
  12. {
  13. public: {
  14. Views: {
  15. listings: {
  16. Row: {
  17. // add a type for the JSON structure
  18. categories: Category[]
  19. // These all come from non-nullable columns but all view columns are inferred as nullable.
  20. // See https://github.com/orgs/supabase/discussions/14151
  21. featured: boolean
  22. partner_name: string
  23. slug: string
  24. title: string
  25. description: string
  26. content: string
  27. website_url: string
  28. documentation_url: string
  29. listing_logo: string
  30. }
  31. }
  32. }
  33. }
  34. }
  35. >
  36. export type Listing = Database['public']['Views']['listings']['Row']
  37. export const createMarketplaceClient = () => {
  38. const API_URL = process.env.NEXT_PUBLIC_MARKETPLACE_API_URL || ''
  39. const PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_MARKETPLACE_PUBLISHABLE_KEY || ''
  40. return createClient<Database>(API_URL, PUBLISHABLE_KEY, {
  41. auth: {
  42. persistSession: false,
  43. autoRefreshToken: false,
  44. detectSessionInUrl: false,
  45. storage: {
  46. getItem: (_key: string) => null,
  47. setItem: (_key: string, _value: string) => {},
  48. removeItem: (_key: string) => {},
  49. },
  50. },
  51. })
  52. }
  53. export const fullImageUrl = (imagePath: string) => {
  54. const API_URL = process.env.NEXT_PUBLIC_MARKETPLACE_API_URL || ''
  55. return `${API_URL}${imagePath}`
  56. }