@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
|
@@ -23,29 +23,33 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
23
23
|
...e,
|
|
24
24
|
variants: n,
|
|
25
25
|
options: r,
|
|
26
|
-
selectedVariantId: i
|
|
26
|
+
selectedVariantId: i,
|
|
27
|
+
availableForSale: n.some((e) => e.availableForSale)
|
|
27
28
|
};
|
|
28
|
-
}, o = (e, t) =>
|
|
29
|
+
}, o = (e, t) => c(e) ? l(e, t, /* @__PURE__ */ new Set()) : t, s = (e, t) => c(e) ? l(e, t, u(e)) : t, c = (e) => !!e.selectedVariants?.length, l = (e, t, n) => t.flatMap((t) => {
|
|
29
30
|
let r = i(e, t);
|
|
30
31
|
if (!r) return [t];
|
|
31
32
|
let o = a(t, [...r, ...t.variants.map((e) => e.id).filter((e) => n.has(e))]);
|
|
32
33
|
return o.variants.length ? [o] : [];
|
|
33
|
-
}),
|
|
34
|
-
...e.dealBars.flatMap(
|
|
34
|
+
}), u = (e) => new Set([
|
|
35
|
+
...e.dealBars.flatMap(d),
|
|
35
36
|
...(e.progressiveGifts?.gifts ?? []).flatMap((e) => e.variantGIDs ?? []),
|
|
36
37
|
...(e.checkboxUpsells?.upsells ?? []).flatMap((e) => e.variantGIDs ?? [])
|
|
37
|
-
].map(
|
|
38
|
+
].map(p)), d = (e) => [
|
|
38
39
|
...e.freeGifts.flatMap((e) => e.variantGIDs ?? []),
|
|
39
40
|
...e.upsells.flatMap((e) => e.variantGIDs ?? []),
|
|
40
41
|
...(e.multipleGiftsSelectors ?? []).flatMap((e) => e.products.flatMap((e) => e.variantGIDs ?? [])),
|
|
41
|
-
...
|
|
42
|
-
],
|
|
42
|
+
...f(e)
|
|
43
|
+
], f = (t) => {
|
|
43
44
|
switch (t.dealBarType) {
|
|
44
45
|
case e.Bundle: return t.bundleProducts.flatMap((e) => e.productGID === "default" ? [] : e.variantGIDs ?? []);
|
|
45
46
|
case e.MixAndMatch: return t.bundleProducts.flatMap((e) => [...e.productGID === "default" ? [] : e.variantGIDs ?? [], ...(e.selectedProducts ?? []).flatMap((e) => e.variantGIDs ?? [])]);
|
|
46
47
|
default: return [];
|
|
47
48
|
}
|
|
48
|
-
},
|
|
49
|
+
}, p = (e) => Number(e.split("/").pop()), m = (e, t) => t ? e : e.map(h), h = (e) => {
|
|
50
|
+
let t = { ...e };
|
|
51
|
+
return delete t.selectedVariants, t;
|
|
52
|
+
}, g = (e, n, i) => {
|
|
49
53
|
let a = (e) => i !== void 0 && r(e, n.id, i), o = e.filter((e) => t(e, n.id)?.some((e) => n.variants.some((t) => t.id === e))), s = o.filter(a), c = [...s], l = o.filter((e) => !s.includes(e)), u = e.filter((e) => e.blockVisibility === "selected-products");
|
|
50
54
|
for (let e of u) e.selectedProductIds.map(Number).includes(n.id) && c.push(e);
|
|
51
55
|
let d = e.filter((e) => e.blockVisibility === "selected-collections");
|
|
@@ -55,24 +59,24 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
55
59
|
let p = e.filter((e) => e.blockVisibility === "all-products");
|
|
56
60
|
for (let e of p) c.push(e);
|
|
57
61
|
return i === void 0 ? c : [...c, ...l];
|
|
58
|
-
},
|
|
59
|
-
let r =
|
|
62
|
+
}, _ = (e, { language: t, country: n }) => {
|
|
63
|
+
let r = x(t, n), i = new Intl.NumberFormat(r, {
|
|
60
64
|
style: "currency",
|
|
61
65
|
currency: e,
|
|
62
66
|
currencyDisplay: "narrowSymbol"
|
|
63
|
-
}).formatToParts(1234567.89), a = i.find((e) => e.type === "decimal")?.value, o =
|
|
67
|
+
}).formatToParts(1234567.89), a = i.find((e) => e.type === "decimal")?.value, o = C(S(i.find((e) => e.type === "group")?.value), a, i.some((e) => e.type === "fraction")), s = i.findIndex(b), c = i.findLastIndex(b);
|
|
64
68
|
return [
|
|
65
|
-
...i.slice(0, s).map(
|
|
69
|
+
...i.slice(0, s).map(v),
|
|
66
70
|
o,
|
|
67
|
-
...i.slice(c + 1).map(
|
|
71
|
+
...i.slice(c + 1).map(v)
|
|
68
72
|
].join("");
|
|
69
|
-
},
|
|
73
|
+
}, v = (e) => y(e.value), y = (e) => e.replace(/\s/g, " "), b = (e) => e.type === "integer" || e.type === "group" || e.type === "decimal" || e.type === "fraction", x = (e, t) => e && t ? `${e}-${t.toUpperCase()}` : e || (t ? t.toUpperCase() : "en"), S = (e) => e === void 0 ? void 0 : y(e).replace(/’/g, "'"), C = (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}}", w = ({ country: e, language: t }) => {
|
|
70
74
|
let n = [];
|
|
71
75
|
return e && n.push(`country: ${e}`), t && n.push(`language: ${t}`), n.length > 0 ? `@inContext(${n.join(", ")})` : "";
|
|
72
|
-
},
|
|
76
|
+
}, T = async (e, { useExternalMetafieldNamespace: t, useMetaobjects: n }) => n ? D(e, t) : E(e, t), E = async (e, t) => {
|
|
73
77
|
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;
|
|
74
78
|
return n ? JSON.parse(n) : [];
|
|
75
|
-
},
|
|
79
|
+
}, D = async (e, t) => {
|
|
76
80
|
let n = t ? "app--2935586817--deal_block" : "$app:deal_block", r = [], i = null;
|
|
77
81
|
for (;;) {
|
|
78
82
|
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: {
|
|
@@ -101,14 +105,14 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
101
105
|
"badgeText",
|
|
102
106
|
"error"
|
|
103
107
|
].map((e) => `brand_${e}`);
|
|
104
|
-
var
|
|
108
|
+
var O = /* @__PURE__ */ function(e) {
|
|
105
109
|
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
106
|
-
}({}),
|
|
110
|
+
}({}), k = async (e, { country: t, language: n, blockVisibility: r, excludedProductGIDs: i, selectedProductGIDs: a, selectedCollectionGIDs: o, limit: s = 1e3 }) => {
|
|
107
111
|
switch (r) {
|
|
108
112
|
case "selected-products": return a.slice(0, s);
|
|
109
113
|
case "all-products":
|
|
110
114
|
case "excluded-products": {
|
|
111
|
-
let a =
|
|
115
|
+
let a = w({
|
|
112
116
|
country: t,
|
|
113
117
|
language: n
|
|
114
118
|
}), o = [], c = null;
|
|
@@ -139,7 +143,7 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
139
143
|
return o;
|
|
140
144
|
}
|
|
141
145
|
case "selected-collections": {
|
|
142
|
-
let r =
|
|
146
|
+
let r = w({
|
|
143
147
|
country: t,
|
|
144
148
|
language: n
|
|
145
149
|
}), i = (await e.query(`
|
|
@@ -161,12 +165,12 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
161
165
|
return Array.from(new Set(i)).slice(0, s);
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
|
-
},
|
|
168
|
+
}, A = "\n id\n availableForSale\n price {\n amount\n }\n compareAtPrice {\n amount\n }\n selectedOptions {\n name\n value\n }\n image {\n id\n url(transform: $variantImageTransform)\n }\n unitPriceMeasurement {\n quantityUnit\n quantityValue\n referenceUnit\n referenceValue\n }\n requiresComponents\n sellingPlanAllocations(first: 100) @include(if: $includeSellingPlans) {\n nodes {\n sellingPlan {\n id\n }\n priceAdjustments {\n price {\n amount\n }\n compareAtPrice {\n amount\n }\n perDeliveryPrice {\n amount\n }\n }\n }\n }\n quantityAvailable @include(if: $includeAvailableQuantity)\n", j = async (e, { country: t, language: n, productIds: r, includeSellingPlans: i = !0, includeAvailableQuantity: a = !0, includeProductRating: o = !1, includeProductSubtitle: s = !1, includeProductTabFields: c = !1, productSubtitleMetafield: l = "descriptors.subtitle", useExternalMetafieldNamespace: u = !1, batchSize: d = 250, onBatchError: f, variantImageTransform: p = {
|
|
165
169
|
maxWidth: 200,
|
|
166
170
|
maxHeight: 200
|
|
167
171
|
} }) => {
|
|
168
172
|
if (!r.length) return [];
|
|
169
|
-
let m = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), h =
|
|
173
|
+
let m = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), h = w({
|
|
170
174
|
country: t,
|
|
171
175
|
language: n
|
|
172
176
|
}), g = `
|
|
@@ -204,7 +208,7 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
204
208
|
}
|
|
205
209
|
variants(first: 250) {
|
|
206
210
|
nodes {
|
|
207
|
-
${
|
|
211
|
+
${A}
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
214
|
collections(first: 50) {
|
|
@@ -270,9 +274,9 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
270
274
|
}
|
|
271
275
|
}
|
|
272
276
|
}
|
|
273
|
-
`, _ = u ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", v = l.indexOf("."), y = l.slice(0, v), b = l.slice(v + 1),
|
|
274
|
-
for (let e = 0; e < m.length; e +=
|
|
275
|
-
let
|
|
277
|
+
`, _ = u ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", v = l.indexOf("."), y = l.slice(0, v), b = l.slice(v + 1), x = [], S = Math.min(d, 250);
|
|
278
|
+
for (let e = 0; e < m.length; e += S) x.push(m.slice(e, e + S));
|
|
279
|
+
let C = 1, T = async (n) => {
|
|
276
280
|
let [r, l] = await Promise.all([e.query(g, { variables: {
|
|
277
281
|
productGIDs: n,
|
|
278
282
|
includeSellingPlans: i,
|
|
@@ -285,35 +289,35 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
285
289
|
metafieldNamespace: _,
|
|
286
290
|
variantImageTransform: p
|
|
287
291
|
} }), c ? ee(e, t, n) : null]);
|
|
288
|
-
return r.shop.currencyRateConstant && (
|
|
292
|
+
return r.shop.currencyRateConstant && (C = JSON.parse(r.shop.currencyRateConstant.value).amount / 1e6), l ? { nodes: r.nodes.map((e) => e && {
|
|
289
293
|
...e,
|
|
290
294
|
productType: l.get(e.id)
|
|
291
295
|
}) } : r;
|
|
292
296
|
}, E;
|
|
293
297
|
if (f) {
|
|
294
|
-
let e = await Promise.allSettled(
|
|
298
|
+
let e = await Promise.allSettled(x.map(T));
|
|
295
299
|
for (let t of e) t.status === "rejected" && f(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
|
|
296
300
|
E = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
|
|
297
|
-
} else E = (await Promise.all(
|
|
298
|
-
let
|
|
301
|
+
} else E = (await Promise.all(x.map(T))).flatMap((e) => e.nodes);
|
|
302
|
+
let D = E.filter((e) => e != null);
|
|
299
303
|
if (f) {
|
|
300
|
-
let t = await Promise.allSettled(
|
|
304
|
+
let t = await Promise.allSettled(D.map(async (t) => N(await M(e, t, {
|
|
301
305
|
includeSellingPlans: i,
|
|
302
306
|
includeAvailableQuantity: a,
|
|
303
307
|
variantImageTransform: p
|
|
304
|
-
}, h), e.shopifyDomain,
|
|
308
|
+
}, h), e.shopifyDomain, C))), n = [];
|
|
305
309
|
for (let e of t) e.status === "fulfilled" ? n.push(e.value) : f(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
|
|
306
310
|
return n;
|
|
307
311
|
}
|
|
308
|
-
return (await Promise.all(
|
|
312
|
+
return (await Promise.all(D.map((t) => M(e, t, {
|
|
309
313
|
includeSellingPlans: i,
|
|
310
314
|
includeAvailableQuantity: a,
|
|
311
315
|
variantImageTransform: p
|
|
312
|
-
}, h)))).map((t) =>
|
|
316
|
+
}, h)))).map((t) => N(t, e.shopifyDomain, C));
|
|
313
317
|
}, ee = async (e, t, n) => {
|
|
314
318
|
try {
|
|
315
319
|
let r = await e.query(`
|
|
316
|
-
query FetchProductTypes($productGIDs: [ID!]!) ${
|
|
320
|
+
query FetchProductTypes($productGIDs: [ID!]!) ${w({ country: t })} {
|
|
317
321
|
nodes(ids: $productGIDs) {
|
|
318
322
|
... on Product {
|
|
319
323
|
id
|
|
@@ -326,7 +330,7 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
326
330
|
} catch (e) {
|
|
327
331
|
return console.error(e), null;
|
|
328
332
|
}
|
|
329
|
-
},
|
|
333
|
+
}, M = async (e, t, n, r = "") => {
|
|
330
334
|
if (t.variants.nodes.length < 250) return t;
|
|
331
335
|
let i = /* @__PURE__ */ new Set(), a = [], o = [], s = async (s) => {
|
|
332
336
|
let c = !0, l = null;
|
|
@@ -336,7 +340,7 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
336
340
|
product(id: $productGID) {
|
|
337
341
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
338
342
|
nodes {
|
|
339
|
-
${
|
|
343
|
+
${A}
|
|
340
344
|
}
|
|
341
345
|
pageInfo {
|
|
342
346
|
endCursor
|
|
@@ -362,7 +366,7 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
362
366
|
}
|
|
363
367
|
};
|
|
364
368
|
return await Promise.all([s(!1), s(!0)]), t.variants.nodes = [...a, ...o.reverse()], t;
|
|
365
|
-
},
|
|
369
|
+
}, N = (e, t, n) => {
|
|
366
370
|
let r = e.variants.nodes.map(({ unitPriceMeasurement: e, ...t }) => ({
|
|
367
371
|
id: Number(t.id.split("/").pop()),
|
|
368
372
|
availableForSale: t.availableForSale,
|
|
@@ -470,8 +474,8 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
470
474
|
} catch {
|
|
471
475
|
return null;
|
|
472
476
|
}
|
|
473
|
-
}, re = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0),
|
|
474
|
-
let i = r ? `${
|
|
477
|
+
}, re = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0), P = "app--2935586817", ie = async (e, { language: t, country: n, useExternalMetafieldNamespace: r }) => {
|
|
478
|
+
let i = r ? `${P}--kaching_bundles` : "$app:kaching_bundles", a = r ? P : "$app", o = w({ country: n }), { localization: { country: { currency: { isoCode: s } } }, shop: { moneyFormat: c, paymentSettings: { currencyCode: l }, currencyRateConstant: u, primaryDomain: d, settingsMetafield: f } } = await e.query(`
|
|
475
479
|
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${o} {
|
|
476
480
|
localization {
|
|
477
481
|
country {
|
|
@@ -499,29 +503,29 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
499
503
|
`, { variables: {
|
|
500
504
|
metafieldNamespace: i,
|
|
501
505
|
settingsNamespace: a
|
|
502
|
-
} }), p = s === l ? c :
|
|
506
|
+
} }), p = s === l ? c : _(s, {
|
|
503
507
|
language: t,
|
|
504
508
|
country: n
|
|
505
|
-
}),
|
|
509
|
+
}), m = u ? ae(u.value) : 1, h = f ? JSON.parse(f.value) : null, g = h?.feature_flags ?? {}, v = h?.custom_selectors ?? {};
|
|
506
510
|
return {
|
|
507
511
|
shopifyDomain: d.host,
|
|
508
512
|
moneyFormat: p,
|
|
509
513
|
locale: t?.toLowerCase() || "en",
|
|
510
514
|
liquidLocale: t?.toLowerCase() || "en",
|
|
511
515
|
country: n ?? "US",
|
|
512
|
-
currencyRate:
|
|
516
|
+
currencyRate: m,
|
|
513
517
|
marketId: 0,
|
|
514
518
|
productId: null,
|
|
515
|
-
storefrontAccessToken:
|
|
516
|
-
includeSellingPlans:
|
|
517
|
-
includeAvailableQuantity:
|
|
518
|
-
customApiHost:
|
|
519
|
-
keepQuantityInput:
|
|
520
|
-
ignoreDeselect:
|
|
521
|
-
ignoreUnitPrice:
|
|
522
|
-
requireCustomerLogin:
|
|
523
|
-
abTestsRunning:
|
|
524
|
-
webPixel:
|
|
519
|
+
storefrontAccessToken: h?.storefront_access_token ?? null,
|
|
520
|
+
includeSellingPlans: h?.include_selling_plans ?? !1,
|
|
521
|
+
includeAvailableQuantity: h?.include_available_quantity ?? !1,
|
|
522
|
+
customApiHost: h?.custom_api_host ?? null,
|
|
523
|
+
keepQuantityInput: h?.keep_quantity_input ?? !1,
|
|
524
|
+
ignoreDeselect: h?.ignore_deselect ?? !1,
|
|
525
|
+
ignoreUnitPrice: h?.ignore_unit_price ?? !1,
|
|
526
|
+
requireCustomerLogin: h?.require_customer_login ?? !1,
|
|
527
|
+
abTestsRunning: h?.ab_tests_running ?? !1,
|
|
528
|
+
webPixel: h?.web_pixel ?? !1,
|
|
525
529
|
b2bCustomer: !1,
|
|
526
530
|
isLoggedIn: !1,
|
|
527
531
|
preview: !1,
|
|
@@ -559,9 +563,9 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
559
563
|
price: v.price ?? null,
|
|
560
564
|
priceCompare: v.price_compare ?? null
|
|
561
565
|
},
|
|
562
|
-
shopCustomStyles:
|
|
563
|
-
featureFlags:
|
|
564
|
-
brandColors:
|
|
566
|
+
shopCustomStyles: h?.shop_custom_styles ?? "",
|
|
567
|
+
featureFlags: g,
|
|
568
|
+
brandColors: h?.brand_colors ?? null
|
|
565
569
|
};
|
|
566
570
|
}, ae = (e) => JSON.parse(e).amount / 1e6, oe = async (e, t, n = 200) => {
|
|
567
571
|
let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
|
|
@@ -576,9 +580,9 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
576
580
|
url: e.image.url
|
|
577
581
|
}] : []);
|
|
578
582
|
}, se = 100, ce = async (e, { dealBlock: t, country: n, language: r }) => {
|
|
579
|
-
let i = [...new Set(t.dealBars.flatMap((e) => e.dealBarType ===
|
|
583
|
+
let i = [...new Set(t.dealBars.flatMap((e) => e.dealBarType === O.MixAndMatch ? e.bundleProducts : []).flatMap((e) => (e.selectedCollections ?? []).map((e) => e.id)))];
|
|
580
584
|
if (i.length === 0) return [];
|
|
581
|
-
let a =
|
|
585
|
+
let a = w({
|
|
582
586
|
country: n,
|
|
583
587
|
language: r
|
|
584
588
|
}), o = await e.query(`
|
|
@@ -607,46 +611,46 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
607
611
|
...fe(e),
|
|
608
612
|
...pe(e),
|
|
609
613
|
...me(e),
|
|
610
|
-
...M(e),
|
|
611
|
-
...N(e),
|
|
612
|
-
...P(e),
|
|
613
614
|
...F(e),
|
|
614
615
|
...I(e),
|
|
615
616
|
...L(e),
|
|
616
617
|
...R(e),
|
|
617
|
-
...z(e)
|
|
618
|
-
|
|
618
|
+
...z(e),
|
|
619
|
+
...he(e),
|
|
620
|
+
...ge(e),
|
|
621
|
+
..._e(e)
|
|
622
|
+
].filter((e) => e != null && !e.includes("placeholder")), ue = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), de = (e) => e.dealBars.flatMap((e) => e.dealBarType === O.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), fe = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), pe = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), me = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), F = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
|
|
619
623
|
let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
|
|
620
624
|
return [...e, ...n];
|
|
621
|
-
}, []) : [],
|
|
625
|
+
}, []) : [], I = (e) => {
|
|
622
626
|
if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
|
|
623
627
|
let t = e.collectionBreaks.mediaImageGID;
|
|
624
628
|
return t ? [t] : [];
|
|
625
|
-
},
|
|
629
|
+
}, L = (e) => e.progressiveGifts ? [
|
|
626
630
|
...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
|
|
627
631
|
e.progressiveGifts.style?.lockedMediaImageGID,
|
|
628
632
|
e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
|
|
629
|
-
].filter((e) => e != null) : [],
|
|
633
|
+
].filter((e) => e != null) : [], R = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), z = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), he = (e) => {
|
|
630
634
|
let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
|
|
631
635
|
return n ? [...t, n] : t;
|
|
632
|
-
},
|
|
636
|
+
}, ge = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), _e = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], ve = (e, { includeMixAndMatchSwapProducts: t = !0 } = {}) => {
|
|
633
637
|
let n = [
|
|
634
|
-
...ge(e),
|
|
635
|
-
..._e(e),
|
|
636
|
-
...ve(e),
|
|
637
638
|
...ye(e),
|
|
638
639
|
...be(e),
|
|
639
|
-
...xe(e
|
|
640
|
+
...xe(e),
|
|
640
641
|
...Se(e),
|
|
641
|
-
...Ce(e)
|
|
642
|
+
...Ce(e),
|
|
643
|
+
...we(e, t),
|
|
644
|
+
...Te(e),
|
|
645
|
+
...Ee(e)
|
|
642
646
|
];
|
|
643
647
|
return Array.from(new Set(n.filter((e) => e != null)));
|
|
644
|
-
},
|
|
648
|
+
}, ye = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), be = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), xe = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], Se = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), Ce = (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"), we = (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"), Te = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), Ee = (e) => e.dealBars.filter((e) => e.dealBarType === O.Sku).flatMap(({ productGID: e }) => e ? [e] : []), B = class extends Error {
|
|
645
649
|
constructor({ status: e, operationName: t, graphqlErrors: n }) {
|
|
646
650
|
let r = n.length ? `: ${n.join("; ")}` : "";
|
|
647
651
|
super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
|
|
648
652
|
}
|
|
649
|
-
},
|
|
653
|
+
}, De = async (e, t) => {
|
|
650
654
|
let n = await e.text();
|
|
651
655
|
if (!n) throw Error("Empty graphql response");
|
|
652
656
|
let r;
|
|
@@ -665,13 +669,13 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
665
669
|
graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
|
|
666
670
|
});
|
|
667
671
|
return r.data;
|
|
668
|
-
},
|
|
672
|
+
}, Oe = class {
|
|
669
673
|
constructor(e, t) {
|
|
670
674
|
this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
|
|
671
675
|
}
|
|
672
676
|
async query(e, t) {
|
|
673
677
|
let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
|
|
674
|
-
return i && (r += `?operation_name=${i}`),
|
|
678
|
+
return i && (r += `?operation_name=${i}`), De(await fetch(r, {
|
|
675
679
|
method: "POST",
|
|
676
680
|
headers: {
|
|
677
681
|
"Content-Type": "application/json",
|
|
@@ -699,18 +703,18 @@ var T = /* @__PURE__ */ function(e) {
|
|
|
699
703
|
].map((e) => `brand_${e}`);
|
|
700
704
|
var V = /* @__PURE__ */ function(e) {
|
|
701
705
|
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
702
|
-
}({}),
|
|
706
|
+
}({}), ke = async (e, t, { country: n, language: r }) => {
|
|
703
707
|
let i = t.collectionBreaks;
|
|
704
708
|
if (!t.collectionBreaksEnabled || !i) return;
|
|
705
709
|
let a;
|
|
706
|
-
a = i.visibility === "deal-products" ? await
|
|
710
|
+
a = i.visibility === "deal-products" ? await k(e, {
|
|
707
711
|
country: n,
|
|
708
712
|
language: r,
|
|
709
713
|
blockVisibility: t.blockVisibility,
|
|
710
714
|
excludedProductGIDs: (t.excludedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
|
|
711
|
-
selectedProductGIDs:
|
|
715
|
+
selectedProductGIDs: [...t.selectedProductIds || [], ...(t.selectedVariants || []).map(({ productId: e }) => e)].map((e) => `gid://shopify/Product/${e}`),
|
|
712
716
|
selectedCollectionGIDs: (t.selectedCollectionIds || []).map((e) => `gid://shopify/Collection/${e}`)
|
|
713
|
-
}) : await
|
|
717
|
+
}) : await k(e, {
|
|
714
718
|
country: n,
|
|
715
719
|
language: r,
|
|
716
720
|
blockVisibility: i.visibility,
|
|
@@ -718,14 +722,14 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
718
722
|
selectedProductGIDs: (i.selectedProducts || []).map(({ id: e }) => e),
|
|
719
723
|
selectedCollectionGIDs: (i.selectedCollections || []).map(({ id: e }) => e)
|
|
720
724
|
});
|
|
721
|
-
let
|
|
725
|
+
let s = await j(e, {
|
|
722
726
|
country: n,
|
|
723
727
|
language: r,
|
|
724
728
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
725
729
|
useExternalMetafieldNamespace: !0
|
|
726
|
-
}),
|
|
727
|
-
return o
|
|
728
|
-
},
|
|
730
|
+
}), c = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
|
|
731
|
+
return o(t, s).filter((e) => e.availableForSale && (!c || g([t], e).length > 0));
|
|
732
|
+
}, Ae = ({ language: e, dealBlockId: t }) => {
|
|
729
733
|
let n = {
|
|
730
734
|
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
731
735
|
"system.invalid_variant": "Sorry, this is not currently available.",
|
|
@@ -752,13 +756,13 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
752
756
|
"system.numbers_only": "Only numbers are allowed.",
|
|
753
757
|
"system.personalisation_required_alert": "Please add personalisation for every item to continue.",
|
|
754
758
|
"system.gifts_required_alert": "Please choose your free gifts"
|
|
755
|
-
}, r = e ?
|
|
759
|
+
}, r = e ? je(e) : void 0;
|
|
756
760
|
return {
|
|
757
761
|
...n,
|
|
758
762
|
...r?.system,
|
|
759
763
|
...r?.dealBlocks[t]
|
|
760
764
|
};
|
|
761
|
-
},
|
|
765
|
+
}, je = (e) => {
|
|
762
766
|
if (typeof document > "u") return;
|
|
763
767
|
let t = document.querySelector("script#kaching-bundles-translations");
|
|
764
768
|
if (!t?.textContent) return;
|
|
@@ -770,9 +774,9 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
770
774
|
}
|
|
771
775
|
let r = H(e);
|
|
772
776
|
return n.find((e) => H(e.locale) === r)?.translations;
|
|
773
|
-
}, H = (e) => e.toLowerCase().replace(/_/g, "-"),
|
|
777
|
+
}, H = (e) => e.toLowerCase().replace(/_/g, "-"), Me = "2026-07", U = async (e, { productId: t, dealBlockId: n, abTestVariantId: r, country: i = void 0, language: a = void 0 }) => {
|
|
774
778
|
try {
|
|
775
|
-
let
|
|
779
|
+
let o = [Number(t.split("/").pop())], c = new Le(e);
|
|
776
780
|
i ||= c.i18n?.country, a ||= c.i18n?.language;
|
|
777
781
|
let l = await ie(c, {
|
|
778
782
|
language: a,
|
|
@@ -780,56 +784,56 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
780
784
|
useExternalMetafieldNamespace: !0
|
|
781
785
|
});
|
|
782
786
|
c.shopifyDomain = l.shopifyDomain;
|
|
783
|
-
let u = l.storefrontAccessToken ? new
|
|
787
|
+
let u = l.storefrontAccessToken ? new Oe(l.shopifyDomain, l.storefrontAccessToken) : c, [d, f] = await Promise.all([j(u, {
|
|
784
788
|
country: i,
|
|
785
789
|
language: a,
|
|
786
|
-
productIds:
|
|
790
|
+
productIds: o,
|
|
787
791
|
useExternalMetafieldNamespace: !0
|
|
788
|
-
}),
|
|
792
|
+
}), T(u, {
|
|
789
793
|
useExternalMetafieldNamespace: !0,
|
|
790
794
|
useMetaobjects: l.featureFlags.storefront_metaobjects
|
|
791
|
-
})]), m = d[0];
|
|
792
|
-
if (!
|
|
793
|
-
let
|
|
794
|
-
if (!
|
|
795
|
-
let
|
|
796
|
-
otherProductGIDs:
|
|
795
|
+
})]), p = m(f, l.featureFlags.selected_variants), h = d[0];
|
|
796
|
+
if (!h) return null;
|
|
797
|
+
let _ = g(p, h), v = n ? _.filter((e) => e.id === n || e.nanoId === n) : _, y = (r ? v.find((e) => e.abTestVariantId === r) : void 0) ?? v[0] ?? _[0];
|
|
798
|
+
if (!y) return null;
|
|
799
|
+
let b = ve(y, { includeMixAndMatchSwapProducts: !1 }), x = Ne(u, y, {
|
|
800
|
+
otherProductGIDs: b,
|
|
797
801
|
country: i,
|
|
798
802
|
language: a
|
|
799
|
-
}), [
|
|
800
|
-
|
|
803
|
+
}), [S, C, w] = await Promise.all([
|
|
804
|
+
j(u, {
|
|
801
805
|
country: i,
|
|
802
806
|
language: a,
|
|
803
|
-
productIds:
|
|
807
|
+
productIds: b,
|
|
804
808
|
useExternalMetafieldNamespace: !0
|
|
805
809
|
}),
|
|
806
|
-
oe(u, le(
|
|
807
|
-
|
|
810
|
+
oe(u, le(y), 300),
|
|
811
|
+
Ae({
|
|
808
812
|
language: a,
|
|
809
|
-
dealBlockId:
|
|
813
|
+
dealBlockId: y.id
|
|
810
814
|
})
|
|
811
815
|
]);
|
|
812
816
|
return {
|
|
813
817
|
data: {
|
|
814
818
|
config: l,
|
|
815
|
-
dealBlock:
|
|
816
|
-
product:
|
|
817
|
-
otherProducts:
|
|
818
|
-
mediaImages:
|
|
819
|
-
translations:
|
|
819
|
+
dealBlock: y,
|
|
820
|
+
product: h,
|
|
821
|
+
otherProducts: s(y, S),
|
|
822
|
+
mediaImages: C,
|
|
823
|
+
translations: w
|
|
820
824
|
},
|
|
821
|
-
modalProducts:
|
|
825
|
+
modalProducts: x
|
|
822
826
|
};
|
|
823
827
|
} catch (e) {
|
|
824
828
|
return console.error(e), null;
|
|
825
829
|
}
|
|
826
|
-
},
|
|
827
|
-
let [r, i] = await Promise.all([
|
|
830
|
+
}, Ne = async (e, t, n) => {
|
|
831
|
+
let [r, i] = await Promise.all([Pe(e, t, n), Ie(e, t, n)]);
|
|
828
832
|
return {
|
|
829
833
|
mixAndMatchSwapProducts: r,
|
|
830
834
|
collectionBreaksProducts: i
|
|
831
835
|
};
|
|
832
|
-
},
|
|
836
|
+
}, Pe = async (e, t, { otherProductGIDs: n, country: r, language: i }) => {
|
|
833
837
|
try {
|
|
834
838
|
let a = [];
|
|
835
839
|
try {
|
|
@@ -841,8 +845,8 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
841
845
|
} catch (e) {
|
|
842
846
|
console.error(e);
|
|
843
847
|
}
|
|
844
|
-
let
|
|
845
|
-
return c.length ?
|
|
848
|
+
let o = new Set(n), c = [.../* @__PURE__ */ new Set([...Fe(t), ...a])].filter((e) => !o.has(e));
|
|
849
|
+
return c.length ? s(t, await j(e, {
|
|
846
850
|
country: r,
|
|
847
851
|
language: i,
|
|
848
852
|
productIds: c,
|
|
@@ -851,16 +855,16 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
851
855
|
} catch (e) {
|
|
852
856
|
return console.error(e), [];
|
|
853
857
|
}
|
|
854
|
-
},
|
|
858
|
+
}, Fe = (e) => e.dealBars.flatMap((e) => e.dealBarType === V.MixAndMatch ? e.bundleProducts.flatMap((e) => (e.selectedProducts ?? []).map((e) => e.id)) : []), Ie = async (e, t, { country: n, language: r }) => {
|
|
855
859
|
try {
|
|
856
|
-
return await
|
|
860
|
+
return await ke(e, t, {
|
|
857
861
|
country: n,
|
|
858
862
|
language: r
|
|
859
863
|
}) ?? [];
|
|
860
864
|
} catch (e) {
|
|
861
865
|
return console.error(e), [];
|
|
862
866
|
}
|
|
863
|
-
},
|
|
867
|
+
}, Le = class {
|
|
864
868
|
constructor(e) {
|
|
865
869
|
this.storefront = e, this.shopifyDomain = "";
|
|
866
870
|
}
|
|
@@ -873,7 +877,7 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
873
877
|
}
|
|
874
878
|
if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
|
|
875
879
|
if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
|
|
876
|
-
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${
|
|
880
|
+
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${Me}/graphql.json`, {
|
|
877
881
|
body: JSON.stringify({
|
|
878
882
|
query: e,
|
|
879
883
|
variables: t?.variables
|
|
@@ -903,46 +907,46 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
903
907
|
get i18n() {
|
|
904
908
|
if ("i18n" in this.storefront) return this.storefront.i18n;
|
|
905
909
|
}
|
|
906
|
-
}, W = "kaching-bundles-block", G = 1e4, K = "/kaching-bundles-block.js",
|
|
910
|
+
}, W = "kaching-bundles-block", G = 1e4, K = "/kaching-bundles-block.js", Re = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", ze = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", q = /* @__PURE__ */ new WeakSet(), J = async (e) => {
|
|
907
911
|
let t = e.document;
|
|
908
912
|
if (!e.customElements.get(W)) {
|
|
909
|
-
if (q.has(t)) return
|
|
913
|
+
if (q.has(t)) return X(e, W);
|
|
910
914
|
q.add(t);
|
|
911
915
|
try {
|
|
912
|
-
await
|
|
916
|
+
await He(e);
|
|
913
917
|
} catch (e) {
|
|
914
918
|
throw q.delete(t), e;
|
|
915
919
|
}
|
|
916
920
|
}
|
|
917
|
-
},
|
|
918
|
-
let t = e.document, n =
|
|
919
|
-
if (t.querySelector(`script[src="${n}"]`)) return
|
|
920
|
-
let r =
|
|
921
|
-
if (r && await
|
|
921
|
+
}, Be = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Ve = () => Be() ? Re : ze, He = async (e) => {
|
|
922
|
+
let t = e.document, n = Ve();
|
|
923
|
+
if (t.querySelector(`script[src="${n}"]`)) return X(e, W);
|
|
924
|
+
let r = Ue(t);
|
|
925
|
+
if (r && await Ge(t, r)) return X(e, W);
|
|
922
926
|
let i = t.createElement("script");
|
|
923
|
-
return i.src = n, await
|
|
924
|
-
},
|
|
927
|
+
return i.src = n, await Y(t, i), X(e, W);
|
|
928
|
+
}, Ue = (e) => {
|
|
925
929
|
let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${K}"]`);
|
|
926
|
-
return Array.from(t, (e) => e.href).find(
|
|
927
|
-
},
|
|
930
|
+
return Array.from(t, (e) => e.href).find(We);
|
|
931
|
+
}, We = (e) => {
|
|
928
932
|
try {
|
|
929
933
|
return new URL(e).pathname.endsWith(K);
|
|
930
934
|
} catch {
|
|
931
935
|
return !1;
|
|
932
936
|
}
|
|
933
|
-
},
|
|
937
|
+
}, Ge = async (e, t) => {
|
|
934
938
|
let n = e.createElement("script");
|
|
935
939
|
n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
|
|
936
940
|
try {
|
|
937
|
-
return await
|
|
941
|
+
return await Y(e, n), !0;
|
|
938
942
|
} catch {
|
|
939
943
|
return n.remove(), !1;
|
|
940
944
|
}
|
|
941
|
-
},
|
|
945
|
+
}, Y = (e, t) => new Promise((n, r) => {
|
|
942
946
|
t.onload = () => n(), t.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), e.head.appendChild(t);
|
|
943
|
-
}),
|
|
947
|
+
}), X = (e, t) => new Promise((n, r) => {
|
|
944
948
|
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 ${G}ms`)), G))]).then(() => n()).catch(r);
|
|
945
|
-
}),
|
|
949
|
+
}), Z = {
|
|
946
950
|
config: {
|
|
947
951
|
shopifyDomain: "",
|
|
948
952
|
moneyFormat: "${{amount}}",
|
|
@@ -1342,7 +1346,7 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
1342
1346
|
mediaImages: [],
|
|
1343
1347
|
collectionBreaksProducts: [],
|
|
1344
1348
|
translations: {}
|
|
1345
|
-
},
|
|
1349
|
+
}, Q = async (e, t) => {
|
|
1346
1350
|
try {
|
|
1347
1351
|
let n = await U(e, t);
|
|
1348
1352
|
if (!n) return null;
|
|
@@ -1360,7 +1364,7 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
1360
1364
|
} catch (e) {
|
|
1361
1365
|
return console.error(e), null;
|
|
1362
1366
|
}
|
|
1363
|
-
},
|
|
1367
|
+
}, Ke = class extends HTMLElement {
|
|
1364
1368
|
constructor(...e) {
|
|
1365
1369
|
super(...e), this.innerElement = null, this.handleItemsChanged = null, this.initializeId = 0;
|
|
1366
1370
|
}
|
|
@@ -1379,7 +1383,7 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
1379
1383
|
let e = ++this.initializeId;
|
|
1380
1384
|
if (this.cleanup(), this.hasAttribute("demo")) {
|
|
1381
1385
|
if (await J(window), e !== this.initializeId) return;
|
|
1382
|
-
$(this.renderInnerElement(
|
|
1386
|
+
$(this.renderInnerElement(Z), Z);
|
|
1383
1387
|
return;
|
|
1384
1388
|
}
|
|
1385
1389
|
let t = this.getAttribute("shop-domain"), n = this.getAttribute("storefront-token"), r = this.getAttribute("product-id");
|
|
@@ -1434,5 +1438,5 @@ var V = /* @__PURE__ */ function(e) {
|
|
|
1434
1438
|
}, $ = (e, { mixAndMatchSwapProducts: t, collectionBreaksProducts: n }) => {
|
|
1435
1439
|
t.length && e.setAttribute("mix-and-match-swap-products", JSON.stringify(t)), e.setAttribute("collection-breaks-products", JSON.stringify(n));
|
|
1436
1440
|
};
|
|
1437
|
-
customElements.define("kaching-bundle-component",
|
|
1438
|
-
export {
|
|
1441
|
+
customElements.define("kaching-bundle-component", Ke);
|
|
1442
|
+
export { Q as fetchKachingBundlesData };
|