@kachingappz/bundles-js 1.2.0 → 1.2.1
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/dist/bundles-js.iife.js +17 -17
- package/dist/index.d.ts +1 -0
- package/dist/index.js +131 -127
- package/dist/kaching-bundle-component/index.d.ts +1 -0
- package/dist/kaching-bundle-component/index.js +144 -140
- package/dist/react/index.cjs +17 -17
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +126 -122
- package/package.json +3 -3
package/dist/react/index.js
CHANGED
|
@@ -25,29 +25,33 @@ var a = /* @__PURE__ */ function(e) {
|
|
|
25
25
|
...e,
|
|
26
26
|
variants: n,
|
|
27
27
|
options: r,
|
|
28
|
-
selectedVariantId: i
|
|
28
|
+
selectedVariantId: i,
|
|
29
|
+
availableForSale: n.some((e) => e.availableForSale)
|
|
29
30
|
};
|
|
30
|
-
}, d = (e, t) =>
|
|
31
|
+
}, d = (e, t) => p(e) ? m(e, t, /* @__PURE__ */ new Set()) : t, f = (e, t) => p(e) ? m(e, t, h(e)) : t, p = (e) => !!e.selectedVariants?.length, m = (e, t, n) => t.flatMap((t) => {
|
|
31
32
|
let r = l(e, t);
|
|
32
33
|
if (!r) return [t];
|
|
33
34
|
let i = u(t, [...r, ...t.variants.map((e) => e.id).filter((e) => n.has(e))]);
|
|
34
35
|
return i.variants.length ? [i] : [];
|
|
35
|
-
}),
|
|
36
|
-
...e.dealBars.flatMap(
|
|
36
|
+
}), h = (e) => new Set([
|
|
37
|
+
...e.dealBars.flatMap(g),
|
|
37
38
|
...(e.progressiveGifts?.gifts ?? []).flatMap((e) => e.variantGIDs ?? []),
|
|
38
39
|
...(e.checkboxUpsells?.upsells ?? []).flatMap((e) => e.variantGIDs ?? [])
|
|
39
|
-
].map(
|
|
40
|
+
].map(v)), g = (e) => [
|
|
40
41
|
...e.freeGifts.flatMap((e) => e.variantGIDs ?? []),
|
|
41
42
|
...e.upsells.flatMap((e) => e.variantGIDs ?? []),
|
|
42
43
|
...(e.multipleGiftsSelectors ?? []).flatMap((e) => e.products.flatMap((e) => e.variantGIDs ?? [])),
|
|
43
|
-
...
|
|
44
|
-
],
|
|
44
|
+
..._(e)
|
|
45
|
+
], _ = (e) => {
|
|
45
46
|
switch (e.dealBarType) {
|
|
46
47
|
case a.Bundle: return e.bundleProducts.flatMap((e) => e.productGID === "default" ? [] : e.variantGIDs ?? []);
|
|
47
48
|
case a.MixAndMatch: return e.bundleProducts.flatMap((e) => [...e.productGID === "default" ? [] : e.variantGIDs ?? [], ...(e.selectedProducts ?? []).flatMap((e) => e.variantGIDs ?? [])]);
|
|
48
49
|
default: return [];
|
|
49
50
|
}
|
|
50
|
-
},
|
|
51
|
+
}, v = (e) => Number(e.split("/").pop()), y = (e, t) => t ? e : e.map(b), b = (e) => {
|
|
52
|
+
let t = { ...e };
|
|
53
|
+
return delete t.selectedVariants, t;
|
|
54
|
+
}, x = (e, t, n) => {
|
|
51
55
|
let r = (e) => n !== void 0 && c(e, t.id, n), i = e.filter((e) => o(e, t.id)?.some((e) => t.variants.some((t) => t.id === e))), a = i.filter(r), s = [...a], l = i.filter((e) => !a.includes(e)), u = e.filter((e) => e.blockVisibility === "selected-products");
|
|
52
56
|
for (let e of u) e.selectedProductIds.map(Number).includes(t.id) && s.push(e);
|
|
53
57
|
let d = e.filter((e) => e.blockVisibility === "selected-collections");
|
|
@@ -57,24 +61,24 @@ var a = /* @__PURE__ */ function(e) {
|
|
|
57
61
|
let p = e.filter((e) => e.blockVisibility === "all-products");
|
|
58
62
|
for (let e of p) s.push(e);
|
|
59
63
|
return n === void 0 ? s : [...s, ...l];
|
|
60
|
-
},
|
|
61
|
-
let r =
|
|
64
|
+
}, S = (e, { language: t, country: n }) => {
|
|
65
|
+
let r = E(t, n), i = new Intl.NumberFormat(r, {
|
|
62
66
|
style: "currency",
|
|
63
67
|
currency: e,
|
|
64
68
|
currencyDisplay: "narrowSymbol"
|
|
65
|
-
}).formatToParts(1234567.89), a = i.find((e) => e.type === "decimal")?.value, o =
|
|
69
|
+
}).formatToParts(1234567.89), a = i.find((e) => e.type === "decimal")?.value, o = te(ee(i.find((e) => e.type === "group")?.value), a, i.some((e) => e.type === "fraction")), s = i.findIndex(T), c = i.findLastIndex(T);
|
|
66
70
|
return [
|
|
67
|
-
...i.slice(0, s).map(
|
|
71
|
+
...i.slice(0, s).map(C),
|
|
68
72
|
o,
|
|
69
|
-
...i.slice(c + 1).map(
|
|
73
|
+
...i.slice(c + 1).map(C)
|
|
70
74
|
].join("");
|
|
71
|
-
},
|
|
75
|
+
}, C = (e) => w(e.value), w = (e) => e.replace(/\s/g, " "), T = (e) => e.type === "integer" || e.type === "group" || e.type === "decimal" || e.type === "fraction", E = (e, t) => e && t ? `${e}-${t.toUpperCase()}` : e || (t ? t.toUpperCase() : "en"), ee = (e) => e === void 0 ? void 0 : w(e).replace(/’/g, "'"), te = (e, t, n) => t === "," && e === "." ? n ? "{{amount_with_comma_separator}}" : "{{amount_no_decimals_with_comma_separator}}" : t === "," && e === " " ? n ? "{{amount_with_space_separator}}" : "{{amount_no_decimals_with_space_separator}}" : t === "." && e === " " ? "{{amount_with_period_and_space_separator}}" : t === "." && e === "'" ? "{{amount_with_apostrophe_separator}}" : n ? "{{amount}}" : "{{amount_no_decimals}}", D = ({ country: e, language: t }) => {
|
|
72
76
|
let n = [];
|
|
73
77
|
return e && n.push(`country: ${e}`), t && n.push(`language: ${t}`), n.length > 0 ? `@inContext(${n.join(", ")})` : "";
|
|
74
|
-
},
|
|
78
|
+
}, ne = async (e, { useExternalMetafieldNamespace: t, useMetaobjects: n }) => n ? ie(e, t) : re(e, t), re = async (e, t) => {
|
|
75
79
|
let n = (await e.query("\n query FetchDealBlocks($metafieldNamespace: String!) {\n shop {\n metafield(namespace: $metafieldNamespace, key: \"deal_blocks\") {\n value\n }\n }\n }\n ", { variables: { metafieldNamespace: t ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles" } })).shop.metafield?.value;
|
|
76
80
|
return n ? JSON.parse(n) : [];
|
|
77
|
-
},
|
|
81
|
+
}, ie = async (e, t) => {
|
|
78
82
|
let n = t ? "app--2935586817--deal_block" : "$app:deal_block", r = [], i = null;
|
|
79
83
|
for (;;) {
|
|
80
84
|
let t = await e.query("\n query FetchDealBlockMetaobjects($type: String!, $cursor: String) {\n metaobjects(type: $type, first: 250, after: $cursor) {\n nodes {\n fields {\n key\n value\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n ", { variables: {
|
|
@@ -110,7 +114,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
110
114
|
case "selected-products": return a.slice(0, s);
|
|
111
115
|
case "all-products":
|
|
112
116
|
case "excluded-products": {
|
|
113
|
-
let a =
|
|
117
|
+
let a = D({
|
|
114
118
|
country: t,
|
|
115
119
|
language: n
|
|
116
120
|
}), o = [], c = null;
|
|
@@ -141,7 +145,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
141
145
|
return o;
|
|
142
146
|
}
|
|
143
147
|
case "selected-collections": {
|
|
144
|
-
let r =
|
|
148
|
+
let r = D({
|
|
145
149
|
country: t,
|
|
146
150
|
language: n
|
|
147
151
|
}), i = (await e.query(`
|
|
@@ -168,7 +172,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
168
172
|
maxHeight: 200
|
|
169
173
|
} }) => {
|
|
170
174
|
if (!r.length) return [];
|
|
171
|
-
let m = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), h =
|
|
175
|
+
let m = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), h = D({
|
|
172
176
|
country: t,
|
|
173
177
|
language: n
|
|
174
178
|
}), g = `
|
|
@@ -286,7 +290,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
286
290
|
subtitleKey: b,
|
|
287
291
|
metafieldNamespace: _,
|
|
288
292
|
variantImageTransform: p
|
|
289
|
-
} }), c ?
|
|
293
|
+
} }), c ? ae(e, t, n) : null]);
|
|
290
294
|
return r.shop.currencyRateConstant && (C = JSON.parse(r.shop.currencyRateConstant.value).amount / 1e6), l ? { nodes: r.nodes.map((e) => e && {
|
|
291
295
|
...e,
|
|
292
296
|
productType: l.get(e.id)
|
|
@@ -297,9 +301,9 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
297
301
|
for (let t of e) t.status === "rejected" && f(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
|
|
298
302
|
T = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
|
|
299
303
|
} else T = (await Promise.all(x.map(w))).flatMap((e) => e.nodes);
|
|
300
|
-
let
|
|
304
|
+
let E = T.filter((e) => e != null);
|
|
301
305
|
if (f) {
|
|
302
|
-
let t = await Promise.allSettled(
|
|
306
|
+
let t = await Promise.allSettled(E.map(async (t) => N(await M(e, t, {
|
|
303
307
|
includeSellingPlans: i,
|
|
304
308
|
includeAvailableQuantity: a,
|
|
305
309
|
variantImageTransform: p
|
|
@@ -307,15 +311,15 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
307
311
|
for (let e of t) e.status === "fulfilled" ? n.push(e.value) : f(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
|
|
308
312
|
return n;
|
|
309
313
|
}
|
|
310
|
-
return (await Promise.all(
|
|
314
|
+
return (await Promise.all(E.map((t) => M(e, t, {
|
|
311
315
|
includeSellingPlans: i,
|
|
312
316
|
includeAvailableQuantity: a,
|
|
313
317
|
variantImageTransform: p
|
|
314
318
|
}, h)))).map((t) => N(t, e.shopifyDomain, C));
|
|
315
|
-
},
|
|
319
|
+
}, ae = async (e, t, n) => {
|
|
316
320
|
try {
|
|
317
321
|
let r = await e.query(`
|
|
318
|
-
query FetchProductTypes($productGIDs: [ID!]!) ${
|
|
322
|
+
query FetchProductTypes($productGIDs: [ID!]!) ${D({ country: t })} {
|
|
319
323
|
nodes(ids: $productGIDs) {
|
|
320
324
|
... on Product {
|
|
321
325
|
id
|
|
@@ -402,7 +406,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
402
406
|
defaultName: e.name,
|
|
403
407
|
name: e.name,
|
|
404
408
|
position: t + 1,
|
|
405
|
-
optionValues:
|
|
409
|
+
optionValues: ce(n, t, r)
|
|
406
410
|
};
|
|
407
411
|
}), a = (e) => {
|
|
408
412
|
let t = e.priceAdjustments[0];
|
|
@@ -450,30 +454,30 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
450
454
|
text3: e.metafield3?.value || null,
|
|
451
455
|
text4: e.metafield4?.value || null
|
|
452
456
|
},
|
|
453
|
-
rating:
|
|
457
|
+
rating: oe(e.reviewsRating, e.reviewsRatingCount),
|
|
454
458
|
subtitle: e.subtitle?.value || null,
|
|
455
459
|
productType: e.productType || null,
|
|
456
460
|
categoryGid: e.category?.id ?? null,
|
|
457
461
|
tags: e.tags ?? []
|
|
458
462
|
};
|
|
459
|
-
},
|
|
463
|
+
}, oe = (e, t) => {
|
|
460
464
|
if (!e) return null;
|
|
461
|
-
let n =
|
|
465
|
+
let n = se(e.value);
|
|
462
466
|
if (n === null) return null;
|
|
463
467
|
let r = Number(t?.value);
|
|
464
468
|
return {
|
|
465
469
|
value: n,
|
|
466
470
|
count: Number.isInteger(r) && r > 0 ? r : null
|
|
467
471
|
};
|
|
468
|
-
},
|
|
472
|
+
}, se = (e) => {
|
|
469
473
|
try {
|
|
470
474
|
let { value: t, scale_max: n } = JSON.parse(e), r = Number(t) / Number(n) * 5;
|
|
471
475
|
return Number.isFinite(r) && r > 0 ? Math.min(5, r) : null;
|
|
472
476
|
} catch {
|
|
473
477
|
return null;
|
|
474
478
|
}
|
|
475
|
-
},
|
|
476
|
-
let i = r ? `${P}--kaching_bundles` : "$app:kaching_bundles", a = r ? P : "$app", o =
|
|
479
|
+
}, ce = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0), P = "app--2935586817", le = async (e, { language: t, country: n, useExternalMetafieldNamespace: r }) => {
|
|
480
|
+
let i = r ? `${P}--kaching_bundles` : "$app:kaching_bundles", a = r ? P : "$app", o = D({ country: n }), { localization: { country: { currency: { isoCode: s } } }, shop: { moneyFormat: c, paymentSettings: { currencyCode: l }, currencyRateConstant: u, primaryDomain: d, settingsMetafield: f } } = await e.query(`
|
|
477
481
|
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${o} {
|
|
478
482
|
localization {
|
|
479
483
|
country {
|
|
@@ -501,10 +505,10 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
501
505
|
`, { variables: {
|
|
502
506
|
metafieldNamespace: i,
|
|
503
507
|
settingsNamespace: a
|
|
504
|
-
} }), p = s === l ? c :
|
|
508
|
+
} }), p = s === l ? c : S(s, {
|
|
505
509
|
language: t,
|
|
506
510
|
country: n
|
|
507
|
-
}), m = u ?
|
|
511
|
+
}), m = u ? ue(u.value) : 1, h = f ? JSON.parse(f.value) : null, g = h?.feature_flags ?? {}, _ = h?.custom_selectors ?? {};
|
|
508
512
|
return {
|
|
509
513
|
shopifyDomain: d.host,
|
|
510
514
|
moneyFormat: p,
|
|
@@ -565,7 +569,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
565
569
|
featureFlags: g,
|
|
566
570
|
brandColors: h?.brand_colors ?? null
|
|
567
571
|
};
|
|
568
|
-
},
|
|
572
|
+
}, ue = (e) => JSON.parse(e).amount / 1e6, de = async (e, t, n = 200) => {
|
|
569
573
|
let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
|
|
570
574
|
if (r.length === 0) return [];
|
|
571
575
|
let i = [];
|
|
@@ -577,10 +581,10 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
577
581
|
gid: e.id,
|
|
578
582
|
url: e.image.url
|
|
579
583
|
}] : []);
|
|
580
|
-
},
|
|
584
|
+
}, F = 100, I = async (e, { dealBlock: t, country: n, language: r }) => {
|
|
581
585
|
let i = [...new Set(t.dealBars.flatMap((e) => e.dealBarType === O.MixAndMatch ? e.bundleProducts : []).flatMap((e) => (e.selectedCollections ?? []).map((e) => e.id)))];
|
|
582
586
|
if (i.length === 0) return [];
|
|
583
|
-
let a =
|
|
587
|
+
let a = D({
|
|
584
588
|
country: n,
|
|
585
589
|
language: r
|
|
586
590
|
}), o = await e.query(`
|
|
@@ -588,7 +592,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
588
592
|
nodes(ids: $collectionGIDs) {
|
|
589
593
|
... on Collection {
|
|
590
594
|
id
|
|
591
|
-
products(first: ${
|
|
595
|
+
products(first: ${F}) {
|
|
592
596
|
nodes {
|
|
593
597
|
id
|
|
594
598
|
variants(first: 1) {
|
|
@@ -603,10 +607,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
603
607
|
}
|
|
604
608
|
`, { variables: { collectionGIDs: i } });
|
|
605
609
|
return [...new Set(o.nodes.filter((e) => e !== null).flatMap((e) => e.products.nodes).filter((e) => !e.variants.nodes.some((e) => e.requiresComponents)).map((e) => e.id))];
|
|
606
|
-
},
|
|
607
|
-
...F(e),
|
|
608
|
-
...I(e),
|
|
609
|
-
...L(e),
|
|
610
|
+
}, L = (e) => [
|
|
610
611
|
...R(e),
|
|
611
612
|
...z(e),
|
|
612
613
|
...B(e),
|
|
@@ -616,39 +617,42 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
616
617
|
...pe(e),
|
|
617
618
|
...me(e),
|
|
618
619
|
...he(e),
|
|
619
|
-
...ge(e)
|
|
620
|
-
|
|
620
|
+
...ge(e),
|
|
621
|
+
..._e(e),
|
|
622
|
+
...ve(e),
|
|
623
|
+
...ye(e)
|
|
624
|
+
].filter((e) => e != null && !e.includes("placeholder")), R = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), z = (e) => e.dealBars.flatMap((e) => e.dealBarType === O.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), B = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), V = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), H = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), fe = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
|
|
621
625
|
let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
|
|
622
626
|
return [...e, ...n];
|
|
623
|
-
}, []) : [],
|
|
627
|
+
}, []) : [], pe = (e) => {
|
|
624
628
|
if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
|
|
625
629
|
let t = e.collectionBreaks.mediaImageGID;
|
|
626
630
|
return t ? [t] : [];
|
|
627
|
-
},
|
|
631
|
+
}, me = (e) => e.progressiveGifts ? [
|
|
628
632
|
...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
|
|
629
633
|
e.progressiveGifts.style?.lockedMediaImageGID,
|
|
630
634
|
e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
|
|
631
|
-
].filter((e) => e != null) : [],
|
|
635
|
+
].filter((e) => e != null) : [], he = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ge = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), _e = (e) => {
|
|
632
636
|
let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
|
|
633
637
|
return n ? [...t, n] : t;
|
|
634
|
-
},
|
|
638
|
+
}, ve = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), ye = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], be = (e, { includeMixAndMatchSwapProducts: t = !0 } = {}) => {
|
|
635
639
|
let n = [
|
|
636
|
-
...ve(e),
|
|
637
|
-
...ye(e),
|
|
638
|
-
...be(e),
|
|
639
640
|
...xe(e),
|
|
640
641
|
...Se(e),
|
|
641
|
-
...Ce(e
|
|
642
|
+
...Ce(e),
|
|
642
643
|
...we(e),
|
|
643
|
-
...Te(e)
|
|
644
|
+
...Te(e),
|
|
645
|
+
...Ee(e, t),
|
|
646
|
+
...De(e),
|
|
647
|
+
...Oe(e)
|
|
644
648
|
];
|
|
645
649
|
return Array.from(new Set(n.filter((e) => e != null)));
|
|
646
|
-
},
|
|
650
|
+
}, xe = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), Se = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), Ce = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], we = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), Te = (e) => e.dealBars.filter((e) => e.dealBarType === O.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), Ee = (e, t) => e.dealBars.filter((e) => e.dealBarType === O.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...t ? e.selectedProducts?.map((e) => e.id) ?? [] : []]) : []).filter((e) => e != null).filter((e) => e !== "default"), De = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), Oe = (e) => e.dealBars.filter((e) => e.dealBarType === O.Sku).flatMap(({ productGID: e }) => e ? [e] : []), U = class extends Error {
|
|
647
651
|
constructor({ status: e, operationName: t, graphqlErrors: n }) {
|
|
648
652
|
let r = n.length ? `: ${n.join("; ")}` : "";
|
|
649
653
|
super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
|
|
650
654
|
}
|
|
651
|
-
},
|
|
655
|
+
}, ke = async (e, t) => {
|
|
652
656
|
let n = await e.text();
|
|
653
657
|
if (!n) throw Error("Empty graphql response");
|
|
654
658
|
let r;
|
|
@@ -667,13 +671,13 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
667
671
|
graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
|
|
668
672
|
});
|
|
669
673
|
return r.data;
|
|
670
|
-
},
|
|
674
|
+
}, Ae = class {
|
|
671
675
|
constructor(e, t) {
|
|
672
676
|
this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
|
|
673
677
|
}
|
|
674
678
|
async query(e, t) {
|
|
675
679
|
let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
|
|
676
|
-
return i && (r += `?operation_name=${i}`),
|
|
680
|
+
return i && (r += `?operation_name=${i}`), ke(await fetch(r, {
|
|
677
681
|
method: "POST",
|
|
678
682
|
headers: {
|
|
679
683
|
"Content-Type": "application/json",
|
|
@@ -701,7 +705,7 @@ var O = /* @__PURE__ */ function(e) {
|
|
|
701
705
|
].map((e) => `brand_${e}`);
|
|
702
706
|
var W = /* @__PURE__ */ function(e) {
|
|
703
707
|
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
704
|
-
}({}),
|
|
708
|
+
}({}), je = async (e, t, { country: n, language: r }) => {
|
|
705
709
|
let i = t.collectionBreaks;
|
|
706
710
|
if (!t.collectionBreaksEnabled || !i) return;
|
|
707
711
|
let a;
|
|
@@ -710,7 +714,7 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
710
714
|
language: r,
|
|
711
715
|
blockVisibility: t.blockVisibility,
|
|
712
716
|
excludedProductGIDs: (t.excludedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
|
|
713
|
-
selectedProductGIDs:
|
|
717
|
+
selectedProductGIDs: [...t.selectedProductIds || [], ...(t.selectedVariants || []).map(({ productId: e }) => e)].map((e) => `gid://shopify/Product/${e}`),
|
|
714
718
|
selectedCollectionGIDs: (t.selectedCollectionIds || []).map((e) => `gid://shopify/Collection/${e}`)
|
|
715
719
|
}) : await k(e, {
|
|
716
720
|
country: n,
|
|
@@ -726,8 +730,8 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
726
730
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
727
731
|
useExternalMetafieldNamespace: !0
|
|
728
732
|
}), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
|
|
729
|
-
return
|
|
730
|
-
},
|
|
733
|
+
return d(t, o).filter((e) => e.availableForSale && (!s || x([t], e).length > 0));
|
|
734
|
+
}, Me = ({ language: e, dealBlockId: t }) => {
|
|
731
735
|
let n = {
|
|
732
736
|
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
733
737
|
"system.invalid_variant": "Sorry, this is not currently available.",
|
|
@@ -754,13 +758,13 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
754
758
|
"system.numbers_only": "Only numbers are allowed.",
|
|
755
759
|
"system.personalisation_required_alert": "Please add personalisation for every item to continue.",
|
|
756
760
|
"system.gifts_required_alert": "Please choose your free gifts"
|
|
757
|
-
}, r = e ?
|
|
761
|
+
}, r = e ? Ne(e) : void 0;
|
|
758
762
|
return {
|
|
759
763
|
...n,
|
|
760
764
|
...r?.system,
|
|
761
765
|
...r?.dealBlocks[t]
|
|
762
766
|
};
|
|
763
|
-
},
|
|
767
|
+
}, Ne = (e) => {
|
|
764
768
|
if (typeof document > "u") return;
|
|
765
769
|
let t = document.querySelector("script#kaching-bundles-translations");
|
|
766
770
|
if (!t?.textContent) return;
|
|
@@ -772,70 +776,70 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
772
776
|
}
|
|
773
777
|
let r = G(e);
|
|
774
778
|
return n.find((e) => G(e.locale) === r)?.translations;
|
|
775
|
-
}, G = (e) => e.toLowerCase().replace(/_/g, "-"),
|
|
779
|
+
}, G = (e) => e.toLowerCase().replace(/_/g, "-"), Pe = "2026-07", Fe = async (e, { productId: t, dealBlockId: n, abTestVariantId: r, country: i = void 0, language: a = void 0 }) => {
|
|
776
780
|
try {
|
|
777
|
-
let o = [Number(t.split("/").pop())], s = new
|
|
781
|
+
let o = [Number(t.split("/").pop())], s = new Be(e);
|
|
778
782
|
i ||= s.i18n?.country, a ||= s.i18n?.language;
|
|
779
|
-
let c = await
|
|
783
|
+
let c = await le(s, {
|
|
780
784
|
language: a,
|
|
781
785
|
country: i,
|
|
782
786
|
useExternalMetafieldNamespace: !0
|
|
783
787
|
});
|
|
784
788
|
s.shopifyDomain = c.shopifyDomain;
|
|
785
|
-
let l = c.storefrontAccessToken ? new
|
|
789
|
+
let l = c.storefrontAccessToken ? new Ae(c.shopifyDomain, c.storefrontAccessToken) : s, [u, d] = await Promise.all([j(l, {
|
|
786
790
|
country: i,
|
|
787
791
|
language: a,
|
|
788
792
|
productIds: o,
|
|
789
793
|
useExternalMetafieldNamespace: !0
|
|
790
|
-
}),
|
|
794
|
+
}), ne(l, {
|
|
791
795
|
useExternalMetafieldNamespace: !0,
|
|
792
796
|
useMetaobjects: c.featureFlags.storefront_metaobjects
|
|
793
|
-
})]), p = u[0];
|
|
794
|
-
if (!
|
|
795
|
-
let
|
|
796
|
-
if (!
|
|
797
|
-
let
|
|
798
|
-
otherProductGIDs:
|
|
797
|
+
})]), p = y(d, c.featureFlags.selected_variants), m = u[0];
|
|
798
|
+
if (!m) return null;
|
|
799
|
+
let h = x(p, m), g = n ? h.filter((e) => e.id === n || e.nanoId === n) : h, _ = (r ? g.find((e) => e.abTestVariantId === r) : void 0) ?? g[0] ?? h[0];
|
|
800
|
+
if (!_) return null;
|
|
801
|
+
let v = be(_, { includeMixAndMatchSwapProducts: !1 }), b = Ie(l, _, {
|
|
802
|
+
otherProductGIDs: v,
|
|
799
803
|
country: i,
|
|
800
804
|
language: a
|
|
801
|
-
}), [
|
|
805
|
+
}), [S, C, w] = await Promise.all([
|
|
802
806
|
j(l, {
|
|
803
807
|
country: i,
|
|
804
808
|
language: a,
|
|
805
|
-
productIds:
|
|
809
|
+
productIds: v,
|
|
806
810
|
useExternalMetafieldNamespace: !0
|
|
807
811
|
}),
|
|
808
|
-
|
|
809
|
-
|
|
812
|
+
de(l, L(_), 300),
|
|
813
|
+
Me({
|
|
810
814
|
language: a,
|
|
811
|
-
dealBlockId:
|
|
815
|
+
dealBlockId: _.id
|
|
812
816
|
})
|
|
813
817
|
]);
|
|
814
818
|
return {
|
|
815
819
|
data: {
|
|
816
820
|
config: c,
|
|
817
|
-
dealBlock:
|
|
818
|
-
product:
|
|
819
|
-
otherProducts:
|
|
820
|
-
mediaImages:
|
|
821
|
-
translations:
|
|
821
|
+
dealBlock: _,
|
|
822
|
+
product: m,
|
|
823
|
+
otherProducts: f(_, S),
|
|
824
|
+
mediaImages: C,
|
|
825
|
+
translations: w
|
|
822
826
|
},
|
|
823
|
-
modalProducts:
|
|
827
|
+
modalProducts: b
|
|
824
828
|
};
|
|
825
829
|
} catch (e) {
|
|
826
830
|
return console.error(e), null;
|
|
827
831
|
}
|
|
828
|
-
},
|
|
829
|
-
let [r, i] = await Promise.all([
|
|
832
|
+
}, Ie = async (e, t, n) => {
|
|
833
|
+
let [r, i] = await Promise.all([Le(e, t, n), ze(e, t, n)]);
|
|
830
834
|
return {
|
|
831
835
|
mixAndMatchSwapProducts: r,
|
|
832
836
|
collectionBreaksProducts: i
|
|
833
837
|
};
|
|
834
|
-
},
|
|
838
|
+
}, Le = async (e, t, { otherProductGIDs: n, country: r, language: i }) => {
|
|
835
839
|
try {
|
|
836
840
|
let a = [];
|
|
837
841
|
try {
|
|
838
|
-
a = await
|
|
842
|
+
a = await I(e, {
|
|
839
843
|
dealBlock: t,
|
|
840
844
|
country: r,
|
|
841
845
|
language: i
|
|
@@ -843,8 +847,8 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
843
847
|
} catch (e) {
|
|
844
848
|
console.error(e);
|
|
845
849
|
}
|
|
846
|
-
let o = new Set(n), s = [.../* @__PURE__ */ new Set([...
|
|
847
|
-
return s.length ?
|
|
850
|
+
let o = new Set(n), s = [.../* @__PURE__ */ new Set([...Re(t), ...a])].filter((e) => !o.has(e));
|
|
851
|
+
return s.length ? f(t, await j(e, {
|
|
848
852
|
country: r,
|
|
849
853
|
language: i,
|
|
850
854
|
productIds: s,
|
|
@@ -853,16 +857,16 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
853
857
|
} catch (e) {
|
|
854
858
|
return console.error(e), [];
|
|
855
859
|
}
|
|
856
|
-
},
|
|
860
|
+
}, Re = (e) => e.dealBars.flatMap((e) => e.dealBarType === W.MixAndMatch ? e.bundleProducts.flatMap((e) => (e.selectedProducts ?? []).map((e) => e.id)) : []), ze = async (e, t, { country: n, language: r }) => {
|
|
857
861
|
try {
|
|
858
|
-
return await
|
|
862
|
+
return await je(e, t, {
|
|
859
863
|
country: n,
|
|
860
864
|
language: r
|
|
861
865
|
}) ?? [];
|
|
862
866
|
} catch (e) {
|
|
863
867
|
return console.error(e), [];
|
|
864
868
|
}
|
|
865
|
-
},
|
|
869
|
+
}, Be = class {
|
|
866
870
|
constructor(e) {
|
|
867
871
|
this.storefront = e, this.shopifyDomain = "";
|
|
868
872
|
}
|
|
@@ -875,7 +879,7 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
875
879
|
}
|
|
876
880
|
if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
|
|
877
881
|
if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
|
|
878
|
-
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${
|
|
882
|
+
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${Pe}/graphql.json`, {
|
|
879
883
|
body: JSON.stringify({
|
|
880
884
|
query: e,
|
|
881
885
|
variables: t?.variables
|
|
@@ -905,9 +909,9 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
905
909
|
get i18n() {
|
|
906
910
|
if ("i18n" in this.storefront) return this.storefront.i18n;
|
|
907
911
|
}
|
|
908
|
-
},
|
|
912
|
+
}, Ve = async (e, t) => {
|
|
909
913
|
try {
|
|
910
|
-
let n = await
|
|
914
|
+
let n = await Fe(e, t);
|
|
911
915
|
if (!n) return null;
|
|
912
916
|
let { config: r, dealBlock: i, product: a, otherProducts: o, mediaImages: s, translations: c } = n.data, { mixAndMatchSwapProducts: l, collectionBreaksProducts: u } = await n.modalProducts;
|
|
913
917
|
return {
|
|
@@ -923,34 +927,34 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
923
927
|
} catch (e) {
|
|
924
928
|
return console.error(e), null;
|
|
925
929
|
}
|
|
926
|
-
}, K = "kaching-bundles-block", q = 1e4, J = "/kaching-bundles-block.js",
|
|
930
|
+
}, K = "kaching-bundles-block", q = 1e4, J = "/kaching-bundles-block.js", He = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", Ue = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", Y = /* @__PURE__ */ new WeakSet(), We = async (e) => {
|
|
927
931
|
let t = e.document;
|
|
928
932
|
if (!e.customElements.get(K)) {
|
|
929
933
|
if (Y.has(t)) return Z(e, K);
|
|
930
934
|
Y.add(t);
|
|
931
935
|
try {
|
|
932
|
-
await
|
|
936
|
+
await qe(e);
|
|
933
937
|
} catch (e) {
|
|
934
938
|
throw Y.delete(t), e;
|
|
935
939
|
}
|
|
936
940
|
}
|
|
937
|
-
},
|
|
938
|
-
let t = e.document, n =
|
|
941
|
+
}, Ge = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Ke = () => Ge() ? He : Ue, qe = async (e) => {
|
|
942
|
+
let t = e.document, n = Ke();
|
|
939
943
|
if (t.querySelector(`script[src="${n}"]`)) return Z(e, K);
|
|
940
|
-
let r =
|
|
941
|
-
if (r && await
|
|
944
|
+
let r = Je(t);
|
|
945
|
+
if (r && await Xe(t, r)) return Z(e, K);
|
|
942
946
|
let i = t.createElement("script");
|
|
943
947
|
return i.src = n, await X(t, i), Z(e, K);
|
|
944
|
-
},
|
|
948
|
+
}, Je = (e) => {
|
|
945
949
|
let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${J}"]`);
|
|
946
|
-
return Array.from(t, (e) => e.href).find(
|
|
947
|
-
},
|
|
950
|
+
return Array.from(t, (e) => e.href).find(Ye);
|
|
951
|
+
}, Ye = (e) => {
|
|
948
952
|
try {
|
|
949
953
|
return new URL(e).pathname.endsWith(J);
|
|
950
954
|
} catch {
|
|
951
955
|
return !1;
|
|
952
956
|
}
|
|
953
|
-
},
|
|
957
|
+
}, Xe = async (e, t) => {
|
|
954
958
|
let n = e.createElement("script");
|
|
955
959
|
n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
|
|
956
960
|
try {
|
|
@@ -962,9 +966,9 @@ var W = /* @__PURE__ */ function(e) {
|
|
|
962
966
|
t.onload = () => n(), t.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), e.head.appendChild(t);
|
|
963
967
|
}), Z = (e, t) => new Promise((n, r) => {
|
|
964
968
|
e.customElements.get(t) ? n() : Promise.race([e.customElements.whenDefined(t), new Promise((e, n) => setTimeout(() => n(/* @__PURE__ */ Error(`Custom element "${t}" failed to register within ${q}ms`)), q))]).then(() => n()).catch(r);
|
|
965
|
-
}), Q = "a-f\\d",
|
|
966
|
-
function
|
|
967
|
-
if (typeof e != "string" ||
|
|
969
|
+
}), Q = "a-f\\d", Ze = `#?[${Q}]{3}[${Q}]?`, $ = `#?[${Q}]{6}([${Q}]{2})?`, Qe = RegExp(`[^#${Q}]`, "gi"), $e = RegExp(`^${Ze}$|^${$}$`, "i");
|
|
970
|
+
function et(e, t = {}) {
|
|
971
|
+
if (typeof e != "string" || Qe.test(e) || !$e.test(e)) throw TypeError("Expected a valid hex string");
|
|
968
972
|
e = e.replace(/^#/, "");
|
|
969
973
|
let n = 1;
|
|
970
974
|
e.length === 8 && (n = Number.parseInt(e.slice(6, 8), 16) / 255, e = e.slice(0, 6)), e.length === 4 && (n = Number.parseInt(e.slice(3, 4).repeat(2), 16) / 255, e = e.slice(0, 3)), e.length === 3 && (e = e[0] + e[0] + e[1] + e[1] + e[2] + e[2]);
|
|
@@ -982,7 +986,7 @@ function $(e, t = {}) {
|
|
|
982
986
|
};
|
|
983
987
|
}
|
|
984
988
|
// src/react/preview.ts
|
|
985
|
-
var
|
|
989
|
+
var tt = ({ price: e }) => ({
|
|
986
990
|
id: 123,
|
|
987
991
|
handle: "123",
|
|
988
992
|
url: null,
|
|
@@ -1015,7 +1019,7 @@ var Qe = ({ price: e }) => ({
|
|
|
1015
1019
|
text4: null
|
|
1016
1020
|
},
|
|
1017
1021
|
isNativeBundle: !1
|
|
1018
|
-
}),
|
|
1022
|
+
}), nt = () => ({
|
|
1019
1023
|
shopifyDomain: "",
|
|
1020
1024
|
moneyFormat: "${{amount_with_comma_separator}}",
|
|
1021
1025
|
locale: "en",
|
|
@@ -1071,7 +1075,7 @@ var Qe = ({ price: e }) => ({
|
|
|
1071
1075
|
},
|
|
1072
1076
|
shopCustomStyles: "",
|
|
1073
1077
|
featureFlags: {}
|
|
1074
|
-
}),
|
|
1078
|
+
}), rt = ({ color: e, cornerRadius: t }) => {
|
|
1075
1079
|
let n = {
|
|
1076
1080
|
id: "123",
|
|
1077
1081
|
nanoId: "123",
|
|
@@ -1331,14 +1335,14 @@ var Qe = ({ price: e }) => ({
|
|
|
1331
1335
|
imageCornerRadius: 6
|
|
1332
1336
|
};
|
|
1333
1337
|
return e !== void 0 && (n.colors.border = {
|
|
1334
|
-
|
|
1338
|
+
...et(e),
|
|
1335
1339
|
alpha: 1
|
|
1336
1340
|
}), n;
|
|
1337
|
-
},
|
|
1341
|
+
}, it = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
|
|
1338
1342
|
let l = n(null), [u, d] = r(!1), f = n(!1);
|
|
1339
1343
|
e(() => {
|
|
1340
1344
|
l.current && !u && (async () => {
|
|
1341
|
-
await
|
|
1345
|
+
await We(c ?? window), d(!0);
|
|
1342
1346
|
})();
|
|
1343
1347
|
}, [u, c]), e(() => {
|
|
1344
1348
|
let e = l.current;
|
|
@@ -1359,8 +1363,8 @@ var Qe = ({ price: e }) => ({
|
|
|
1359
1363
|
e.removeEventListener("kaching-bundles-block-loaded", t), e.removeEventListener("variants-changed", t);
|
|
1360
1364
|
};
|
|
1361
1365
|
}, [u, s]);
|
|
1362
|
-
let p = t ?
|
|
1363
|
-
return
|
|
1366
|
+
let p = t ? ot(t, a) : o ? st(o) : null;
|
|
1367
|
+
return at(() => {
|
|
1364
1368
|
let e = l.current;
|
|
1365
1369
|
if (e && p) for (let [t, n] of Object.entries(p.jsonAttributes)) e.getAttribute(t) !== n && e.setAttribute(t, n);
|
|
1366
1370
|
}), p ? /* @__PURE__ */ i("kaching-bundles-block", {
|
|
@@ -1369,7 +1373,7 @@ var Qe = ({ price: e }) => ({
|
|
|
1369
1373
|
...p.jsonAttributes,
|
|
1370
1374
|
"current-variant-id": p.currentVariantId
|
|
1371
1375
|
}) : null;
|
|
1372
|
-
},
|
|
1376
|
+
}, at = typeof window > "u" ? e : t, ot = ({ config: e, dealBlock: t, product: n, otherProducts: r, mixAndMatchSwapProducts: i, mediaImages: a, collectionBreaksProducts: o, translations: s }, c) => ({
|
|
1373
1377
|
dealBlockId: t.id,
|
|
1374
1378
|
currentVariantId: c ? c.split("/").pop() : String(n.variants[0].id),
|
|
1375
1379
|
jsonAttributes: {
|
|
@@ -1382,8 +1386,8 @@ var Qe = ({ price: e }) => ({
|
|
|
1382
1386
|
"collection-breaks-products": JSON.stringify(o),
|
|
1383
1387
|
translations: JSON.stringify(s)
|
|
1384
1388
|
}
|
|
1385
|
-
}),
|
|
1386
|
-
let r =
|
|
1389
|
+
}), st = ({ cornerRadius: e, color: t, price: n }) => {
|
|
1390
|
+
let r = tt({ price: n }), i = nt(), a = rt({
|
|
1387
1391
|
color: t,
|
|
1388
1392
|
cornerRadius: e
|
|
1389
1393
|
});
|
|
@@ -1402,4 +1406,4 @@ var Qe = ({ price: e }) => ({
|
|
|
1402
1406
|
}
|
|
1403
1407
|
};
|
|
1404
1408
|
};
|
|
1405
|
-
export {
|
|
1409
|
+
export { it as KachingBundle, Ve as fetchKachingBundlesData };
|