@kachingappz/bundles-js 1.1.3 → 1.1.5

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.
@@ -33,7 +33,23 @@ var a = (e, { language: t, country: n }) => {
33
33
  i = t.metaobjects.pageInfo.endCursor;
34
34
  }
35
35
  return r;
36
- }, g = async (e, { country: t, language: n, blockVisibility: r, excludedProductGIDs: i, selectedProductGIDs: a, selectedCollectionGIDs: o, limit: s = 1e3 }) => {
36
+ };
37
+ [
38
+ "primaryBackground",
39
+ "secondaryBackground",
40
+ "primaryText",
41
+ "secondaryText",
42
+ "border",
43
+ "overlay",
44
+ "primaryAccent",
45
+ "primaryAccentText",
46
+ "badgeBackground",
47
+ "badgeText",
48
+ "error"
49
+ ].map((e) => `brand_${e}`);
50
+ var g = /* @__PURE__ */ function(e) {
51
+ return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
52
+ }({}), _ = async (e, { country: t, language: n, blockVisibility: r, excludedProductGIDs: i, selectedProductGIDs: a, selectedCollectionGIDs: o, limit: s = 1e3 }) => {
37
53
  switch (r) {
38
54
  case "selected-products": return a.slice(0, s);
39
55
  case "all-products":
@@ -91,16 +107,16 @@ var a = (e, { language: t, country: n }) => {
91
107
  return Array.from(new Set(i)).slice(0, s);
92
108
  }
93
109
  }
94
- }, _ = "\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", v = async (e, { country: t, language: n, productIds: r, includeSellingPlans: i = !0, includeAvailableQuantity: a = !0, includeProductRating: o = !1, useExternalMetafieldNamespace: s = !1, batchSize: c = 250, onBatchError: l, variantImageTransform: u = {
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 = {
95
111
  maxWidth: 200,
96
112
  maxHeight: 200
97
113
  } }) => {
98
114
  if (!r.length) return [];
99
- let d = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), p = f({
115
+ let m = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), h = f({
100
116
  country: t,
101
117
  language: n
102
- }), m = `
103
- query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${p} {
118
+ }), g = `
119
+ query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${h} {
104
120
  shop {
105
121
  currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
106
122
  value
@@ -134,7 +150,7 @@ var a = (e, { language: t, country: n }) => {
134
150
  }
135
151
  variants(first: 250) {
136
152
  nodes {
137
- ${_}
153
+ ${v}
138
154
  }
139
155
  }
140
156
  collections(first: 50) {
@@ -160,6 +176,9 @@ var a = (e, { language: t, country: n }) => {
160
176
  reviewsRatingCount: metafield(namespace: "reviews", key: "rating_count") @include(if: $includeProductRating) {
161
177
  value
162
178
  }
179
+ subtitle: metafield(namespace: $subtitleNamespace, key: $subtitleKey) @include(if: $includeProductSubtitle) {
180
+ value
181
+ }
163
182
  requiresSellingPlan
164
183
  sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
165
184
  nodes {
@@ -192,40 +211,43 @@ var a = (e, { language: t, country: n }) => {
192
211
  }
193
212
  }
194
213
  }
195
- `, h = s ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", g = [], v = Math.min(c, 250);
196
- for (let e = 0; e < d.length; e += v) g.push(d.slice(e, e + v));
197
- let x = 1, S = async (t) => {
198
- let n = await e.query(m, { variables: {
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: {
199
218
  productGIDs: t,
200
219
  includeSellingPlans: i,
201
220
  includeAvailableQuantity: a,
202
221
  includeProductRating: o,
203
- metafieldNamespace: h,
204
- variantImageTransform: u
222
+ includeProductSubtitle: s,
223
+ subtitleNamespace: S,
224
+ subtitleKey: C,
225
+ metafieldNamespace: _,
226
+ variantImageTransform: p
205
227
  } });
206
- return n.shop.currencyRateConstant && (x = JSON.parse(n.shop.currencyRateConstant.value).amount / 1e6), n;
207
- }, C;
208
- if (l) {
209
- let e = await Promise.allSettled(g.map(S));
210
- for (let t of e) t.status === "rejected" && l(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
211
- C = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
212
- } else C = (await Promise.all(g.map(S))).flatMap((e) => e.nodes);
213
- let w = C.filter((e) => e != null);
214
- if (l) {
215
- let t = await Promise.allSettled(w.map(async (t) => b(await y(e, t, {
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, {
216
238
  includeSellingPlans: i,
217
239
  includeAvailableQuantity: a,
218
- variantImageTransform: u
219
- }, p), e.shopifyDomain, x))), n = [];
220
- for (let e of t) e.status === "fulfilled" ? n.push(e.value) : l(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
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)));
221
243
  return n;
222
244
  }
223
- return (await Promise.all(w.map((t) => y(e, t, {
245
+ return (await Promise.all(k.map((t) => b(e, t, {
224
246
  includeSellingPlans: i,
225
247
  includeAvailableQuantity: a,
226
- variantImageTransform: u
227
- }, p)))).map((t) => b(t, e.shopifyDomain, x));
228
- }, y = async (e, t, n, r = "") => {
248
+ variantImageTransform: p
249
+ }, h)))).map((t) => x(t, e.shopifyDomain, E));
250
+ }, b = async (e, t, n, r = "") => {
229
251
  if (t.variants.nodes.length < 250) return t;
230
252
  let i = /* @__PURE__ */ new Set(), a = [], o = [], s = async (s) => {
231
253
  let c = !0, l = null;
@@ -235,7 +257,7 @@ var a = (e, { language: t, country: n }) => {
235
257
  product(id: $productGID) {
236
258
  variants(first: 250, after: $cursor, reverse: $reverse) {
237
259
  nodes {
238
- ${_}
260
+ ${v}
239
261
  }
240
262
  pageInfo {
241
263
  endCursor
@@ -261,7 +283,7 @@ var a = (e, { language: t, country: n }) => {
261
283
  }
262
284
  };
263
285
  return await Promise.all([s(!1), s(!0)]), t.variants.nodes = [...a, ...o.reverse()], t;
264
- }, b = (e, t, n) => {
286
+ }, x = (e, t, n) => {
265
287
  let r = e.variants.nodes.map(({ unitPriceMeasurement: e, ...t }) => ({
266
288
  id: Number(t.id.split("/").pop()),
267
289
  availableForSale: t.availableForSale,
@@ -299,7 +321,7 @@ var a = (e, { language: t, country: n }) => {
299
321
  defaultName: e.name,
300
322
  name: e.name,
301
323
  position: t + 1,
302
- optionValues: C(n, t, r)
324
+ optionValues: w(n, t, r)
303
325
  };
304
326
  }), a = (e) => {
305
327
  let t = e.priceAdjustments[0];
@@ -346,26 +368,27 @@ var a = (e, { language: t, country: n }) => {
346
368
  text3: e.metafield3?.value || null,
347
369
  text4: e.metafield4?.value || null
348
370
  },
349
- rating: x(e.reviewsRating, e.reviewsRatingCount)
371
+ rating: S(e.reviewsRating, e.reviewsRatingCount),
372
+ subtitle: e.subtitle?.value || null
350
373
  };
351
- }, x = (e, t) => {
374
+ }, S = (e, t) => {
352
375
  if (!e) return null;
353
- let n = S(e.value);
376
+ let n = C(e.value);
354
377
  if (n === null) return null;
355
378
  let r = Number(t?.value);
356
379
  return {
357
380
  value: n,
358
381
  count: Number.isInteger(r) && r > 0 ? r : null
359
382
  };
360
- }, S = (e) => {
383
+ }, C = (e) => {
361
384
  try {
362
385
  let { value: t, scale_max: n } = JSON.parse(e), r = Number(t) / Number(n) * 5;
363
386
  return Number.isFinite(r) && r > 0 ? Math.min(5, r) : null;
364
387
  } catch {
365
388
  return null;
366
389
  }
367
- }, C = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0), w = "app--2935586817", ee = async (e, { language: t, country: n, useExternalMetafieldNamespace: r }) => {
368
- let i = r ? `${w}--kaching_bundles` : "$app:kaching_bundles", o = r ? w : "$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(`
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(`
369
392
  query config($metafieldNamespace: String!, $settingsNamespace: String!) ${s} {
370
393
  localization {
371
394
  country {
@@ -396,7 +419,7 @@ var a = (e, { language: t, country: n }) => {
396
419
  } }), h = c === u ? l : a(c, {
397
420
  language: t,
398
421
  country: n
399
- }), g = d ? T(d.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
422
+ }), g = d ? D(d.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
400
423
  return {
401
424
  shopifyDomain: p.host,
402
425
  moneyFormat: h,
@@ -457,7 +480,7 @@ var a = (e, { language: t, country: n }) => {
457
480
  featureFlags: v,
458
481
  brandColors: _?.brand_colors ?? null
459
482
  };
460
- }, T = (e) => JSON.parse(e).amount / 1e6, te = async (e, t, n = 200) => {
483
+ }, D = (e) => JSON.parse(e).amount / 1e6, O = async (e, t, n = 200) => {
461
484
  let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
462
485
  if (r.length === 0) return [];
463
486
  let i = [];
@@ -469,93 +492,77 @@ var a = (e, { language: t, country: n }) => {
469
492
  gid: e.id,
470
493
  url: e.image.url
471
494
  }] : []);
472
- };
473
- [
474
- "primaryBackground",
475
- "secondaryBackground",
476
- "primaryText",
477
- "secondaryText",
478
- "border",
479
- "overlay",
480
- "primaryAccent",
481
- "primaryAccentText",
482
- "badgeBackground",
483
- "badgeText",
484
- "error"
485
- ].map((e) => `brand_${e}`);
486
- var E = /* @__PURE__ */ function(e) {
487
- return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
488
- }({}), ne = (e) => [
495
+ }, k = (e) => [
496
+ ...A(e),
497
+ ...ee(e),
498
+ ...te(e),
499
+ ...ne(e),
489
500
  ...re(e),
490
501
  ...ie(e),
491
502
  ...ae(e),
492
503
  ...oe(e),
493
504
  ...se(e),
494
505
  ...ce(e),
495
- ...D(e),
496
- ...O(e),
497
- ...k(e),
498
- ...A(e),
499
- ...j(e),
500
- ...M(e),
501
- ...N(e)
502
- ].filter((e) => e != null && !e.includes("placeholder")), re = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ie = (e) => e.dealBars.flatMap((e) => e.dealBarType === E.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), ae = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), oe = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), se = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ce = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
506
+ ...le(e),
507
+ ...ue(e),
508
+ ...j(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) => {
503
510
  let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
504
511
  return [...e, ...n];
505
- }, []) : [], D = (e) => {
512
+ }, []) : [], ae = (e) => {
506
513
  if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
507
514
  let t = e.collectionBreaks.mediaImageGID;
508
515
  return t ? [t] : [];
509
- }, O = (e) => e.progressiveGifts ? [
516
+ }, oe = (e) => e.progressiveGifts ? [
510
517
  ...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
511
518
  e.progressiveGifts.style?.lockedMediaImageGID,
512
519
  e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
513
- ].filter((e) => e != null) : [], k = (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) => {
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) => {
514
521
  let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
515
522
  return n ? [...t, n] : t;
516
- }, M = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), N = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], P = (e) => {
523
+ }, ue = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), j = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], M = (e) => {
517
524
  let t = [
525
+ ...N(e),
526
+ ...P(e),
518
527
  ...F(e),
519
528
  ...I(e),
520
529
  ...L(e),
521
530
  ...R(e),
522
531
  ...z(e),
523
- ...B(e),
524
- ...V(e),
525
- ...H(e)
532
+ ...B(e)
526
533
  ];
527
534
  return Array.from(new Set(t.filter((e) => e != null)));
528
- }, F = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), I = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), L = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], R = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), z = (e) => e.dealBars.filter((e) => e.dealBarType === E.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), B = (e) => e.dealBars.filter((e) => e.dealBarType === E.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...e.selectedProducts?.map((e) => e.id) ?? []]) : []).filter((e) => e != null).filter((e) => e !== "default"), V = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), H = (e) => e.dealBars.filter((e) => e.dealBarType === E.Sku).flatMap(({ productGID: e }) => e ? [e] : []), U = class extends Error {
535
+ }, N = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), P = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), F = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], I = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), L = (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"), R = (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"), z = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), B = (e) => e.dealBars.filter((e) => e.dealBarType === g.Sku).flatMap(({ productGID: e }) => e ? [e] : []), V = class extends Error {
529
536
  constructor({ status: e, operationName: t, graphqlErrors: n }) {
530
537
  let r = n.length ? `: ${n.join("; ")}` : "";
531
538
  super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
532
539
  }
533
- }, W = async (e, t) => {
540
+ }, H = async (e, t) => {
534
541
  let n = await e.text();
535
542
  if (!n) throw Error("Empty graphql response");
536
543
  let r;
537
544
  try {
538
545
  r = JSON.parse(n);
539
546
  } catch (n) {
540
- throw e.ok ? n : new U({
547
+ throw e.ok ? n : new V({
541
548
  status: e.status,
542
549
  operationName: t,
543
550
  graphqlErrors: []
544
551
  });
545
552
  }
546
- if (!e.ok || r.data === null || r.data === void 0) throw new U({
553
+ if (!e.ok || r.data === null || r.data === void 0) throw new V({
547
554
  status: e.status,
548
555
  operationName: t,
549
556
  graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
550
557
  });
551
558
  return r.data;
552
- }, G = class {
559
+ }, U = class {
553
560
  constructor(e, t) {
554
561
  this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
555
562
  }
556
563
  async query(e, t) {
557
564
  let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
558
- return i && (r += `?operation_name=${i}`), W(await fetch(r, {
565
+ return i && (r += `?operation_name=${i}`), H(await fetch(r, {
559
566
  method: "POST",
560
567
  headers: {
561
568
  "Content-Type": "application/json",
@@ -567,7 +574,7 @@ var E = /* @__PURE__ */ function(e) {
567
574
  })
568
575
  }), i);
569
576
  }
570
- }, le = (e, t) => {
577
+ }, de = (e, t) => {
571
578
  let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
572
579
  for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
573
580
  let i = e.filter((e) => e.blockVisibility === "selected-collections");
@@ -577,18 +584,18 @@ var E = /* @__PURE__ */ function(e) {
577
584
  let o = e.filter((e) => e.blockVisibility === "all-products");
578
585
  for (let e of o) n.push(e);
579
586
  return n;
580
- }, ue = async (e, t, { country: n, language: r }) => {
587
+ }, fe = async (e, t, { country: n, language: r }) => {
581
588
  let i = t.collectionBreaks;
582
589
  if (!t.collectionBreaksEnabled || !i) return;
583
590
  let a;
584
- a = i.visibility === "deal-products" ? await g(e, {
591
+ a = i.visibility === "deal-products" ? await _(e, {
585
592
  country: n,
586
593
  language: r,
587
594
  blockVisibility: t.blockVisibility,
588
595
  excludedProductGIDs: (t.excludedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
589
596
  selectedProductGIDs: (t.selectedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
590
597
  selectedCollectionGIDs: (t.selectedCollectionIds || []).map((e) => `gid://shopify/Collection/${e}`)
591
- }) : await g(e, {
598
+ }) : await _(e, {
592
599
  country: n,
593
600
  language: r,
594
601
  blockVisibility: i.visibility,
@@ -596,14 +603,14 @@ var E = /* @__PURE__ */ function(e) {
596
603
  selectedProductGIDs: (i.selectedProducts || []).map(({ id: e }) => e),
597
604
  selectedCollectionGIDs: (i.selectedCollections || []).map(({ id: e }) => e)
598
605
  });
599
- let o = await v(e, {
606
+ let o = await y(e, {
600
607
  country: n,
601
608
  language: r,
602
609
  productIds: a.map((e) => Number(e.split("/").pop())),
603
610
  useExternalMetafieldNamespace: !0
604
611
  });
605
612
  return o = o.filter((e) => e.availableForSale), o;
606
- }, de = ({ language: e, dealBlockId: t }) => {
613
+ }, pe = ({ language: e, dealBlockId: t }) => {
607
614
  let n = {
608
615
  "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
609
616
  "system.invalid_variant": "Sorry, this is not currently available.",
@@ -629,13 +636,13 @@ var E = /* @__PURE__ */ function(e) {
629
636
  "system.letters_only": "Only letters are allowed.",
630
637
  "system.numbers_only": "Only numbers are allowed.",
631
638
  "system.personalisation_required_alert": "Please add personalisation for every item to continue."
632
- }, r = e ? fe(e) : void 0;
639
+ }, r = e ? me(e) : void 0;
633
640
  return {
634
641
  ...n,
635
642
  ...r?.system,
636
643
  ...r?.dealBlocks[t]
637
644
  };
638
- }, fe = (e) => {
645
+ }, me = (e) => {
639
646
  if (typeof document > "u") return;
640
647
  let t = document.querySelector("script#kaching-bundles-translations");
641
648
  if (!t?.textContent) return;
@@ -645,19 +652,19 @@ var E = /* @__PURE__ */ function(e) {
645
652
  } catch {
646
653
  return;
647
654
  }
648
- let r = K(e);
649
- return n.find((e) => K(e.locale) === r)?.translations;
650
- }, K = (e) => e.toLowerCase().replace(/_/g, "-"), pe = "2026-07", me = async (e, { productId: t, dealBlockId: n, country: r = void 0, language: i = void 0 }) => {
655
+ let r = W(e);
656
+ return n.find((e) => W(e.locale) === r)?.translations;
657
+ }, W = (e) => e.toLowerCase().replace(/_/g, "-"), he = "2026-07", ge = async (e, { productId: t, dealBlockId: n, country: r = void 0, language: i = void 0 }) => {
651
658
  try {
652
- let a = [Number(t.split("/").pop())], o = new he(e);
659
+ let a = [Number(t.split("/").pop())], o = new _e(e);
653
660
  r ||= o.i18n?.country, i ||= o.i18n?.language;
654
- let s = await ee(o, {
661
+ let s = await E(o, {
655
662
  language: i,
656
663
  country: r,
657
664
  useExternalMetafieldNamespace: !0
658
665
  });
659
666
  o.shopifyDomain = s.shopifyDomain;
660
- let c = s.storefrontAccessToken ? new G(s.shopifyDomain, s.storefrontAccessToken) : o, [l, u] = await Promise.all([v(c, {
667
+ let c = s.storefrontAccessToken ? new U(s.shopifyDomain, s.storefrontAccessToken) : o, [l, u] = await Promise.all([y(c, {
661
668
  country: r,
662
669
  language: i,
663
670
  productIds: a,
@@ -667,21 +674,21 @@ var E = /* @__PURE__ */ function(e) {
667
674
  useMetaobjects: s.featureFlags.storefront_metaobjects
668
675
  })]), d = l[0];
669
676
  if (!d) return null;
670
- let f = le(u, d), m;
677
+ let f = de(u, d), m;
671
678
  if (n ? (m = f.find((e) => e.id === n || e.nanoId === n), m ||= f[0]) : m = f[0], !m) return null;
672
- let h = ne(m), g = P(m), [_, y, b, x] = await Promise.all([
673
- v(c, {
679
+ let h = k(m), g = M(m), [_, v, b, x] = await Promise.all([
680
+ y(c, {
674
681
  country: r,
675
682
  language: i,
676
683
  productIds: g,
677
684
  useExternalMetafieldNamespace: !0
678
685
  }),
679
- te(c, h, 300),
680
- ue(c, m, {
686
+ O(c, h, 300),
687
+ fe(c, m, {
681
688
  country: r,
682
689
  language: i
683
690
  }),
684
- de({
691
+ pe({
685
692
  language: i,
686
693
  dealBlockId: m.id
687
694
  })
@@ -691,14 +698,14 @@ var E = /* @__PURE__ */ function(e) {
691
698
  dealBlock: m,
692
699
  config: s,
693
700
  otherProducts: _,
694
- mediaImages: y,
701
+ mediaImages: v,
695
702
  collectionBreaksProducts: b ?? [],
696
703
  translations: x
697
704
  };
698
705
  } catch (e) {
699
706
  return console.error(e), null;
700
707
  }
701
- }, he = class {
708
+ }, _e = class {
702
709
  constructor(e) {
703
710
  this.storefront = e, this.shopifyDomain = "";
704
711
  }
@@ -711,7 +718,7 @@ var E = /* @__PURE__ */ function(e) {
711
718
  }
712
719
  if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
713
720
  if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
714
- let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${pe}/graphql.json`, {
721
+ let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${he}/graphql.json`, {
715
722
  body: JSON.stringify({
716
723
  query: e,
717
724
  variables: t?.variables
@@ -741,30 +748,45 @@ var E = /* @__PURE__ */ function(e) {
741
748
  get i18n() {
742
749
  if ("i18n" in this.storefront) return this.storefront.i18n;
743
750
  }
744
- }, ge = me, q = "kaching-bundles-block", J = 1e4, _e = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", ve = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", Y = /* @__PURE__ */ new WeakSet(), ye = async (e) => {
751
+ }, 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) => {
745
752
  let t = e.document;
746
- if (!e.customElements.get(q)) {
747
- if (Y.has(t)) return X(e, q);
748
- Y.add(t);
753
+ if (!e.customElements.get(G)) {
754
+ if (J.has(t)) return X(e, G);
755
+ J.add(t);
749
756
  try {
750
- await Se(e);
757
+ await we(e);
751
758
  } catch (e) {
752
- throw Y.delete(t), e;
759
+ throw J.delete(t), e;
753
760
  }
754
761
  }
755
- }, be = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, xe = () => be() ? _e : ve, Se = (e) => {
756
- let t = e.document;
757
- return new Promise((n, r) => {
758
- let i = xe();
759
- if (t.querySelector(`script[src="${i}"]`)) {
760
- X(e, q).then(n).catch(r);
761
- return;
762
- }
763
- let a = t.createElement("script");
764
- a.src = i, a.onload = () => X(e, q).then(n).catch(r), a.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), t.head.appendChild(a);
765
- });
766
- }, X = (e, t) => new Promise((n, r) => {
767
- 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 ${J}ms`)), J))]).then(() => n()).catch(r);
762
+ }, Se = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Ce = () => Se() ? ye : be, we = async (e) => {
763
+ let t = e.document, n = Ce();
764
+ if (t.querySelector(`script[src="${n}"]`)) return X(e, G);
765
+ let r = Te(t);
766
+ if (r && await De(t, r)) return X(e, G);
767
+ let i = t.createElement("script");
768
+ return i.src = n, await Y(t, i), X(e, G);
769
+ }, Te = (e) => {
770
+ let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);
771
+ return Array.from(t, (e) => e.href).find(Ee);
772
+ }, Ee = (e) => {
773
+ try {
774
+ return new URL(e).pathname.endsWith(q);
775
+ } catch {
776
+ return !1;
777
+ }
778
+ }, De = async (e, t) => {
779
+ let n = e.createElement("script");
780
+ n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
781
+ try {
782
+ return await Y(e, n), !0;
783
+ } catch {
784
+ return n.remove(), !1;
785
+ }
786
+ }, Y = (e, t) => new Promise((n, r) => {
787
+ t.onload = () => n(), t.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), e.head.appendChild(t);
788
+ }), X = (e, t) => new Promise((n, r) => {
789
+ 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);
768
790
  });
769
791
  [
770
792
  "primaryBackground",
@@ -781,9 +803,9 @@ var E = /* @__PURE__ */ function(e) {
781
803
  ].map((e) => `brand_${e}`);
782
804
  var Z = /* @__PURE__ */ function(e) {
783
805
  return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
784
- }({}), Q = "a-f\\d", Ce = `#?[${Q}]{3}[${Q}]?`, we = `#?[${Q}]{6}([${Q}]{2})?`, Te = RegExp(`[^#${Q}]`, "gi"), Ee = RegExp(`^${Ce}$|^${we}$`, "i");
785
- function De(e, t = {}) {
786
- if (typeof e != "string" || Te.test(e) || !Ee.test(e)) throw TypeError("Expected a valid hex string");
806
+ }({}), Q = "a-f\\d", Oe = `#?[${Q}]{3}[${Q}]?`, ke = `#?[${Q}]{6}([${Q}]{2})?`, Ae = RegExp(`[^#${Q}]`, "gi"), $ = RegExp(`^${Oe}$|^${ke}$`, "i");
807
+ function je(e, t = {}) {
808
+ if (typeof e != "string" || Ae.test(e) || !$.test(e)) throw TypeError("Expected a valid hex string");
787
809
  e = e.replace(/^#/, "");
788
810
  let n = 1;
789
811
  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]);
@@ -801,7 +823,7 @@ function De(e, t = {}) {
801
823
  };
802
824
  }
803
825
  // src/react/preview.ts
804
- var $ = ({ price: e }) => ({
826
+ var Me = ({ price: e }) => ({
805
827
  id: 123,
806
828
  handle: "123",
807
829
  url: null,
@@ -834,7 +856,7 @@ var $ = ({ price: e }) => ({
834
856
  text4: null
835
857
  },
836
858
  isNativeBundle: !1
837
- }), Oe = () => ({
859
+ }), Ne = () => ({
838
860
  shopifyDomain: "",
839
861
  moneyFormat: "${{amount_with_comma_separator}}",
840
862
  locale: "en",
@@ -890,7 +912,7 @@ var $ = ({ price: e }) => ({
890
912
  },
891
913
  shopCustomStyles: "",
892
914
  featureFlags: {}
893
- }), ke = ({ color: e, cornerRadius: t }) => {
915
+ }), Pe = ({ color: e, cornerRadius: t }) => {
894
916
  let n = {
895
917
  id: "123",
896
918
  nanoId: "123",
@@ -1150,14 +1172,14 @@ var $ = ({ price: e }) => ({
1150
1172
  imageCornerRadius: 6
1151
1173
  };
1152
1174
  return e !== void 0 && (n.colors.border = {
1153
- ...De(e),
1175
+ ...je(e),
1154
1176
  alpha: 1
1155
1177
  }), n;
1156
- }, Ae = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1178
+ }, Fe = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1157
1179
  let l = n(null), [u, d] = r(!1), f = n(!1);
1158
1180
  e(() => {
1159
1181
  l.current && !u && (async () => {
1160
- await ye(c ?? window), d(!0);
1182
+ await xe(c ?? window), d(!0);
1161
1183
  })();
1162
1184
  }, [u, c]), e(() => {
1163
1185
  let e = l.current;
@@ -1178,8 +1200,8 @@ var $ = ({ price: e }) => ({
1178
1200
  e.removeEventListener("kaching-bundles-block-loaded", t), e.removeEventListener("variants-changed", t);
1179
1201
  };
1180
1202
  }, [u, s]);
1181
- let p = t ? Me(t, a) : o ? Ne(o) : null;
1182
- return je(() => {
1203
+ let p = t ? Le(t, a) : o ? Re(o) : null;
1204
+ return Ie(() => {
1183
1205
  let e = l.current;
1184
1206
  if (e && p) for (let [t, n] of Object.entries(p.jsonAttributes)) e.getAttribute(t) !== n && e.setAttribute(t, n);
1185
1207
  }), p ? /* @__PURE__ */ i("kaching-bundles-block", {
@@ -1188,7 +1210,7 @@ var $ = ({ price: e }) => ({
1188
1210
  ...p.jsonAttributes,
1189
1211
  "current-variant-id": p.currentVariantId
1190
1212
  }) : null;
1191
- }, je = typeof window > "u" ? e : t, Me = ({ config: e, dealBlock: t, product: n, otherProducts: r, mediaImages: i, collectionBreaksProducts: a, translations: o }, s) => ({
1213
+ }, Ie = typeof window > "u" ? e : t, Le = ({ config: e, dealBlock: t, product: n, otherProducts: r, mediaImages: i, collectionBreaksProducts: a, translations: o }, s) => ({
1192
1214
  dealBlockId: t.id,
1193
1215
  currentVariantId: s ? s.split("/").pop() : String(n.variants[0].id),
1194
1216
  jsonAttributes: {
@@ -1200,8 +1222,8 @@ var $ = ({ price: e }) => ({
1200
1222
  "collection-breaks-products": JSON.stringify(a),
1201
1223
  translations: JSON.stringify(o)
1202
1224
  }
1203
- }), Ne = ({ cornerRadius: e, color: t, price: n }) => {
1204
- let r = $({ price: n }), i = Oe(), a = ke({
1225
+ }), Re = ({ cornerRadius: e, color: t, price: n }) => {
1226
+ let r = Me({ price: n }), i = Ne(), a = Pe({
1205
1227
  color: t,
1206
1228
  cornerRadius: e
1207
1229
  });
@@ -1219,4 +1241,4 @@ var $ = ({ price: e }) => ({
1219
1241
  }
1220
1242
  };
1221
1243
  };
1222
- export { Ae as KachingBundle, ge as fetchKachingBundlesData };
1244
+ export { Fe as KachingBundle, ve as fetchKachingBundlesData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kachingappz/bundles-js",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/kachingappz/bundles.git",
@@ -51,7 +51,7 @@
51
51
  ],
52
52
  "devDependencies": {
53
53
  "@kachingappz/bundles-storefront-api": "^0.1.0",
54
- "@kachingappz/bundles-types": "^0.2.0",
54
+ "@kachingappz/bundles-types": "^0.4.3",
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",