Headless API
SDK reference
hydrogen
server

server

Interfaces

GetJoyInitialDataOptions

Properties

accountUrl?
accountUrl?: string;

Defaults mirror Liquid's routes.account_url.

apiUrl
apiUrl: string;

Base URL of the Joy Headless API.

assetUrl?
assetUrl?: string;

Widget-core CDN origin override (JOY_WIDGET_ASSET_URL) — the same value the host passes to <JoyWidget assetUrl>. Used only to read the core's build.json for JoyInitialDataResult.core.

customerAccount
customerAccount: JoyCustomerAccount;

Hydrogen route context's customerAccount handle — same shape mintJoyToken needs.

deferCustomerBalance?
deferCustomerBalance?: boolean;

Skip the server-side GET /customer balance read (perf H4). The mint → balance pair is SERIAL (the balance needs the minted JWT) and sits inside TTFB for every logged-in page view; with it off the loader returns the customer's identity + token only, customer stays absent, and the widget / loyalty page fetch the balance client-side on demand (they do anyway on open). Default false keeps the result shape and timing unchanged.

exposeToken?
exposeToken?: boolean;

Include the minted JWT on the result so the browser can skip a second /api/joy-token exchange. OFF by default: the JWT is customer-scoped with a short TTL (see mintJoyToken's expiresIn, typically ~60min), and turning this on rides it into the SSR HTML payload — anything that caches/logs that response (CDN, error tracker) would then carry a live customer credential. Only opt in with a concrete reason to save the round trip.

locale?
locale?: string;

Joy-normalised locale — forwarded to createJoyClient for customer-text localisation. Defaults to storefront.i18n.language (Liquid: Shopify.locale), so a /fr-ca request renders the widget in French without the host threading it through by hand.

loginUrl?
loginUrl?: string;

Defaults mirror Liquid's routes.storefront_login_url (app-data.liquid).

registerUrl?
registerUrl?: string;

Defaults mirror Liquid's routes.account_register_url.

request?
request?: Request;

The incoming request — used only to synthesize page from its URL pathname. Omit → {type: 'index', ...}.

secret
secret: string;

PRIVATE — the shop's secretKey. Server-only; never returned or logged.

shopDomain
shopDomain: string;

The shop's myshopify domain.

storefront
storefront: JoyStorefrontClient;

The merchant's own Storefront API client (context.storefront).


GetJoyLoyaltyPageDataOptions

Properties

apiUrl
apiUrl: string;

Base URL of the Joy Headless API.

assetUrl?
assetUrl?: string;

Widget-core CDN origin override (JOY_WIDGET_ASSET_URL), for the core manifest read.

fetch?
fetch?: {
  (input, init?): Promise<Response>;
  (input, init?): Promise<Response>;
};

Override fetch (tests). Defaults to globalThis.fetch.

Call Signature
(input, init?): Promise<Response>;

MDN Reference (opens in a new tab)

Parameters
ParameterType
inputURL | RequestInfo
init?RequestInit
Returns

Promise<Response>

Call Signature
(input, init?): Promise<Response>;

MDN Reference (opens in a new tab)

Parameters
ParameterType
inputstring | URL | Request
init?RequestInit
Returns

Promise<Response>

shopDomain
shopDomain: string;

The shop's myshopify domain — the structure endpoint's ?shop= query param.

storefront
storefront: JoyStorefrontClient;

The merchant's own Storefront API client (context.storefront) — also the blob-memo key (see below).


GetWidgetCoreManifestOptions

Properties

assetUrl?
assetUrl?: string;

CDN origin override (JOY_WIDGET_ASSET_URL). Defaults to JOY_CDN_ORIGIN.

fetch?
fetch?: {
  (input, init?): Promise<Response>;
  (input, init?): Promise<Response>;
};

Override fetch (tests). Defaults to globalThis.fetch.

Call Signature
(input, init?): Promise<Response>;

MDN Reference (opens in a new tab)

Parameters
ParameterType
inputURL | RequestInfo
init?RequestInit
Returns

Promise<Response>

Call Signature
(input, init?): Promise<Response>;

MDN Reference (opens in a new tab)

Parameters
ParameterType
inputstring | URL | Request
init?RequestInit
Returns

Promise<Response>


JoyInitialDataPage

Route-derived page info a loader can know first-hand (mirrors HeadlessHostContext.page, joy-widget.tsx's own hardcoded shape).

Properties

handle
handle: string;
resourceId
resourceId: string;
type
type: string;

JoyInitialDataResult

Properties

account_url
account_url: string;
blob?
blob?: JoyMetafieldBlob;

Beat-1 blob, or undefined on any failure (metafield missing/404, parse error, query error — beat-2-only mode).

core?
core?: WidgetCoreManifest;

The widget core's published build manifest (build.json), read server-side with a one-minute memo. <JoyWidget/> / <JoyLoyaltyPage/> hand it to the client loader so the browser skips its own no-store manifest fetch and can modulepreload the core's entry graph from the HTML (perf H1). Absent on a CDN miss — the client then falls back to its own fetch.

country?
country?: string;

Buyer country for this request (storefront.i18n.country, Liquid: Shopify.country). <JoyWidget/> falls back to it when no country prop is given — it drives free-gift stock and the market the product cards price in.

customer?
customer?: Customer;

The logged-in customer's Joy balance (GET /customer), or undefined for a guest or on any failure.

locale?
locale?: string;

options.locale (else storefront.i18n.language), clamped to a language the shop serves.

login_url
login_url: string;
page
page: JoyInitialDataPage;
register_url
register_url: string;
shopifyCustomer?
shopifyCustomer?: MintedCustomerIdentity;

Thin Shopify Customer Account identity, riding the same query mintJoyToken already ran. undefined for a guest or on mint failure.

token?
token?: string;

The minted JWT — present only when exposeToken is true AND the mint succeeded.


JoyLoyaltyPageData

The source mountLoyaltyPageV2(client, source) (and, eventually, checkLoyaltyPageEligibility) can be built from — the SSR-safe subset of @joy-loyalty/sdk/loyalty-page-contracts's LoyaltyPageHostInput. Deliberately carries NO customer field — see this module's own header (D2).

Properties

core?
core?: WidgetCoreManifest;

The widget core's build.json — see JoyInitialDataResult.core. Lets the page modulepreload the core + loyalty-page chunks from the HTML.

country?
country?: string;

Buyer country for this request (storefront.i18n.country, e.g. US) — the headless stand-in for Liquid's window.Shopify.country, which multi-region referral rewards resolve against. Request/market context, not customer data (D2 holds). Absent when the storefront client carries no i18n.

faqs?
faqs?: JoyLoyaltyPageFaq[];

Already orderBy-sorted, same as the Liquid host's island. undefined only on a fetch failure — a shop with none published gets [], never a missing key.

home?
home?: Omit<JoyMetafieldBlob, "translation" | "shop">;

The REST of the blob, for composeLoyaltyPageHome (D8): getHome() on Liquid is a composite built mostly out of window.AVADA_JOY, so a headless host that forwards only translations/shop leaves the earn/spend/tier sections empty no matter how well the API half works.

translation and shop are EXCLUDED on purpose — they are already the two fields above, and this whole object is serialized into the SSR payload, so carrying them twice would double a translation dictionary in every page's HTML. The client re-attaches them from those fields before composing.

Shop-level only, so this stays inside D2 (no customer data on the SSR path) — the same blob translations/shop already come from.

locale?
locale?: string;

Buyer language as a Shopify locale (storefront.i18n.language PT_BR → pt-BR, Liquid: Shopify.locale) — sent as ?locale= so the member home read returns that language's shop translation. Absent when the storefront client carries no i18n.

shop
shop: Record<string, unknown>;

Same shape as AVADA_JOY.shop in Liquid — the blob's shop field.

structure?
structure?: unknown;

Parsed structure document, or undefined when the shop has none published (or the fetch failed).

translations
translations: Record<string, unknown>;

Same shape as AVADA_JOY.translation in Liquid — the blob's translation field, nested per locale — but PROJECTED to the dictionaries this page can actually use: the resolved request locale and the shop's primary language (the fallback every resolver takes). A five-language shop otherwise ships four dictionaries it never reads in every page's HTML and .data fetch (perf FE M2). Projection only happens when a locale was resolved; without storefront.i18n the full doc passes through unchanged.


JoyLoyaltyPageFaq

One raw FAQ record — same shape the Liquid host's joy-lp-v2-faqs island carries.

Properties

content
content: string;
orderBy?
orderBy?: number;
title
title: string;

Functions

getJoyInitialData()

function getJoyInitialData(options): Promise<JoyInitialDataResult>;

Runs the beat-1 blob read and the logged-in-customer fetch in parallel (Promise.allSettled semantics — see the file header); synthesizes the Layer-2 runtime keys onto the result unconditionally.

🔴 SECURITY — the result carries customer PII (customer = points/tier, shopifyCustomer = name/email, and the JWT when exposeToken is on). Unlike /api/joy-token (which sets its own Cache-Control: private, no-store), THIS helper cannot set headers — it only returns data. Any loader that embeds this result into an SSR response MUST mark that response uncacheable, or a shared cache (CDN, Oxygen's full-page cache, browser back/forward) could serve one shopper's balance and email to the next. Use isJoyInitialDataPersonalized (../cache-control.ts, also re-exported from this /server subpath) rather than re-deriving the same customer/shopifyCustomer/token check:

import {isJoyInitialDataPersonalized, JOY_PERSONALIZED_CACHE_CONTROL} from '@joy-loyalty/hydrogen';
 
const joy = await getJoyInitialData({...});
if (isJoyInitialDataPersonalized(joy)) {
  responseHeaders.set('Cache-Control', JOY_PERSONALIZED_CACHE_CONTROL);
  // AND skip any shared/full-page-cache opt-in (e.g. Oxygen's
  // `Oxygen-Cache-Control`) for this response — a standard `Cache-Control`
  // header alone does not stop Oxygen's proprietary full-page cache.
}

Parameters

ParameterType
optionsGetJoyInitialDataOptions

Returns

Promise<JoyInitialDataResult>


getJoyLoyaltyPageData()

function getJoyLoyaltyPageData(options): Promise<JoyLoyaltyPageData>;

Assemble JoyLoyaltyPageData. Runs the structure+faqs fetch and the blob read in parallel — they are fully independent, so either one failing never blocks or rejects the other (same Promise.all shape as get-joy-initial-data.ts's two halves).

Parameters

ParameterType
optionsGetJoyLoyaltyPageDataOptions

Returns

Promise<JoyLoyaltyPageData>


getWidgetCoreManifest()

function getWidgetCoreManifest(options?): Promise<WidgetCoreManifest | undefined>;

Read (and memoize for a minute) the published core manifest, or undefined on any failure.

Parameters

ParameterType
options?GetWidgetCoreManifestOptions

Returns

Promise<WidgetCoreManifest | undefined>

References

isJoyInitialDataPersonalized

Re-exports isJoyInitialDataPersonalized


JOY_PERSONALIZED_CACHE_CONTROL

Re-exports JOY_PERSONALIZED_CACHE_CONTROL


JoyMetafieldBlob

Re-exports JoyMetafieldBlob


JoyStorefrontClient

Re-exports JoyStorefrontClient


WidgetCoreManifest

Re-exports WidgetCoreManifest