index
Namespaces
Interfaces
JoyBlockVisibility
What a block's loader surfaces so its component (and useJoyMemberReveal) can finish the job.
Properties
eligibility?
eligibility?: JoyCustomerLoyaltyEligibility;The shop's setting, forwarded so the component knows whether the post-hydrate member gate applies. Omitted in Studio, which bypasses the gate on both sides.
hidden
hidden: boolean;The SSR verdict — true means render nothing at all.
personalized?
personalized?: boolean;true when the verdict is personalized to a logged-in customer. Loaders
that read this field must set Cache-Control: private, no-store (via
JOY_PERSONALIZED_CACHE_CONTROL from @joy-loyalty/hydrogen) when this is
true, to prevent an intermediate cache (CDN, Oxygen full-page, or shared
layers) from serving a logged-in customer's eligibility to a different
visitor. Omitted in Studio.
JoyConfig
Properties
apiUrl
apiUrl: string | null;locale?
locale?: string;loginUrl
loginUrl: string;shopDomain?
shopDomain?: string;tokenRoute
tokenRoute: string;Type Aliases
JoyCustomerState
type JoyCustomerState<T> =
| {
status: "loading";
}
| {
status: "guest";
}
| {
data: T;
status: "ready";
}
| {
message: string;
status: "error";
};Type Parameters
Variables
DEFAULT_TOKEN_ROUTE
const DEFAULT_TOKEN_ROUTE: "/api/joy-token" = "/api/joy-token";JOY_PERSONALIZED_CACHE_CONTROL
const JOY_PERSONALIZED_CACHE_CONTROL: "private, no-store" = "private, no-store";joyComponents
const joyComponents: HydrogenComponent[];Module-shaped entries ({default, schema, loader} — equivalent to
import * as Block namespaces) ready to spread into the Weaverse
components array.
Functions
clearJoyToken()
function clearJoyToken(): void;Returns
void
getJoyToken()
function getJoyToken(options?): Promise<string | null>;Parameters
| Parameter | Type |
|---|---|
options? | GetJoyTokenOptions |
Returns
Promise<string | null>
isJoyBlockDataPersonalized()
function isJoyBlockDataPersonalized(data): boolean;Checks whether a Weaverse block loader result carries personalized verdicts — verdicts scoped to a logged-in customer.
Use this in your route handler to set Cache-Control: private, no-store
(via JOY_PERSONALIZED_CACHE_CONTROL) when any Joy block on your page
has personalized content, to prevent intermediate caches (CDN, Oxygen's
full-page cache, or shared layers) from serving one shopper's eligibility
verdict to a different visitor.
Parameters
| Parameter | Type |
|---|---|
data | | Partial<JoyBlockVisibility> | null | undefined |
Returns
boolean
Example
import {isJoyBlockDataPersonalized, JOY_PERSONALIZED_CACHE_CONTROL} from '@joy-loyalty/weaverse-hydrogen';
export async function loader({context}: Route.LoaderArgs) {
const visibility = await resolveJoyBlockVisibility(context.weaverse);
// ... render your page with the visibility data
if (isJoyBlockDataPersonalized(visibility)) {
context.cacheControl.set('Cache-Control', JOY_PERSONALIZED_CACHE_CONTROL);
}
return json({visibility});
}JoyProvider()
function JoyProvider(__namedParameters): Element;Parameters
| Parameter | Type |
|---|---|
__namedParameters | Partial<Omit<JoyConfig, "apiUrl">> & JoyProviderCartHandlers & object |
Returns
Element
useJoyConfig()
function useJoyConfig(fallback): JoyConfig;Parameters
| Parameter | Type |
|---|---|
fallback | { apiUrl: string | null; locale?: string; loginUrl: string; shopDomain?: string; } |
fallback.apiUrl | string | null |
fallback.locale? | string |
fallback.loginUrl | string |
fallback.shopDomain? | string |
Returns
useJoyCustomer()
function useJoyCustomer<T>(fetcher, options): JoyCustomerState<T>;Type Parameters
Parameters
| Parameter | Type |
|---|---|
fetcher | (client) => Promise<T> |
options | { apiUrl: string | null; deps?: readonly unknown[]; enabled?: boolean; locale?: string; shopDomain?: string; tokenRoute: string; } |
options.apiUrl | string | null |
options.deps? | readonly unknown[] |
options.enabled? | boolean |
options.locale? | string |
options.shopDomain? | string |
options.tokenRoute | string |