@kachingappz/bundles-js 1.1.8 → 1.1.10

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.
@@ -107,16 +107,16 @@ var g = /* @__PURE__ */ function(e) {
107
107
  return Array.from(new Set(i)).slice(0, s);
108
108
  }
109
109
  }
110
- }, v = "\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", y = 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: l = !1, batchSize: u = 250, onBatchError: d, variantImageTransform: p = {
110
+ }, v = "\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", y = 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: p, variantImageTransform: m = {
111
111
  maxWidth: 200,
112
112
  maxHeight: 200
113
113
  } }) => {
114
114
  if (!r.length) return [];
115
- let m = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), h = f({
115
+ let h = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), g = f({
116
116
  country: t,
117
117
  language: n
118
- }), g = `
119
- query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${h} {
118
+ }), _ = `
119
+ query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $includeProductTabFields: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${g} {
120
120
  shop {
121
121
  currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
122
122
  value
@@ -179,6 +179,10 @@ var g = /* @__PURE__ */ function(e) {
179
179
  subtitle: metafield(namespace: $subtitleNamespace, key: $subtitleKey) @include(if: $includeProductSubtitle) {
180
180
  value
181
181
  }
182
+ category @include(if: $includeProductTabFields) {
183
+ id
184
+ }
185
+ tags @include(if: $includeProductTabFields)
182
186
  requiresSellingPlan
183
187
  sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
184
188
  nodes {
@@ -186,6 +190,7 @@ var g = /* @__PURE__ */ function(e) {
186
190
  nodes {
187
191
  id
188
192
  name
193
+ recurringDeliveries
189
194
  priceAdjustments {
190
195
  adjustmentValue {
191
196
  __typename
@@ -211,43 +216,63 @@ var g = /* @__PURE__ */ function(e) {
211
216
  }
212
217
  }
213
218
  }
214
- `, _ = l ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", y = c.indexOf("."), S = c.slice(0, y), C = c.slice(y + 1), w = [], T = Math.min(u, 250);
215
- for (let e = 0; e < m.length; e += T) w.push(m.slice(e, e + T));
216
- let E = 1, D = async (t) => {
217
- let n = await e.query(g, { variables: {
218
- productGIDs: t,
219
+ `, y = u ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", C = l.indexOf("."), w = l.slice(0, C), T = l.slice(C + 1), E = [], D = Math.min(d, 250);
220
+ for (let e = 0; e < h.length; e += D) E.push(h.slice(e, e + D));
221
+ let O = 1, k = async (n) => {
222
+ let [r, l] = await Promise.all([e.query(_, { variables: {
223
+ productGIDs: n,
219
224
  includeSellingPlans: i,
220
225
  includeAvailableQuantity: a,
221
226
  includeProductRating: o,
222
227
  includeProductSubtitle: s,
223
- subtitleNamespace: S,
224
- subtitleKey: C,
225
- metafieldNamespace: _,
226
- variantImageTransform: p
227
- } });
228
- return n.shop.currencyRateConstant && (E = JSON.parse(n.shop.currencyRateConstant.value).amount / 1e6), n;
229
- }, O;
230
- if (d) {
231
- let e = await Promise.allSettled(w.map(D));
232
- for (let t of e) t.status === "rejected" && d(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
233
- O = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
234
- } else O = (await Promise.all(w.map(D))).flatMap((e) => e.nodes);
235
- let k = O.filter((e) => e != null);
236
- if (d) {
237
- let t = await Promise.allSettled(k.map(async (t) => x(await b(e, t, {
228
+ includeProductTabFields: c,
229
+ subtitleNamespace: w,
230
+ subtitleKey: T,
231
+ metafieldNamespace: y,
232
+ variantImageTransform: m
233
+ } }), c ? b(e, t, n) : null]);
234
+ return r.shop.currencyRateConstant && (O = JSON.parse(r.shop.currencyRateConstant.value).amount / 1e6), l ? { nodes: r.nodes.map((e) => e && {
235
+ ...e,
236
+ productType: l.get(e.id)
237
+ }) } : r;
238
+ }, A;
239
+ if (p) {
240
+ let e = await Promise.allSettled(E.map(k));
241
+ for (let t of e) t.status === "rejected" && p(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
242
+ A = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
243
+ } else A = (await Promise.all(E.map(k))).flatMap((e) => e.nodes);
244
+ let j = A.filter((e) => e != null);
245
+ if (p) {
246
+ let t = await Promise.allSettled(j.map(async (t) => S(await x(e, t, {
238
247
  includeSellingPlans: i,
239
248
  includeAvailableQuantity: a,
240
- variantImageTransform: p
241
- }, h), e.shopifyDomain, E))), n = [];
242
- for (let e of t) e.status === "fulfilled" ? n.push(e.value) : d(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
249
+ variantImageTransform: m
250
+ }, g), e.shopifyDomain, O))), n = [];
251
+ for (let e of t) e.status === "fulfilled" ? n.push(e.value) : p(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
243
252
  return n;
244
253
  }
245
- return (await Promise.all(k.map((t) => b(e, t, {
254
+ return (await Promise.all(j.map((t) => x(e, t, {
246
255
  includeSellingPlans: i,
247
256
  includeAvailableQuantity: a,
248
- variantImageTransform: p
249
- }, h)))).map((t) => x(t, e.shopifyDomain, E));
250
- }, b = async (e, t, n, r = "") => {
257
+ variantImageTransform: m
258
+ }, g)))).map((t) => S(t, e.shopifyDomain, O));
259
+ }, b = async (e, t, n) => {
260
+ try {
261
+ let r = await e.query(`
262
+ query FetchProductTypes($productGIDs: [ID!]!) ${f({ country: t })} {
263
+ nodes(ids: $productGIDs) {
264
+ ... on Product {
265
+ id
266
+ productType
267
+ }
268
+ }
269
+ }
270
+ `, { variables: { productGIDs: n } });
271
+ return new Map(r.nodes.filter((e) => e != null).map((e) => [e.id, e.productType]));
272
+ } catch (e) {
273
+ return console.error(e), null;
274
+ }
275
+ }, x = async (e, t, n, r = "") => {
251
276
  if (t.variants.nodes.length < 250) return t;
252
277
  let i = /* @__PURE__ */ new Set(), a = [], o = [], s = async (s) => {
253
278
  let c = !0, l = null;
@@ -283,7 +308,7 @@ var g = /* @__PURE__ */ function(e) {
283
308
  }
284
309
  };
285
310
  return await Promise.all([s(!1), s(!0)]), t.variants.nodes = [...a, ...o.reverse()], t;
286
- }, x = (e, t, n) => {
311
+ }, S = (e, t, n) => {
287
312
  let r = e.variants.nodes.map(({ unitPriceMeasurement: e, ...t }) => ({
288
313
  id: Number(t.id.split("/").pop()),
289
314
  availableForSale: t.availableForSale,
@@ -321,7 +346,7 @@ var g = /* @__PURE__ */ function(e) {
321
346
  defaultName: e.name,
322
347
  name: e.name,
323
348
  position: t + 1,
324
- optionValues: w(n, t, r)
349
+ optionValues: T(n, t, r)
325
350
  };
326
351
  }), a = (e) => {
327
352
  let t = e.priceAdjustments[0];
@@ -345,6 +370,7 @@ var g = /* @__PURE__ */ function(e) {
345
370
  }, o = (e) => n === 1 ? Number(e) * 100 : Math.round(Number(e) * 100 * n), s = e.sellingPlanGroups?.nodes.flatMap((e) => e.sellingPlans.nodes.map((e) => ({
346
371
  id: Number(e.id.split("/").pop()),
347
372
  name: e.name,
373
+ recurringDeliveries: e.recurringDeliveries,
348
374
  priceAdjustment: a(e)
349
375
  }))) || [], c = e.variants.nodes.some((e) => e.requiresComponents);
350
376
  return {
@@ -368,27 +394,45 @@ var g = /* @__PURE__ */ function(e) {
368
394
  text3: e.metafield3?.value || null,
369
395
  text4: e.metafield4?.value || null
370
396
  },
371
- rating: S(e.reviewsRating, e.reviewsRatingCount),
372
- subtitle: e.subtitle?.value || null
397
+ rating: C(e.reviewsRating, e.reviewsRatingCount),
398
+ subtitle: e.subtitle?.value || null,
399
+ productType: e.productType || null,
400
+ categoryGid: e.category?.id ?? null,
401
+ tags: e.tags ?? []
373
402
  };
374
- }, S = (e, t) => {
403
+ }, C = (e, t) => {
375
404
  if (!e) return null;
376
- let n = C(e.value);
405
+ let n = w(e.value);
377
406
  if (n === null) return null;
378
407
  let r = Number(t?.value);
379
408
  return {
380
409
  value: n,
381
410
  count: Number.isInteger(r) && r > 0 ? r : null
382
411
  };
383
- }, C = (e) => {
412
+ }, w = (e) => {
384
413
  try {
385
414
  let { value: t, scale_max: n } = JSON.parse(e), r = Number(t) / Number(n) * 5;
386
415
  return Number.isFinite(r) && r > 0 ? Math.min(5, r) : null;
387
416
  } catch {
388
417
  return null;
389
418
  }
390
- }, w = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0), T = "app--2935586817", E = async (e, { language: t, country: n, useExternalMetafieldNamespace: r }) => {
391
- let i = r ? `${T}--kaching_bundles` : "$app:kaching_bundles", o = r ? T : "$app", s = f({ country: n }), { localization: { country: { currency: { isoCode: c } } }, shop: { moneyFormat: l, paymentSettings: { currencyCode: u }, currencyRateConstant: d, primaryDomain: p, settingsMetafield: m } } = await e.query(`
419
+ }, T = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0);
420
+ [
421
+ "primaryBackground",
422
+ "secondaryBackground",
423
+ "primaryText",
424
+ "secondaryText",
425
+ "border",
426
+ "overlay",
427
+ "primaryAccent",
428
+ "primaryAccentText",
429
+ "badgeBackground",
430
+ "badgeText",
431
+ "error"
432
+ ].map((e) => `brand_${e}`);
433
+ // ../bundles-storefront-api/dist/fetchGlobalConfig.js
434
+ var E = "app--2935586817", D = async (e, { language: t, country: n, useExternalMetafieldNamespace: r }) => {
435
+ let i = r ? `${E}--kaching_bundles` : "$app:kaching_bundles", o = r ? E : "$app", s = f({ country: n }), { localization: { country: { currency: { isoCode: c } } }, shop: { moneyFormat: l, paymentSettings: { currencyCode: u }, currencyRateConstant: d, primaryDomain: p, settingsMetafield: m } } = await e.query(`
392
436
  query config($metafieldNamespace: String!, $settingsNamespace: String!) ${s} {
393
437
  localization {
394
438
  country {
@@ -419,7 +463,7 @@ var g = /* @__PURE__ */ function(e) {
419
463
  } }), h = c === u ? l : a(c, {
420
464
  language: t,
421
465
  country: n
422
- }), g = d ? D(d.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
466
+ }), g = d ? O(d.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
423
467
  return {
424
468
  shopifyDomain: p.host,
425
469
  moneyFormat: h,
@@ -480,7 +524,7 @@ var g = /* @__PURE__ */ function(e) {
480
524
  featureFlags: v,
481
525
  brandColors: _?.brand_colors ?? null
482
526
  };
483
- }, D = (e) => JSON.parse(e).amount / 1e6, O = async (e, t, n = 200) => {
527
+ }, O = (e) => JSON.parse(e).amount / 1e6, k = async (e, t, n = 200) => {
484
528
  let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
485
529
  if (r.length === 0) return [];
486
530
  let i = [];
@@ -492,9 +536,33 @@ var g = /* @__PURE__ */ function(e) {
492
536
  gid: e.id,
493
537
  url: e.image.url
494
538
  }] : []);
495
- }, k = (e) => [
496
- ...A(e),
497
- ...ee(e),
539
+ }, A = 100, j = async (e, { dealBlock: t, country: n, language: r }) => {
540
+ let i = [...new Set(t.dealBars.flatMap((e) => e.dealBarType === g.MixAndMatch ? e.bundleProducts : []).flatMap((e) => (e.selectedCollections ?? []).map((e) => e.id)))];
541
+ if (i.length === 0) return [];
542
+ let a = f({
543
+ country: n,
544
+ language: r
545
+ }), o = await e.query(`
546
+ query FetchMixAndMatchCollectionProductGIDs($collectionGIDs: [ID!]!) ${a} {
547
+ nodes(ids: $collectionGIDs) {
548
+ ... on Collection {
549
+ id
550
+ products(first: ${A}) {
551
+ nodes {
552
+ id
553
+ variants(first: 1) {
554
+ nodes {
555
+ requiresComponents
556
+ }
557
+ }
558
+ }
559
+ }
560
+ }
561
+ }
562
+ }
563
+ `, { variables: { collectionGIDs: i } });
564
+ 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))];
565
+ }, ee = (e) => [
498
566
  ...te(e),
499
567
  ...ne(e),
500
568
  ...re(e),
@@ -505,64 +573,66 @@ var g = /* @__PURE__ */ function(e) {
505
573
  ...ce(e),
506
574
  ...le(e),
507
575
  ...ue(e),
508
- ...de(e)
509
- ].filter((e) => e != null && !e.includes("placeholder")), A = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ee = (e) => e.dealBars.flatMap((e) => e.dealBarType === g.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), te = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ne = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), re = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ie = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
576
+ ...de(e),
577
+ ...fe(e),
578
+ ...M(e)
579
+ ].filter((e) => e != null && !e.includes("placeholder")), te = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ne = (e) => e.dealBars.flatMap((e) => e.dealBarType === g.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), re = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ie = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), ae = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), oe = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
510
580
  let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
511
581
  return [...e, ...n];
512
- }, []) : [], ae = (e) => {
582
+ }, []) : [], se = (e) => {
513
583
  if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
514
584
  let t = e.collectionBreaks.mediaImageGID;
515
585
  return t ? [t] : [];
516
- }, oe = (e) => e.progressiveGifts ? [
586
+ }, ce = (e) => e.progressiveGifts ? [
517
587
  ...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
518
588
  e.progressiveGifts.style?.lockedMediaImageGID,
519
589
  e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
520
- ].filter((e) => e != null) : [], se = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ce = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), le = (e) => {
590
+ ].filter((e) => e != null) : [], le = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ue = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), de = (e) => {
521
591
  let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
522
592
  return n ? [...t, n] : t;
523
- }, ue = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), de = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], j = (e) => {
524
- let t = [
525
- ...M(e),
526
- ...N(e),
593
+ }, fe = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), M = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], N = (e, { includeMixAndMatchSwapProducts: t = !0 } = {}) => {
594
+ let n = [
527
595
  ...P(e),
528
596
  ...F(e),
529
597
  ...I(e),
530
598
  ...L(e),
531
599
  ...R(e),
532
- ...z(e)
600
+ ...z(e, t),
601
+ ...B(e),
602
+ ...V(e)
533
603
  ];
534
- return Array.from(new Set(t.filter((e) => e != null)));
535
- }, 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 === g.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 === g.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 === g.Sku).flatMap(({ productGID: e }) => e ? [e] : []), B = class extends Error {
604
+ return Array.from(new Set(n.filter((e) => e != null)));
605
+ }, P = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), F = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), I = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], L = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), R = (e) => e.dealBars.filter((e) => e.dealBarType === g.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), z = (e, t) => e.dealBars.filter((e) => e.dealBarType === g.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"), B = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), V = (e) => e.dealBars.filter((e) => e.dealBarType === g.Sku).flatMap(({ productGID: e }) => e ? [e] : []), H = class extends Error {
536
606
  constructor({ status: e, operationName: t, graphqlErrors: n }) {
537
607
  let r = n.length ? `: ${n.join("; ")}` : "";
538
608
  super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
539
609
  }
540
- }, V = async (e, t) => {
610
+ }, pe = async (e, t) => {
541
611
  let n = await e.text();
542
612
  if (!n) throw Error("Empty graphql response");
543
613
  let r;
544
614
  try {
545
615
  r = JSON.parse(n);
546
616
  } catch (n) {
547
- throw e.ok ? n : new B({
617
+ throw e.ok ? n : new H({
548
618
  status: e.status,
549
619
  operationName: t,
550
620
  graphqlErrors: []
551
621
  });
552
622
  }
553
- if (!e.ok || r.data === null || r.data === void 0) throw new B({
623
+ if (!e.ok || r.data === null || r.data === void 0) throw new H({
554
624
  status: e.status,
555
625
  operationName: t,
556
626
  graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
557
627
  });
558
628
  return r.data;
559
- }, H = class {
629
+ }, me = class {
560
630
  constructor(e, t) {
561
631
  this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
562
632
  }
563
633
  async query(e, t) {
564
634
  let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
565
- return i && (r += `?operation_name=${i}`), V(await fetch(r, {
635
+ return i && (r += `?operation_name=${i}`), pe(await fetch(r, {
566
636
  method: "POST",
567
637
  headers: {
568
638
  "Content-Type": "application/json",
@@ -584,7 +654,23 @@ var g = /* @__PURE__ */ function(e) {
584
654
  let o = e.filter((e) => e.blockVisibility === "all-products");
585
655
  for (let e of o) n.push(e);
586
656
  return n;
587
- }, fe = async (e, t, { country: n, language: r }) => {
657
+ };
658
+ [
659
+ "primaryBackground",
660
+ "secondaryBackground",
661
+ "primaryText",
662
+ "secondaryText",
663
+ "border",
664
+ "overlay",
665
+ "primaryAccent",
666
+ "primaryAccentText",
667
+ "badgeBackground",
668
+ "badgeText",
669
+ "error"
670
+ ].map((e) => `brand_${e}`);
671
+ var W = /* @__PURE__ */ function(e) {
672
+ return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
673
+ }({}), he = async (e, t, { country: n, language: r }) => {
588
674
  let i = t.collectionBreaks;
589
675
  if (!t.collectionBreaksEnabled || !i) return;
590
676
  let a;
@@ -610,7 +696,7 @@ var g = /* @__PURE__ */ function(e) {
610
696
  useExternalMetafieldNamespace: !0
611
697
  }), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
612
698
  return o = o.filter((e) => e.availableForSale && (!s || U([t], e).length > 0)), o;
613
- }, pe = ({ language: e, dealBlockId: t }) => {
699
+ }, ge = ({ language: e, dealBlockId: t }) => {
614
700
  let n = {
615
701
  "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
616
702
  "system.invalid_variant": "Sorry, this is not currently available.",
@@ -637,13 +723,13 @@ var g = /* @__PURE__ */ function(e) {
637
723
  "system.numbers_only": "Only numbers are allowed.",
638
724
  "system.personalisation_required_alert": "Please add personalisation for every item to continue.",
639
725
  "system.gifts_required_alert": "Please choose your free gifts"
640
- }, r = e ? me(e) : void 0;
726
+ }, r = e ? _e(e) : void 0;
641
727
  return {
642
728
  ...n,
643
729
  ...r?.system,
644
730
  ...r?.dealBlocks[t]
645
731
  };
646
- }, me = (e) => {
732
+ }, _e = (e) => {
647
733
  if (typeof document > "u") return;
648
734
  let t = document.querySelector("script#kaching-bundles-translations");
649
735
  if (!t?.textContent) return;
@@ -653,19 +739,19 @@ var g = /* @__PURE__ */ function(e) {
653
739
  } catch {
654
740
  return;
655
741
  }
656
- let r = W(e);
657
- return n.find((e) => W(e.locale) === r)?.translations;
658
- }, W = (e) => e.toLowerCase().replace(/_/g, "-"), he = "2026-07", ge = async (e, { productId: t, dealBlockId: n, abTestVariantId: r, country: i = void 0, language: a = void 0 }) => {
742
+ let r = G(e);
743
+ return n.find((e) => G(e.locale) === r)?.translations;
744
+ }, G = (e) => e.toLowerCase().replace(/_/g, "-"), ve = "2026-07", ye = async (e, { productId: t, dealBlockId: n, abTestVariantId: r, country: i = void 0, language: a = void 0 }) => {
659
745
  try {
660
- let o = [Number(t.split("/").pop())], s = new _e(e);
746
+ let o = [Number(t.split("/").pop())], s = new we(e);
661
747
  i ||= s.i18n?.country, a ||= s.i18n?.language;
662
- let c = await E(s, {
748
+ let c = await D(s, {
663
749
  language: a,
664
750
  country: i,
665
751
  useExternalMetafieldNamespace: !0
666
752
  });
667
753
  s.shopifyDomain = c.shopifyDomain;
668
- let l = c.storefrontAccessToken ? new H(c.shopifyDomain, c.storefrontAccessToken) : s, [u, d] = await Promise.all([y(l, {
754
+ let l = c.storefrontAccessToken ? new me(c.shopifyDomain, c.storefrontAccessToken) : s, [u, d] = await Promise.all([y(l, {
669
755
  country: i,
670
756
  language: a,
671
757
  productIds: o,
@@ -677,36 +763,75 @@ var g = /* @__PURE__ */ function(e) {
677
763
  if (!f) return null;
678
764
  let m = U(d, f), h = n ? m.filter((e) => e.id === n || e.nanoId === n) : m, g = (r ? h.find((e) => e.abTestVariantId === r) : void 0) ?? h[0] ?? m[0];
679
765
  if (!g) return null;
680
- let _ = k(g), v = j(g), [b, x, S, C] = await Promise.all([
766
+ let _ = N(g, { includeMixAndMatchSwapProducts: !1 }), v = be(l, g, {
767
+ otherProductGIDs: _,
768
+ country: i,
769
+ language: a
770
+ }), [b, x, S] = await Promise.all([
681
771
  y(l, {
682
772
  country: i,
683
773
  language: a,
684
- productIds: v,
774
+ productIds: _,
685
775
  useExternalMetafieldNamespace: !0
686
776
  }),
687
- O(l, _, 300),
688
- fe(l, g, {
689
- country: i,
690
- language: a
691
- }),
692
- pe({
777
+ k(l, ee(g), 300),
778
+ ge({
693
779
  language: a,
694
780
  dealBlockId: g.id
695
781
  })
696
782
  ]);
697
783
  return {
698
- product: f,
699
- dealBlock: g,
700
- config: c,
701
- otherProducts: b,
702
- mediaImages: x,
703
- collectionBreaksProducts: S ?? [],
704
- translations: C
784
+ data: {
785
+ config: c,
786
+ dealBlock: g,
787
+ product: f,
788
+ otherProducts: b,
789
+ mediaImages: x,
790
+ translations: S
791
+ },
792
+ modalProducts: v
705
793
  };
706
794
  } catch (e) {
707
795
  return console.error(e), null;
708
796
  }
709
- }, _e = class {
797
+ }, be = async (e, t, n) => {
798
+ let [r, i] = await Promise.all([xe(e, t, n), Ce(e, t, n)]);
799
+ return {
800
+ mixAndMatchSwapProducts: r,
801
+ collectionBreaksProducts: i
802
+ };
803
+ }, xe = async (e, t, { otherProductGIDs: n, country: r, language: i }) => {
804
+ try {
805
+ let a = [];
806
+ try {
807
+ a = await j(e, {
808
+ dealBlock: t,
809
+ country: r,
810
+ language: i
811
+ });
812
+ } catch (e) {
813
+ console.error(e);
814
+ }
815
+ let o = new Set(n), s = [.../* @__PURE__ */ new Set([...Se(t), ...a])].filter((e) => !o.has(e));
816
+ return s.length ? await y(e, {
817
+ country: r,
818
+ language: i,
819
+ productIds: s,
820
+ useExternalMetafieldNamespace: !0
821
+ }) : [];
822
+ } catch (e) {
823
+ return console.error(e), [];
824
+ }
825
+ }, Se = (e) => e.dealBars.flatMap((e) => e.dealBarType === W.MixAndMatch ? e.bundleProducts.flatMap((e) => (e.selectedProducts ?? []).map((e) => e.id)) : []), Ce = async (e, t, { country: n, language: r }) => {
826
+ try {
827
+ return await he(e, t, {
828
+ country: n,
829
+ language: r
830
+ }) ?? [];
831
+ } catch (e) {
832
+ return console.error(e), [];
833
+ }
834
+ }, we = class {
710
835
  constructor(e) {
711
836
  this.storefront = e, this.shopifyDomain = "";
712
837
  }
@@ -719,7 +844,7 @@ var g = /* @__PURE__ */ function(e) {
719
844
  }
720
845
  if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
721
846
  if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
722
- let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${he}/graphql.json`, {
847
+ let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${ve}/graphql.json`, {
723
848
  body: JSON.stringify({
724
849
  query: e,
725
850
  variables: t?.variables
@@ -749,64 +874,66 @@ var g = /* @__PURE__ */ function(e) {
749
874
  get i18n() {
750
875
  if ("i18n" in this.storefront) return this.storefront.i18n;
751
876
  }
752
- }, ve = ge, G = "kaching-bundles-block", K = 1e4, q = "/kaching-bundles-block.js", ye = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", be = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", J = /* @__PURE__ */ new WeakSet(), xe = async (e) => {
877
+ }, Te = async (e, t) => {
878
+ try {
879
+ let n = await ye(e, t);
880
+ if (!n) return null;
881
+ let { config: r, dealBlock: i, product: a, otherProducts: o, mediaImages: s, translations: c } = n.data, { mixAndMatchSwapProducts: l, collectionBreaksProducts: u } = await n.modalProducts;
882
+ return {
883
+ config: r,
884
+ dealBlock: i,
885
+ product: a,
886
+ otherProducts: o,
887
+ mixAndMatchSwapProducts: l,
888
+ mediaImages: s,
889
+ collectionBreaksProducts: u,
890
+ translations: c
891
+ };
892
+ } catch (e) {
893
+ return console.error(e), null;
894
+ }
895
+ }, K = "kaching-bundles-block", q = 1e4, J = "/kaching-bundles-block.js", Ee = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", De = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", Y = /* @__PURE__ */ new WeakSet(), Oe = async (e) => {
753
896
  let t = e.document;
754
- if (!e.customElements.get(G)) {
755
- if (J.has(t)) return X(e, G);
756
- J.add(t);
897
+ if (!e.customElements.get(K)) {
898
+ if (Y.has(t)) return Z(e, K);
899
+ Y.add(t);
757
900
  try {
758
- await we(e);
901
+ await je(e);
759
902
  } catch (e) {
760
- throw J.delete(t), e;
903
+ throw Y.delete(t), e;
761
904
  }
762
905
  }
763
- }, Se = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Ce = () => Se() ? ye : be, we = async (e) => {
764
- let t = e.document, n = Ce();
765
- if (t.querySelector(`script[src="${n}"]`)) return X(e, G);
766
- let r = Te(t);
767
- if (r && await De(t, r)) return X(e, G);
906
+ }, ke = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Ae = () => ke() ? Ee : De, je = async (e) => {
907
+ let t = e.document, n = Ae();
908
+ if (t.querySelector(`script[src="${n}"]`)) return Z(e, K);
909
+ let r = Me(t);
910
+ if (r && await Pe(t, r)) return Z(e, K);
768
911
  let i = t.createElement("script");
769
- return i.src = n, await Y(t, i), X(e, G);
770
- }, Te = (e) => {
771
- let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);
772
- return Array.from(t, (e) => e.href).find(Ee);
773
- }, Ee = (e) => {
912
+ return i.src = n, await X(t, i), Z(e, K);
913
+ }, Me = (e) => {
914
+ let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${J}"]`);
915
+ return Array.from(t, (e) => e.href).find(Ne);
916
+ }, Ne = (e) => {
774
917
  try {
775
- return new URL(e).pathname.endsWith(q);
918
+ return new URL(e).pathname.endsWith(J);
776
919
  } catch {
777
920
  return !1;
778
921
  }
779
- }, De = async (e, t) => {
922
+ }, Pe = async (e, t) => {
780
923
  let n = e.createElement("script");
781
924
  n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
782
925
  try {
783
- return await Y(e, n), !0;
926
+ return await X(e, n), !0;
784
927
  } catch {
785
928
  return n.remove(), !1;
786
929
  }
787
- }, Y = (e, t) => new Promise((n, r) => {
930
+ }, X = (e, t) => new Promise((n, r) => {
788
931
  t.onload = () => n(), t.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), e.head.appendChild(t);
789
- }), X = (e, t) => new Promise((n, r) => {
790
- 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 ${K}ms`)), K))]).then(() => n()).catch(r);
791
- });
792
- [
793
- "primaryBackground",
794
- "secondaryBackground",
795
- "primaryText",
796
- "secondaryText",
797
- "border",
798
- "overlay",
799
- "primaryAccent",
800
- "primaryAccentText",
801
- "badgeBackground",
802
- "badgeText",
803
- "error"
804
- ].map((e) => `brand_${e}`);
805
- var Z = /* @__PURE__ */ function(e) {
806
- return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
807
- }({}), Q = "a-f\\d", Oe = `#?[${Q}]{3}[${Q}]?`, ke = `#?[${Q}]{6}([${Q}]{2})?`, Ae = RegExp(`[^#${Q}]`, "gi"), $ = RegExp(`^${Oe}$|^${ke}$`, "i");
808
- function je(e, t = {}) {
809
- if (typeof e != "string" || Ae.test(e) || !$.test(e)) throw TypeError("Expected a valid hex string");
932
+ }), Z = (e, t) => new Promise((n, r) => {
933
+ 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);
934
+ }), Q = "a-f\\d", $ = `#?[${Q}]{3}[${Q}]?`, Fe = `#?[${Q}]{6}([${Q}]{2})?`, Ie = RegExp(`[^#${Q}]`, "gi"), Le = RegExp(`^${$}$|^${Fe}$`, "i");
935
+ function Re(e, t = {}) {
936
+ if (typeof e != "string" || Ie.test(e) || !Le.test(e)) throw TypeError("Expected a valid hex string");
810
937
  e = e.replace(/^#/, "");
811
938
  let n = 1;
812
939
  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]);
@@ -824,7 +951,7 @@ function je(e, t = {}) {
824
951
  };
825
952
  }
826
953
  // src/react/preview.ts
827
- var Me = ({ price: e }) => ({
954
+ var ze = ({ price: e }) => ({
828
955
  id: 123,
829
956
  handle: "123",
830
957
  url: null,
@@ -857,7 +984,7 @@ var Me = ({ price: e }) => ({
857
984
  text4: null
858
985
  },
859
986
  isNativeBundle: !1
860
- }), Ne = () => ({
987
+ }), Be = () => ({
861
988
  shopifyDomain: "",
862
989
  moneyFormat: "${{amount_with_comma_separator}}",
863
990
  locale: "en",
@@ -913,7 +1040,7 @@ var Me = ({ price: e }) => ({
913
1040
  },
914
1041
  shopCustomStyles: "",
915
1042
  featureFlags: {}
916
- }), Pe = ({ color: e, cornerRadius: t }) => {
1043
+ }), Ve = ({ color: e, cornerRadius: t }) => {
917
1044
  let n = {
918
1045
  id: "123",
919
1046
  nanoId: "123",
@@ -963,7 +1090,7 @@ var Me = ({ price: e }) => ({
963
1090
  lowStockAlert: null,
964
1091
  dealBars: [{
965
1092
  id: "PfFU",
966
- dealBarType: Z.QuantityBreak,
1093
+ dealBarType: W.QuantityBreak,
967
1094
  title: "1 pack",
968
1095
  subtitle: "Standard price",
969
1096
  label: "",
@@ -982,7 +1109,7 @@ var Me = ({ price: e }) => ({
982
1109
  productPersonalisation: null
983
1110
  }, {
984
1111
  id: "1f-9",
985
- dealBarType: Z.QuantityBreak,
1112
+ dealBarType: W.QuantityBreak,
986
1113
  title: "2 pack",
987
1114
  subtitle: "You save {{saved_percentage}}",
988
1115
  label: "SAVE {{saved_total}}",
@@ -1173,14 +1300,14 @@ var Me = ({ price: e }) => ({
1173
1300
  imageCornerRadius: 6
1174
1301
  };
1175
1302
  return e !== void 0 && (n.colors.border = {
1176
- ...je(e),
1303
+ ...Re(e),
1177
1304
  alpha: 1
1178
1305
  }), n;
1179
- }, Fe = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1306
+ }, He = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1180
1307
  let l = n(null), [u, d] = r(!1), f = n(!1);
1181
1308
  e(() => {
1182
1309
  l.current && !u && (async () => {
1183
- await xe(c ?? window), d(!0);
1310
+ await Oe(c ?? window), d(!0);
1184
1311
  })();
1185
1312
  }, [u, c]), e(() => {
1186
1313
  let e = l.current;
@@ -1201,8 +1328,8 @@ var Me = ({ price: e }) => ({
1201
1328
  e.removeEventListener("kaching-bundles-block-loaded", t), e.removeEventListener("variants-changed", t);
1202
1329
  };
1203
1330
  }, [u, s]);
1204
- let p = t ? Le(t, a) : o ? Re(o) : null;
1205
- return Ie(() => {
1331
+ let p = t ? We(t, a) : o ? Ge(o) : null;
1332
+ return Ue(() => {
1206
1333
  let e = l.current;
1207
1334
  if (e && p) for (let [t, n] of Object.entries(p.jsonAttributes)) e.getAttribute(t) !== n && e.setAttribute(t, n);
1208
1335
  }), p ? /* @__PURE__ */ i("kaching-bundles-block", {
@@ -1211,20 +1338,21 @@ var Me = ({ price: e }) => ({
1211
1338
  ...p.jsonAttributes,
1212
1339
  "current-variant-id": p.currentVariantId
1213
1340
  }) : null;
1214
- }, Ie = typeof window > "u" ? e : t, Le = ({ config: e, dealBlock: t, product: n, otherProducts: r, mediaImages: i, collectionBreaksProducts: a, translations: o }, s) => ({
1341
+ }, Ue = typeof window > "u" ? e : t, We = ({ config: e, dealBlock: t, product: n, otherProducts: r, mixAndMatchSwapProducts: i, mediaImages: a, collectionBreaksProducts: o, translations: s }, c) => ({
1215
1342
  dealBlockId: t.id,
1216
- currentVariantId: s ? s.split("/").pop() : String(n.variants[0].id),
1343
+ currentVariantId: c ? c.split("/").pop() : String(n.variants[0].id),
1217
1344
  jsonAttributes: {
1218
1345
  config: JSON.stringify(e),
1219
1346
  "deal-block": JSON.stringify(t),
1220
- "media-images": JSON.stringify(i),
1347
+ "media-images": JSON.stringify(a),
1221
1348
  product: JSON.stringify(n),
1222
1349
  "other-products": JSON.stringify(r),
1223
- "collection-breaks-products": JSON.stringify(a),
1224
- translations: JSON.stringify(o)
1350
+ "mix-and-match-swap-products": JSON.stringify(i ?? []),
1351
+ "collection-breaks-products": JSON.stringify(o),
1352
+ translations: JSON.stringify(s)
1225
1353
  }
1226
- }), Re = ({ cornerRadius: e, color: t, price: n }) => {
1227
- let r = Me({ price: n }), i = Ne(), a = Pe({
1354
+ }), Ge = ({ cornerRadius: e, color: t, price: n }) => {
1355
+ let r = ze({ price: n }), i = Be(), a = Ve({
1228
1356
  color: t,
1229
1357
  cornerRadius: e
1230
1358
  });
@@ -1237,9 +1365,10 @@ var Me = ({ price: e }) => ({
1237
1365
  "media-images": JSON.stringify([]),
1238
1366
  product: JSON.stringify(r),
1239
1367
  "other-products": JSON.stringify([]),
1368
+ "mix-and-match-swap-products": JSON.stringify([]),
1240
1369
  "collection-breaks-products": JSON.stringify([]),
1241
1370
  translations: JSON.stringify({})
1242
1371
  }
1243
1372
  };
1244
1373
  };
1245
- export { Fe as KachingBundle, ve as fetchKachingBundlesData };
1374
+ export { He as KachingBundle, Te as fetchKachingBundlesData };