@arolariu/website / lib/actions/invoices/fetchMerchant / default
Function: default()
default(
input):ServerActionOutputType
Defined in: lib/actions/invoices/fetchMerchant.ts:83
Fetches a single merchant by its unique identifier.
Parameters
input
ServerActionInputType
The fetch parameters
Returns
ServerActionOutputType
Promise resolving to the complete Merchant entity
Remarks
Execution Context: Server-side only (Next.js server action).
Authentication: Automatically fetches JWT from Clerk auth service.
Data Returned:
- Full merchant entity with location and category
- Aggregate statistics (invoice count, total spent)
- AI-enriched fields if available
Access Control:
- Returns 404 if merchant doesn't exist
- Users can only fetch merchants linked to their invoices
Side Effects: Emits OpenTelemetry spans for tracing.
Throws
When merchantId is not a valid GUID
Throws
When authentication fails
Throws
When merchant not found (404)
Example
import fetchMerchant from "@/lib/actions/invoices/fetchMerchant";
const merchant = await fetchMerchant({
merchantId: "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
});
console.log("Merchant name:", merchant.name);
console.log("Category:", merchant.category);
See
- Merchant for the complete data structure
- fetchInvoice for getting the merchant reference from an invoice