Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib/data/wholesale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Channel, ProductListParams } from "@spree/sdk";
import {
getAccessToken,
getWholesaleClient,
isWholesaleEnabled,
withAuthRefresh,
} from "@/lib/spree";
import {
Expand All @@ -17,8 +18,17 @@ import { withFallback } from "./utils";
* Fetch the wholesale channel's resolved configuration (access posture, guest
* checkout). Reachable without authentication even on the gated channel so the
* portal can render a sign-in wall.
*
* Returns null when the wholesale addon is off. The `(wholesale)` layout 404s
* those routes, but Next.js renders layouts and pages concurrently — during
* static generation the page below it still runs, so this must not throw when
* the addon is disabled. Null is already the "channel unreachable" value every
* caller handles, so a DTC-only build degrades to the sign-in wall rather than
* failing the build.
*/
export async function getWholesaleChannel(): Promise<Channel | null> {
if (!isWholesaleEnabled()) return null;

return withFallback(async () => getWholesaleClient().channel.get(), null);
}

Expand Down
Loading