@joy-loyalty/hydrogen 0.2.1 → 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 +282 -1
- package/dist/hydrogen-cart-port.d.ts +49 -1
- package/dist/hydrogen-cart-port.js +23 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/lib/core-loader.d.ts +55 -0
- package/dist/lib/points-calculator-snapshot.d.ts +155 -0
- package/dist/lib/points-calculator-snapshot.js +139 -0
- package/dist/lib/redeem-cart-snapshot.d.ts +51 -0
- package/dist/lib/redeem-cart-snapshot.js +173 -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/orchestrator/handlers/milestone-tier.js +1 -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/redeem-cart/JoyRedeemCart.d.ts +19 -0
- package/dist/redeem-cart/JoyRedeemCart.js +321 -0
- package/dist/render-adapter.js +4 -0
- package/dist/widget-orchestrator.js +2 -1
- package/package.json +2 -2
|
@@ -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,51 @@
|
|
|
1
|
+
import type { StorefrontCart } from '../hydrogen-cart-port.js';
|
|
2
|
+
export type RedeemCartLineAllocation = {
|
|
3
|
+
amount: number;
|
|
4
|
+
discount_application: {
|
|
5
|
+
type: string;
|
|
6
|
+
title: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export type RedeemCartLevelApplication = {
|
|
10
|
+
type: string;
|
|
11
|
+
title: string;
|
|
12
|
+
total_allocated_amount: number;
|
|
13
|
+
};
|
|
14
|
+
export type RedeemCartItem = {
|
|
15
|
+
id: number | null;
|
|
16
|
+
product_id: number | null;
|
|
17
|
+
variant_id: number | null;
|
|
18
|
+
quantity: number;
|
|
19
|
+
original_line_price: number;
|
|
20
|
+
final_line_price: number;
|
|
21
|
+
final_price: number;
|
|
22
|
+
collectionIds: number[];
|
|
23
|
+
};
|
|
24
|
+
export type RedeemCartInfoItem = {
|
|
25
|
+
variant_id: number | null;
|
|
26
|
+
product_id: number | null;
|
|
27
|
+
quantity: number;
|
|
28
|
+
original_line_price: number;
|
|
29
|
+
final_line_price: number;
|
|
30
|
+
line_level_total_discount: number;
|
|
31
|
+
line_level_discount_allocations: RedeemCartLineAllocation[];
|
|
32
|
+
};
|
|
33
|
+
export type RedeemCartInfo = {
|
|
34
|
+
currency: string | null;
|
|
35
|
+
original_total_price: number;
|
|
36
|
+
total_discount: number;
|
|
37
|
+
discount_codes: Array<{
|
|
38
|
+
code: string;
|
|
39
|
+
applicable: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
items?: RedeemCartInfoItem[];
|
|
42
|
+
cart_level_discount_applications?: RedeemCartLevelApplication[];
|
|
43
|
+
};
|
|
44
|
+
export type RedeemCartSnapshot = {
|
|
45
|
+
cartItems: RedeemCartItem[];
|
|
46
|
+
cartInfo: RedeemCartInfo;
|
|
47
|
+
cartStateKnown: boolean;
|
|
48
|
+
collectionIdsKnown: boolean;
|
|
49
|
+
currency: string | null;
|
|
50
|
+
};
|
|
51
|
+
export declare function normalizeRedeemCartSnapshot(cart: StorefrontCart | null | undefined): RedeemCartSnapshot | null;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
const COLLECTIONS_PAGE_SIZE = 20;
|
|
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
|
+
function readAllocations(list) {
|
|
11
|
+
return (list || []).flatMap(allocation => {
|
|
12
|
+
const cents = toCents(allocation?.discountedAmount?.amount);
|
|
13
|
+
if (!allocation || cents == null)
|
|
14
|
+
return [];
|
|
15
|
+
const code = allocation.code || null;
|
|
16
|
+
return [{ key: code ? code.toUpperCase() : '', code, cents, shipping: allocation.targetType === 'SHIPPING_LINE' }];
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const merchandise = (allocations) => allocations.filter(allocation => !allocation.shipping);
|
|
20
|
+
const sum = (allocations) => allocations.reduce((total, allocation) => total + allocation.cents, 0);
|
|
21
|
+
function application(allocation) {
|
|
22
|
+
return { type: allocation.code ? 'discount_code' : 'automatic', title: allocation.code || '' };
|
|
23
|
+
}
|
|
24
|
+
function orderShares(all, lineLevel) {
|
|
25
|
+
const byKey = new Map();
|
|
26
|
+
for (const allocation of all) {
|
|
27
|
+
const existing = byKey.get(allocation.key);
|
|
28
|
+
byKey.set(allocation.key, existing ? { ...existing, cents: existing.cents + allocation.cents } : { ...allocation });
|
|
29
|
+
}
|
|
30
|
+
for (const allocation of lineLevel) {
|
|
31
|
+
const existing = byKey.get(allocation.key);
|
|
32
|
+
if (!existing)
|
|
33
|
+
return null;
|
|
34
|
+
existing.cents -= allocation.cents;
|
|
35
|
+
}
|
|
36
|
+
const shares = [...byKey.values()];
|
|
37
|
+
return shares.some(share => share.cents < 0) ? null : shares.filter(share => share.cents > 0);
|
|
38
|
+
}
|
|
39
|
+
function legacyOrderAllocations(cartLevel, lineLevel) {
|
|
40
|
+
const lineByKey = new Map();
|
|
41
|
+
for (const allocation of lineLevel.flat()) {
|
|
42
|
+
if (!allocation.key)
|
|
43
|
+
continue;
|
|
44
|
+
const existing = lineByKey.get(allocation.key) || { cents: 0, count: 0 };
|
|
45
|
+
lineByKey.set(allocation.key, { cents: existing.cents + allocation.cents, count: existing.count + 1 });
|
|
46
|
+
}
|
|
47
|
+
const byKey = new Map();
|
|
48
|
+
for (const allocation of cartLevel) {
|
|
49
|
+
const existing = byKey.get(allocation.key);
|
|
50
|
+
byKey.set(allocation.key, existing ? { ...existing, cents: existing.cents + allocation.cents } : { ...allocation });
|
|
51
|
+
}
|
|
52
|
+
const shares = [];
|
|
53
|
+
for (const allocation of byKey.values()) {
|
|
54
|
+
const line = allocation.key ? lineByKey.get(allocation.key) : undefined;
|
|
55
|
+
const cents = line ? allocation.cents - line.cents : allocation.cents;
|
|
56
|
+
if (line && cents < -line.count)
|
|
57
|
+
return null;
|
|
58
|
+
if (cents > 0)
|
|
59
|
+
shares.push({ ...allocation, cents });
|
|
60
|
+
}
|
|
61
|
+
return shares;
|
|
62
|
+
}
|
|
63
|
+
function collectionsOf(line) {
|
|
64
|
+
const collections = line.merchandise?.product?.collections;
|
|
65
|
+
if (!collections || !Array.isArray(collections.nodes))
|
|
66
|
+
return { ids: [], known: false };
|
|
67
|
+
const ids = collections.nodes.flatMap(node => {
|
|
68
|
+
const id = numericId(node?.id);
|
|
69
|
+
return id == null ? [] : [id];
|
|
70
|
+
});
|
|
71
|
+
const complete = collections.pageInfo
|
|
72
|
+
? collections.pageInfo.hasNextPage !== true
|
|
73
|
+
: collections.nodes.length < COLLECTIONS_PAGE_SIZE;
|
|
74
|
+
return { ids, known: complete };
|
|
75
|
+
}
|
|
76
|
+
function currencyOf(cart, lines) {
|
|
77
|
+
const lineCurrency = lines.find(line => line?.cost?.subtotalAmount?.currencyCode)?.cost?.subtotalAmount?.currencyCode;
|
|
78
|
+
return cart.cost?.totalAmount?.currencyCode || cart.cost?.subtotalAmount?.currencyCode || lineCurrency || null;
|
|
79
|
+
}
|
|
80
|
+
export function normalizeRedeemCartSnapshot(cart) {
|
|
81
|
+
if (!cart)
|
|
82
|
+
return null;
|
|
83
|
+
const lines = (Array.isArray(cart.lines?.nodes) ? cart.lines.nodes : []).filter((line) => !!line);
|
|
84
|
+
const currency = currencyOf(cart, lines);
|
|
85
|
+
const discountCodes = (Array.isArray(cart.discountCodes) ? cart.discountCodes : []).flatMap(discount => discount?.code ? [{ code: discount.code, applicable: discount.applicable === true }] : []);
|
|
86
|
+
const originals = lines.map(line => toCents(line.cost?.subtotalAmount?.amount));
|
|
87
|
+
const hasLineLevel = lines.every(line => Array.isArray(line.discountAllocations));
|
|
88
|
+
const hasAll = lines.every(line => Array.isArray(line.joyAllDiscounts));
|
|
89
|
+
const hasLegacyCartLevel = Array.isArray(cart.discountAllocations);
|
|
90
|
+
const discountComplete = !discountCodes.some(discount => discount.applicable) || (hasLineLevel && (hasLegacyCartLevel || hasAll));
|
|
91
|
+
const cartStateKnown = Array.isArray(cart.lines?.nodes) && originals.every(original => original != null) && discountComplete;
|
|
92
|
+
const lineLevel = lines.map(line => merchandise(readAllocations(line.discountAllocations)));
|
|
93
|
+
let productByLine = lines.map(() => []);
|
|
94
|
+
let orderAllocations = [];
|
|
95
|
+
let classesKnown = false;
|
|
96
|
+
if (hasLineLevel && hasAll) {
|
|
97
|
+
const shares = lines.map((line, index) => orderShares(merchandise(readAllocations(line.joyAllDiscounts)), lineLevel[index]));
|
|
98
|
+
if (shares.every(share => share)) {
|
|
99
|
+
productByLine = lineLevel;
|
|
100
|
+
orderAllocations = shares.flatMap(share => share || []);
|
|
101
|
+
classesKnown = true;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
productByLine = lines.map(line => merchandise(readAllocations(line.joyAllDiscounts)));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (hasAll) {
|
|
108
|
+
productByLine = lines.map(line => merchandise(readAllocations(line.joyAllDiscounts)));
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
productByLine = lineLevel;
|
|
112
|
+
const cartLevel = merchandise(readAllocations(cart.discountAllocations));
|
|
113
|
+
const shares = legacyOrderAllocations(cartLevel, lineLevel);
|
|
114
|
+
orderAllocations = shares || cartLevel;
|
|
115
|
+
classesKnown = !!shares && hasLineLevel && hasLegacyCartLevel;
|
|
116
|
+
}
|
|
117
|
+
const infoItems = [];
|
|
118
|
+
const cartItems = lines.map((line, index) => {
|
|
119
|
+
const productId = numericId(line.merchandise?.product?.id);
|
|
120
|
+
const variantId = numericId(line.merchandise?.id);
|
|
121
|
+
const quantity = typeof line.quantity === 'number' && Number.isFinite(line.quantity) ? line.quantity : 0;
|
|
122
|
+
const original = originals[index] ?? 0;
|
|
123
|
+
const lineDiscount = cartStateKnown ? sum(productByLine[index]) : 0;
|
|
124
|
+
const finalLinePrice = original - lineDiscount;
|
|
125
|
+
infoItems.push({
|
|
126
|
+
variant_id: variantId,
|
|
127
|
+
product_id: productId,
|
|
128
|
+
quantity,
|
|
129
|
+
original_line_price: original,
|
|
130
|
+
final_line_price: finalLinePrice,
|
|
131
|
+
line_level_total_discount: lineDiscount,
|
|
132
|
+
line_level_discount_allocations: productByLine[index].map(allocation => ({
|
|
133
|
+
amount: allocation.cents,
|
|
134
|
+
discount_application: application(allocation)
|
|
135
|
+
}))
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
id: productId,
|
|
139
|
+
product_id: productId,
|
|
140
|
+
variant_id: variantId,
|
|
141
|
+
quantity,
|
|
142
|
+
original_line_price: original,
|
|
143
|
+
final_line_price: finalLinePrice,
|
|
144
|
+
final_price: quantity > 0 ? Math.round(finalLinePrice / quantity) : finalLinePrice,
|
|
145
|
+
collectionIds: collectionsOf(line).ids
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
const cartLevel = new Map();
|
|
149
|
+
for (const allocation of orderAllocations) {
|
|
150
|
+
const existing = cartLevel.get(allocation.key);
|
|
151
|
+
if (existing)
|
|
152
|
+
existing.total_allocated_amount += allocation.cents;
|
|
153
|
+
else
|
|
154
|
+
cartLevel.set(allocation.key, { ...application(allocation), total_allocated_amount: allocation.cents });
|
|
155
|
+
}
|
|
156
|
+
const originalTotal = cartStateKnown ? cartItems.reduce((total, item) => total + item.original_line_price, 0) : 0;
|
|
157
|
+
const totalDiscount = cartStateKnown
|
|
158
|
+
? infoItems.reduce((total, item) => total + item.line_level_total_discount, 0) + sum(orderAllocations)
|
|
159
|
+
: 0;
|
|
160
|
+
return {
|
|
161
|
+
cartItems,
|
|
162
|
+
cartInfo: {
|
|
163
|
+
currency,
|
|
164
|
+
original_total_price: originalTotal,
|
|
165
|
+
total_discount: totalDiscount,
|
|
166
|
+
discount_codes: discountCodes,
|
|
167
|
+
...(classesKnown ? { items: infoItems, cart_level_discount_applications: [...cartLevel.values()] } : {})
|
|
168
|
+
},
|
|
169
|
+
cartStateKnown,
|
|
170
|
+
collectionIdsKnown: lines.every(line => collectionsOf(line).known),
|
|
171
|
+
currency
|
|
172
|
+
};
|
|
173
|
+
}
|
|
@@ -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 ?? {},
|
|
@@ -30,7 +30,7 @@ export function registerMilestoneTierHandlers(ctx, deps) {
|
|
|
30
30
|
const facade = buildLoaderFacade();
|
|
31
31
|
if (!facade)
|
|
32
32
|
return;
|
|
33
|
-
surface(Promise.resolve(apply(facade, {})));
|
|
33
|
+
surface(Promise.resolve(apply(facade, facade._renderInput || {})));
|
|
34
34
|
}
|
|
35
35
|
async function runMilestoneClaim(d) {
|
|
36
36
|
const { programId } = d;
|
|
@@ -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;
|