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