lib/metafield-blob
Interfaces
JoyBlobShopConfig
The ShopConfig fields the Weaverse blocks consume — the shop's currency,
its money format, its word for points, whether it runs self-serve opt-in
enrollment, and who it lets into the program at all. The first four are
field-for-field the same values /shop-config
derives, including its fallbacks, so a block cannot tell which source served
it; customerLoyaltyEligibility has no /shop-config counterpart and comes
only from the blob.
Properties
currency
currency: string;currencyFormat
currencyFormat: string;customerFreeGiftBehavior
customerFreeGiftBehavior: JoyCustomerFreeGiftBehavior;What the shop does with a redeemed free gift — see JoyCustomerFreeGiftBehavior.
REQUIRED and fail-closed to 'manual_add_to_cart' in
shopConfigFromBlob: an absent or unrecognised value must leave the
shopper pressing the button themselves. The other direction would have a
block put a real product in a real cart off a field its blob predates.
customerLoyaltyEligibility
customerLoyaltyEligibility: JoyCustomerLoyaltyEligibility;Who the shop admits to the program — see
JoyCustomerLoyaltyEligibility. REQUIRED for the same reason
optInEnrollmentEnabled is: shopConfigFromBlob resolves an absent
or unrecognised value to 'customer_eligible_all' in one place, so no
block has to decide what a missing gate means.
facebookPageId
facebookPageId: string | null;The Facebook Page the shop has connected — top-level blob.facebookPageId,
present ONLY when the shop wired a Facebook integration (the backend
writes it conditionally). The visible half of
the m.me/{facebookPageId}?ref=... Messenger link the comment_facebook
modal builds; null when unset, and the modal falls back to its plain
"visit our page" link. Pair with CustomerSocial.facebookConnected.
isNewFormatDOB
isNewFormatDOB: boolean;Whether the shop's birthday form collects a YEAR as well as day/month —
shop.isNewFormatDOB, the same field /shop-config publishes under this
name, and the backend
gates the widget's own two birthday screens on.
REQUIRED and coerced in shopConfigFromBlob, the same shape
optInEnrollmentEnabled has, and fail-closed for a sharper reason: a block
that guesses this one wrong asks a shopper for a birth year the merchant
chose not to collect.
optInEnrollmentEnabled
optInEnrollmentEnabled: boolean;Whether the shop runs the self-serve "opt-in" enrollment flow — half of the
join gate, Customer.type is the other half.
REQUIRED, not optional: the blob's own shop.optInEnrollmentEnabled is
what may be absent (a shop whose metafield predates the field), and
shopConfigFromBlob collapses that absence to false right there.
Making it optional here would push the same fail-closed coercion onto every
block instead, which is how one of them eventually forgets and shows a Join
button the server then refuses.
pointLabel
pointLabel: object;plural
plural: string;singular
singular: string;shopId
shopId: string | null;The shop's own id — top-level blob.shopId, always present. It is the HMAC
KEY (and the sid claim) for the Facebook Messenger "connect" ref link the
comment_facebook modal builds in the browser — see
generateFacebookRefLink and earn-modal.tsx's renderFacebook. Not
a server secret: shopId is a plaintext value the same blob already ships,
which is why no signing endpoint is involved. null only when the metafield
is malformed (a string is expected); the modal then hides its Connect button
rather than build an unsignable link.
JoyStorefrontClient
Structural type for the merchant's Storefront API client
(context.storefront in a Hydrogen loader, weaverse.storefront in a
Weaverse component loader). Deliberately NOT the real @shopify/hydrogen
Storefront generic — this package treats @shopify/hydrogen as an
optional peer (see hydrogen-cart-port.ts's CartForm import for the one
place it's a hard dependency); a structural type keeps this file buildable
without it.
Properties
CacheCustom?
CacheCustom?: (strategy) => unknown;Hydrogen's cache-strategy factory — optional so a bare {query} stub still satisfies the type.
Parameters
| Parameter | Type |
|---|---|
strategy | { maxAge?: number; mode?: string; staleWhileRevalidate?: number; } |
strategy.maxAge? | number |
strategy.mode? | string |
strategy.staleWhileRevalidate? | number |
Returns
unknown
i18n?
i18n?: object;Hydrogen's request localization (storefront.i18n) — optional, only read where a caller needs the buyer's market.
country?
country?: string;language?
language?: string;Methods
query()
query(query, options?): Promise<unknown>;Parameters
| Parameter | Type |
|---|---|
query | string |
options? | unknown |
Returns
Promise<unknown>
Type Aliases
JoyCustomerFreeGiftBehavior
type JoyCustomerFreeGiftBehavior =
| "manual_add_to_cart"
| "auto_add_to_cart"
| "auto_add_to_cart_drawer_hide_modal";What the shop does with a free gift the moment its reward is redeemed —
settings.customerFreeGiftBehavior. The two auto_ values both mean
"put the gift in the cart without asking"; they differ only in what the
widget does with its own modal afterwards, which is why every gate in the
theme tests them with an includes over BOTH.
A union rather than string for the same reason
JoyCustomerLoyaltyEligibility is one: a typo in a block comparison
has to be a compile error, not a gift that silently never reaches the cart.
JoyCustomerLoyaltyEligibility
type JoyCustomerLoyaltyEligibility =
| "customer_eligible_all"
| "exclude_b2b_customers"
| "manually_assigned_only";Who the shop lets into its loyalty program — the shop-side half of the
visibility gate the Joy theme app extension applies to 19 of its 21 Liquid
blocks. The three values are the whole set; a union rather than string so a typo in a block
comparison is a compile error rather than a gate that silently never fires.
JoyMetafieldBlob
type JoyMetafieldBlob = Record<string, unknown>;The joy_loyalty_avada/data shop metafield blob — the exact shape
window.AVADA_JOY carries in Liquid (shop flags, shopId, settings,
program, allTiers, translation, …). Loosely typed here; only the
façade needs to know its full shape, and re-declaring updateMetaFieldJoy's
~30 keys in this package would be a drift bomb.
Functions
fetchMetafieldBlob()
function fetchMetafieldBlob(storefront): Promise<JoyMetafieldBlob | undefined>;Read + parse the shop metafield. Never throws — a missing metafield, a query
error, or a non-JSON/non-object value all resolve undefined.
Parameters
| Parameter | Type |
|---|---|
storefront | JoyStorefrontClient |
Returns
Promise<JoyMetafieldBlob | undefined>
getJoyMetafieldBlob()
function getJoyMetafieldBlob(storefront): Promise<JoyMetafieldBlob | undefined>;The whole blob, read at most ONCE per request — what getJoyInitialData
seeds the popup from. Each caller gets its own copy, so the popup and the
blocks cannot corrupt each other through it (file header). Never throws.
Parameters
| Parameter | Type |
|---|---|
storefront | JoyStorefrontClient |
Returns
Promise<JoyMetafieldBlob | undefined>
getJoyShopConfig()
function getJoyShopConfig(storefront): Promise<JoyBlobShopConfig | undefined>;The blob's shop-config subset, off that same single read — what the Weaverse blocks consume. Never throws.
Parameters
| Parameter | Type |
|---|---|
storefront | JoyStorefrontClient |
Returns
Promise<JoyBlobShopConfig | undefined>
shopConfigFromBlob()
function shopConfigFromBlob(blob): JoyBlobShopConfig | undefined;Project the blob onto JoyBlobShopConfig. currency/moneyFormat
live on the blob's shop and
pointSingular/pointPlural on its settings (preserved
verbatim through the V3→V4 settings migration) — the same two documents
/shop-config reads, so the fallbacks below are its fallbacks.
optInEnrollmentEnabled sits on shop too, but is COMPUTED server-side
(by the same opt-in check
/shop-config uses) rather than picked, so this package never re-derives
the plan-tier rule behind it.
undefined in (no metafield) means undefined out.
Parameters
| Parameter | Type |
|---|---|
blob | JoyMetafieldBlob | undefined |
Returns
JoyBlobShopConfig | undefined