Floralé’s data-fetching layer lives inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dlampatricio/florale/llms.txt
Use this file to discover all available pages before exploring further.
lib/products.ts and exposes four async functions for reading products and categories from Supabase. All calls go directly to the Supabase REST API using the native fetch with cache: 'no-store' — the Supabase JS client is intentionally not used here — making these functions safe to call from any Next.js Server Component or Route Handler without accidental caching.
Both
NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY must be
present in your environment. If either variable is missing, every function
returns a safe empty value ([] for list functions, undefined for
getProductById) rather than throwing, so the UI degrades gracefully during
misconfigured builds.Environment variables
| Variable | Description |
|---|---|
NEXT_PUBLIC_SUPABASE_URL | The base URL of your Supabase project (e.g. https://xyz.supabase.co) |
NEXT_PUBLIC_SUPABASE_ANON_KEY | The public anonymous key issued by Supabase |
NEXT_PUBLIC_ prefix, but the fetching functions run exclusively on the server — no credentials are ever exposed to the client bundle through this module.
Internal: mapProduct
Before any data reaches your components, rows returned from the products table are normalised by an internal mapProduct helper. The database uses snake_case column names; the TypeScript types use camelCase. The only structural change is:
id, name, description, price, image) are copied as-is. Fields that may be null in the database (description, image) are coerced to empty strings.
getProducts
Returns every product in the catalogue, ordered by creation date (oldest first).
Parameters
This function takes no parameters.Return type
An array of
Product objects ordered by created_at ASC. Returns an empty
array if the environment variables are missing or if the request fails.Unique product identifier (UUID).
Display name of the product.
Long-form product description. Empty string when not set.
Price in the store’s base currency unit (e.g. cents or dollars).
URL or path for the product’s primary image. Empty string when not set.
ID of the category this product belongs to (mapped from
category_id).Usage
getProductById
Fetches a single product by its UUID. Returns undefined when no matching record is found.
Parameters
The UUID of the product to retrieve. The value is URL-encoded before being
appended to the REST filter query.
Return type
A single
Product object when found, or undefined when no product matches
the given id or when the request fails.Unique product identifier (UUID).
Display name of the product.
Long-form description. Empty string when not set.
Price in the store’s base currency unit.
URL or path for the primary image. Empty string when not set.
Owning category ID (mapped from
category_id).Usage
getProductsByCategory
Returns all products that belong to a specific category, ordered by creation date (oldest first). This is the preferred way to power category landing pages.
Parameters
The ID of the category to filter by. Mapped to the
category_id column in
the database via the eq. PostgREST filter. The value is URL-encoded.Return type
An array of
Product objects filtered to the given category, ordered by
created_at ASC. Returns an empty array if no products exist in the
category, if the environment variables are missing, or if the request fails.Usage
getCategories
Fetches every category available in the store, ordered by id ASC.
Parameters
This function takes no parameters.Return type
An array of
Category objects ordered by id ASC. Returns an empty array
if the environment variables are missing or if the request fails.Unique category identifier.
Human-readable category name (e.g. “Dried Florals”).
A short description of the category’s contents.
Usage
Error handling and graceful degradation
All four functions share the same internalfetchFromSupabase helper, which applies a consistent error-handling strategy:
| Condition | getProducts / getProductsByCategory / getCategories | getProductById |
|---|---|---|
NEXT_PUBLIC_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_ANON_KEY not set | Returns [] immediately | Returns undefined immediately |
Non-ok HTTP response from Supabase | Returns [] | Returns undefined |
| Network error or thrown exception | Returns [] (caught internally) | Returns undefined (caught internally) |
| Empty result set | Returns [] normally | Returns undefined (no matching row) |