@kachingappz/bundles-js 1.1.3 → 1.1.4
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 +13 -10
- package/dist/index.d.ts +57 -9
- package/dist/index.js +86 -79
- package/dist/kaching-bundle-component/index.d.ts +57 -9
- package/dist/kaching-bundle-component/index.js +106 -99
- package/dist/react/index.cjs +13 -10
- package/dist/react/index.d.ts +57 -9
- package/dist/react/index.js +82 -75
- package/package.json +2 -2
|
@@ -31,7 +31,23 @@ var e = (e, { language: n, country: s }) => {
|
|
|
31
31
|
i = t.metaobjects.pageInfo.endCursor;
|
|
32
32
|
}
|
|
33
33
|
return r;
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
|
+
[
|
|
36
|
+
"primaryBackground",
|
|
37
|
+
"secondaryBackground",
|
|
38
|
+
"primaryText",
|
|
39
|
+
"secondaryText",
|
|
40
|
+
"border",
|
|
41
|
+
"overlay",
|
|
42
|
+
"primaryAccent",
|
|
43
|
+
"primaryAccentText",
|
|
44
|
+
"badgeBackground",
|
|
45
|
+
"badgeText",
|
|
46
|
+
"error"
|
|
47
|
+
].map((e) => `brand_${e}`);
|
|
48
|
+
var d = /* @__PURE__ */ function(e) {
|
|
49
|
+
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
50
|
+
}({}), f = async (e, { country: t, language: n, blockVisibility: r, excludedProductGIDs: i, selectedProductGIDs: a, selectedCollectionGIDs: o, limit: c = 1e3 }) => {
|
|
35
51
|
switch (r) {
|
|
36
52
|
case "selected-products": return a.slice(0, c);
|
|
37
53
|
case "all-products":
|
|
@@ -89,16 +105,16 @@ var e = (e, { language: n, country: s }) => {
|
|
|
89
105
|
return Array.from(new Set(i)).slice(0, c);
|
|
90
106
|
}
|
|
91
107
|
}
|
|
92
|
-
},
|
|
108
|
+
}, p = "\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", m = async (e, { country: t, language: n, productIds: r, includeSellingPlans: i = !0, includeAvailableQuantity: a = !0, includeProductRating: o = !1, includeProductSubtitle: c = !1, productSubtitleMetafield: l = "descriptors.subtitle", useExternalMetafieldNamespace: u = !1, batchSize: d = 250, onBatchError: f, variantImageTransform: m = {
|
|
93
109
|
maxWidth: 200,
|
|
94
110
|
maxHeight: 200
|
|
95
111
|
} }) => {
|
|
96
112
|
if (!r.length) return [];
|
|
97
|
-
let
|
|
113
|
+
let _ = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), v = s({
|
|
98
114
|
country: t,
|
|
99
115
|
language: n
|
|
100
|
-
}),
|
|
101
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${
|
|
116
|
+
}), y = `
|
|
117
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${v} {
|
|
102
118
|
shop {
|
|
103
119
|
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
104
120
|
value
|
|
@@ -132,7 +148,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
132
148
|
}
|
|
133
149
|
variants(first: 250) {
|
|
134
150
|
nodes {
|
|
135
|
-
${
|
|
151
|
+
${p}
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
154
|
collections(first: 50) {
|
|
@@ -158,6 +174,9 @@ var e = (e, { language: n, country: s }) => {
|
|
|
158
174
|
reviewsRatingCount: metafield(namespace: "reviews", key: "rating_count") @include(if: $includeProductRating) {
|
|
159
175
|
value
|
|
160
176
|
}
|
|
177
|
+
subtitle: metafield(namespace: $subtitleNamespace, key: $subtitleKey) @include(if: $includeProductSubtitle) {
|
|
178
|
+
value
|
|
179
|
+
}
|
|
161
180
|
requiresSellingPlan
|
|
162
181
|
sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
|
|
163
182
|
nodes {
|
|
@@ -190,40 +209,43 @@ var e = (e, { language: n, country: s }) => {
|
|
|
190
209
|
}
|
|
191
210
|
}
|
|
192
211
|
}
|
|
193
|
-
`,
|
|
194
|
-
for (let e = 0; e <
|
|
195
|
-
let
|
|
196
|
-
let n = await e.query(
|
|
212
|
+
`, b = u ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", x = l.indexOf("."), S = l.slice(0, x), C = l.slice(x + 1), w = [], T = Math.min(d, 250);
|
|
213
|
+
for (let e = 0; e < _.length; e += T) w.push(_.slice(e, e + T));
|
|
214
|
+
let E = 1, D = async (t) => {
|
|
215
|
+
let n = await e.query(y, { variables: {
|
|
197
216
|
productGIDs: t,
|
|
198
217
|
includeSellingPlans: i,
|
|
199
218
|
includeAvailableQuantity: a,
|
|
200
219
|
includeProductRating: o,
|
|
201
|
-
|
|
202
|
-
|
|
220
|
+
includeProductSubtitle: c,
|
|
221
|
+
subtitleNamespace: S,
|
|
222
|
+
subtitleKey: C,
|
|
223
|
+
metafieldNamespace: b,
|
|
224
|
+
variantImageTransform: m
|
|
203
225
|
} });
|
|
204
|
-
return n.shop.currencyRateConstant && (
|
|
205
|
-
},
|
|
206
|
-
if (
|
|
207
|
-
let e = await Promise.allSettled(
|
|
208
|
-
for (let t of e) t.status === "rejected" &&
|
|
209
|
-
|
|
210
|
-
} else
|
|
211
|
-
let
|
|
212
|
-
if (
|
|
213
|
-
let t = await Promise.allSettled(
|
|
226
|
+
return n.shop.currencyRateConstant && (E = JSON.parse(n.shop.currencyRateConstant.value).amount / 1e6), n;
|
|
227
|
+
}, O;
|
|
228
|
+
if (f) {
|
|
229
|
+
let e = await Promise.allSettled(w.map(D));
|
|
230
|
+
for (let t of e) t.status === "rejected" && f(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
|
|
231
|
+
O = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
|
|
232
|
+
} else O = (await Promise.all(w.map(D))).flatMap((e) => e.nodes);
|
|
233
|
+
let k = O.filter((e) => e != null);
|
|
234
|
+
if (f) {
|
|
235
|
+
let t = await Promise.allSettled(k.map(async (t) => g(await h(e, t, {
|
|
214
236
|
includeSellingPlans: i,
|
|
215
237
|
includeAvailableQuantity: a,
|
|
216
|
-
variantImageTransform:
|
|
217
|
-
},
|
|
218
|
-
for (let e of t) e.status === "fulfilled" ? n.push(e.value) :
|
|
238
|
+
variantImageTransform: m
|
|
239
|
+
}, v), e.shopifyDomain, E))), n = [];
|
|
240
|
+
for (let e of t) e.status === "fulfilled" ? n.push(e.value) : f(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
|
|
219
241
|
return n;
|
|
220
242
|
}
|
|
221
|
-
return (await Promise.all(
|
|
243
|
+
return (await Promise.all(k.map((t) => h(e, t, {
|
|
222
244
|
includeSellingPlans: i,
|
|
223
245
|
includeAvailableQuantity: a,
|
|
224
|
-
variantImageTransform:
|
|
225
|
-
},
|
|
226
|
-
},
|
|
246
|
+
variantImageTransform: m
|
|
247
|
+
}, v)))).map((t) => g(t, e.shopifyDomain, E));
|
|
248
|
+
}, h = async (e, t, n, r = "") => {
|
|
227
249
|
if (t.variants.nodes.length < 250) return t;
|
|
228
250
|
let i = /* @__PURE__ */ new Set(), a = [], o = [], s = async (s) => {
|
|
229
251
|
let c = !0, l = null;
|
|
@@ -233,7 +255,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
233
255
|
product(id: $productGID) {
|
|
234
256
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
235
257
|
nodes {
|
|
236
|
-
${
|
|
258
|
+
${p}
|
|
237
259
|
}
|
|
238
260
|
pageInfo {
|
|
239
261
|
endCursor
|
|
@@ -259,7 +281,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
259
281
|
}
|
|
260
282
|
};
|
|
261
283
|
return await Promise.all([s(!1), s(!0)]), t.variants.nodes = [...a, ...o.reverse()], t;
|
|
262
|
-
},
|
|
284
|
+
}, g = (e, t, n) => {
|
|
263
285
|
let r = e.variants.nodes.map(({ unitPriceMeasurement: e, ...t }) => ({
|
|
264
286
|
id: Number(t.id.split("/").pop()),
|
|
265
287
|
availableForSale: t.availableForSale,
|
|
@@ -297,7 +319,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
297
319
|
defaultName: e.name,
|
|
298
320
|
name: e.name,
|
|
299
321
|
position: t + 1,
|
|
300
|
-
optionValues:
|
|
322
|
+
optionValues: y(n, t, r)
|
|
301
323
|
};
|
|
302
324
|
}), a = (e) => {
|
|
303
325
|
let t = e.priceAdjustments[0];
|
|
@@ -344,26 +366,27 @@ var e = (e, { language: n, country: s }) => {
|
|
|
344
366
|
text3: e.metafield3?.value || null,
|
|
345
367
|
text4: e.metafield4?.value || null
|
|
346
368
|
},
|
|
347
|
-
rating:
|
|
369
|
+
rating: _(e.reviewsRating, e.reviewsRatingCount),
|
|
370
|
+
subtitle: e.subtitle?.value || null
|
|
348
371
|
};
|
|
349
|
-
},
|
|
372
|
+
}, _ = (e, t) => {
|
|
350
373
|
if (!e) return null;
|
|
351
|
-
let n =
|
|
374
|
+
let n = v(e.value);
|
|
352
375
|
if (n === null) return null;
|
|
353
376
|
let r = Number(t?.value);
|
|
354
377
|
return {
|
|
355
378
|
value: n,
|
|
356
379
|
count: Number.isInteger(r) && r > 0 ? r : null
|
|
357
380
|
};
|
|
358
|
-
},
|
|
381
|
+
}, v = (e) => {
|
|
359
382
|
try {
|
|
360
383
|
let { value: t, scale_max: n } = JSON.parse(e), r = Number(t) / Number(n) * 5;
|
|
361
384
|
return Number.isFinite(r) && r > 0 ? Math.min(5, r) : null;
|
|
362
385
|
} catch {
|
|
363
386
|
return null;
|
|
364
387
|
}
|
|
365
|
-
},
|
|
366
|
-
let a = i ? `${
|
|
388
|
+
}, y = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0), b = "app--2935586817", x = async (t, { language: n, country: r, useExternalMetafieldNamespace: i }) => {
|
|
389
|
+
let a = i ? `${b}--kaching_bundles` : "$app:kaching_bundles", o = i ? b : "$app", c = s({ country: r }), { localization: { country: { currency: { isoCode: l } } }, shop: { moneyFormat: u, paymentSettings: { currencyCode: d }, currencyRateConstant: f, primaryDomain: p, settingsMetafield: m } } = await t.query(`
|
|
367
390
|
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${c} {
|
|
368
391
|
localization {
|
|
369
392
|
country {
|
|
@@ -394,7 +417,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
394
417
|
} }), h = l === d ? u : e(l, {
|
|
395
418
|
language: n,
|
|
396
419
|
country: r
|
|
397
|
-
}), g = f ?
|
|
420
|
+
}), g = f ? S(f.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
|
|
398
421
|
return {
|
|
399
422
|
shopifyDomain: p.host,
|
|
400
423
|
moneyFormat: h,
|
|
@@ -445,17 +468,17 @@ var e = (e, { language: n, country: s }) => {
|
|
|
445
468
|
"system.numbers_only": "Only numbers are allowed."
|
|
446
469
|
},
|
|
447
470
|
customSelectors: {
|
|
448
|
-
quantity:
|
|
449
|
-
addToCartButton:
|
|
450
|
-
variantPicker:
|
|
451
|
-
price:
|
|
452
|
-
priceCompare:
|
|
471
|
+
quantity: y.quantity ?? null,
|
|
472
|
+
addToCartButton: y.add_to_cart_button ?? null,
|
|
473
|
+
variantPicker: y.variant_picker ?? null,
|
|
474
|
+
price: y.price ?? null,
|
|
475
|
+
priceCompare: y.price_compare ?? null
|
|
453
476
|
},
|
|
454
477
|
shopCustomStyles: _?.shop_custom_styles ?? "",
|
|
455
478
|
featureFlags: v,
|
|
456
479
|
brandColors: _?.brand_colors ?? null
|
|
457
480
|
};
|
|
458
|
-
},
|
|
481
|
+
}, S = (e) => JSON.parse(e).amount / 1e6, C = async (e, t, n = 200) => {
|
|
459
482
|
let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
|
|
460
483
|
if (r.length === 0) return [];
|
|
461
484
|
let i = [];
|
|
@@ -467,93 +490,77 @@ var e = (e, { language: n, country: s }) => {
|
|
|
467
490
|
gid: e.id,
|
|
468
491
|
url: e.image.url
|
|
469
492
|
}] : []);
|
|
470
|
-
}
|
|
471
|
-
[
|
|
472
|
-
"primaryBackground",
|
|
473
|
-
"secondaryBackground",
|
|
474
|
-
"primaryText",
|
|
475
|
-
"secondaryText",
|
|
476
|
-
"border",
|
|
477
|
-
"overlay",
|
|
478
|
-
"primaryAccent",
|
|
479
|
-
"primaryAccentText",
|
|
480
|
-
"badgeBackground",
|
|
481
|
-
"badgeText",
|
|
482
|
-
"error"
|
|
483
|
-
].map((e) => `brand_${e}`);
|
|
484
|
-
var C = /* @__PURE__ */ function(e) {
|
|
485
|
-
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
486
|
-
}({}), w = (e) => [
|
|
487
|
-
...ee(e),
|
|
488
|
-
...te(e),
|
|
489
|
-
...ne(e),
|
|
490
|
-
...re(e),
|
|
491
|
-
...ie(e),
|
|
493
|
+
}, w = (e) => [
|
|
492
494
|
...T(e),
|
|
493
495
|
...E(e),
|
|
494
496
|
...D(e),
|
|
495
497
|
...O(e),
|
|
496
|
-
...ae(e),
|
|
497
|
-
...oe(e),
|
|
498
498
|
...k(e),
|
|
499
|
-
...
|
|
500
|
-
|
|
499
|
+
...ee(e),
|
|
500
|
+
...te(e),
|
|
501
|
+
...ne(e),
|
|
502
|
+
...re(e),
|
|
503
|
+
...A(e),
|
|
504
|
+
...j(e),
|
|
505
|
+
...M(e),
|
|
506
|
+
...ie(e)
|
|
507
|
+
].filter((e) => e != null && !e.includes("placeholder")), T = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), E = (e) => e.dealBars.flatMap((e) => e.dealBarType === d.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), D = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), O = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), k = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ee = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
|
|
501
508
|
let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
|
|
502
509
|
return [...e, ...n];
|
|
503
|
-
}, []) : [],
|
|
510
|
+
}, []) : [], te = (e) => {
|
|
504
511
|
if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
|
|
505
512
|
let t = e.collectionBreaks.mediaImageGID;
|
|
506
513
|
return t ? [t] : [];
|
|
507
|
-
},
|
|
514
|
+
}, ne = (e) => e.progressiveGifts ? [
|
|
508
515
|
...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
|
|
509
516
|
e.progressiveGifts.style?.lockedMediaImageGID,
|
|
510
517
|
e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
|
|
511
|
-
].filter((e) => e != null) : [],
|
|
518
|
+
].filter((e) => e != null) : [], re = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), A = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), j = (e) => {
|
|
512
519
|
let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
|
|
513
520
|
return n ? [...t, n] : t;
|
|
514
|
-
},
|
|
521
|
+
}, M = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), ie = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], ae = (e) => {
|
|
515
522
|
let t = [
|
|
516
|
-
...
|
|
523
|
+
...oe(e),
|
|
524
|
+
...se(e),
|
|
517
525
|
...N(e),
|
|
518
526
|
...P(e),
|
|
519
527
|
...F(e),
|
|
520
528
|
...I(e),
|
|
521
529
|
...L(e),
|
|
522
|
-
...R(e)
|
|
523
|
-
...z(e)
|
|
530
|
+
...R(e)
|
|
524
531
|
];
|
|
525
532
|
return Array.from(new Set(t.filter((e) => e != null)));
|
|
526
|
-
},
|
|
533
|
+
}, oe = (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), N = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], P = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), F = (e) => e.dealBars.filter((e) => e.dealBarType === d.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), I = (e) => e.dealBars.filter((e) => e.dealBarType === d.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...e.selectedProducts?.map((e) => e.id) ?? []]) : []).filter((e) => e != null).filter((e) => e !== "default"), L = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), R = (e) => e.dealBars.filter((e) => e.dealBarType === d.Sku).flatMap(({ productGID: e }) => e ? [e] : []), z = class extends Error {
|
|
527
534
|
constructor({ status: e, operationName: t, graphqlErrors: n }) {
|
|
528
535
|
let r = n.length ? `: ${n.join("; ")}` : "";
|
|
529
536
|
super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
|
|
530
537
|
}
|
|
531
|
-
},
|
|
538
|
+
}, B = async (e, t) => {
|
|
532
539
|
let n = await e.text();
|
|
533
540
|
if (!n) throw Error("Empty graphql response");
|
|
534
541
|
let r;
|
|
535
542
|
try {
|
|
536
543
|
r = JSON.parse(n);
|
|
537
544
|
} catch (n) {
|
|
538
|
-
throw e.ok ? n : new
|
|
545
|
+
throw e.ok ? n : new z({
|
|
539
546
|
status: e.status,
|
|
540
547
|
operationName: t,
|
|
541
548
|
graphqlErrors: []
|
|
542
549
|
});
|
|
543
550
|
}
|
|
544
|
-
if (!e.ok || r.data === null || r.data === void 0) throw new
|
|
551
|
+
if (!e.ok || r.data === null || r.data === void 0) throw new z({
|
|
545
552
|
status: e.status,
|
|
546
553
|
operationName: t,
|
|
547
554
|
graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
|
|
548
555
|
});
|
|
549
556
|
return r.data;
|
|
550
|
-
},
|
|
557
|
+
}, V = class {
|
|
551
558
|
constructor(e, t) {
|
|
552
559
|
this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
|
|
553
560
|
}
|
|
554
561
|
async query(e, t) {
|
|
555
562
|
let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
|
|
556
|
-
return i && (r += `?operation_name=${i}`),
|
|
563
|
+
return i && (r += `?operation_name=${i}`), B(await fetch(r, {
|
|
557
564
|
method: "POST",
|
|
558
565
|
headers: {
|
|
559
566
|
"Content-Type": "application/json",
|
|
@@ -565,7 +572,7 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
565
572
|
})
|
|
566
573
|
}), i);
|
|
567
574
|
}
|
|
568
|
-
},
|
|
575
|
+
}, H = (e, t) => {
|
|
569
576
|
let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
|
|
570
577
|
for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
|
|
571
578
|
let i = e.filter((e) => e.blockVisibility === "selected-collections");
|
|
@@ -575,18 +582,18 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
575
582
|
let o = e.filter((e) => e.blockVisibility === "all-products");
|
|
576
583
|
for (let e of o) n.push(e);
|
|
577
584
|
return n;
|
|
578
|
-
},
|
|
585
|
+
}, U = async (e, t, { country: n, language: r }) => {
|
|
579
586
|
let i = t.collectionBreaks;
|
|
580
587
|
if (!t.collectionBreaksEnabled || !i) return;
|
|
581
588
|
let a;
|
|
582
|
-
a = i.visibility === "deal-products" ? await
|
|
589
|
+
a = i.visibility === "deal-products" ? await f(e, {
|
|
583
590
|
country: n,
|
|
584
591
|
language: r,
|
|
585
592
|
blockVisibility: t.blockVisibility,
|
|
586
593
|
excludedProductGIDs: (t.excludedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
|
|
587
594
|
selectedProductGIDs: (t.selectedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
|
|
588
595
|
selectedCollectionGIDs: (t.selectedCollectionIds || []).map((e) => `gid://shopify/Collection/${e}`)
|
|
589
|
-
}) : await
|
|
596
|
+
}) : await f(e, {
|
|
590
597
|
country: n,
|
|
591
598
|
language: r,
|
|
592
599
|
blockVisibility: i.visibility,
|
|
@@ -594,7 +601,7 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
594
601
|
selectedProductGIDs: (i.selectedProducts || []).map(({ id: e }) => e),
|
|
595
602
|
selectedCollectionGIDs: (i.selectedCollections || []).map(({ id: e }) => e)
|
|
596
603
|
});
|
|
597
|
-
let o = await
|
|
604
|
+
let o = await m(e, {
|
|
598
605
|
country: n,
|
|
599
606
|
language: r,
|
|
600
607
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
@@ -649,13 +656,13 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
649
656
|
try {
|
|
650
657
|
let a = [Number(t.split("/").pop())], o = new le(e);
|
|
651
658
|
r ||= o.i18n?.country, i ||= o.i18n?.language;
|
|
652
|
-
let s = await
|
|
659
|
+
let s = await x(o, {
|
|
653
660
|
language: i,
|
|
654
661
|
country: r,
|
|
655
662
|
useExternalMetafieldNamespace: !0
|
|
656
663
|
});
|
|
657
664
|
o.shopifyDomain = s.shopifyDomain;
|
|
658
|
-
let l = s.storefrontAccessToken ? new
|
|
665
|
+
let l = s.storefrontAccessToken ? new V(s.shopifyDomain, s.storefrontAccessToken) : o, [u, d] = await Promise.all([m(l, {
|
|
659
666
|
country: r,
|
|
660
667
|
language: i,
|
|
661
668
|
productIds: a,
|
|
@@ -665,17 +672,17 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
665
672
|
useMetaobjects: s.featureFlags.storefront_metaobjects
|
|
666
673
|
})]), f = u[0];
|
|
667
674
|
if (!f) return null;
|
|
668
|
-
let
|
|
669
|
-
if (n ? (h =
|
|
670
|
-
let g = w(h), _ =
|
|
671
|
-
|
|
675
|
+
let p = H(d, f), h;
|
|
676
|
+
if (n ? (h = p.find((e) => e.id === n || e.nanoId === n), h ||= p[0]) : h = p[0], !h) return null;
|
|
677
|
+
let g = w(h), _ = ae(h), [v, y, b, S] = await Promise.all([
|
|
678
|
+
m(l, {
|
|
672
679
|
country: r,
|
|
673
680
|
language: i,
|
|
674
681
|
productIds: _,
|
|
675
682
|
useExternalMetafieldNamespace: !0
|
|
676
683
|
}),
|
|
677
|
-
|
|
678
|
-
|
|
684
|
+
C(l, g, 300),
|
|
685
|
+
U(l, h, {
|
|
679
686
|
country: r,
|
|
680
687
|
language: i
|
|
681
688
|
}),
|
|
@@ -690,8 +697,8 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
690
697
|
config: s,
|
|
691
698
|
otherProducts: v,
|
|
692
699
|
mediaImages: y,
|
|
693
|
-
collectionBreaksProducts:
|
|
694
|
-
translations:
|
|
700
|
+
collectionBreaksProducts: b ?? [],
|
|
701
|
+
translations: S
|
|
695
702
|
};
|
|
696
703
|
} catch (e) {
|
|
697
704
|
return console.error(e), null;
|
package/dist/react/index.cjs
CHANGED
|
@@ -21,7 +21,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
`,{variables:{type:n,cursor:i}});for(let e of t.metaobjects.nodes){let t=e.fields.find(e=>e.key===`settings`);t?.value&&r.push(JSON.parse(t.value))}if(!t.metaobjects.pageInfo.hasNextPage)break;i=t.metaobjects.pageInfo.endCursor}return r}
|
|
24
|
+
`,{variables:{type:n,cursor:i}});for(let e of t.metaobjects.nodes){let t=e.fields.find(e=>e.key===`settings`);t?.value&&r.push(JSON.parse(t.value))}if(!t.metaobjects.pageInfo.hasNextPage)break;i=t.metaobjects.pageInfo.endCursor}return r};[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var p=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),m=async(e,{country:t,language:n,blockVisibility:r,excludedProductGIDs:i,selectedProductGIDs:a,selectedCollectionGIDs:o,limit:s=1e3})=>{switch(r){case`selected-products`:return a.slice(0,s);case`all-products`:case`excluded-products`:{let a=l({country:t,language:n}),o=[],c=null;for(;o.length<s;){let t=Math.min(s-o.length,250),n=await e.query(`
|
|
25
25
|
query FetchProductGIDs($limit: Int!, $cursor: String) ${a} {
|
|
26
26
|
products(first: $limit, after: $cursor) {
|
|
27
27
|
nodes {
|
|
@@ -45,7 +45,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
`,{variables:{collectionGIDs:o,limit:Math.min(s,250)}})).nodes.filter(e=>e!==null).flatMap(e=>e.products.nodes.map(e=>e.id));return Array.from(new Set(i)).slice(0,s)}}},
|
|
48
|
+
`,{variables:{collectionGIDs:o,limit:Math.min(s,250)}})).nodes.filter(e=>e!==null).flatMap(e=>e.products.nodes.map(e=>e.id));return Array.from(new Set(i)).slice(0,s)}}},h=`
|
|
49
49
|
id
|
|
50
50
|
availableForSale
|
|
51
51
|
price {
|
|
@@ -88,8 +88,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
quantityAvailable @include(if: $includeAvailableQuantity)
|
|
91
|
-
`,
|
|
92
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${
|
|
91
|
+
`,g=async(e,{country:t,language:n,productIds:r,includeSellingPlans:i=!0,includeAvailableQuantity:a=!0,includeProductRating:o=!1,includeProductSubtitle:s=!1,productSubtitleMetafield:c=`descriptors.subtitle`,useExternalMetafieldNamespace:u=!1,batchSize:d=250,onBatchError:f,variantImageTransform:p={maxWidth:200,maxHeight:200}})=>{if(!r.length)return[];let m=r.map(e=>typeof e==`string`&&e.startsWith(`gid://`)?e:`gid://shopify/Product/${e}`),g=l({country:t,language:n}),y=`
|
|
92
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${g} {
|
|
93
93
|
shop {
|
|
94
94
|
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
95
95
|
value
|
|
@@ -123,7 +123,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
123
123
|
}
|
|
124
124
|
variants(first: 250) {
|
|
125
125
|
nodes {
|
|
126
|
-
${
|
|
126
|
+
${h}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
collections(first: 50) {
|
|
@@ -149,6 +149,9 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
149
149
|
reviewsRatingCount: metafield(namespace: "reviews", key: "rating_count") @include(if: $includeProductRating) {
|
|
150
150
|
value
|
|
151
151
|
}
|
|
152
|
+
subtitle: metafield(namespace: $subtitleNamespace, key: $subtitleKey) @include(if: $includeProductSubtitle) {
|
|
153
|
+
value
|
|
154
|
+
}
|
|
152
155
|
requiresSellingPlan
|
|
153
156
|
sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
|
|
154
157
|
nodes {
|
|
@@ -181,12 +184,12 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
|
-
`,
|
|
187
|
+
`,b=u?`app--2935586817--kaching_bundles`:`$app:kaching_bundles`,x=c.indexOf(`.`),S=c.slice(0,x),C=c.slice(x+1),w=[],T=Math.min(d,250);for(let e=0;e<m.length;e+=T)w.push(m.slice(e,e+T));let E=1,D=async t=>{let n=await e.query(y,{variables:{productGIDs:t,includeSellingPlans:i,includeAvailableQuantity:a,includeProductRating:o,includeProductSubtitle:s,subtitleNamespace:S,subtitleKey:C,metafieldNamespace:b,variantImageTransform:p}});return n.shop.currencyRateConstant&&(E=JSON.parse(n.shop.currencyRateConstant.value).amount/1e6),n},O;if(f){let e=await Promise.allSettled(w.map(D));for(let t of e)t.status===`rejected`&&f(t.reason instanceof Error?t.reason:Error(String(t.reason)));O=e.filter(e=>e.status===`fulfilled`).flatMap(e=>e.value.nodes)}else O=(await Promise.all(w.map(D))).flatMap(e=>e.nodes);let k=O.filter(e=>e!=null);if(f){let t=await Promise.allSettled(k.map(async t=>v(await _(e,t,{includeSellingPlans:i,includeAvailableQuantity:a,variantImageTransform:p},g),e.shopifyDomain,E))),n=[];for(let e of t)e.status===`fulfilled`?n.push(e.value):f(e.reason instanceof Error?e.reason:Error(String(e.reason)));return n}return(await Promise.all(k.map(t=>_(e,t,{includeSellingPlans:i,includeAvailableQuantity:a,variantImageTransform:p},g)))).map(t=>v(t,e.shopifyDomain,E))},_=async(e,t,n,r=``)=>{if(t.variants.nodes.length<250)return t;let i=new Set,a=[],o=[],s=async s=>{let c=!0,l=null;for(;c;){let{nodes:u,pageInfo:d}=(await e.query(`
|
|
185
188
|
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $variantImageTransform: ImageTransformInput) ${r} {
|
|
186
189
|
product(id: $productGID) {
|
|
187
190
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
188
191
|
nodes {
|
|
189
|
-
${
|
|
192
|
+
${h}
|
|
190
193
|
}
|
|
191
194
|
pageInfo {
|
|
192
195
|
endCursor
|
|
@@ -195,7 +198,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
|
-
`,{variables:{productGID:t.id,cursor:l,reverse:s,...n}})).product.variants;for(let e of u){if(i.has(e.id)){c=!1;break}i.add(e.id),s?o.push(e):a.push(e)}d.hasNextPage||(c=!1),l=d.endCursor}};return await Promise.all([s(!1),s(!0)]),t.variants.nodes=[...a,...o.reverse()],t},
|
|
201
|
+
`,{variables:{productGID:t.id,cursor:l,reverse:s,...n}})).product.variants;for(let e of u){if(i.has(e.id)){c=!1;break}i.add(e.id),s?o.push(e):a.push(e)}d.hasNextPage||(c=!1),l=d.endCursor}};return await Promise.all([s(!1),s(!0)]),t.variants.nodes=[...a,...o.reverse()],t},v=(e,t,n)=>{let r=e.variants.nodes.map(({unitPriceMeasurement:e,...t})=>({id:Number(t.id.split(`/`).pop()),availableForSale:t.availableForSale,price:Math.round(Number(t.price.amount)*100),compareAtPrice:t.compareAtPrice?Math.round(Number(t.compareAtPrice.amount)*100):null,options:t.selectedOptions.map(e=>e.value),imageId:t.image?Number(t.image.id.split(`/`).pop()):null,image:t.image?.url||null,sellingPlans:t.sellingPlanAllocations?.nodes.map(e=>({id:Number(e.sellingPlan.id.split(`/`).pop()),price:e.priceAdjustments.length>0?Math.round(Number(e.priceAdjustments[0].price.amount)*100):Math.round(Number(t.price.amount)*100),compareAtPrice:e.priceAdjustments.length>0?Math.round(Number(e.priceAdjustments[0].compareAtPrice.amount)*100):Math.round(Number(t.price.amount)*100),perDeliveryPrice:e.priceAdjustments.length>0?Math.round(Number(e.priceAdjustments[0].perDeliveryPrice.amount)*100):Math.round(Number(t.price.amount)*100)}))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:t.quantityAvailable??null,unitPriceMeasurement:e?.quantityUnit&&e?.referenceUnit?{quantityValue:e.quantityValue,quantityUnit:e.quantityUnit.toLowerCase(),referenceValue:e.referenceValue,referenceUnit:e.referenceUnit.toLowerCase()}:null})),i=e.options.map((e,t)=>{let n=e.optionValues.map(e=>({id:Number(e.id.split(`/`).pop()),defaultName:e.name,name:e.name,swatch:{color:e.swatch?.color||null,image:e.swatch?.image?.previewImage?.url||null}}));return{defaultName:e.name,name:e.name,position:t+1,optionValues:x(n,t,r)}}),a=e=>{let t=e.priceAdjustments[0];if(!t)return null;let n=t.adjustmentValue;switch(n.__typename){case`SellingPlanPercentagePriceAdjustment`:return{type:`percentage`,value:n.adjustmentPercentage};case`SellingPlanFixedAmountPriceAdjustment`:return{type:`fixed_amount`,value:o(n.adjustmentAmount.amount)};case`SellingPlanFixedPriceAdjustment`:return{type:`price`,value:o(n.price.amount)};default:throw Error(`Unknown price adjustment type: ${n.__typename}`)}},o=e=>n===1?Number(e)*100:Math.round(Number(e)*100*n),s=e.sellingPlanGroups?.nodes.flatMap(e=>e.sellingPlans.nodes.map(e=>({id:Number(e.id.split(`/`).pop()),name:e.name,priceAdjustment:a(e)})))||[],c=e.variants.nodes.some(e=>e.requiresComponents);return{id:Number(e.id.split(`/`).pop()),handle:e.handle,url:e.onlineStoreUrl||`https://${t}/products/${e.handle}`,availableForSale:e.availableForSale,createdAt:e.createdAt,title:e.title,image:e.featuredImage?.url||null,collectionIds:e.collections.nodes.map(e=>Number(e.id.split(`/`).pop())),options:i,selectedVariantId:Number(e.variants.nodes[0].id.split(`/`).pop()),variants:r,requiresSellingPlan:e.requiresSellingPlan,sellingPlans:s,isNativeBundle:c,metafields:{text:e.metafield?.value||null,text2:e.metafield2?.value||null,text3:e.metafield3?.value||null,text4:e.metafield4?.value||null},rating:y(e.reviewsRating,e.reviewsRatingCount),subtitle:e.subtitle?.value||null}},y=(e,t)=>{if(!e)return null;let n=b(e.value);if(n===null)return null;let r=Number(t?.value);return{value:n,count:Number.isInteger(r)&&r>0?r:null}},b=e=>{try{let{value:t,scale_max:n}=JSON.parse(e),r=Number(t)/Number(n)*5;return Number.isFinite(r)&&r>0?Math.min(5,r):null}catch{return null}},x=(e,t,n)=>e.filter(e=>n.filter(n=>n.options[t]===e.name).length>0),S=`app--2935586817`,C=async(e,{language:t,country:r,useExternalMetafieldNamespace:i})=>{let a=i?`${S}--kaching_bundles`:`$app:kaching_bundles`,o=i?S:`$app`,s=l({country:r}),{localization:{country:{currency:{isoCode:c}}},shop:{moneyFormat:u,paymentSettings:{currencyCode:d},currencyRateConstant:f,primaryDomain:p,settingsMetafield:m}}=await e.query(`
|
|
199
202
|
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${s} {
|
|
200
203
|
localization {
|
|
201
204
|
country {
|
|
@@ -220,7 +223,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
220
223
|
}
|
|
221
224
|
}
|
|
222
225
|
}
|
|
223
|
-
`,{variables:{metafieldNamespace:a,settingsNamespace:o}}),h=c===d?u:n(c,{language:t,country:r}),g=f?
|
|
226
|
+
`,{variables:{metafieldNamespace:a,settingsNamespace:o}}),h=c===d?u:n(c,{language:t,country:r}),g=f?w(f.value):1,_=m?JSON.parse(m.value):null,v=_?.feature_flags??{},y=_?.custom_selectors??{};return{shopifyDomain:p.host,moneyFormat:h,locale:t?.toLowerCase()||`en`,liquidLocale:t?.toLowerCase()||`en`,country:r??`US`,currencyRate:g,marketId:0,productId:null,storefrontAccessToken:_?.storefront_access_token??null,includeSellingPlans:_?.include_selling_plans??!1,includeAvailableQuantity:_?.include_available_quantity??!1,customApiHost:_?.custom_api_host??null,keepQuantityInput:_?.keep_quantity_input??!1,ignoreDeselect:_?.ignore_deselect??!1,ignoreUnitPrice:_?.ignore_unit_price??!1,requireCustomerLogin:_?.require_customer_login??!1,abTestsRunning:_?.ab_tests_running??!1,webPixel:_?.web_pixel??!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,previewScratchOff:!1,defaultTranslations:{"system.out_of_stock":`Out of stock`,"system.invalid_variant":`Invalid variant`,"system.unavailable_option_value":`Unavailable option value`,"system.confirm":`Confirm`,"system.cancel":`Cancel`,"system.free":`FREE`,"system.search":`Search`,"system.quantity":`Quantity`,"system.subscription_plan":`Subscription plan`,"system.remove":`Remove`,"system.sort_by":`Sort by`,"system.sort_relevance":`Relevance`,"system.sort_newest_first":`Newest first`,"system.sort_price_low_to_high":`Price: Low → High`,"system.sort_price_high_to_low":`Price: High → Low`,"system.no_results_found":`No results found`,"system.no_results_description":`We can't find any item matching your search.`,"system.clear_search":`Clear search`,"system.no_products_available":`No products available`,"system.original_price":`Original price:`,"system.price":`Price:`,"system.letters_only":`Only letters are allowed.`,"system.numbers_only":`Only numbers are allowed.`},customSelectors:{quantity:y.quantity??null,addToCartButton:y.add_to_cart_button??null,variantPicker:y.variant_picker??null,price:y.price??null,priceCompare:y.price_compare??null},shopCustomStyles:_?.shop_custom_styles??``,featureFlags:v,brandColors:_?.brand_colors??null}},w=e=>JSON.parse(e).amount/1e6,T=async(e,t,n=200)=>{let r=[...new Set(t.filter(Boolean).filter(e=>!e.startsWith(`placeholder`)))];if(r.length===0)return[];let i=[];for(let e=0;e<r.length;e+=250)i.push(r.slice(e,e+250));return(await Promise.all(i.map(t=>e.query(`
|
|
224
227
|
query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
|
|
225
228
|
nodes(ids: $mediaImageIds) {
|
|
226
229
|
... on MediaImage {
|
|
@@ -231,5 +234,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
}
|
|
234
|
-
`,{variables:{mediaImageIds:t,size:n}})))).flatMap(e=>e.nodes).flatMap(e=>e?.image?[{gid:e.id,url:e.image.url}]:[])}
|
|
237
|
+
`,{variables:{mediaImageIds:t,size:n}})))).flatMap(e=>e.nodes).flatMap(e=>e?.image?[{gid:e.id,url:e.image.url}]:[])},E=e=>[...D(e),...O(e),...k(e),...A(e),...ee(e),...te(e),...ne(e),...re(e),...ie(e),...ae(e),...oe(e),...se(e),...ce(e)].filter(e=>e!=null&&!e.includes(`placeholder`)),D=e=>e.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),O=e=>e.dealBars.flatMap(e=>e.dealBarType===p.Bundle?e.bundleProducts.map(e=>e.mediaImageGID):[]).filter(e=>e!=null),k=e=>e.dealBars.map(({freeGifts:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),A=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(e=>e.mediaImageGID)).filter(e=>e!=null),ee=e=>e.dealBars.map(({upsells:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),te=e=>e.swatchOptions?e.swatchOptions.reduce((e,t)=>{let n=t.images.map(e=>e.mediaImageGID).filter(e=>e!=null);return[...e,...n]},[]):[],ne=e=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];let t=e.collectionBreaks.mediaImageGID;return t?[t]:[]},re=e=>e.progressiveGifts?[...e.progressiveGifts.gifts?.map(e=>e.mediaImageGID)||[],e.progressiveGifts.style?.lockedMediaImageGID,e.progressiveGifts.dealBarStyle?.lockedMediaImageGID].filter(e=>e!=null):[],ie=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),ae=e=>e.dealBars.map(e=>e.productPersonalisation?.mediaImageGID).filter(e=>e!=null),oe=e=>{let t=e.dealBars.map(e=>e.highlights?.customIconGID).filter(e=>e!=null),n=e.subscriptions?.highlights?.customIconGID;return n?[...t,n]:t},se=e=>(e.badges||[]).flatMap(e=>e.badgeType===`custom`&&e.imageGID?[e.imageGID]:[]),ce=e=>!e.savingsSummaryEnabled||!e.savingsSummary?[]:e.savingsSummary.customIconGID?[e.savingsSummary.customIconGID]:[],j=e=>{let t=[...M(e),...N(e),...P(e),...F(e),...I(e),...L(e),...R(e),...z(e)];return Array.from(new Set(t.filter(e=>e!=null)))},M=e=>e.dealBars.flatMap(({freeGifts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),N=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(e=>e.products?e.products.map(e=>e.id):[]):[]).filter(e=>e!=null),P=e=>e.progressiveGiftsEnabled&&e.progressiveGifts?.gifts.map(e=>e.productGID).filter(e=>e!=null)||[],F=e=>e.dealBars.flatMap(({upsells:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),I=e=>e.dealBars.filter(e=>e.dealBarType===p.Bundle).flatMap(({bundleProducts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),L=e=>e.dealBars.filter(e=>e.dealBarType===p.MixAndMatch).flatMap(({bundleProducts:e})=>e?e.flatMap(e=>[e.productGID,...e.selectedProducts?.map(e=>e.id)??[]]):[]).filter(e=>e!=null).filter(e=>e!=="default"),R=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),z=e=>e.dealBars.filter(e=>e.dealBarType===p.Sku).flatMap(({productGID:e})=>e?[e]:[]),B=class extends Error{constructor({status:e,operationName:t,graphqlErrors:n}){let r=n.length?`: ${n.join(`; `)}`:``;super(`Storefront API ${t??`query`} failed (HTTP ${e})${r}`),this.name=`StorefrontApiError`,this.status=e,this.operationName=t,this.graphqlErrors=n}},V=async(e,t)=>{let n=await e.text();if(!n)throw Error(`Empty graphql response`);let r;try{r=JSON.parse(n)}catch(n){throw e.ok?n:new B({status:e.status,operationName:t,graphqlErrors:[]})}if(!e.ok||r.data===null||r.data===void 0)throw new B({status:e.status,operationName:t,graphqlErrors:(r.errors??[]).map(({message:e})=>e).filter(Boolean)});return r.data},H=class{constructor(e,t){this.storefrontApiVersion=`2026-07`,this.storefrontAccessToken=t,this.shopifyDomain=e}async query(e,t){let n=t?.variables??{},r=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`,i=e.match(/query\s+(\w+)/)?.[1];return i&&(r+=`?operation_name=${i}`),V(await fetch(r,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:n})}),i)}},U=(e,t)=>{let n=[],r=e.filter(e=>e.blockVisibility===`selected-products`);for(let e of r)e.selectedProductIds.map(Number).includes(t.id)&&n.push(e);let i=e.filter(e=>e.blockVisibility===`selected-collections`);for(let e of i)t.collectionIds.some(t=>e.selectedCollectionIds.map(Number).includes(t))&&n.push(e);let a=e.filter(e=>e.blockVisibility===`excluded-products`);for(let e of a)!e.excludedProductIds.map(Number).includes(t.id)&&!(e.excludedCollectionIds||[]).some(e=>t.collectionIds.includes(e))&&n.push(e);let o=e.filter(e=>e.blockVisibility===`all-products`);for(let e of o)n.push(e);return n},W=async(e,t,{country:n,language:r})=>{let i=t.collectionBreaks;if(!t.collectionBreaksEnabled||!i)return;let a;a=i.visibility===`deal-products`?await m(e,{country:n,language:r,blockVisibility:t.blockVisibility,excludedProductGIDs:(t.excludedProductIds||[]).map(e=>`gid://shopify/Product/${e}`),selectedProductGIDs:(t.selectedProductIds||[]).map(e=>`gid://shopify/Product/${e}`),selectedCollectionGIDs:(t.selectedCollectionIds||[]).map(e=>`gid://shopify/Collection/${e}`)}):await m(e,{country:n,language:r,blockVisibility:i.visibility,excludedProductGIDs:(i.excludedProducts||[]).map(({id:e})=>e),selectedProductGIDs:(i.selectedProducts||[]).map(({id:e})=>e),selectedCollectionGIDs:(i.selectedCollections||[]).map(({id:e})=>e)});let o=await g(e,{country:n,language:r,productIds:a.map(e=>Number(e.split(`/`).pop())),useExternalMetafieldNamespace:!0});return o=o.filter(e=>e.availableForSale),o},G=({language:e,dealBlockId:t})=>{let n={"system.out_of_stock":`There's not enough items in our stock, please select smaller bundle.`,"system.invalid_variant":`Sorry, this is not currently available.`,"system.unavailable_option_value":`Unavailable`,"system.confirm":`Confirm`,"system.cancel":`Cancel`,"system.free":`FREE`,"system.search":`Search`,"system.quantity":`Quantity`,"system.subscription_plan":`Subscription plan`,"system.remove":`Remove`,"system.sort_by":`Sort by`,"system.sort_relevance":`Relevance`,"system.sort_newest_first":`Newest first`,"system.sort_price_low_to_high":`Price: Low → High`,"system.sort_price_high_to_low":`Price: High → Low`,"system.no_results_found":`No results found`,"system.no_results_description":`We can't find any item matching your search.`,"system.clear_search":`Clear search`,"system.no_products_available":`No products available`,"system.original_price":`Original price:`,"system.price":`Price:`,"system.letters_only":`Only letters are allowed.`,"system.numbers_only":`Only numbers are allowed.`,"system.personalisation_required_alert":`Please add personalisation for every item to continue.`},r=e?le(e):void 0;return{...n,...r?.system,...r?.dealBlocks[t]}},le=e=>{if(typeof document>`u`)return;let t=document.querySelector(`script#kaching-bundles-translations`);if(!t?.textContent)return;let n;try{n=JSON.parse(t.textContent)}catch{return}let r=K(e);return n.find(e=>K(e.locale)===r)?.translations},K=e=>e.toLowerCase().replace(/_/g,`-`),ue=`2026-07`,de=async(e,{productId:t,dealBlockId:n,country:r=void 0,language:i=void 0})=>{try{let a=[Number(t.split(`/`).pop())],o=new fe(e);r||=o.i18n?.country,i||=o.i18n?.language;let s=await C(o,{language:i,country:r,useExternalMetafieldNamespace:!0});o.shopifyDomain=s.shopifyDomain;let c=s.storefrontAccessToken?new H(s.shopifyDomain,s.storefrontAccessToken):o,[l,d]=await Promise.all([g(c,{country:r,language:i,productIds:a,useExternalMetafieldNamespace:!0}),u(c,{useExternalMetafieldNamespace:!0,useMetaobjects:s.featureFlags.storefront_metaobjects})]),f=l[0];if(!f)return null;let p=U(d,f),m;if(n?(m=p.find(e=>e.id===n||e.nanoId===n),m||=p[0]):m=p[0],!m)return null;let h=E(m),_=j(m),[v,y,b,x]=await Promise.all([g(c,{country:r,language:i,productIds:_,useExternalMetafieldNamespace:!0}),T(c,h,300),W(c,m,{country:r,language:i}),G({language:i,dealBlockId:m.id})]);return{product:f,dealBlock:m,config:s,otherProducts:v,mediaImages:y,collectionBreaksProducts:b??[],translations:x}}catch(e){return console.error(e),null}},fe=class{constructor(e){this.storefront=e,this.shopifyDomain=``}async query(e,t){if(`query`in this.storefront&&`i18n`in this.storefront)return await this.storefront.query(e,t);if(`graphql`in this.storefront){let n=await this.storefront.graphql(e,t);if(n.errors?.length)throw Error(n.errors.map(e=>e.message).join(`
|
|
235
238
|
`));return n.data}if(`request`in this.storefront)return(await this.storefront.request(e,t)).data;if(`shopifyDomain`in this.storefront&&`storefrontAccessToken`in this.storefront){let n=await fetch(`https://${this.storefront.shopifyDomain}/api/${ue}/graphql.json`,{body:JSON.stringify({query:e,variables:t?.variables}),headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}{let n=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:e,variables:t?.variables}),headers:this.storefront.getPublicTokenHeaders(),method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}}get i18n(){if(`i18n`in this.storefront)return this.storefront.i18n}},pe=de,q=`kaching-bundles-block`,J=1e4,me=`https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js`,he=`https://bundles-integrations.kachingappz.app/kaching-bundles-block.js`,Y=new WeakSet,ge=async e=>{let t=e.document;if(!e.customElements.get(q)){if(Y.has(t))return X(e,q);Y.add(t);try{await ye(e)}catch(e){throw Y.delete(t),e}}},_e=()=>typeof window<`u`&&window.__KACHING_DEV__!==void 0,ve=()=>_e()?me:he,ye=e=>{let t=e.document;return new Promise((n,r)=>{let i=ve();if(t.querySelector(`script[src="${i}"]`)){X(e,q).then(n).catch(r);return}let a=t.createElement(`script`);a.src=i,a.onload=()=>X(e,q).then(n).catch(r),a.onerror=()=>r(Error(`Failed to load script`)),t.head.appendChild(a)})},X=(e,t)=>new Promise((n,r)=>{e.customElements.get(t)?n():Promise.race([e.customElements.whenDefined(t),new Promise((e,n)=>setTimeout(()=>n(Error(`Custom element "${t}" failed to register within ${J}ms`)),J))]).then(()=>n()).catch(r)});[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var Z=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),Q=`a-f\\d`,be=`#?[${Q}]{3}[${Q}]?`,xe=`#?[${Q}]{6}([${Q}]{2})?`,Se=RegExp(`[^#${Q}]`,`gi`),Ce=RegExp(`^${be}$|^${xe}$`,`i`);function $(e,t={}){if(typeof e!=`string`||Se.test(e)||!Ce.test(e))throw TypeError(`Expected a valid hex string`);e=e.replace(/^#/,``);let n=1;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]);let r=Number.parseInt(e,16),i=r>>16,a=r>>8&255,o=r&255,s=typeof t.alpha==`number`?t.alpha:n;return t.format===`array`?[i,a,o,s]:t.format===`css`?`rgb(${i} ${a} ${o}${s===1?``:` / ${Number((s*100).toFixed(2))}%`})`:{red:i,green:a,blue:o,alpha:s}}var we=({price:e})=>({id:123,handle:`123`,url:null,availableForSale:!0,requiresSellingPlan:!1,title:``,image:null,selectedVariantId:456,collectionIds:[],options:[],sellingPlans:[],variants:[{id:456,availableForSale:!0,price:Math.round((e??10)*100),compareAtPrice:null,options:[],imageId:null,image:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50,unitPriceMeasurement:null}],metafields:{text:null,text2:null,text3:null,text4:null},isNativeBundle:!1}),Te=()=>({shopifyDomain:``,moneyFormat:"${{amount_with_comma_separator}}",locale:`en`,liquidLocale:`en`,country:`US`,marketId:0,productId:null,storefrontAccessToken:null,includeSellingPlans:!1,includeAvailableQuantity:!1,customApiHost:null,keepQuantityInput:!1,ignoreDeselect:!1,ignoreUnitPrice:!1,requireCustomerLogin:!1,abTestsRunning:!1,webPixel:!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,previewScratchOff:!1,currencyRate:1,defaultTranslations:{"system.out_of_stock":``,"system.invalid_variant":``,"system.unavailable_option_value":``,"system.confirm":``,"system.cancel":``,"system.free":``,"system.search":``,"system.quantity":``,"system.subscription_plan":``,"system.remove":``,"system.sort_by":``,"system.sort_relevance":``,"system.sort_newest_first":``,"system.sort_price_low_to_high":``,"system.sort_price_high_to_low":``,"system.no_results_found":``,"system.no_results_description":``,"system.clear_search":``,"system.no_products_available":``,"system.original_price":``,"system.price":``,"system.letters_only":``,"system.numbers_only":``},customSelectors:{quantity:null,addToCartButton:null,variantPicker:null},shopCustomStyles:``,featureFlags:{}}),Ee=({color:e,cornerRadius:t})=>{let n={id:`123`,nanoId:`123`,blockName:`Bundle`,discountName:``,blockTitle:`BUNDLE & SAVE`,blockLayout:`vertical`,blockVisibility:`all-products`,marketId:null,currency:null,excludedProductIds:[],excludedCollectionIds:[],selectedProductIds:[],selectedCollectionIds:[],excludeB2bCustomers:!1,excludePos:!1,startTimestamp:175811496e4,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!1,showPricesPerItem:!1,showBothPrices:!1,useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:`.00`,updateNativePrice:!1,updateNativePriceType:`item`,skipCart:!1,showVariantsForSingleQuantity:!0,preselectedDealBarId:`1f-9`,defaultVariantsV2:[],collectionBreaksEnabled:!1,collectionBreaks:null,chooseProductModal:null,timerEnabled:!1,timer:null,subscriptionsEnabled:!1,subscriptions:null,stickyAtcEnabled:!1,stickyAtc:null,progressiveGiftsEnabled:!1,progressiveGifts:null,checkboxUpsellsEnabled:!1,checkboxUpsells:null,lowStockAlertEnabled:!1,lowStockAlert:null,dealBars:[{id:`PfFU`,dealBarType:Z.QuantityBreak,title:`1 pack`,subtitle:`Standard price`,label:``,quantity:1,discountType:`default`,discountValue:``,badgeStyle:`simple`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null},{id:`1f-9`,dealBarType:Z.QuantityBreak,title:`2 pack`,subtitle:`You save {{saved_percentage}}`,label:`SAVE {{saved_total}}`,quantity:2,discountType:`percentage`,discountValue:`15`,badgeStyle:`most-popular`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null}],badgesEnabled:!0,badges:[{id:`bdg1`,attachedTo:{type:`dealBar`,dealBarId:`1f-9`},text:`MOST POPULAR`,colors:null,badgeType:`most-popular`,size:90}],cornerRadius:t??8,spacing:1,colors:{background:{red:255,green:255,blue:255,alpha:1},selectedBackground:{red:255,green:255,blue:255,alpha:1},border:{red:0,green:0,blue:0,alpha:1},blockTitle:{red:0,green:0,blue:0,alpha:1},title:{red:0,green:0,blue:0,alpha:1},subtitle:{red:85,green:85,blue:85,alpha:1},price:{red:0,green:0,blue:0,alpha:1},fullPrice:{red:85,green:85,blue:85,alpha:1},labelBackground:{red:238,green:238,blue:238,alpha:1},label:{red:0,green:0,blue:0,alpha:1},badgeBackground:{red:255,green:17,blue:17,alpha:1},badgeText:{red:255,green:255,blue:255,alpha:1},freeGiftBackground:{red:0,green:0,blue:0,alpha:.3},freeGiftText:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedBackground:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedText:{red:255,green:255,blue:255,alpha:1},upsellBackground:{red:0,green:0,blue:0,alpha:.2},upsellText:{red:0,green:0,blue:0,alpha:1},upsellSelectedBackground:{red:0,green:0,blue:0,alpha:.2},upsellSelectedText:{red:0,green:0,blue:0,alpha:1}},fonts:{blockTitle:{size:`14`,style:`bold`},title:{size:`20`,style:`bold`},subtitle:{size:`14`,style:`regular`},label:{size:`12`,style:`regular`},freeGift:{size:`13`,style:`bold`},upsell:{size:`13`,style:`bold`},unitLabel:{size:`14`,style:`regular`}},swatchOptions:[],swatchSize:18,swatchShape:`circle`,imageSize:48,imageCornerRadius:6};return e!==void 0&&(n.colors.border={...$(e),alpha:1}),n},De=({data:n,selectedVariantId:r,preview:i,onLinesChange:a,targetWindow:o})=>{let s=(0,e.useRef)(null),[c,l]=(0,e.useState)(!1),u=(0,e.useRef)(!1);(0,e.useEffect)(()=>{s.current&&!c&&(async()=>{await ge(o??window),l(!0)})()},[c,o]),(0,e.useEffect)(()=>{let e=s.current;if(!c||!e)return;let t=()=>{let t=e.items().map(e=>({merchandiseId:`gid://shopify/ProductVariant/${e.id}`,quantity:e.quantity,attributes:Object.entries(e.properties).map(([e,t])=>({key:e,value:String(t)})),sellingPlanId:e.selling_plan?`gid://shopify/SellingPlan/${e.selling_plan}`:void 0}));a?.(t)};return u.current||=(typeof e.items==`function`?t():e.addEventListener(`kaching-bundles-block-loaded`,t),!0),e.addEventListener(`variants-changed`,t),()=>{e.removeEventListener(`kaching-bundles-block-loaded`,t),e.removeEventListener(`variants-changed`,t)}},[c,a]);let d=n?ke(n,r):i?Ae(i):null;return Oe(()=>{let e=s.current;if(e&&d)for(let[t,n]of Object.entries(d.jsonAttributes))e.getAttribute(t)!==n&&e.setAttribute(t,n)}),d?(0,t.jsx)(`kaching-bundles-block`,{ref:s,"deal-block-id":d.dealBlockId,...d.jsonAttributes,"current-variant-id":d.currentVariantId}):null},Oe=typeof window>`u`?e.useEffect:e.useLayoutEffect,ke=({config:e,dealBlock:t,product:n,otherProducts:r,mediaImages:i,collectionBreaksProducts:a,translations:o},s)=>({dealBlockId:t.id,currentVariantId:s?s.split(`/`).pop():String(n.variants[0].id),jsonAttributes:{config:JSON.stringify(e),"deal-block":JSON.stringify(t),"media-images":JSON.stringify(i),product:JSON.stringify(n),"other-products":JSON.stringify(r),"collection-breaks-products":JSON.stringify(a),translations:JSON.stringify(o)}}),Ae=({cornerRadius:e,color:t,price:n})=>{let r=we({price:n}),i=Te(),a=Ee({color:t,cornerRadius:e});return{dealBlockId:a.id,currentVariantId:String(r.variants[0].id),jsonAttributes:{config:JSON.stringify(i),"deal-block":JSON.stringify(a),"media-images":JSON.stringify([]),product:JSON.stringify(r),"other-products":JSON.stringify([]),"collection-breaks-products":JSON.stringify([]),translations:JSON.stringify({})}}};exports.KachingBundle=De,exports.fetchKachingBundlesData=pe;
|