loyalty-page-contracts
Interfaces
LoyaltyPageCartPort
The one cart fact <joy-loyalty-page-v2>'s redeem dialog needs: the
shopper's current cart total, for the max-redeemable clamp
(hasLimitCartValue). Deliberately narrower than @joy-loyalty/sdk/ports'
CartPort (line items, discounts, mutations) — the redeem dialog only ever
reads a total, never mutates the cart, so a host implementing this needs no
write capability at all.
A Hydrogen host can satisfy this by wrapping HydrogenCartPort.getCart()
from @joy-loyalty/hydrogen — note that port's
cost.totalAmount.amount is a decimal-currency STRING (e.g. "12.50"),
while the Shopify Ajax Cart API (original_total_price, what this replaces on
Liquid) is an INTEGER in the smallest currency unit (e.g. 1250). A future
adapter over HydrogenCartPort must convert; this contract only fixes the
unit joy-redeem-detail's cartTotalPrice already expects (cents-like),
not who is responsible for the conversion.
Methods
getTotal()
getTotal(): Promise<number | null>;Resolve the shopper's current cart total, or null when unavailable.
Returns
Promise<number | null>
LoyaltyPageCursorQuery
GET /customer/activities / GET /customer/referral-history cursor params.
Properties
after?
after?: string;before?
before?: string;limit?
limit?: number;LoyaltyPageDataClient
The data-source surface the shared Loyalty Page V2 code needs —
the page's live hydration AND
its click handlers (earn, redeem, milestone,
birthday, newsletter …) — both of which call ctx.joyInstance.<method>(...).
NAMED — and SHAPED — to literally duck-type the real Joy storefront class: the shared code keeps calling
joyInstance.<method>(...) unchanged on Liquid, so a headless
implementation must answer to the SAME method names with the SAME call
shape (positional vs. object args) AND resolve the SAME result shape — a
list method resolves {success, data, pageInfo} (not the unwrapped array),
a bare-payload method resolves the bare payload. A method that answered the
right name with the wrong shape makes every list render empty with no error.
Methods
accountInvite()
accountInvite(input): Promise<never>;No /headless/* route exists for POST /popup/accountInvite. Every
implementation must reject with a clear "not available on headless yet"
error — never invent an endpoint.
Parameters
| Parameter | Type |
|---|---|
input | { email: string; phone: string; } |
input.email | string |
input.phone | string |
Returns
Promise<never>
customerHistory()
customerHistory(query?): Promise<LoyaltyPagePassthroughResult>;Point history — /popup/activities' {data: activity[], pageInfo}. customerId is unused (JWT-scoped).
Parameters
| Parameter | Type |
|---|---|
query? | LoyaltyPageCursorQuery & object |
Returns
Promise<LoyaltyPagePassthroughResult>
generateLinkReferral()
generateLinkReferral(email, options?): Promise<unknown>;Public referral-link generation — no Bearer token. Resolves the bare
payload ({urlReferral, referralCode, …}) or a LoyaltyPageHandledError,
like Joy.generateLinkReferral. options (Liquid attribution hints) are ignored.
Parameters
| Parameter | Type |
|---|---|
email | string |
options? | { path?: string; product?: unknown; useMarketing?: boolean; } |
options.path? | string |
options.product? | unknown |
options.useMarketing? | boolean |
Returns
Promise<unknown>
get()
get(options): Promise<LoyaltyPagePassthroughResult>;Generic GET passthrough — Joy.get({path}). Allowlisted paths only
(/pending-rewards?…); anything else resolves a NOT_IMPLEMENTED failure
envelope rather than being forwarded.
Parameters
| Parameter | Type |
|---|---|
options | { cacheKey?: string; customerId?: string; path: string; } |
options.cacheKey? | string |
options.customerId? | string |
options.path | string |
Returns
Promise<LoyaltyPagePassthroughResult>
getCustomerMilestone()
getCustomerMilestone(params?): Promise<unknown>;{[typeMilestone]: number} — Joy.getCustomerMilestone's bare map — or a LoyaltyPageHandledError. customerId is unused.
Parameters
| Parameter | Type |
|---|---|
params? | { customerId?: string; } |
params.customerId? | string |
Returns
Promise<unknown>
getLoyaltyPageV2Home()
getLoyaltyPageV2Home(params?): Promise<{
applePassWalletSetting: unknown;
customEarnStatus: Record<string, boolean>;
customer: unknown;
rewards?: unknown[];
}>;Composite home read — the network half of the Liquid widget's loyalty page home read:
.../loyalty-page/home, .../loyalty-page/wallet-state,
.../programs/custom-earn-status and (when shouldFetchRewards, default
true) the customer's coupons.
customEarnStatus ({[programId]: boolean}) is returned RAW —
compose-home.ts (@joy-loyalty/hydrogen) merges it into the blob's program list.
rewards is the coupon list the Liquid composite returns under the same
key — the SAME item shape as rewardList()'s
data (raw /popup/rewards docs). [] when not requested or on failure,
never a rejection. Optional in the type only so a caller composing a
guest fallback need not invent it.
Rejects (a JoyApiError, UNAUTHORIZED for a guest) when the home call
itself fails — @joy-loyalty/hydrogen's withHomeComposite relies on that.
Parameters
| Parameter | Type |
|---|---|
params? | { customerId?: string; hasWalletPass?: boolean; shouldFetchRewards?: boolean; } |
params.customerId? | string |
params.hasWalletPass? | boolean |
params.shouldFetchRewards? | boolean |
Returns
Promise<{
applePassWalletSetting: unknown;
customEarnStatus: Record<string, boolean>;
customer: unknown;
rewards?: unknown[];
}>
getTierRewards()
getTierRewards(params?): Promise<LoyaltyPagePassthroughResult>;Every tier joined with its live tierRewards — /popup/tierRewards' {data: tier[]}. Same for guests and members.
Parameters
| Parameter | Type |
|---|---|
params? | { customerId?: string; } |
params.customerId? | string |
Returns
Promise<LoyaltyPagePassthroughResult>
handleEarningProgram()
handleEarningProgram(input): Promise<LoyaltyPageEarnActionResult>;Joy.handleEarningProgram — the one-click earn path. Opens the program's
link (social / survey / visit-page) synchronously, before any await, then
claims where a claim exists. {shouldOpenModal: true} for a program that
needs its detail dialog instead.
Parameters
| Parameter | Type |
|---|---|
input | { customer: unknown; program: unknown; } |
input.customer | unknown |
input.program | unknown |
Returns
Promise<LoyaltyPageEarnActionResult>
post()
post(path, data?): Promise<LoyaltyPagePassthroughResult>;Generic POST passthrough — Joy.post(path, data), the /popup/* path the
shared code names, TRANSLATED onto its /headless/customer/* route (body
and response). Explicit path→route map only; an unmapped path resolves a
NOT_IMPLEMENTED failure envelope — never forwarded. Identity fields in
data (shopId, customerId, shopifyCustomerId) are never sent: the
JWT is the identity.
Parameters
| Parameter | Type |
|---|---|
path | string |
data? | unknown |
Returns
Promise<LoyaltyPagePassthroughResult>
redeem()
redeem(
programId,
points?,
variantIdSelected?,
recipient?
): Promise<unknown>;Spend points on a reward — Joy.redeem(id, points, variantIdSelected, recipient).
Resolves the bare redeem payload ({discount: {id, code}, point, …}) or a
LoyaltyPageHandledError.
Parameters
| Parameter | Type |
|---|---|
programId | string |
points? | number |
variantIdSelected? | string | number |
recipient? | unknown |
Returns
Promise<unknown>
referredHistory()
referredHistory(query?): Promise<LoyaltyPagePassthroughResult>;Referred-friend history — /popup/referred' {data: row[], pageInfo}. customerId is unused (JWT-scoped).
Parameters
| Parameter | Type |
|---|---|
query? | LoyaltyPageCursorQuery & object |
Returns
Promise<LoyaltyPagePassthroughResult>
revokeCoupon()
revokeCoupon(rewardId): Promise<unknown>;Self-revoke a coupon. {success: true, data} or a LoyaltyPageHandledError whose error is the popup's limit code (TIME_LIMIT_EXCEEDED …) when one applies.
Parameters
| Parameter | Type |
|---|---|
rewardId | string |
Returns
Promise<unknown>
rewardList()
rewardList(query?): Promise<LoyaltyPagePassthroughResult>;The customer's coupons — /popup/rewards' {data: reward[], pageInfo}. customerId is unused (JWT-scoped).
Parameters
| Parameter | Type |
|---|---|
query? | LoyaltyPageRewardsQuery & object |
Returns
Promise<LoyaltyPagePassthroughResult>
sendReferralEmail()
sendReferralEmail(input): Promise<unknown>;Email the referral link to a friend. Bare payload or a LoyaltyPageHandledError. emailCustomer is unused (JWT-scoped).
Parameters
| Parameter | Type |
|---|---|
input | { emailCustomer?: string; refereeEmail: string; } |
input.emailCustomer? | string |
input.refereeEmail | string |
Returns
Promise<unknown>
LoyaltyPageEarnActionResult
The result handleEarningProgram resolves — Joy.handleEarningProgram's
shape: status/error for the verdict, plus the three flags
the shared Loyalty Page V2 click handlers branch on.
Indexable
[key: string]: unknownProperties
error?
error?: string;openedLinkOnly?
openedLinkOnly?: boolean;The click only opened the merchant's link; nothing was earned here.
point?
point?: number;Balance after the earn, when one happened.
popupBlocked?
popupBlocked?: boolean;The browser refused to open the program's link.
shouldOpenModal?
shouldOpenModal?: boolean;No earn happens on this click — the caller opens its own detail dialog.
status?
status?: boolean;success?
success?: boolean;LoyaltyPageHandledError
The Liquid storefront widget's handled-failure shape: methods that resolve a BARE
payload on success (redeem, generateLinkReferral, sendReferralEmail,
getCustomerMilestone, handleEarningProgram) resolve this on failure
instead of rejecting, exactly like the Liquid widget — the shared code reads
status === false / error.
Properties
error
error: string;errorCode?
errorCode?: string;status
status: false;success
success: false;LoyaltyPageHostInput
Everything the Liquid host currently gathers into JSON islands + globals
before mountLoyaltyPageV2 paints the page. A headless host assembles the
same shape from its own data layer instead of parsing script tags.
structure is intentionally unknown — its real shape is
LoyaltyPageV2Structure (owned by the Joy backend and the widget core), and this contract must not take on a dependency
that would make it a 3-way merge point between the backend, the widget core,
and every host. Callers pass it through opaquely.
Properties
customer?
customer?: object;The shopper — read by checkLoyaltyPageEligibility and checkLoyaltyPageReferralEligibility.
id?
id?: string | number;isCustomerB2B?
isCustomerB2B?: boolean;tags?
tags?: string | string[];type?
type?: string;faqs?
faqs?: object[];Raw FAQ records, sorted by orderBy (the Liquid host sorts before writing
its joy-lp-v2-faqs island — a caller should do the same, since nothing
downstream re-sorts them).
content
content: string;orderBy?
orderBy?: number;title
title: string;shop
shop: object;API response shop (or the storefront's AVADA_JOY.shop global) — read by checkLoyaltyPageEligibility.
Index Signature
[key: string]: unknowncustomerLoyaltyEligibility?
customerLoyaltyEligibility?: string;structure
structure: unknown;translations
translations: Record<string, unknown>;Same shape as the storefront's AVADA_JOY.translation global — the shared Joy translation key map.
LoyaltyPagePassthroughResult
The {success, data, error} envelope a list/passthrough call resolves with —
the SAME shape the Liquid storefront widget resolves (it returns the raw /popup/*
body). error is a STRING on failure (the popup's own error text), never
the headless {message, code} object — the shared LP V2 code renders it as
a toast verbatim. errorCode carries the headless error code alongside.
pageInfo is present on the cursor-paginated lists.
Indexable
[key: string]: unknownProperties
data?
data?: unknown;error?
error?: unknown;errorCode?
errorCode?: string;pageInfo?
pageInfo?: object;hasNext?
hasNext?: boolean;hasPre?
hasPre?: boolean;success?
success?: boolean;LoyaltyPageRewardsQuery
GET /customer/rewards params — pagination + which coupon bucket.
Properties
after?
after?: string;before?
before?: string;couponStatus?
couponStatus?: "available" | "unavailable";limit?
limit?: number;Type Aliases
LoyaltyPageSkeletonShape
type LoyaltyPageSkeletonShape = "banner" | "split" | "table" | "grid" | "rows" | "panel";Every band shape loyalty-page-v2-skeleton-band.liquid can draw.
'panel' is in the union rather than cast in at the one use site: a host
rendering these shapes writes an exhaustive switch, and a shape hidden
behind a cast compiles clean while rendering the wrong band for
accountDashboard — which is the layout shift the skeleton exists to
prevent, reintroduced by the type that was supposed to rule it out.
Variables
LOYALTY_PAGE_DEFAULT_SECTION_IDS
const LOYALTY_PAGE_DEFAULT_SECTION_IDS: readonly string[];The default page's 11 sections, mirrored from the backend's
LOYALTY_PAGE_V2_DEFAULT_SECTION_IDS. See that file's own comment for why
this is a distinct, non-catalog-ordered list.
LOYALTY_PAGE_SECTION_IDS
const LOYALTY_PAGE_SECTION_IDS: readonly string[];The Loyalty Page V2 section catalog, mirrored from the Joy backend's
section list (LOYALTY_PAGE_V2_SECTION_IDS). The backend module cannot be
imported here, so the 15 values are inlined — loyalty-page-contracts.test.ts asserts this stays in
sync with the backend source.
LOYALTY_PAGE_SKELETON_SHAPES
const LOYALTY_PAGE_SKELETON_SHAPES: Record<string, LoyaltyPageSkeletonShape>;The DEFAULT skeleton shape per section id — what Liquid's
loyalty-page-v2-skeleton-band.liquid draws with no stored structure.content
for that section. Three sections (tiers, earn, redeem) can draw a
DIFFERENT shape depending on merchant-authored layout config; use
resolveLoyaltyPageV2SkeletonShape for the shape that actually
matches a given structure, not this flat map alone.
Functions
checkLoyaltyPageEligibility()
function checkLoyaltyPageEligibility(__namedParameters?): object;Decide whether the loyalty page's personalized sections are visible for this shopper. Translates V1's 5-flag Liquid predicate exactly.
Parameters
| Parameter | Type |
|---|---|
__namedParameters? | { customer?: { id?: string | number; isCustomerB2B?: boolean; tags?: string | string[]; type?: string; }; shop?: { [key: string]: unknown; customerLoyaltyEligibility?: string; }; } |
__namedParameters.customer? | { id?: string | number; isCustomerB2B?: boolean; tags?: string | string[]; type?: string; } |
__namedParameters.customer.id? | string | number |
__namedParameters.customer.isCustomerB2B? | boolean |
__namedParameters.customer.tags? | string | string[] |
__namedParameters.customer.type? | string |
__namedParameters.shop? | { [key: string]: unknown; customerLoyaltyEligibility?: string; } |
__namedParameters.shop.customerLoyaltyEligibility? | string |
Returns
object
personalizedSectionsVisible
personalizedSectionsVisible: boolean;checkLoyaltyPageReferralEligibility()
function checkLoyaltyPageReferralEligibility(__namedParameters?): object;Preserve the three legacy referral blocks' tag-restriction gate after they move from Liquid to the shared V2 web-component adapter. Same rule as the Liquid storefront.
Parameters
| Parameter | Type |
|---|---|
__namedParameters? | { customer?: { id?: string | number; isCustomerB2B?: boolean; tags?: string | string[]; type?: string; }; referralProgram?: { allowedReferralTags?: string[]; restrictReferralAccessByTags?: boolean; }; } |
__namedParameters.customer? | { id?: string | number; isCustomerB2B?: boolean; tags?: string | string[]; type?: string; } |
__namedParameters.customer.id? | string | number |
__namedParameters.customer.isCustomerB2B? | boolean |
__namedParameters.customer.tags? | string | string[] |
__namedParameters.customer.type? | string |
__namedParameters.referralProgram? | { allowedReferralTags?: string[]; restrictReferralAccessByTags?: boolean; } |
__namedParameters.referralProgram.allowedReferralTags? | string[] |
__namedParameters.referralProgram.restrictReferralAccessByTags? | boolean |
Returns
object
referralSectionsVisible
referralSectionsVisible: boolean;resolveLoyaltyPageV2SkeletonShape()
function resolveLoyaltyPageV2SkeletonShape(sectionId, structure): LoyaltyPageSkeletonShape;The skeleton shape Liquid actually draws for sectionId, given structure
— ports loyalty-page-v2-skeleton-band.liquid's {%- case section_id -%}
block (the theme snippet's whole reason for existing: three sections do NOT
draw the two-shape default, and getting this wrong reflows the page the
moment live data arrives). structure is read the same way the Liquid does
(structure.content[sectionId]), so pass the same value given to
LoyaltyPageHostInput.structure.
'panel' (accountDashboard) is a real sixth shape, not one of the five the
interface sketch this file was scoped from listed — the Liquid snippet draws
a distinct panel band for it (its {%- when 'accountDashboard' -%} branch).
LoyaltyPageSkeletonShape carries it in the union for that reason.
Parameters
| Parameter | Type |
|---|---|
sectionId | string |
structure | unknown |