@kachingappz/bundles-js 1.1.8 → 1.1.9

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,7 @@ 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
+ }, he = async (e, t, { country: n, language: r }) => {
588
658
  let i = t.collectionBreaks;
589
659
  if (!t.collectionBreaksEnabled || !i) return;
590
660
  let a;
@@ -610,7 +680,7 @@ var g = /* @__PURE__ */ function(e) {
610
680
  useExternalMetafieldNamespace: !0
611
681
  }), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
612
682
  return o = o.filter((e) => e.availableForSale && (!s || U([t], e).length > 0)), o;
613
- }, pe = ({ language: e, dealBlockId: t }) => {
683
+ }, ge = ({ language: e, dealBlockId: t }) => {
614
684
  let n = {
615
685
  "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
616
686
  "system.invalid_variant": "Sorry, this is not currently available.",
@@ -637,13 +707,13 @@ var g = /* @__PURE__ */ function(e) {
637
707
  "system.numbers_only": "Only numbers are allowed.",
638
708
  "system.personalisation_required_alert": "Please add personalisation for every item to continue.",
639
709
  "system.gifts_required_alert": "Please choose your free gifts"
640
- }, r = e ? me(e) : void 0;
710
+ }, r = e ? _e(e) : void 0;
641
711
  return {
642
712
  ...n,
643
713
  ...r?.system,
644
714
  ...r?.dealBlocks[t]
645
715
  };
646
- }, me = (e) => {
716
+ }, _e = (e) => {
647
717
  if (typeof document > "u") return;
648
718
  let t = document.querySelector("script#kaching-bundles-translations");
649
719
  if (!t?.textContent) return;
@@ -655,17 +725,17 @@ var g = /* @__PURE__ */ function(e) {
655
725
  }
656
726
  let r = W(e);
657
727
  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 }) => {
728
+ }, W = (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
729
  try {
660
- let o = [Number(t.split("/").pop())], s = new _e(e);
730
+ let o = [Number(t.split("/").pop())], s = new be(e);
661
731
  i ||= s.i18n?.country, a ||= s.i18n?.language;
662
- let c = await E(s, {
732
+ let c = await D(s, {
663
733
  language: a,
664
734
  country: i,
665
735
  useExternalMetafieldNamespace: !0
666
736
  });
667
737
  s.shopifyDomain = c.shopifyDomain;
668
- let l = c.storefrontAccessToken ? new H(c.shopifyDomain, c.storefrontAccessToken) : s, [u, d] = await Promise.all([y(l, {
738
+ let l = c.storefrontAccessToken ? new me(c.shopifyDomain, c.storefrontAccessToken) : s, [u, d] = await Promise.all([y(l, {
669
739
  country: i,
670
740
  language: a,
671
741
  productIds: o,
@@ -677,19 +747,31 @@ var g = /* @__PURE__ */ function(e) {
677
747
  if (!f) return null;
678
748
  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
749
  if (!g) return null;
680
- let _ = k(g), v = j(g), [b, x, S, C] = await Promise.all([
681
- y(l, {
682
- country: i,
683
- language: a,
684
- productIds: v,
685
- useExternalMetafieldNamespace: !0
686
- }),
687
- O(l, _, 300),
688
- fe(l, g, {
750
+ let _ = ee(g), [v, b, x, S] = await Promise.all([
751
+ (async () => {
752
+ let e = [];
753
+ try {
754
+ e = await j(l, {
755
+ dealBlock: g,
756
+ country: i,
757
+ language: a
758
+ });
759
+ } catch (e) {
760
+ console.error(e);
761
+ }
762
+ return y(l, {
763
+ country: i,
764
+ language: a,
765
+ productIds: [.../* @__PURE__ */ new Set([...N(g), ...e])],
766
+ useExternalMetafieldNamespace: !0
767
+ });
768
+ })(),
769
+ k(l, _, 300),
770
+ he(l, g, {
689
771
  country: i,
690
772
  language: a
691
773
  }),
692
- pe({
774
+ ge({
693
775
  language: a,
694
776
  dealBlockId: g.id
695
777
  })
@@ -698,15 +780,15 @@ var g = /* @__PURE__ */ function(e) {
698
780
  product: f,
699
781
  dealBlock: g,
700
782
  config: c,
701
- otherProducts: b,
702
- mediaImages: x,
703
- collectionBreaksProducts: S ?? [],
704
- translations: C
783
+ otherProducts: v,
784
+ mediaImages: b,
785
+ collectionBreaksProducts: x ?? [],
786
+ translations: S
705
787
  };
706
788
  } catch (e) {
707
789
  return console.error(e), null;
708
790
  }
709
- }, _e = class {
791
+ }, be = class {
710
792
  constructor(e) {
711
793
  this.storefront = e, this.shopifyDomain = "";
712
794
  }
@@ -719,7 +801,7 @@ var g = /* @__PURE__ */ function(e) {
719
801
  }
720
802
  if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
721
803
  if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
722
- let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${he}/graphql.json`, {
804
+ let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${ve}/graphql.json`, {
723
805
  body: JSON.stringify({
724
806
  query: e,
725
807
  variables: t?.variables
@@ -749,34 +831,34 @@ var g = /* @__PURE__ */ function(e) {
749
831
  get i18n() {
750
832
  if ("i18n" in this.storefront) return this.storefront.i18n;
751
833
  }
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) => {
834
+ }, xe = ye, G = "kaching-bundles-block", K = 1e4, q = "/kaching-bundles-block.js", Se = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", Ce = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", J = /* @__PURE__ */ new WeakSet(), we = async (e) => {
753
835
  let t = e.document;
754
836
  if (!e.customElements.get(G)) {
755
837
  if (J.has(t)) return X(e, G);
756
838
  J.add(t);
757
839
  try {
758
- await we(e);
840
+ await De(e);
759
841
  } catch (e) {
760
842
  throw J.delete(t), e;
761
843
  }
762
844
  }
763
- }, Se = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Ce = () => Se() ? ye : be, we = async (e) => {
764
- let t = e.document, n = Ce();
845
+ }, Te = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Ee = () => Te() ? Se : Ce, De = async (e) => {
846
+ let t = e.document, n = Ee();
765
847
  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);
848
+ let r = Oe(t);
849
+ if (r && await Ae(t, r)) return X(e, G);
768
850
  let i = t.createElement("script");
769
851
  return i.src = n, await Y(t, i), X(e, G);
770
- }, Te = (e) => {
852
+ }, Oe = (e) => {
771
853
  let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);
772
- return Array.from(t, (e) => e.href).find(Ee);
773
- }, Ee = (e) => {
854
+ return Array.from(t, (e) => e.href).find(ke);
855
+ }, ke = (e) => {
774
856
  try {
775
857
  return new URL(e).pathname.endsWith(q);
776
858
  } catch {
777
859
  return !1;
778
860
  }
779
- }, De = async (e, t) => {
861
+ }, Ae = async (e, t) => {
780
862
  let n = e.createElement("script");
781
863
  n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
782
864
  try {
@@ -804,9 +886,9 @@ var g = /* @__PURE__ */ function(e) {
804
886
  ].map((e) => `brand_${e}`);
805
887
  var Z = /* @__PURE__ */ function(e) {
806
888
  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");
889
+ }({}), Q = "a-f\\d", je = `#?[${Q}]{3}[${Q}]?`, Me = `#?[${Q}]{6}([${Q}]{2})?`, Ne = RegExp(`[^#${Q}]`, "gi"), Pe = RegExp(`^${je}$|^${Me}$`, "i");
890
+ function $(e, t = {}) {
891
+ if (typeof e != "string" || Ne.test(e) || !Pe.test(e)) throw TypeError("Expected a valid hex string");
810
892
  e = e.replace(/^#/, "");
811
893
  let n = 1;
812
894
  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 +906,7 @@ function je(e, t = {}) {
824
906
  };
825
907
  }
826
908
  // src/react/preview.ts
827
- var Me = ({ price: e }) => ({
909
+ var Fe = ({ price: e }) => ({
828
910
  id: 123,
829
911
  handle: "123",
830
912
  url: null,
@@ -857,7 +939,7 @@ var Me = ({ price: e }) => ({
857
939
  text4: null
858
940
  },
859
941
  isNativeBundle: !1
860
- }), Ne = () => ({
942
+ }), Ie = () => ({
861
943
  shopifyDomain: "",
862
944
  moneyFormat: "${{amount_with_comma_separator}}",
863
945
  locale: "en",
@@ -913,7 +995,7 @@ var Me = ({ price: e }) => ({
913
995
  },
914
996
  shopCustomStyles: "",
915
997
  featureFlags: {}
916
- }), Pe = ({ color: e, cornerRadius: t }) => {
998
+ }), Le = ({ color: e, cornerRadius: t }) => {
917
999
  let n = {
918
1000
  id: "123",
919
1001
  nanoId: "123",
@@ -1173,14 +1255,14 @@ var Me = ({ price: e }) => ({
1173
1255
  imageCornerRadius: 6
1174
1256
  };
1175
1257
  return e !== void 0 && (n.colors.border = {
1176
- ...je(e),
1258
+ ...$(e),
1177
1259
  alpha: 1
1178
1260
  }), n;
1179
- }, Fe = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1261
+ }, Re = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1180
1262
  let l = n(null), [u, d] = r(!1), f = n(!1);
1181
1263
  e(() => {
1182
1264
  l.current && !u && (async () => {
1183
- await xe(c ?? window), d(!0);
1265
+ await we(c ?? window), d(!0);
1184
1266
  })();
1185
1267
  }, [u, c]), e(() => {
1186
1268
  let e = l.current;
@@ -1201,8 +1283,8 @@ var Me = ({ price: e }) => ({
1201
1283
  e.removeEventListener("kaching-bundles-block-loaded", t), e.removeEventListener("variants-changed", t);
1202
1284
  };
1203
1285
  }, [u, s]);
1204
- let p = t ? Le(t, a) : o ? Re(o) : null;
1205
- return Ie(() => {
1286
+ let p = t ? Be(t, a) : o ? Ve(o) : null;
1287
+ return ze(() => {
1206
1288
  let e = l.current;
1207
1289
  if (e && p) for (let [t, n] of Object.entries(p.jsonAttributes)) e.getAttribute(t) !== n && e.setAttribute(t, n);
1208
1290
  }), p ? /* @__PURE__ */ i("kaching-bundles-block", {
@@ -1211,7 +1293,7 @@ var Me = ({ price: e }) => ({
1211
1293
  ...p.jsonAttributes,
1212
1294
  "current-variant-id": p.currentVariantId
1213
1295
  }) : null;
1214
- }, Ie = typeof window > "u" ? e : t, Le = ({ config: e, dealBlock: t, product: n, otherProducts: r, mediaImages: i, collectionBreaksProducts: a, translations: o }, s) => ({
1296
+ }, ze = typeof window > "u" ? e : t, Be = ({ config: e, dealBlock: t, product: n, otherProducts: r, mediaImages: i, collectionBreaksProducts: a, translations: o }, s) => ({
1215
1297
  dealBlockId: t.id,
1216
1298
  currentVariantId: s ? s.split("/").pop() : String(n.variants[0].id),
1217
1299
  jsonAttributes: {
@@ -1223,8 +1305,8 @@ var Me = ({ price: e }) => ({
1223
1305
  "collection-breaks-products": JSON.stringify(a),
1224
1306
  translations: JSON.stringify(o)
1225
1307
  }
1226
- }), Re = ({ cornerRadius: e, color: t, price: n }) => {
1227
- let r = Me({ price: n }), i = Ne(), a = Pe({
1308
+ }), Ve = ({ cornerRadius: e, color: t, price: n }) => {
1309
+ let r = Fe({ price: n }), i = Ie(), a = Le({
1228
1310
  color: t,
1229
1311
  cornerRadius: e
1230
1312
  });
@@ -1242,4 +1324,4 @@ var Me = ({ price: e }) => ({
1242
1324
  }
1243
1325
  };
1244
1326
  };
1245
- export { Fe as KachingBundle, ve as fetchKachingBundlesData };
1327
+ export { Re as KachingBundle, xe as fetchKachingBundlesData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kachingappz/bundles-js",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/kachingappz/bundles.git",
@@ -50,8 +50,8 @@
50
50
  "README.md"
51
51
  ],
52
52
  "devDependencies": {
53
- "@kachingappz/bundles-storefront-api": "^0.1.0",
54
- "@kachingappz/bundles-types": "^0.4.8",
53
+ "@kachingappz/bundles-storefront-api": "^0.1.3",
54
+ "@kachingappz/bundles-types": "^0.4.11",
55
55
  "@kachingappz/kaching-bundles-block": "^1.0.0",
56
56
  "@microsoft/api-extractor": "^7.57.7",
57
57
  "@testing-library/react": "^16.3.3",