@arolariu/website / lib/actions/invoices/fetchMerchants / default
Function: default()
default(
_void?):ServerActionOutputType
Defined in: lib/actions/invoices/fetchMerchants.ts:82
Fetches all merchants associated with the authenticated user's invoices.
Parameters
_void?
Readonly<{ }>
Reserved parameter for future filter options
Returns
ServerActionOutputType
Promise resolving to array of Merchant entities
Remarks
Execution Context: Server-side only (Next.js server action).
Authentication: Automatically fetches JWT from Clerk auth service.
Data Returned:
- Array of merchant entities linked to user's invoices
- Includes AI-enriched fields (category, normalized name)
- Excludes merchants with no invoice associations
Performance:
- Returns complete entities
- Consider client-side caching for merchant dropdowns
Side Effects: Emits OpenTelemetry spans for tracing.
Throws
When authentication fails
Throws
When API returns non-OK status
Example
import fetchMerchants from "@/lib/actions/invoices/fetchMerchants";
const merchants = await fetchMerchants();
// Group by category
const byCategory = merchants.reduce((acc, m) => {
const cat = m.category ?? "Unknown";
acc[cat] = acc[cat] ?? [];
acc[cat].push(m);
return acc;
}, {} as Record<string, Merchant[]>);
See
- fetchMerchant for fetching a specific merchant
- Merchant for the data structure