@kachingappz/bundles-js 1.1.9 → 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.
@@ -417,13 +417,7 @@ declare type DiscountType = "default" | "percentage" | "amount" | "specific";
417
417
 
418
418
  export declare const fetchKachingBundlesData: (...args: Parameters<typeof fetchKachingBundlesData_2>) => Promise<KachingBundlesData | null>;
419
419
 
420
- declare const fetchKachingBundlesData_2: (storefront: HydrogenV2Storefront | HydrogenStorefrontClient | ReactHydrogenStorefront | ShopifyStorefrontApiClient | StorefrontCredentials, { productId, dealBlockId, abTestVariantId, country, language, }: {
421
- productId: string;
422
- dealBlockId?: string;
423
- abTestVariantId?: string;
424
- country?: string;
425
- language?: string;
426
- }) => Promise<KachingBundlesData_2 | null>;
420
+ declare const fetchKachingBundlesData_2: (storefront: KachingBundlesStorefront, options: KachingBundlesDataOptions) => Promise<KachingBundlesData_2 | null>;
427
421
 
428
422
  declare type Font = {
429
423
  size: string | number;
@@ -752,6 +746,7 @@ declare interface KachingBundlesData_2 {
752
746
  dealBlock: DealBlock;
753
747
  product: Product;
754
748
  otherProducts: Product[];
749
+ mixAndMatchSwapProducts: Product[];
755
750
  mediaImages: {
756
751
  gid: string;
757
752
  url: string;
@@ -762,6 +757,16 @@ declare interface KachingBundlesData_2 {
762
757
  };
763
758
  }
764
759
 
760
+ declare interface KachingBundlesDataOptions {
761
+ productId: string;
762
+ dealBlockId?: string;
763
+ abTestVariantId?: string;
764
+ country?: string;
765
+ language?: string;
766
+ }
767
+
768
+ declare type KachingBundlesStorefront = HydrogenV2Storefront | HydrogenStorefrontClient | ReactHydrogenStorefront | ShopifyStorefrontApiClient | StorefrontCredentials;
769
+
765
770
  declare type LowStockAlert = {
766
771
  threshold: number;
767
772
  message: string;
@@ -654,7 +654,23 @@ var E = "app--2935586817", D = async (e, { language: t, country: n, useExternalM
654
654
  let o = e.filter((e) => e.blockVisibility === "all-products");
655
655
  for (let e of o) n.push(e);
656
656
  return n;
657
- }, he = 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 }) => {
658
674
  let i = t.collectionBreaks;
659
675
  if (!t.collectionBreaksEnabled || !i) return;
660
676
  let a;
@@ -723,11 +739,11 @@ var E = "app--2935586817", D = async (e, { language: t, country: n, useExternalM
723
739
  } catch {
724
740
  return;
725
741
  }
726
- let r = W(e);
727
- return n.find((e) => W(e.locale) === r)?.translations;
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 }) => {
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 }) => {
729
745
  try {
730
- let o = [Number(t.split("/").pop())], s = new be(e);
746
+ let o = [Number(t.split("/").pop())], s = new we(e);
731
747
  i ||= s.i18n?.country, a ||= s.i18n?.language;
732
748
  let c = await D(s, {
733
749
  language: a,
@@ -747,48 +763,75 @@ var E = "app--2935586817", D = async (e, { language: t, country: n, useExternalM
747
763
  if (!f) return null;
748
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];
749
765
  if (!g) return null;
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, {
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([
771
+ y(l, {
771
772
  country: i,
772
- language: a
773
+ language: a,
774
+ productIds: _,
775
+ useExternalMetafieldNamespace: !0
773
776
  }),
777
+ k(l, ee(g), 300),
774
778
  ge({
775
779
  language: a,
776
780
  dealBlockId: g.id
777
781
  })
778
782
  ]);
779
783
  return {
780
- product: f,
781
- dealBlock: g,
782
- config: c,
783
- otherProducts: v,
784
- mediaImages: b,
785
- collectionBreaksProducts: x ?? [],
786
- translations: S
784
+ data: {
785
+ config: c,
786
+ dealBlock: g,
787
+ product: f,
788
+ otherProducts: b,
789
+ mediaImages: x,
790
+ translations: S
791
+ },
792
+ modalProducts: v
787
793
  };
788
794
  } catch (e) {
789
795
  return console.error(e), null;
790
796
  }
791
- }, be = 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 {
792
835
  constructor(e) {
793
836
  this.storefront = e, this.shopifyDomain = "";
794
837
  }
@@ -831,64 +874,66 @@ var E = "app--2935586817", D = async (e, { language: t, country: n, useExternalM
831
874
  get i18n() {
832
875
  if ("i18n" in this.storefront) return this.storefront.i18n;
833
876
  }
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) => {
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) => {
835
896
  let t = e.document;
836
- if (!e.customElements.get(G)) {
837
- if (J.has(t)) return X(e, G);
838
- J.add(t);
897
+ if (!e.customElements.get(K)) {
898
+ if (Y.has(t)) return Z(e, K);
899
+ Y.add(t);
839
900
  try {
840
- await De(e);
901
+ await je(e);
841
902
  } catch (e) {
842
- throw J.delete(t), e;
903
+ throw Y.delete(t), e;
843
904
  }
844
905
  }
845
- }, Te = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Ee = () => Te() ? Se : Ce, De = async (e) => {
846
- let t = e.document, n = Ee();
847
- if (t.querySelector(`script[src="${n}"]`)) return X(e, G);
848
- let r = Oe(t);
849
- if (r && await Ae(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);
850
911
  let i = t.createElement("script");
851
- return i.src = n, await Y(t, i), X(e, G);
852
- }, Oe = (e) => {
853
- let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);
854
- return Array.from(t, (e) => e.href).find(ke);
855
- }, ke = (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) => {
856
917
  try {
857
- return new URL(e).pathname.endsWith(q);
918
+ return new URL(e).pathname.endsWith(J);
858
919
  } catch {
859
920
  return !1;
860
921
  }
861
- }, Ae = async (e, t) => {
922
+ }, Pe = async (e, t) => {
862
923
  let n = e.createElement("script");
863
924
  n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
864
925
  try {
865
- return await Y(e, n), !0;
926
+ return await X(e, n), !0;
866
927
  } catch {
867
928
  return n.remove(), !1;
868
929
  }
869
- }, Y = (e, t) => new Promise((n, r) => {
930
+ }, X = (e, t) => new Promise((n, r) => {
870
931
  t.onload = () => n(), t.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), e.head.appendChild(t);
871
- }), X = (e, t) => new Promise((n, r) => {
872
- 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);
873
- });
874
- [
875
- "primaryBackground",
876
- "secondaryBackground",
877
- "primaryText",
878
- "secondaryText",
879
- "border",
880
- "overlay",
881
- "primaryAccent",
882
- "primaryAccentText",
883
- "badgeBackground",
884
- "badgeText",
885
- "error"
886
- ].map((e) => `brand_${e}`);
887
- var Z = /* @__PURE__ */ function(e) {
888
- return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
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");
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");
892
937
  e = e.replace(/^#/, "");
893
938
  let n = 1;
894
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]);
@@ -906,7 +951,7 @@ function $(e, t = {}) {
906
951
  };
907
952
  }
908
953
  // src/react/preview.ts
909
- var Fe = ({ price: e }) => ({
954
+ var ze = ({ price: e }) => ({
910
955
  id: 123,
911
956
  handle: "123",
912
957
  url: null,
@@ -939,7 +984,7 @@ var Fe = ({ price: e }) => ({
939
984
  text4: null
940
985
  },
941
986
  isNativeBundle: !1
942
- }), Ie = () => ({
987
+ }), Be = () => ({
943
988
  shopifyDomain: "",
944
989
  moneyFormat: "${{amount_with_comma_separator}}",
945
990
  locale: "en",
@@ -995,7 +1040,7 @@ var Fe = ({ price: e }) => ({
995
1040
  },
996
1041
  shopCustomStyles: "",
997
1042
  featureFlags: {}
998
- }), Le = ({ color: e, cornerRadius: t }) => {
1043
+ }), Ve = ({ color: e, cornerRadius: t }) => {
999
1044
  let n = {
1000
1045
  id: "123",
1001
1046
  nanoId: "123",
@@ -1045,7 +1090,7 @@ var Fe = ({ price: e }) => ({
1045
1090
  lowStockAlert: null,
1046
1091
  dealBars: [{
1047
1092
  id: "PfFU",
1048
- dealBarType: Z.QuantityBreak,
1093
+ dealBarType: W.QuantityBreak,
1049
1094
  title: "1 pack",
1050
1095
  subtitle: "Standard price",
1051
1096
  label: "",
@@ -1064,7 +1109,7 @@ var Fe = ({ price: e }) => ({
1064
1109
  productPersonalisation: null
1065
1110
  }, {
1066
1111
  id: "1f-9",
1067
- dealBarType: Z.QuantityBreak,
1112
+ dealBarType: W.QuantityBreak,
1068
1113
  title: "2 pack",
1069
1114
  subtitle: "You save {{saved_percentage}}",
1070
1115
  label: "SAVE {{saved_total}}",
@@ -1255,14 +1300,14 @@ var Fe = ({ price: e }) => ({
1255
1300
  imageCornerRadius: 6
1256
1301
  };
1257
1302
  return e !== void 0 && (n.colors.border = {
1258
- ...$(e),
1303
+ ...Re(e),
1259
1304
  alpha: 1
1260
1305
  }), n;
1261
- }, Re = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1306
+ }, He = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1262
1307
  let l = n(null), [u, d] = r(!1), f = n(!1);
1263
1308
  e(() => {
1264
1309
  l.current && !u && (async () => {
1265
- await we(c ?? window), d(!0);
1310
+ await Oe(c ?? window), d(!0);
1266
1311
  })();
1267
1312
  }, [u, c]), e(() => {
1268
1313
  let e = l.current;
@@ -1283,8 +1328,8 @@ var Fe = ({ price: e }) => ({
1283
1328
  e.removeEventListener("kaching-bundles-block-loaded", t), e.removeEventListener("variants-changed", t);
1284
1329
  };
1285
1330
  }, [u, s]);
1286
- let p = t ? Be(t, a) : o ? Ve(o) : null;
1287
- return ze(() => {
1331
+ let p = t ? We(t, a) : o ? Ge(o) : null;
1332
+ return Ue(() => {
1288
1333
  let e = l.current;
1289
1334
  if (e && p) for (let [t, n] of Object.entries(p.jsonAttributes)) e.getAttribute(t) !== n && e.setAttribute(t, n);
1290
1335
  }), p ? /* @__PURE__ */ i("kaching-bundles-block", {
@@ -1293,20 +1338,21 @@ var Fe = ({ price: e }) => ({
1293
1338
  ...p.jsonAttributes,
1294
1339
  "current-variant-id": p.currentVariantId
1295
1340
  }) : null;
1296
- }, ze = typeof window > "u" ? e : t, Be = ({ 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) => ({
1297
1342
  dealBlockId: t.id,
1298
- currentVariantId: s ? s.split("/").pop() : String(n.variants[0].id),
1343
+ currentVariantId: c ? c.split("/").pop() : String(n.variants[0].id),
1299
1344
  jsonAttributes: {
1300
1345
  config: JSON.stringify(e),
1301
1346
  "deal-block": JSON.stringify(t),
1302
- "media-images": JSON.stringify(i),
1347
+ "media-images": JSON.stringify(a),
1303
1348
  product: JSON.stringify(n),
1304
1349
  "other-products": JSON.stringify(r),
1305
- "collection-breaks-products": JSON.stringify(a),
1306
- 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)
1307
1353
  }
1308
- }), Ve = ({ cornerRadius: e, color: t, price: n }) => {
1309
- let r = Fe({ price: n }), i = Ie(), a = Le({
1354
+ }), Ge = ({ cornerRadius: e, color: t, price: n }) => {
1355
+ let r = ze({ price: n }), i = Be(), a = Ve({
1310
1356
  color: t,
1311
1357
  cornerRadius: e
1312
1358
  });
@@ -1319,9 +1365,10 @@ var Fe = ({ price: e }) => ({
1319
1365
  "media-images": JSON.stringify([]),
1320
1366
  product: JSON.stringify(r),
1321
1367
  "other-products": JSON.stringify([]),
1368
+ "mix-and-match-swap-products": JSON.stringify([]),
1322
1369
  "collection-breaks-products": JSON.stringify([]),
1323
1370
  translations: JSON.stringify({})
1324
1371
  }
1325
1372
  };
1326
1373
  };
1327
- export { Re as KachingBundle, xe as fetchKachingBundlesData };
1374
+ export { He as KachingBundle, Te as fetchKachingBundlesData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kachingappz/bundles-js",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/kachingappz/bundles.git",