@joy-loyalty/hydrogen 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +167 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/lib/core-loader.d.ts +32 -0
- package/dist/lib/points-calculator-snapshot.d.ts +155 -0
- package/dist/lib/points-calculator-snapshot.js +139 -0
- package/dist/lib/submit-form-visibility.d.ts +2 -0
- package/dist/lib/submit-form-visibility.js +15 -0
- package/dist/loyalty-page/compose-home.js +2 -1
- package/dist/points-calculator/JoyPointsCalculator.d.ts +29 -0
- package/dist/points-calculator/JoyPointsCalculator.js +377 -0
- package/dist/points-calculator/fragments.d.ts +7 -0
- package/dist/points-calculator/fragments.js +150 -0
- package/dist/render-adapter.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -204,6 +204,173 @@ fragment JoyRedeemCartModern on Cart {
|
|
|
204
204
|
or mount failure collapses the block and warns once.
|
|
205
205
|
- **Not yet supported:** the "prefer higher-value reward" swap setting (planned for v1.1).
|
|
206
206
|
|
|
207
|
+
### Points calculator (`<JoyPointsCalculator/>`)
|
|
208
|
+
|
|
209
|
+
The headless counterpart of the Liquid "Joy: Point calculator" block: the "Earn X points" estimate
|
|
210
|
+
on the product page, and the cart total's estimate on the cart page or drawer. The estimate is
|
|
211
|
+
computed in the widget core from the same program data the Liquid block reads, so the numbers match.
|
|
212
|
+
`context` is explicit (`"product"` or `"cart"`); anything else renders nothing and warns once.
|
|
213
|
+
|
|
214
|
+
Product page — pass the Storefront product, the selected variant and the quantity state:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
import {JoyPointsCalculator} from '@joy-loyalty/hydrogen';
|
|
218
|
+
|
|
219
|
+
<JoyPointsCalculator
|
|
220
|
+
apiUrl={data.joyApiUrl}
|
|
221
|
+
shopDomain={data.joyShopDomain}
|
|
222
|
+
initialData={data.joy}
|
|
223
|
+
context="product"
|
|
224
|
+
product={product}
|
|
225
|
+
selectedVariant={selectedVariant}
|
|
226
|
+
quantity={quantity}
|
|
227
|
+
customerTags={data.joyPoints.customerTags}
|
|
228
|
+
isB2B={data.joyPoints.isB2B}
|
|
229
|
+
isLoggedIn={data.joyPoints.isLoggedIn}
|
|
230
|
+
/>;
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Cart page or drawer — pass the cart (or rely on `<JoyProvider cart>`); one component for both, cart total only:
|
|
234
|
+
|
|
235
|
+
```tsx
|
|
236
|
+
<JoyPointsCalculator
|
|
237
|
+
apiUrl={root.joyApiUrl}
|
|
238
|
+
shopDomain={root.joyShopDomain}
|
|
239
|
+
initialData={root.joy}
|
|
240
|
+
context="cart"
|
|
241
|
+
cart={cart}
|
|
242
|
+
customerTags={root.joyPoints.customerTags}
|
|
243
|
+
isB2B={root.joyPoints.isB2B}
|
|
244
|
+
isLoggedIn={root.joyPoints.isLoggedIn}
|
|
245
|
+
/>;
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Customer input (host contract).** Customer tags and the B2B flag live in Shopify, not in Joy, so
|
|
249
|
+
the host supplies them. In the loader that calls `getJoyInitialData`, for a logged-in customer run
|
|
250
|
+
the Customer Account query and pass the result through `toJoyPointsCustomerInput`; pass
|
|
251
|
+
`isLoggedIn` for **every** visitor:
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import {
|
|
255
|
+
JOY_POINTS_CUSTOMER_ACCOUNT_QUERY,
|
|
256
|
+
toJoyPointsCustomerInput,
|
|
257
|
+
} from '@joy-loyalty/hydrogen';
|
|
258
|
+
|
|
259
|
+
const isLoggedIn = await context.customerAccount.isLoggedIn();
|
|
260
|
+
// Never let this optional query throw into the root loader (an outage would take the whole page down),
|
|
261
|
+
// and run it in parallel with getJoyInitialData.
|
|
262
|
+
const [joy, account] = await Promise.all([
|
|
263
|
+
getJoyInitialData({/* … as above … */}),
|
|
264
|
+
isLoggedIn
|
|
265
|
+
? context.customerAccount.query(JOY_POINTS_CUSTOMER_ACCOUNT_QUERY).catch(() => null)
|
|
266
|
+
: null,
|
|
267
|
+
]);
|
|
268
|
+
const {customerTags, isB2B} = isLoggedIn
|
|
269
|
+
? toJoyPointsCustomerInput(account?.data?.customer)
|
|
270
|
+
: {customerTags: undefined, isB2B: undefined};
|
|
271
|
+
return {joy, joyPoints: {customerTags, isB2B, isLoggedIn}};
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
If the query fails, `customerTags` / `isB2B` are `undefined` and `isLoggedIn` stays `true`: the block
|
|
275
|
+
degrades as documented below instead of breaking the page.
|
|
276
|
+
|
|
277
|
+
- `isLoggedIn` lets the block **hide** (instead of showing guest numbers) when the Joy token mint
|
|
278
|
+
fails for a logged-in shopper.
|
|
279
|
+
- Never pass `customerTags` / `isB2B` for a guest: when `isLoggedIn` is omitted they imply "logged in".
|
|
280
|
+
- This is personalized data in your root loader — same cache rule as the rest of the logged-in
|
|
281
|
+
root data (see [Caching](#caching)). Nothing personal is rendered on the server: the block emits
|
|
282
|
+
only a small reserved placeholder and reads customer inputs after hydration.
|
|
283
|
+
|
|
284
|
+
| Prop | Type | Required | Notes |
|
|
285
|
+
|---|---|---|---|
|
|
286
|
+
| `apiUrl` | `string` | yes | Headless API base URL (`JOY_API_URL`). Used for "Join Program". |
|
|
287
|
+
| `shopDomain` | `string` | yes | The shop's `*.myshopify.com` domain. |
|
|
288
|
+
| `initialData` | `JoyInitialDataResult \| null` | yes | The root loader's `getJoyInitialData()` result. `null` → renders nothing. |
|
|
289
|
+
| `context` | `'product' \| 'cart'` | yes | Where the block lives. Explicit, never inferred. |
|
|
290
|
+
| `product` | `PointsStorefrontProduct \| null` | product | Storefront product (`JoyPointsProduct` fragment). |
|
|
291
|
+
| `selectedVariant` | `PointsStorefrontVariant \| null` | product | Selected variant (`JoyPointsVariant` fragment). |
|
|
292
|
+
| `quantity` | `number` | no | Quantity picked on the page; default 1. |
|
|
293
|
+
| `sellingPlanId` | `string \| null` | no | Selected selling plan GID; none → one-time purchase. |
|
|
294
|
+
| `cart` | `StorefrontCart \| () => StorefrontCart` | cart | Storefront cart (needs `JoyPointsCartLine`); falls back to `<JoyProvider cart>`. |
|
|
295
|
+
| `customerTags` | `string[]` | no | Customer Account `customer.tags` (logged-in only). |
|
|
296
|
+
| `isB2B` | `boolean` | no | Customer has a company contact (logged-in only). |
|
|
297
|
+
| `isLoggedIn` | `boolean` | no | `await customerAccount.isLoggedIn()` — pass for guests too (`false`). |
|
|
298
|
+
| `align` | `'left' \| 'center' \| 'right'` | no | Default left (as the Liquid block). Read at mount. |
|
|
299
|
+
| `loginUrl` | `string` | no | Fallback join/login target; the merchant's "Call to action link" wins, then this, then `initialData.login_url`, then `/account/login`. |
|
|
300
|
+
| `tokenRoute` | `string` | no | Default `/api/joy-token`. |
|
|
301
|
+
| `onNavigate` | `(url) => void` | no | `useNavigate()`; else a full page load. |
|
|
302
|
+
| `onJoinClick` | `(action) => boolean \| void` | no | Called before a join click is handled; return `true` to take over. |
|
|
303
|
+
| `assetUrl` | `string` | no | Override the widget-core CDN URL. |
|
|
304
|
+
| `className` | `string` | no | Wrapper div CSS class. |
|
|
305
|
+
|
|
306
|
+
**Fragments.** Spread them into your own queries (exported from the package root):
|
|
307
|
+
|
|
308
|
+
- `JOY_POINTS_PRODUCT_FRAGMENT` (on `Product`) and `JOY_POINTS_VARIANT_FRAGMENT` (on the selected
|
|
309
|
+
`ProductVariant`) in the product-page query.
|
|
310
|
+
- `JOY_POINTS_CART_LINE_FRAGMENT` spread **inside** your existing
|
|
311
|
+
`lines(first: $numCartLines) { nodes { … } }` — there is no Cart-level fragment with its own
|
|
312
|
+
`lines`. It and the product fragment select product `title` and `priceRange`, which the
|
|
313
|
+
engine uses; without `priceRange` the line/variant price is used.
|
|
314
|
+
- `collections(first: 20)` must stay 20 — it merges with the redeem-cart fragment's selection.
|
|
315
|
+
- **Cart-level discounts (required for `context="cart"`).** The line fragment carries only the
|
|
316
|
+
line-level allocations. Also select, on the `Cart`, `discountCodes { code applicable }` and the
|
|
317
|
+
order-level allocations — the same fields as the redeem-cart fragment above:
|
|
318
|
+
- default API (2025-10 → 2026-10): `Cart.discountAllocations { targetType discountedAmount { amount currencyCode } ... on CartCodeDiscountAllocation { code } }`;
|
|
319
|
+
- modern (2026-07+): `joyAllDiscounts: discountAllocations(lineLevelOnly: false) { … }` on each `CartLine`.
|
|
320
|
+
|
|
321
|
+
Without one of these two sources the calculator **hides** (one `[joy] JoyPointsCalculator: …`
|
|
322
|
+
warning) — whether or not a discount code is applied, because an automatic order discount
|
|
323
|
+
(no code) is only visible through them. It never shows a wrong estimate.
|
|
324
|
+
- Optional: `JOY_POINTS_VARIANT_SELLING_PLANS_FRAGMENT` / `JOY_POINTS_CART_LINE_SELLING_PLAN_FRAGMENT`
|
|
325
|
+
need the `unauthenticated_read_selling_plans` Storefront scope; without them subscription lines
|
|
326
|
+
count as one-time purchases.
|
|
327
|
+
- `JOY_POINTS_CUSTOMER_ACCOUNT_QUERY` (Customer Account API) as shown above.
|
|
328
|
+
- Don't wrap the query in `useAwaitableOptions`.
|
|
329
|
+
|
|
330
|
+
**Join button.** A guest's button: with the Joy setting `customerPointCalculatorBehavior = open widget`
|
|
331
|
+
it opens the widget via `#joy-open` (needs `<JoyWidget/>` mounted; otherwise it navigates to the
|
|
332
|
+
login URL). A logged-in shopper who has not joined sees "Join Program", which calls
|
|
333
|
+
`POST /customer/join-program` (`joinFrom: product_page`) and reloads on success. `onJoinClick`
|
|
334
|
+
returning `true` overrides both.
|
|
335
|
+
|
|
336
|
+
**Differences from the Liquid block**
|
|
337
|
+
|
|
338
|
+
- V4 look (Lit web component), no counting animation. The icon (preset type, custom `urlIcon` —
|
|
339
|
+
http(s) only — and `iconSize`) and the text size follow the admin settings like Liquid; the gap
|
|
340
|
+
between icon and text is the component's 12px (Liquid: 10px).
|
|
341
|
+
- HTML in the merchant's calculator texts is shown as plain text (tags stripped; entities such as
|
|
342
|
+
`&` / ` ` decoded).
|
|
343
|
+
- Hidden when the cart/buyer currency differs from the shop's base currency (no market-rate
|
|
344
|
+
conversion yet).
|
|
345
|
+
- Cart: one estimate for the cart total — no per-cart-line estimate.
|
|
346
|
+
- The Joy free-gift residue (`shop.freeGiftMinUnitPrice`; DisplayManager `getCartWithoutJoyGiftResidue`)
|
|
347
|
+
is not applied in headless: a cart with a Joy free-gift line can read about one minor unit per gift
|
|
348
|
+
line higher than the Liquid block.
|
|
349
|
+
- Products in more than 20 collections may differ from Liquid (`collections(first: 20)`).
|
|
350
|
+
- Without the cart-line fragment, rules scoped to products/collections/tags are not matched on cart lines.
|
|
351
|
+
- A logged-in shopper whose Joy balance is not loaded (`deferCustomerBalance: true`, or the
|
|
352
|
+
`/customer` read failed) → the block is hidden with one warning; it is never shown with guest numbers.
|
|
353
|
+
- Customer-tag rules, hiding for `joy_customer_left_programs` and the B2B exclusion
|
|
354
|
+
(`exclude_b2b_customers`) need the host to pass `customerTags` / `isB2B`. Without them, tag rules
|
|
355
|
+
evaluate with no tags and B2B customers are not hidden (one warning on `exclude_b2b_customers` shops).
|
|
356
|
+
- A logged-in shopper whose Joy token mint fails → hidden with one warning, **only if** the host
|
|
357
|
+
passes `isLoggedIn` (or `customerTags` / `isB2B`). With none of them, the block shows the guest copy in
|
|
358
|
+
that one state.
|
|
359
|
+
- The join/login link uses the merchant's "Call to action link" (`callActionLink`) first and the
|
|
360
|
+
`loginUrl` prop only when it is empty. Merchant custom login redirects are not applied — use
|
|
361
|
+
`onJoinClick` to override.
|
|
362
|
+
- Default alignment is left on both the product page and the cart, like the Liquid block.
|
|
363
|
+
- No Weaverse block in v1 — use the component directly.
|
|
364
|
+
|
|
365
|
+
**Requirements**
|
|
366
|
+
|
|
367
|
+
- **Backend.** The partial earning-limit cap and the segment/"left" exclusion need a Joy backend
|
|
368
|
+
whose `GET /customer` returns `earningLimit.remainingCapacity` and `excludedFromLoyalty`
|
|
369
|
+
(released before this package). An older backend degrades to "no partial cap / not excluded";
|
|
370
|
+
the page is never affected.
|
|
371
|
+
- **Widget core.** Requires a core with `loadPointsCalculatorCore`. Against an older core the block
|
|
372
|
+
renders nothing and logs one `[joy] JoyPointsCalculator: …` warning. It never throws into your page.
|
|
373
|
+
|
|
207
374
|
## Optional resource routes
|
|
208
375
|
|
|
209
376
|
Each is a one-line re-export; the widget degrades gracefully without them.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export type { JoyLoyaltyPageInitialData, JoyLoyaltyPageProps } from './loyalty-p
|
|
|
5
5
|
export { JoyRedeemCart } from './redeem-cart/JoyRedeemCart.js';
|
|
6
6
|
export type { JoyRedeemCartProps } from './redeem-cart/JoyRedeemCart.js';
|
|
7
7
|
export type { StorefrontCart } from './hydrogen-cart-port.js';
|
|
8
|
+
export { JoyPointsCalculator } from './points-calculator/JoyPointsCalculator.js';
|
|
9
|
+
export type { JoyPointsCalculatorProps } from './points-calculator/JoyPointsCalculator.js';
|
|
10
|
+
export { toJoyPointsCustomerInput } from './lib/points-calculator-snapshot.js';
|
|
11
|
+
export { JOY_POINTS_CART_LINE_FRAGMENT, JOY_POINTS_CART_LINE_SELLING_PLAN_FRAGMENT, JOY_POINTS_CUSTOMER_ACCOUNT_QUERY, JOY_POINTS_CUSTOMER_FRAGMENT, JOY_POINTS_PRODUCT_FRAGMENT, JOY_POINTS_VARIANT_FRAGMENT, JOY_POINTS_VARIANT_SELLING_PLANS_FRAGMENT } from './points-calculator/fragments.js';
|
|
8
12
|
export { createHeadlessHostAdapter, createJoyDataSource } from './headless-host-adapter.js';
|
|
9
13
|
export type { ActivityQuery, DataCapabilities, EarnRequest, HeadlessHostAdapter, HeadlessHostAdapterOptions, HeadlessHostContext, HeadlessDataPort, JoyDataSource, JoyInitialData, RedeemOptions, RedeemRecipient, ReferralHistoryItem, ReferralHistoryPage, RewardQuery } from './headless-host-adapter.js';
|
|
10
14
|
export { JOY_API_ORIGIN, JOY_CDN_ORIGIN, JOY_CSP_DIRECTIVES, joyCspDirectives } from './csp.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { JoyWidget } from './joy-widget.js';
|
|
2
2
|
export { JoyLoyaltyPage, isLoyaltyPageV2Enabled } from './loyalty-page/JoyLoyaltyPage.js';
|
|
3
3
|
export { JoyRedeemCart } from './redeem-cart/JoyRedeemCart.js';
|
|
4
|
+
export { JoyPointsCalculator } from './points-calculator/JoyPointsCalculator.js';
|
|
5
|
+
export { toJoyPointsCustomerInput } from './lib/points-calculator-snapshot.js';
|
|
6
|
+
export { JOY_POINTS_CART_LINE_FRAGMENT, JOY_POINTS_CART_LINE_SELLING_PLAN_FRAGMENT, JOY_POINTS_CUSTOMER_ACCOUNT_QUERY, JOY_POINTS_CUSTOMER_FRAGMENT, JOY_POINTS_PRODUCT_FRAGMENT, JOY_POINTS_VARIANT_FRAGMENT, JOY_POINTS_VARIANT_SELLING_PLANS_FRAGMENT } from './points-calculator/fragments.js';
|
|
4
7
|
export { createHeadlessHostAdapter, createJoyDataSource } from './headless-host-adapter.js';
|
|
5
8
|
export { JOY_API_ORIGIN, JOY_CDN_ORIGIN, JOY_CSP_DIRECTIVES, joyCspDirectives } from './csp.js';
|
|
6
9
|
export { JOY_PERSONALIZED_CACHE_CONTROL, isJoyInitialDataPersonalized } from './cache-control.js';
|
|
@@ -36,6 +36,9 @@ export interface WidgetCoreExports {
|
|
|
36
36
|
loadRedeemCartCore?: () => Promise<{
|
|
37
37
|
mountRedeemCartCore: MountRedeemCartCore;
|
|
38
38
|
}>;
|
|
39
|
+
loadPointsCalculatorCore?: () => Promise<{
|
|
40
|
+
mountPointsCalculatorCore: MountPointsCalculatorCore;
|
|
41
|
+
}>;
|
|
39
42
|
[key: string]: unknown;
|
|
40
43
|
}
|
|
41
44
|
export interface RedeemCartCoreHandle {
|
|
@@ -58,6 +61,35 @@ export type MountRedeemCartCore = (el: HTMLElement, options: {
|
|
|
58
61
|
navigate: (url: string) => void;
|
|
59
62
|
};
|
|
60
63
|
}) => RedeemCartCoreHandle | Promise<RedeemCartCoreHandle>;
|
|
64
|
+
export type PointsCalculatorCoreHandle = RedeemCartCoreHandle;
|
|
65
|
+
export type MountPointsCalculatorCore = (el: HTMLElement, options: {
|
|
66
|
+
source: {
|
|
67
|
+
blob: unknown;
|
|
68
|
+
customer: unknown;
|
|
69
|
+
customerKey: string | null;
|
|
70
|
+
translation: Record<string, string>;
|
|
71
|
+
locale: string;
|
|
72
|
+
loginUrl: string;
|
|
73
|
+
isLoggedIn: boolean;
|
|
74
|
+
customerTags?: string[];
|
|
75
|
+
isB2B?: boolean;
|
|
76
|
+
};
|
|
77
|
+
context: 'product' | 'cart';
|
|
78
|
+
getSnapshot: () => unknown;
|
|
79
|
+
align?: 'left' | 'center' | 'right';
|
|
80
|
+
client: {
|
|
81
|
+
joinProgram: (joinFrom: 'product_page') => Promise<unknown>;
|
|
82
|
+
} | null;
|
|
83
|
+
hooks: {
|
|
84
|
+
navigate: (url: string) => void;
|
|
85
|
+
openWidget: () => boolean;
|
|
86
|
+
reload: () => void;
|
|
87
|
+
onJoinClick?: (action: {
|
|
88
|
+
kind: 'open_widget' | 'login' | 'join_program';
|
|
89
|
+
href: string;
|
|
90
|
+
}) => boolean | void | Promise<boolean | void>;
|
|
91
|
+
};
|
|
92
|
+
}) => PointsCalculatorCoreHandle | Promise<PointsCalculatorCoreHandle>;
|
|
61
93
|
export interface LoadWidgetCoreOptions {
|
|
62
94
|
assetUrl?: string;
|
|
63
95
|
core?: WidgetCoreManifest | null;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { CartLine, StorefrontCart } from '../hydrogen-cart-port.js';
|
|
2
|
+
type StorefrontMoney = {
|
|
3
|
+
amount?: string | null;
|
|
4
|
+
currencyCode?: string | null;
|
|
5
|
+
};
|
|
6
|
+
type StorefrontCollections = {
|
|
7
|
+
nodes?: Array<{
|
|
8
|
+
id?: string | null;
|
|
9
|
+
title?: string | null;
|
|
10
|
+
} | null> | null;
|
|
11
|
+
pageInfo?: {
|
|
12
|
+
hasNextPage?: boolean | null;
|
|
13
|
+
} | null;
|
|
14
|
+
} | null;
|
|
15
|
+
export type PointsProductVariant = {
|
|
16
|
+
id: number;
|
|
17
|
+
price: number;
|
|
18
|
+
compare_at_price: number | null;
|
|
19
|
+
selling_plan_allocations: Array<{
|
|
20
|
+
selling_plan_id: number;
|
|
21
|
+
price: number;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
export type PointsProductLine = {
|
|
25
|
+
id: number;
|
|
26
|
+
title: string;
|
|
27
|
+
price: number;
|
|
28
|
+
tags: string[];
|
|
29
|
+
type: string;
|
|
30
|
+
vendor: string;
|
|
31
|
+
collections: string[];
|
|
32
|
+
collectionIds: number[];
|
|
33
|
+
collectionDetails: Array<{
|
|
34
|
+
id: number;
|
|
35
|
+
title: string;
|
|
36
|
+
}>;
|
|
37
|
+
variants: PointsProductVariant[];
|
|
38
|
+
};
|
|
39
|
+
export type PointsCartLine = {
|
|
40
|
+
product_id: number;
|
|
41
|
+
id: number;
|
|
42
|
+
title: string;
|
|
43
|
+
price: number;
|
|
44
|
+
tags: string[];
|
|
45
|
+
vendor: string;
|
|
46
|
+
type: string;
|
|
47
|
+
collections: string[];
|
|
48
|
+
collectionIds: number[];
|
|
49
|
+
collectionDetails: Array<{
|
|
50
|
+
id: number;
|
|
51
|
+
title: string;
|
|
52
|
+
}>;
|
|
53
|
+
quantity: number;
|
|
54
|
+
variant_id: number;
|
|
55
|
+
final_line_price: number;
|
|
56
|
+
variant_compare_at_price: number | null;
|
|
57
|
+
has_selling_plan: boolean;
|
|
58
|
+
};
|
|
59
|
+
export type PointsSnapshot = {
|
|
60
|
+
surface: 'product' | 'cart';
|
|
61
|
+
moneyUnit: 'cents' | 'units';
|
|
62
|
+
currency: {
|
|
63
|
+
active: string;
|
|
64
|
+
rate: number;
|
|
65
|
+
};
|
|
66
|
+
localePrimary?: boolean;
|
|
67
|
+
now: Date | string | number;
|
|
68
|
+
product?: PointsProductLine;
|
|
69
|
+
selectedVariantId?: number;
|
|
70
|
+
quantity?: number;
|
|
71
|
+
sellingPlanId?: number | null;
|
|
72
|
+
unitPriceOverride?: number | null;
|
|
73
|
+
cart?: {
|
|
74
|
+
items: PointsCartLine[];
|
|
75
|
+
totalDiscount: number;
|
|
76
|
+
lineLevelDiscounts: number[];
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export type PointsStorefrontProduct = {
|
|
80
|
+
id?: string | null;
|
|
81
|
+
title?: string | null;
|
|
82
|
+
tags?: string[] | null;
|
|
83
|
+
vendor?: string | null;
|
|
84
|
+
productType?: string | null;
|
|
85
|
+
priceRange?: {
|
|
86
|
+
minVariantPrice?: StorefrontMoney | null;
|
|
87
|
+
} | null;
|
|
88
|
+
collections?: StorefrontCollections;
|
|
89
|
+
};
|
|
90
|
+
export type PointsStorefrontVariant = {
|
|
91
|
+
id?: string | null;
|
|
92
|
+
price?: StorefrontMoney | null;
|
|
93
|
+
compareAtPrice?: StorefrontMoney | null;
|
|
94
|
+
sellingPlanAllocations?: {
|
|
95
|
+
nodes?: Array<{
|
|
96
|
+
sellingPlan?: {
|
|
97
|
+
id?: string | null;
|
|
98
|
+
} | null;
|
|
99
|
+
checkoutChargeAmount?: StorefrontMoney | null;
|
|
100
|
+
priceAdjustments?: Array<{
|
|
101
|
+
price?: StorefrontMoney | null;
|
|
102
|
+
} | null> | null;
|
|
103
|
+
} | null> | null;
|
|
104
|
+
} | null;
|
|
105
|
+
};
|
|
106
|
+
export type PointsStorefrontCartLine = CartLine & {
|
|
107
|
+
merchandise?: {
|
|
108
|
+
price?: StorefrontMoney | null;
|
|
109
|
+
compareAtPrice?: StorefrontMoney | null;
|
|
110
|
+
product?: PointsStorefrontProduct | null;
|
|
111
|
+
} | null;
|
|
112
|
+
cost?: {
|
|
113
|
+
compareAtAmountPerQuantity?: StorefrontMoney | null;
|
|
114
|
+
} | null;
|
|
115
|
+
sellingPlanAllocation?: {
|
|
116
|
+
sellingPlan?: {
|
|
117
|
+
id?: string | null;
|
|
118
|
+
} | null;
|
|
119
|
+
} | null;
|
|
120
|
+
};
|
|
121
|
+
export type PointsAccountCustomer = {
|
|
122
|
+
tags?: string[] | null;
|
|
123
|
+
companyContacts?: {
|
|
124
|
+
nodes?: Array<{
|
|
125
|
+
id?: string | null;
|
|
126
|
+
} | null> | null;
|
|
127
|
+
} | null;
|
|
128
|
+
};
|
|
129
|
+
export type PointsProductSnapshotInput = {
|
|
130
|
+
product: PointsStorefrontProduct | null | undefined;
|
|
131
|
+
selectedVariant: PointsStorefrontVariant | null | undefined;
|
|
132
|
+
quantity?: number | null;
|
|
133
|
+
sellingPlanId?: string | number | null;
|
|
134
|
+
localePrimary?: boolean;
|
|
135
|
+
};
|
|
136
|
+
export declare function normalizePointsProductSnapshot({ product, selectedVariant, quantity, sellingPlanId, localePrimary }: PointsProductSnapshotInput): {
|
|
137
|
+
snapshot: PointsSnapshot;
|
|
138
|
+
currency: string | null;
|
|
139
|
+
} | null;
|
|
140
|
+
export declare function normalizePointsCartSnapshot(cart: (StorefrontCart & {
|
|
141
|
+
lines?: {
|
|
142
|
+
nodes?: PointsStorefrontCartLine[] | null;
|
|
143
|
+
} | null;
|
|
144
|
+
}) | null | undefined, { localePrimary }?: {
|
|
145
|
+
localePrimary?: boolean;
|
|
146
|
+
}): {
|
|
147
|
+
snapshot: PointsSnapshot;
|
|
148
|
+
currency: string | null;
|
|
149
|
+
cartStateKnown: boolean;
|
|
150
|
+
} | null;
|
|
151
|
+
export declare function toJoyPointsCustomerInput(customer: PointsAccountCustomer | null | undefined): {
|
|
152
|
+
customerTags: string[] | undefined;
|
|
153
|
+
isB2B: boolean | undefined;
|
|
154
|
+
};
|
|
155
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { normalizeRedeemCartSnapshot } from './redeem-cart-snapshot.js';
|
|
2
|
+
function toCents(amount) {
|
|
3
|
+
const value = parseFloat(amount ?? '');
|
|
4
|
+
return Number.isFinite(value) ? Math.round(value * 100) : null;
|
|
5
|
+
}
|
|
6
|
+
function numericId(gid) {
|
|
7
|
+
const id = parseInt(String(gid ?? '').split('?')[0].split('/').pop() || '', 10);
|
|
8
|
+
return Number.isFinite(id) ? id : null;
|
|
9
|
+
}
|
|
10
|
+
const isObject = (value) => !!value && typeof value === 'object';
|
|
11
|
+
const text = (value) => (typeof value === 'string' ? value : '');
|
|
12
|
+
const strings = (value) => (Array.isArray(value) ? value.filter((item) => typeof item === 'string') : []);
|
|
13
|
+
function collectionsOf(product) {
|
|
14
|
+
const nodes = Array.isArray(product?.collections?.nodes) ? product.collections.nodes : [];
|
|
15
|
+
const collectionDetails = nodes.flatMap(node => {
|
|
16
|
+
const id = numericId(node?.id);
|
|
17
|
+
return id == null ? [] : [{ id, title: text(node?.title) }];
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
collections: collectionDetails.map(collection => collection.title),
|
|
21
|
+
collectionIds: collectionDetails.map(collection => collection.id),
|
|
22
|
+
collectionDetails
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function productFields(product) {
|
|
26
|
+
return {
|
|
27
|
+
title: text(product?.title),
|
|
28
|
+
tags: strings(product?.tags),
|
|
29
|
+
vendor: text(product?.vendor),
|
|
30
|
+
type: text(product?.productType),
|
|
31
|
+
...collectionsOf(product)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function sellingPlanAllocations(variant) {
|
|
35
|
+
const nodes = Array.isArray(variant.sellingPlanAllocations?.nodes) ? variant.sellingPlanAllocations.nodes : [];
|
|
36
|
+
return nodes.flatMap(allocation => {
|
|
37
|
+
const sellingPlanId = numericId(allocation?.sellingPlan?.id);
|
|
38
|
+
const adjustments = Array.isArray(allocation?.priceAdjustments) ? allocation.priceAdjustments : [];
|
|
39
|
+
const price = toCents(adjustments[0]?.price?.amount) ?? toCents(allocation?.checkoutChargeAmount?.amount);
|
|
40
|
+
return sellingPlanId == null || price == null ? [] : [{ selling_plan_id: sellingPlanId, price }];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export function normalizePointsProductSnapshot({ product, selectedVariant, quantity, sellingPlanId, localePrimary }) {
|
|
44
|
+
if (!isObject(product) || !isObject(selectedVariant))
|
|
45
|
+
return null;
|
|
46
|
+
const productId = numericId(product.id);
|
|
47
|
+
const variantId = numericId(selectedVariant.id);
|
|
48
|
+
const variantPrice = toCents(selectedVariant.price?.amount);
|
|
49
|
+
if (productId == null || variantId == null || variantPrice == null)
|
|
50
|
+
return null;
|
|
51
|
+
const currency = selectedVariant.price?.currencyCode || null;
|
|
52
|
+
const amount = Number(quantity);
|
|
53
|
+
return {
|
|
54
|
+
snapshot: {
|
|
55
|
+
surface: 'product',
|
|
56
|
+
moneyUnit: 'cents',
|
|
57
|
+
currency: { active: currency ?? '', rate: 1 },
|
|
58
|
+
localePrimary,
|
|
59
|
+
now: new Date(),
|
|
60
|
+
product: {
|
|
61
|
+
id: productId,
|
|
62
|
+
...productFields(product),
|
|
63
|
+
price: toCents(product.priceRange?.minVariantPrice?.amount) ?? variantPrice,
|
|
64
|
+
variants: [
|
|
65
|
+
{
|
|
66
|
+
id: variantId,
|
|
67
|
+
price: variantPrice,
|
|
68
|
+
compare_at_price: toCents(selectedVariant.compareAtPrice?.amount),
|
|
69
|
+
selling_plan_allocations: sellingPlanAllocations(selectedVariant)
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
selectedVariantId: variantId,
|
|
74
|
+
quantity: quantity == null || !Number.isFinite(amount) ? 1 : amount,
|
|
75
|
+
sellingPlanId: numericId(sellingPlanId)
|
|
76
|
+
},
|
|
77
|
+
currency
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function firstLineLevelDiscount(line) {
|
|
81
|
+
const allocations = Array.isArray(line.discountAllocations) ? line.discountAllocations : [];
|
|
82
|
+
for (const allocation of allocations) {
|
|
83
|
+
const cents = toCents(allocation?.discountedAmount?.amount);
|
|
84
|
+
if (cents != null && allocation?.targetType !== 'SHIPPING_LINE')
|
|
85
|
+
return cents;
|
|
86
|
+
}
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
export function normalizePointsCartSnapshot(cart, { localePrimary } = {}) {
|
|
90
|
+
if (!isObject(cart) || !Array.isArray(cart.lines?.nodes))
|
|
91
|
+
return null;
|
|
92
|
+
const redeem = normalizeRedeemCartSnapshot(cart);
|
|
93
|
+
if (!redeem)
|
|
94
|
+
return null;
|
|
95
|
+
const lines = cart.lines.nodes.filter((line) => !!line);
|
|
96
|
+
const items = [];
|
|
97
|
+
for (const [index, item] of redeem.cartItems.entries()) {
|
|
98
|
+
const line = lines[index];
|
|
99
|
+
if (item.product_id == null || item.variant_id == null)
|
|
100
|
+
return null;
|
|
101
|
+
const product = line.merchandise?.product;
|
|
102
|
+
items.push({
|
|
103
|
+
product_id: item.product_id,
|
|
104
|
+
id: item.product_id,
|
|
105
|
+
...productFields(product),
|
|
106
|
+
price: toCents(product?.priceRange?.minVariantPrice?.amount) ?? item.final_price,
|
|
107
|
+
quantity: item.quantity,
|
|
108
|
+
variant_id: item.variant_id,
|
|
109
|
+
final_line_price: item.final_line_price,
|
|
110
|
+
variant_compare_at_price: toCents(line.merchandise?.compareAtPrice?.amount),
|
|
111
|
+
has_selling_plan: !!line.sellingPlanAllocation
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const hasOrderDiscountSource = Array.isArray(cart.discountAllocations) || lines.every(line => Array.isArray(line.joyAllDiscounts));
|
|
115
|
+
return {
|
|
116
|
+
snapshot: {
|
|
117
|
+
surface: 'cart',
|
|
118
|
+
moneyUnit: 'cents',
|
|
119
|
+
currency: { active: redeem.currency ?? '', rate: 1 },
|
|
120
|
+
localePrimary,
|
|
121
|
+
now: new Date(),
|
|
122
|
+
cart: {
|
|
123
|
+
items,
|
|
124
|
+
totalDiscount: redeem.cartInfo.total_discount,
|
|
125
|
+
lineLevelDiscounts: lines.map(firstLineLevelDiscount)
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
currency: redeem.currency,
|
|
129
|
+
cartStateKnown: redeem.cartStateKnown && hasOrderDiscountSource
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export function toJoyPointsCustomerInput(customer) {
|
|
133
|
+
if (!isObject(customer))
|
|
134
|
+
return { customerTags: undefined, isB2B: undefined };
|
|
135
|
+
return {
|
|
136
|
+
customerTags: Array.isArray(customer.tags) ? customer.tags : undefined,
|
|
137
|
+
isB2B: customer.companyContacts ? (customer.companyContacts.nodes?.length ?? 0) > 0 : undefined
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function isLegacySubmitFormShape(fields) {
|
|
2
|
+
if (!Array.isArray(fields))
|
|
3
|
+
return true;
|
|
4
|
+
const [text, upload, ...rest] = fields;
|
|
5
|
+
if (rest.length || text?.type !== 'short_text' || text.required !== true)
|
|
6
|
+
return false;
|
|
7
|
+
return !upload || upload.type === 'file_upload';
|
|
8
|
+
}
|
|
9
|
+
export function isHiddenOnHeadlessSubmitForm(program) {
|
|
10
|
+
const p = program;
|
|
11
|
+
return p?.event === 'submit_form' && !isLegacySubmitFormShape(p.formFields);
|
|
12
|
+
}
|
|
13
|
+
export function withoutHeadlessHiddenPrograms(earning) {
|
|
14
|
+
return earning.filter(program => !isHiddenOnHeadlessSubmitForm(program));
|
|
15
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveShopLocale } from '../lib/shop-locale.js';
|
|
2
|
+
import { withoutHeadlessHiddenPrograms } from '../lib/submit-form-visibility.js';
|
|
2
3
|
const SYSTEM_TIER_BRONZE = 'bronze';
|
|
3
4
|
const SYSTEM_TIER_SILVER = 'silver';
|
|
4
5
|
const SYSTEM_TIER_GOLD = 'gold';
|
|
@@ -96,7 +97,7 @@ function readBlobFields(blob) {
|
|
|
96
97
|
const b = asRecord(blob);
|
|
97
98
|
const program = asRecord(b.program);
|
|
98
99
|
return {
|
|
99
|
-
earning: Array.isArray(program.earning) ? program.earning : [],
|
|
100
|
+
earning: Array.isArray(program.earning) ? withoutHeadlessHiddenPrograms(program.earning) : [],
|
|
100
101
|
spending: Array.isArray(program.spending) ? program.spending : [],
|
|
101
102
|
tiers: mergeTierDefaults(program.tiers),
|
|
102
103
|
settings: b.settings ?? {},
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StorefrontCart } from '../hydrogen-cart-port.js';
|
|
3
|
+
import type { PointsStorefrontProduct, PointsStorefrontVariant } from '../lib/points-calculator-snapshot.js';
|
|
4
|
+
import type { JoyInitialDataResult } from '../server/get-joy-initial-data.js';
|
|
5
|
+
export interface JoyPointsCalculatorProps {
|
|
6
|
+
apiUrl: string;
|
|
7
|
+
shopDomain: string;
|
|
8
|
+
tokenRoute?: string;
|
|
9
|
+
initialData: JoyInitialDataResult | null | undefined;
|
|
10
|
+
context: 'product' | 'cart';
|
|
11
|
+
product?: PointsStorefrontProduct | null;
|
|
12
|
+
selectedVariant?: PointsStorefrontVariant | null;
|
|
13
|
+
quantity?: number;
|
|
14
|
+
sellingPlanId?: string | null;
|
|
15
|
+
cart?: StorefrontCart | (() => StorefrontCart | null | undefined);
|
|
16
|
+
customerTags?: string[];
|
|
17
|
+
isB2B?: boolean;
|
|
18
|
+
isLoggedIn?: boolean;
|
|
19
|
+
align?: 'left' | 'center' | 'right';
|
|
20
|
+
loginUrl?: string;
|
|
21
|
+
onNavigate?: (url: string) => void;
|
|
22
|
+
onJoinClick?: (action: {
|
|
23
|
+
kind: 'open_widget' | 'login' | 'join_program';
|
|
24
|
+
href: string;
|
|
25
|
+
}) => boolean | void;
|
|
26
|
+
assetUrl?: string;
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function JoyPointsCalculator({ apiUrl, shopDomain, tokenRoute, assetUrl, initialData, context, product, selectedVariant, quantity, sellingPlanId, cart, customerTags, isB2B, isLoggedIn: isLoggedInProp, align, loginUrl, onNavigate, onJoinClick, className }: JoyPointsCalculatorProps): ReactNode;
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { loadWidgetCore } from '../lib/core-loader.js';
|
|
4
|
+
import { WidgetCorePreloadLinks } from '../lib/core-preload-links.js';
|
|
5
|
+
import { ensureClient, useJoyProviderCart } from '../lib/JoyProvider.js';
|
|
6
|
+
import { normalizePointsCartSnapshot, normalizePointsProductSnapshot } from '../lib/points-calculator-snapshot.js';
|
|
7
|
+
import { safeNavigationUrl } from '../lib/safe-navigation-url.js';
|
|
8
|
+
import { DEFAULT_TOKEN_ROUTE, getJoyToken } from '../lib/token.js';
|
|
9
|
+
import { resolveActiveTranslation, resolveContentLocale } from '../render-adapter.js';
|
|
10
|
+
const PLACEHOLDER_MIN_HEIGHT = 24;
|
|
11
|
+
const UPDATE_DEBOUNCE_MS = 50;
|
|
12
|
+
const PLACEHOLDER_RELEASE_FALLBACK_MS = 1500;
|
|
13
|
+
const WIDGET_TAG = 'joy-loyalty-widget';
|
|
14
|
+
const OPEN_HASH = 'joy-open';
|
|
15
|
+
const isContext = (value) => value === 'product' || value === 'cart';
|
|
16
|
+
class StageError extends Error {
|
|
17
|
+
stage;
|
|
18
|
+
detail;
|
|
19
|
+
constructor(stage, detail) {
|
|
20
|
+
super(stage);
|
|
21
|
+
this.stage = stage;
|
|
22
|
+
this.detail = detail;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function guarded(stage, run) {
|
|
26
|
+
try {
|
|
27
|
+
return await run();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new StageError(stage, error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function resolveCart(cart) {
|
|
34
|
+
try {
|
|
35
|
+
return typeof cart === 'function' ? cart() : cart;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function resolveCustomerKey(initialData) {
|
|
42
|
+
const shopifyId = initialData?.shopifyCustomer?.id;
|
|
43
|
+
if (shopifyId)
|
|
44
|
+
return `s:${shopifyId}`;
|
|
45
|
+
const joyId = initialData?.customer?.id;
|
|
46
|
+
return joyId ? `j:${joyId}` : null;
|
|
47
|
+
}
|
|
48
|
+
function flattenTranslation(blobTranslation, locale) {
|
|
49
|
+
return { ...resolveActiveTranslation(blobTranslation), ...resolveActiveTranslation(blobTranslation, locale) };
|
|
50
|
+
}
|
|
51
|
+
function createMemberClient(options) {
|
|
52
|
+
const { apiUrl, tokenRoute, locale, shopDomain } = options;
|
|
53
|
+
const client = ensureClient(apiUrl, tokenRoute ?? DEFAULT_TOKEN_ROUTE, locale, shopDomain);
|
|
54
|
+
const withToken = async (run) => {
|
|
55
|
+
const token = await getJoyToken(tokenRoute ? { tokenRoute } : {});
|
|
56
|
+
if (!token)
|
|
57
|
+
throw Object.assign(new Error('Joy token unavailable'), { code: 'TOKEN_UNAVAILABLE' });
|
|
58
|
+
client.setToken(token);
|
|
59
|
+
return run();
|
|
60
|
+
};
|
|
61
|
+
return { joinProgram: (joinFrom) => withToken(() => client.joinProgram(joinFrom)) };
|
|
62
|
+
}
|
|
63
|
+
function cartContentKey(cart) {
|
|
64
|
+
try {
|
|
65
|
+
if (!cart)
|
|
66
|
+
return 'null';
|
|
67
|
+
const c = cart;
|
|
68
|
+
if (c.id == null && c.updatedAt == null && c.totalQuantity == null && c.cost == null)
|
|
69
|
+
return JSON.stringify(cart);
|
|
70
|
+
const lines = (Array.isArray(c.lines?.nodes) ? c.lines.nodes : []).map(line => line ? [line.id, line.merchandise?.id, line.quantity, line.cost?.subtotalAmount?.amount, line.cost?.totalAmount?.amount].join(':') : '');
|
|
71
|
+
const codes = (Array.isArray(c.discountCodes) ? c.discountCodes : []).map(d => `${d?.code}:${d?.applicable}`);
|
|
72
|
+
return [c.id, c.updatedAt, c.totalQuantity, c.cost?.totalAmount?.amount, codes.join(','), lines.join(',')].join('|');
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return cart;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function hasOptimisticLine(cart) {
|
|
79
|
+
const nodes = cart?.lines?.nodes;
|
|
80
|
+
return Array.isArray(nodes) && nodes.some(line => line?.isOptimistic === true);
|
|
81
|
+
}
|
|
82
|
+
function pointCalculatorConfig(blob) {
|
|
83
|
+
const b = blob;
|
|
84
|
+
return b?.pointCalculator || b?.placeOrder?.productPointsCalculator || b?.settings?.pointCalculator || {};
|
|
85
|
+
}
|
|
86
|
+
function resolveIsLoggedIn(data, host) {
|
|
87
|
+
const hostSignal = host.isLoggedIn ?? (host.customerTags !== undefined || host.isB2B !== undefined ? true : undefined);
|
|
88
|
+
return !!(data?.shopifyCustomer?.id || data?.customer) || hostSignal === true;
|
|
89
|
+
}
|
|
90
|
+
export function JoyPointsCalculator({ apiUrl, shopDomain, tokenRoute, assetUrl, initialData, context, product, selectedVariant, quantity, sellingPlanId, cart, customerTags, isB2B, isLoggedIn: isLoggedInProp, align, loginUrl, onNavigate, onJoinClick, className }) {
|
|
91
|
+
const providerCart = useJoyProviderCart();
|
|
92
|
+
const effectiveCart = cart ?? providerCart;
|
|
93
|
+
const productRef = useRef(product);
|
|
94
|
+
productRef.current = product;
|
|
95
|
+
const variantRef = useRef(selectedVariant);
|
|
96
|
+
variantRef.current = selectedVariant;
|
|
97
|
+
const quantityRef = useRef(quantity);
|
|
98
|
+
quantityRef.current = quantity;
|
|
99
|
+
const sellingPlanRef = useRef(sellingPlanId);
|
|
100
|
+
sellingPlanRef.current = sellingPlanId;
|
|
101
|
+
const cartRef = useRef(effectiveCart);
|
|
102
|
+
cartRef.current = effectiveCart;
|
|
103
|
+
const customerTagsRef = useRef(customerTags);
|
|
104
|
+
customerTagsRef.current = customerTags;
|
|
105
|
+
const isB2BRef = useRef(isB2B);
|
|
106
|
+
isB2BRef.current = isB2B;
|
|
107
|
+
const isLoggedInRef = useRef(isLoggedInProp);
|
|
108
|
+
isLoggedInRef.current = isLoggedInProp;
|
|
109
|
+
const onNavigateRef = useRef(onNavigate);
|
|
110
|
+
onNavigateRef.current = onNavigate;
|
|
111
|
+
const onJoinClickRef = useRef(onJoinClick);
|
|
112
|
+
onJoinClickRef.current = onJoinClick;
|
|
113
|
+
const loginUrlRef = useRef(loginUrl);
|
|
114
|
+
loginUrlRef.current = loginUrl;
|
|
115
|
+
const initialDataRef = useRef(initialData);
|
|
116
|
+
initialDataRef.current = initialData;
|
|
117
|
+
const alignRef = useRef(align);
|
|
118
|
+
alignRef.current = align;
|
|
119
|
+
const handleRef = useRef(null);
|
|
120
|
+
const hostRef = useRef(null);
|
|
121
|
+
const updateWarnedRef = useRef(false);
|
|
122
|
+
const [reserved, setReserved] = useState(true);
|
|
123
|
+
const [collapsed, setCollapsed] = useState(false);
|
|
124
|
+
const customerKey = resolveCustomerKey(initialData);
|
|
125
|
+
const hasCustomer = Boolean(initialData?.customer);
|
|
126
|
+
const locale = initialData?.locale;
|
|
127
|
+
const hasInitialData = Boolean(initialData);
|
|
128
|
+
const validContext = isContext(context);
|
|
129
|
+
const isCollapsed = collapsed || !hasInitialData || !validContext;
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!hasInitialData)
|
|
132
|
+
return;
|
|
133
|
+
if (!validContext) {
|
|
134
|
+
console.warn(`[joy] JoyPointsCalculator: context must be "product" or "cart" (got ${JSON.stringify(context)}), rendering nothing`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
setCollapsed(false);
|
|
138
|
+
setReserved(true);
|
|
139
|
+
let disposed = false;
|
|
140
|
+
let handle = null;
|
|
141
|
+
let releaseObserver = null;
|
|
142
|
+
let releaseTimer;
|
|
143
|
+
const warned = new Set();
|
|
144
|
+
const warnOnce = (message, detail) => {
|
|
145
|
+
if (warned.has(message))
|
|
146
|
+
return;
|
|
147
|
+
warned.add(message);
|
|
148
|
+
console.warn(`[joy] JoyPointsCalculator: ${message}`, ...(detail === undefined ? [] : [detail]));
|
|
149
|
+
};
|
|
150
|
+
const disposeHandle = () => {
|
|
151
|
+
const current = handle;
|
|
152
|
+
handle = null;
|
|
153
|
+
if (handleRef.current === current)
|
|
154
|
+
handleRef.current = null;
|
|
155
|
+
if (!current)
|
|
156
|
+
return;
|
|
157
|
+
try {
|
|
158
|
+
current.dispose();
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
warnOnce('dispose failed', error);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const fail = (message, detail) => {
|
|
165
|
+
if (disposed)
|
|
166
|
+
return;
|
|
167
|
+
disposeHandle();
|
|
168
|
+
warnOnce(message, detail);
|
|
169
|
+
setCollapsed(true);
|
|
170
|
+
};
|
|
171
|
+
const hostHook = (name, run) => {
|
|
172
|
+
try {
|
|
173
|
+
const result = run();
|
|
174
|
+
if (result && typeof result.then === 'function') {
|
|
175
|
+
return result.then(undefined, error => warnOnce(`${name} failed`, error));
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
warnOnce(`${name} failed`, error);
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const getSnapshot = () => {
|
|
185
|
+
try {
|
|
186
|
+
const blob = initialDataRef.current?.blob;
|
|
187
|
+
const localePrimary = !blob?.collectionDefaultTitles;
|
|
188
|
+
if (context === 'product') {
|
|
189
|
+
const currentProduct = productRef.current;
|
|
190
|
+
const currentVariant = variantRef.current;
|
|
191
|
+
if (!currentProduct || !currentVariant)
|
|
192
|
+
return null;
|
|
193
|
+
const normalized = normalizePointsProductSnapshot({
|
|
194
|
+
product: currentProduct,
|
|
195
|
+
selectedVariant: currentVariant,
|
|
196
|
+
quantity: quantityRef.current,
|
|
197
|
+
sellingPlanId: sellingPlanRef.current,
|
|
198
|
+
localePrimary
|
|
199
|
+
});
|
|
200
|
+
if (!normalized)
|
|
201
|
+
warnOnce('the product or selected variant could not be read (missing or non-numeric id, or no price), hiding');
|
|
202
|
+
return normalized?.snapshot ?? null;
|
|
203
|
+
}
|
|
204
|
+
const currentCart = resolveCart(cartRef.current);
|
|
205
|
+
if (!currentCart)
|
|
206
|
+
return null;
|
|
207
|
+
const normalized = normalizePointsCartSnapshot(currentCart, { localePrimary });
|
|
208
|
+
if (!normalized)
|
|
209
|
+
warnOnce('the cart could not be read (no lines list, or a line without a product / variant id), hiding');
|
|
210
|
+
if (normalized && !normalized.cartStateKnown) {
|
|
211
|
+
warnOnce('the cart money or discounts are unknown (a line without cost.subtotalAmount, or an applicable ' +
|
|
212
|
+
'discount code but no cart-level allocations: select Cart.discountAllocations, or ' +
|
|
213
|
+
'CartLine.joyAllDiscounts on 2026-07+), hiding');
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
return normalized?.snapshot ?? null;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
warnOnce('reading the page snapshot failed', error);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const run = async () => {
|
|
224
|
+
const data = initialDataRef.current;
|
|
225
|
+
if (!data)
|
|
226
|
+
return;
|
|
227
|
+
const loadOptions = {
|
|
228
|
+
core: data.core,
|
|
229
|
+
preloadLazy: ['pointsCalculator'],
|
|
230
|
+
...(assetUrl ? { assetUrl } : {})
|
|
231
|
+
};
|
|
232
|
+
const loaded = await guarded('widget core load failed', () => loadWidgetCore(loadOptions));
|
|
233
|
+
if (disposed)
|
|
234
|
+
return;
|
|
235
|
+
if (!loaded.loaded)
|
|
236
|
+
throw new StageError('widget core load failed', loaded);
|
|
237
|
+
const loadPointsCalculatorCore = loaded.coreExports?.loadPointsCalculatorCore;
|
|
238
|
+
if (typeof loadPointsCalculatorCore !== 'function') {
|
|
239
|
+
throw new StageError('the widget core has no points-calculator surface (older CDN core), rendering nothing', undefined);
|
|
240
|
+
}
|
|
241
|
+
const surface = await guarded('loading the points-calculator core failed', () => loadPointsCalculatorCore());
|
|
242
|
+
if (disposed)
|
|
243
|
+
return;
|
|
244
|
+
const mount = surface?.mountPointsCalculatorCore;
|
|
245
|
+
if (typeof mount !== 'function') {
|
|
246
|
+
throw new StageError('the points-calculator core has no mountPointsCalculatorCore, rendering nothing', undefined);
|
|
247
|
+
}
|
|
248
|
+
const options = await guarded('setting up the mount failed', () => {
|
|
249
|
+
const blob = data.blob;
|
|
250
|
+
const blobTranslation = blob?.translation;
|
|
251
|
+
const loggedIn = () => resolveIsLoggedIn(initialDataRef.current, {
|
|
252
|
+
isLoggedIn: isLoggedInRef.current,
|
|
253
|
+
customerTags: customerTagsRef.current,
|
|
254
|
+
isB2B: isB2BRef.current
|
|
255
|
+
});
|
|
256
|
+
return {
|
|
257
|
+
source: {
|
|
258
|
+
blob,
|
|
259
|
+
customer: data.customer ?? null,
|
|
260
|
+
customerKey: resolveCustomerKey(data),
|
|
261
|
+
translation: flattenTranslation(blobTranslation, data.locale),
|
|
262
|
+
locale: resolveContentLocale(data.locale, blobTranslation),
|
|
263
|
+
loginUrl: pointCalculatorConfig(blob).callActionLink ||
|
|
264
|
+
loginUrlRef.current ||
|
|
265
|
+
data.login_url ||
|
|
266
|
+
'/account/login',
|
|
267
|
+
get isLoggedIn() {
|
|
268
|
+
return loggedIn();
|
|
269
|
+
},
|
|
270
|
+
get customerTags() {
|
|
271
|
+
return loggedIn() ? customerTagsRef.current : undefined;
|
|
272
|
+
},
|
|
273
|
+
get isB2B() {
|
|
274
|
+
return loggedIn() ? isB2BRef.current : undefined;
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
context,
|
|
278
|
+
...(alignRef.current ? { align: alignRef.current } : {}),
|
|
279
|
+
getSnapshot,
|
|
280
|
+
client: data.customer ? createMemberClient({ apiUrl, tokenRoute, locale: data.locale, shopDomain }) : null,
|
|
281
|
+
hooks: {
|
|
282
|
+
navigate: (url) => {
|
|
283
|
+
hostHook('navigate', () => {
|
|
284
|
+
const target = safeNavigationUrl(url);
|
|
285
|
+
if (onNavigateRef.current && target?.origin === window.location.origin) {
|
|
286
|
+
return onNavigateRef.current(`${target.pathname}${target.search}${target.hash}`);
|
|
287
|
+
}
|
|
288
|
+
return window.location.assign(target?.href ?? '/');
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
openWidget: () => hostHook('openWidget', () => {
|
|
292
|
+
if (!document.querySelector(WIDGET_TAG))
|
|
293
|
+
return false;
|
|
294
|
+
if (window.location.hash === `#${OPEN_HASH}`) {
|
|
295
|
+
window.dispatchEvent(new HashChangeEvent('hashchange'));
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
window.location.hash = OPEN_HASH;
|
|
299
|
+
return true;
|
|
300
|
+
}) === true,
|
|
301
|
+
reload: () => {
|
|
302
|
+
hostHook('reload', () => window.location.reload());
|
|
303
|
+
},
|
|
304
|
+
onJoinClick: (action) => hostHook('onJoinClick', () => onJoinClickRef.current?.(action))
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
if (disposed)
|
|
309
|
+
return;
|
|
310
|
+
const host = hostRef.current;
|
|
311
|
+
if (!host)
|
|
312
|
+
return;
|
|
313
|
+
const created = await guarded('mount failed', () => mount(host, options));
|
|
314
|
+
handle = created ?? null;
|
|
315
|
+
if (disposed) {
|
|
316
|
+
disposeHandle();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
handleRef.current = handle;
|
|
320
|
+
if (host.childNodes.length > 0)
|
|
321
|
+
return setReserved(false);
|
|
322
|
+
releaseObserver = new MutationObserver(() => {
|
|
323
|
+
if (host.childNodes.length === 0)
|
|
324
|
+
return;
|
|
325
|
+
releaseObserver?.disconnect();
|
|
326
|
+
setReserved(false);
|
|
327
|
+
});
|
|
328
|
+
releaseObserver.observe(host, { childList: true });
|
|
329
|
+
releaseTimer = setTimeout(() => {
|
|
330
|
+
releaseObserver?.disconnect();
|
|
331
|
+
setReserved(false);
|
|
332
|
+
}, PLACEHOLDER_RELEASE_FALLBACK_MS);
|
|
333
|
+
};
|
|
334
|
+
void run()
|
|
335
|
+
.catch(error => {
|
|
336
|
+
if (error instanceof StageError)
|
|
337
|
+
fail(error.stage, error.detail);
|
|
338
|
+
else
|
|
339
|
+
fail('unexpected failure', error);
|
|
340
|
+
})
|
|
341
|
+
.catch(() => { });
|
|
342
|
+
return () => {
|
|
343
|
+
disposed = true;
|
|
344
|
+
releaseObserver?.disconnect();
|
|
345
|
+
clearTimeout(releaseTimer);
|
|
346
|
+
disposeHandle();
|
|
347
|
+
};
|
|
348
|
+
}, [apiUrl, shopDomain, tokenRoute, assetUrl, customerKey, hasCustomer, locale, hasInitialData, context]);
|
|
349
|
+
const cartKey = context === 'cart' ? cartContentKey(resolveCart(effectiveCart)) : undefined;
|
|
350
|
+
const customerTagsKey = customerTags?.join('\u0000');
|
|
351
|
+
const loggedInNow = resolveIsLoggedIn(initialData, { isLoggedIn: isLoggedInProp, customerTags, isB2B });
|
|
352
|
+
useEffect(() => {
|
|
353
|
+
if (!handleRef.current)
|
|
354
|
+
return;
|
|
355
|
+
const timer = setTimeout(() => {
|
|
356
|
+
const current = handleRef.current;
|
|
357
|
+
if (!current)
|
|
358
|
+
return;
|
|
359
|
+
if (context === 'cart' && hasOptimisticLine(resolveCart(cartRef.current)))
|
|
360
|
+
return;
|
|
361
|
+
Promise.resolve()
|
|
362
|
+
.then(() => current.update())
|
|
363
|
+
.catch(error => {
|
|
364
|
+
if (updateWarnedRef.current)
|
|
365
|
+
return;
|
|
366
|
+
updateWarnedRef.current = true;
|
|
367
|
+
console.warn('[joy] JoyPointsCalculator: update failed', error);
|
|
368
|
+
});
|
|
369
|
+
}, UPDATE_DEBOUNCE_MS);
|
|
370
|
+
return () => clearTimeout(timer);
|
|
371
|
+
}, [product?.id, selectedVariant?.id, quantity, sellingPlanId, cartKey, customerTagsKey, isB2B, loggedInNow]);
|
|
372
|
+
return (_jsxs("div", { className: className, hidden: isCollapsed, style: isCollapsed ? { display: 'none' } : undefined, children: [_jsx(WidgetCorePreloadLinks, { core: initialData?.core, assetUrl: assetUrl, lazy: ['pointsCalculator'] }), createElement('div', {
|
|
373
|
+
ref: hostRef,
|
|
374
|
+
'data-joy-points-calculator': '',
|
|
375
|
+
style: reserved && !isCollapsed ? { minHeight: PLACEHOLDER_MIN_HEIGHT } : undefined
|
|
376
|
+
})] }));
|
|
377
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const JOY_POINTS_PRODUCT_FRAGMENT = "#graphql\n fragment JoyPointsProduct on Product {\n id\n title\n tags\n vendor\n productType\n priceRange {\n minVariantPrice {\n amount\n currencyCode\n }\n }\n collections(first: 20) {\n nodes {\n id\n title\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n";
|
|
2
|
+
export declare const JOY_POINTS_VARIANT_FRAGMENT = "#graphql\n fragment JoyPointsVariant on ProductVariant {\n id\n price {\n amount\n currencyCode\n }\n compareAtPrice {\n amount\n currencyCode\n }\n }\n";
|
|
3
|
+
export declare const JOY_POINTS_VARIANT_SELLING_PLANS_FRAGMENT = "#graphql\n fragment JoyPointsVariantSellingPlans on ProductVariant {\n sellingPlanAllocations(first: 10) {\n nodes {\n sellingPlan {\n id\n }\n checkoutChargeAmount {\n amount\n currencyCode\n }\n priceAdjustments {\n price {\n amount\n currencyCode\n }\n }\n }\n }\n }\n";
|
|
4
|
+
export declare const JOY_POINTS_CART_LINE_FRAGMENT = "#graphql\n fragment JoyPointsCartLine on CartLine {\n id\n quantity\n cost {\n totalAmount {\n amount\n currencyCode\n }\n subtotalAmount {\n amount\n currencyCode\n }\n compareAtAmountPerQuantity {\n amount\n currencyCode\n }\n }\n discountAllocations {\n targetType\n discountedAmount {\n amount\n currencyCode\n }\n ... on CartCodeDiscountAllocation {\n code\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n price {\n amount\n currencyCode\n }\n compareAtPrice {\n amount\n currencyCode\n }\n product {\n id\n title\n tags\n vendor\n productType\n priceRange {\n minVariantPrice {\n amount\n currencyCode\n }\n }\n collections(first: 20) {\n nodes {\n id\n title\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n }\n }\n }\n";
|
|
5
|
+
export declare const JOY_POINTS_CART_LINE_SELLING_PLAN_FRAGMENT = "#graphql\n fragment JoyPointsCartLineSellingPlan on CartLine {\n sellingPlanAllocation {\n sellingPlan {\n id\n }\n }\n }\n";
|
|
6
|
+
export declare const JOY_POINTS_CUSTOMER_FRAGMENT = "#graphql\n fragment JoyPointsCustomer on Customer {\n tags\n companyContacts(first: 1) {\n nodes {\n id\n }\n }\n }\n";
|
|
7
|
+
export declare const JOY_POINTS_CUSTOMER_ACCOUNT_QUERY = "#graphql\n query JoyPointsCustomer {\n customer {\n ...JoyPointsCustomer\n }\n }\n #graphql\n fragment JoyPointsCustomer on Customer {\n tags\n companyContacts(first: 1) {\n nodes {\n id\n }\n }\n }\n\n";
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
export const JOY_POINTS_PRODUCT_FRAGMENT = `#graphql
|
|
2
|
+
fragment JoyPointsProduct on Product {
|
|
3
|
+
id
|
|
4
|
+
title
|
|
5
|
+
tags
|
|
6
|
+
vendor
|
|
7
|
+
productType
|
|
8
|
+
priceRange {
|
|
9
|
+
minVariantPrice {
|
|
10
|
+
amount
|
|
11
|
+
currencyCode
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
collections(first: 20) {
|
|
15
|
+
nodes {
|
|
16
|
+
id
|
|
17
|
+
title
|
|
18
|
+
}
|
|
19
|
+
pageInfo {
|
|
20
|
+
hasNextPage
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
export const JOY_POINTS_VARIANT_FRAGMENT = `#graphql
|
|
26
|
+
fragment JoyPointsVariant on ProductVariant {
|
|
27
|
+
id
|
|
28
|
+
price {
|
|
29
|
+
amount
|
|
30
|
+
currencyCode
|
|
31
|
+
}
|
|
32
|
+
compareAtPrice {
|
|
33
|
+
amount
|
|
34
|
+
currencyCode
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
export const JOY_POINTS_VARIANT_SELLING_PLANS_FRAGMENT = `#graphql
|
|
39
|
+
fragment JoyPointsVariantSellingPlans on ProductVariant {
|
|
40
|
+
sellingPlanAllocations(first: 10) {
|
|
41
|
+
nodes {
|
|
42
|
+
sellingPlan {
|
|
43
|
+
id
|
|
44
|
+
}
|
|
45
|
+
checkoutChargeAmount {
|
|
46
|
+
amount
|
|
47
|
+
currencyCode
|
|
48
|
+
}
|
|
49
|
+
priceAdjustments {
|
|
50
|
+
price {
|
|
51
|
+
amount
|
|
52
|
+
currencyCode
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
export const JOY_POINTS_CART_LINE_FRAGMENT = `#graphql
|
|
60
|
+
fragment JoyPointsCartLine on CartLine {
|
|
61
|
+
id
|
|
62
|
+
quantity
|
|
63
|
+
cost {
|
|
64
|
+
totalAmount {
|
|
65
|
+
amount
|
|
66
|
+
currencyCode
|
|
67
|
+
}
|
|
68
|
+
subtotalAmount {
|
|
69
|
+
amount
|
|
70
|
+
currencyCode
|
|
71
|
+
}
|
|
72
|
+
compareAtAmountPerQuantity {
|
|
73
|
+
amount
|
|
74
|
+
currencyCode
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
discountAllocations {
|
|
78
|
+
targetType
|
|
79
|
+
discountedAmount {
|
|
80
|
+
amount
|
|
81
|
+
currencyCode
|
|
82
|
+
}
|
|
83
|
+
... on CartCodeDiscountAllocation {
|
|
84
|
+
code
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
merchandise {
|
|
88
|
+
... on ProductVariant {
|
|
89
|
+
id
|
|
90
|
+
price {
|
|
91
|
+
amount
|
|
92
|
+
currencyCode
|
|
93
|
+
}
|
|
94
|
+
compareAtPrice {
|
|
95
|
+
amount
|
|
96
|
+
currencyCode
|
|
97
|
+
}
|
|
98
|
+
product {
|
|
99
|
+
id
|
|
100
|
+
title
|
|
101
|
+
tags
|
|
102
|
+
vendor
|
|
103
|
+
productType
|
|
104
|
+
priceRange {
|
|
105
|
+
minVariantPrice {
|
|
106
|
+
amount
|
|
107
|
+
currencyCode
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
collections(first: 20) {
|
|
111
|
+
nodes {
|
|
112
|
+
id
|
|
113
|
+
title
|
|
114
|
+
}
|
|
115
|
+
pageInfo {
|
|
116
|
+
hasNextPage
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
export const JOY_POINTS_CART_LINE_SELLING_PLAN_FRAGMENT = `#graphql
|
|
125
|
+
fragment JoyPointsCartLineSellingPlan on CartLine {
|
|
126
|
+
sellingPlanAllocation {
|
|
127
|
+
sellingPlan {
|
|
128
|
+
id
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
export const JOY_POINTS_CUSTOMER_FRAGMENT = `#graphql
|
|
134
|
+
fragment JoyPointsCustomer on Customer {
|
|
135
|
+
tags
|
|
136
|
+
companyContacts(first: 1) {
|
|
137
|
+
nodes {
|
|
138
|
+
id
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
export const JOY_POINTS_CUSTOMER_ACCOUNT_QUERY = `#graphql
|
|
144
|
+
query JoyPointsCustomer {
|
|
145
|
+
customer {
|
|
146
|
+
...JoyPointsCustomer
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
${JOY_POINTS_CUSTOMER_FRAGMENT}
|
|
150
|
+
`;
|
package/dist/render-adapter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { buildWriteReviewProps } from './lib/write-review.js';
|
|
2
2
|
import { formatMoney } from './lib/money.js';
|
|
3
3
|
import { formatPointsNumber } from './lib/points.js';
|
|
4
|
+
import { withoutHeadlessHiddenPrograms } from './lib/submit-form-visibility.js';
|
|
4
5
|
const TYPE_BRANDING_DEFAULT = 'default';
|
|
5
6
|
const TYPE_BRANDING_IMAGE = 'image';
|
|
6
7
|
const TYPE_BRANDING_BLANK = 'blank';
|
|
@@ -82,6 +83,9 @@ function assembleHeadlessFacade(params) {
|
|
|
82
83
|
const rawSettings = applyTranslatedPointLabel({ ...rawSettings0 }, activeTranslation);
|
|
83
84
|
const resolvedSettings = asRecord(resolveWidgetSettings(rawSettings0));
|
|
84
85
|
const clonedProgram = blob.program != null ? structuredClone(blob.program) : blob.program;
|
|
86
|
+
const clonedEarning = asRecord(clonedProgram).earning;
|
|
87
|
+
if (Array.isArray(clonedEarning))
|
|
88
|
+
asRecord(clonedProgram).earning = withoutHeadlessHiddenPrograms(clonedEarning);
|
|
85
89
|
const data = {
|
|
86
90
|
...blob,
|
|
87
91
|
program: clonedProgram,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joy-loyalty/hydrogen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Joy Loyalty Widget V4 for any Hydrogen / headless Shopify storefront — host-neutral core embedded through HeadlessHostAdapter. No Weaverse dependency.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|