# server

> Source: https://devdocs.joy.so/joy-headless-api/sdk-reference/hydrogen/server/ · Last updated: 2026-11-25

## Interfaces

### GetJoyInitialDataOptions

#### Properties

##### accountUrl?

```ts
accountUrl?: string;
```

Defaults mirror Liquid's `routes.account_url`.

##### apiUrl

```ts
apiUrl: string;
```

Base URL of the Joy Headless API.

##### assetUrl?

```ts
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](#core).

##### customerAccount

```ts
customerAccount: JoyCustomerAccount;
```

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

##### deferCustomerBalance?

```ts
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?

```ts
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?

```ts
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?

```ts
loginUrl?: string;
```

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

##### registerUrl?

```ts
registerUrl?: string;
```

Defaults mirror Liquid's `routes.account_register_url`.

##### request?

```ts
request?: Request;
```

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

##### secret

```ts
secret: string;
```

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

##### shopDomain

```ts
shopDomain: string;
```

The shop's myshopify domain.

##### storefront

```ts
storefront: JoyStorefrontClient;
```

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

***

### GetJoyLoyaltyPageDataOptions

#### Properties

##### apiUrl

```ts
apiUrl: string;
```

Base URL of the Joy Headless API.

##### assetUrl?

```ts
assetUrl?: string;
```

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

##### fetch?

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

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

###### Call Signature

```ts
(input, init?): Promise<Response>;
```

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

###### Parameters

| Parameter | Type                   |
| --------- | ---------------------- |
| `input`   | `URL` \| `RequestInfo` |
| `init?`   | `RequestInit`          |

###### Returns

`Promise`<`Response`>

###### Call Signature

```ts
(input, init?): Promise<Response>;
```

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

###### Parameters

| Parameter | Type                           |
| --------- | ------------------------------ |
| `input`   | `string` \| `URL` \| `Request` |
| `init?`   | `RequestInit`                  |

###### Returns

`Promise`<`Response`>

##### shopDomain

```ts
shopDomain: string;
```

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

##### storefront

```ts
storefront: JoyStorefrontClient;
```

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

***

### GetWidgetCoreManifestOptions

#### Properties

##### assetUrl?

```ts
assetUrl?: string;
```

CDN origin override (`JOY_WIDGET_ASSET_URL`). Defaults to `JOY_CDN_ORIGIN`.

##### fetch?

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

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

###### Call Signature

```ts
(input, init?): Promise<Response>;
```

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

###### Parameters

| Parameter | Type                   |
| --------- | ---------------------- |
| `input`   | `URL` \| `RequestInfo` |
| `init?`   | `RequestInit`          |

###### Returns

`Promise`<`Response`>

###### Call Signature

```ts
(input, init?): Promise<Response>;
```

[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

###### Parameters

| Parameter | Type                           |
| --------- | ------------------------------ |
| `input`   | `string` \| `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

```ts
handle: string;
```

##### resourceId

```ts
resourceId: string;
```

##### type

```ts
type: string;
```

***

### JoyInitialDataResult

#### Properties

##### account_url

```ts
account_url: string;
```

##### blob?

```ts
blob?: JoyMetafieldBlob;
```

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

##### core?

```ts
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?

```ts
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?

```ts
customer?: Customer;
```

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

##### locale?

```ts
locale?: string;
```

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

##### login_url

```ts
login_url: string;
```

##### page

```ts
page: JoyInitialDataPage;
```

##### register_url

```ts
register_url: string;
```

##### shopifyCustomer?

```ts
shopifyCustomer?: MintedCustomerIdentity;
```

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

##### token?

```ts
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?

```ts
core?: WidgetCoreManifest;
```

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

##### country?

```ts
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?

```ts
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?

```ts
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?

```ts
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

```ts
shop: Record<string, unknown>;
```

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

##### structure?

```ts
structure?: unknown;
```

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

##### translations

```ts
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

```ts
content: string;
```

##### orderBy?

```ts
orderBy?: number;
```

##### title

```ts
title: string;
```

## Functions

### getJoyInitialData()

```ts
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:

```ts
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

| Parameter | Type                                                    |
| --------- | ------------------------------------------------------- |
| `options` | [`GetJoyInitialDataOptions`](#getjoyinitialdataoptions) |

#### Returns

`Promise`<[`JoyInitialDataResult`](#joyinitialdataresult)>

***

### getJoyLoyaltyPageData()

```ts
function getJoyLoyaltyPageData(options): Promise<JoyLoyaltyPageData>;
```

Assemble [JoyLoyaltyPageData](#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

| Parameter | Type                                                            |
| --------- | --------------------------------------------------------------- |
| `options` | [`GetJoyLoyaltyPageDataOptions`](#getjoyloyaltypagedataoptions) |

#### Returns

`Promise`<[`JoyLoyaltyPageData`](#joyloyaltypagedata)>

***

### getWidgetCoreManifest()

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

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

#### Parameters

| Parameter  | Type                                                            |
| ---------- | --------------------------------------------------------------- |
| `options?` | [`GetWidgetCoreManifestOptions`](#getwidgetcoremanifestoptions) |

#### Returns

`Promise`<[`WidgetCoreManifest`](https://devdocs.joy.so/joy-headless-api/sdk-reference/hydrogen/root/#widgetcoremanifest) | `undefined`>

## References

### isJoyInitialDataPersonalized

Re-exports [isJoyInitialDataPersonalized](https://devdocs.joy.so/joy-headless-api/sdk-reference/hydrogen/root/#isjoyinitialdatapersonalized)

***

### JOY_PERSONALIZED_CACHE_CONTROL

Re-exports [JOY_PERSONALIZED_CACHE_CONTROL](https://devdocs.joy.so/joy-headless-api/sdk-reference/hydrogen/root/#joy_personalized_cache_control)

***

### JoyMetafieldBlob

Re-exports [JoyMetafieldBlob](https://devdocs.joy.so/joy-headless-api/sdk-reference/hydrogen/lib/metafield-blob/#joymetafieldblob)

***

### JoyStorefrontClient

Re-exports [JoyStorefrontClient](https://devdocs.joy.so/joy-headless-api/sdk-reference/hydrogen/lib/metafield-blob/#joystorefrontclient)

***

### WidgetCoreManifest

Re-exports [WidgetCoreManifest](https://devdocs.joy.so/joy-headless-api/sdk-reference/hydrogen/root/#widgetcoremanifest)
