@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.
- package/dist/bundles-js.iife.js +14 -11
- package/dist/index.d.ts +58 -9
- package/dist/index.js +86 -79
- package/dist/kaching-bundle-component/index.d.ts +58 -9
- package/dist/kaching-bundle-component/index.js +160 -138
- package/dist/react/index.cjs +14 -11
- package/dist/react/index.d.ts +58 -9
- package/dist/react/index.js +157 -135
- package/package.json +2 -2
|
@@ -31,7 +31,23 @@ var e = (e, { language: n, country: s }) => {
|
|
|
31
31
|
i = t.metaobjects.pageInfo.endCursor;
|
|
32
32
|
}
|
|
33
33
|
return r;
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
|
+
[
|
|
36
|
+
"primaryBackground",
|
|
37
|
+
"secondaryBackground",
|
|
38
|
+
"primaryText",
|
|
39
|
+
"secondaryText",
|
|
40
|
+
"border",
|
|
41
|
+
"overlay",
|
|
42
|
+
"primaryAccent",
|
|
43
|
+
"primaryAccentText",
|
|
44
|
+
"badgeBackground",
|
|
45
|
+
"badgeText",
|
|
46
|
+
"error"
|
|
47
|
+
].map((e) => `brand_${e}`);
|
|
48
|
+
var d = /* @__PURE__ */ function(e) {
|
|
49
|
+
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
50
|
+
}({}), f = async (e, { country: t, language: n, blockVisibility: r, excludedProductGIDs: i, selectedProductGIDs: a, selectedCollectionGIDs: o, limit: c = 1e3 }) => {
|
|
35
51
|
switch (r) {
|
|
36
52
|
case "selected-products": return a.slice(0, c);
|
|
37
53
|
case "all-products":
|
|
@@ -89,16 +105,16 @@ var e = (e, { language: n, country: s }) => {
|
|
|
89
105
|
return Array.from(new Set(i)).slice(0, c);
|
|
90
106
|
}
|
|
91
107
|
}
|
|
92
|
-
},
|
|
108
|
+
}, p = "\n id\n availableForSale\n price {\n amount\n }\n compareAtPrice {\n amount\n }\n selectedOptions {\n name\n value\n }\n image {\n id\n url(transform: $variantImageTransform)\n }\n unitPriceMeasurement {\n quantityUnit\n quantityValue\n referenceUnit\n referenceValue\n }\n requiresComponents\n sellingPlanAllocations(first: 100) @include(if: $includeSellingPlans) {\n nodes {\n sellingPlan {\n id\n }\n priceAdjustments {\n price {\n amount\n }\n compareAtPrice {\n amount\n }\n perDeliveryPrice {\n amount\n }\n }\n }\n }\n quantityAvailable @include(if: $includeAvailableQuantity)\n", m = async (e, { country: t, language: n, productIds: r, includeSellingPlans: i = !0, includeAvailableQuantity: a = !0, includeProductRating: o = !1, includeProductSubtitle: c = !1, productSubtitleMetafield: l = "descriptors.subtitle", useExternalMetafieldNamespace: u = !1, batchSize: d = 250, onBatchError: f, variantImageTransform: m = {
|
|
93
109
|
maxWidth: 200,
|
|
94
110
|
maxHeight: 200
|
|
95
111
|
} }) => {
|
|
96
112
|
if (!r.length) return [];
|
|
97
|
-
let
|
|
113
|
+
let _ = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), v = s({
|
|
98
114
|
country: t,
|
|
99
115
|
language: n
|
|
100
|
-
}),
|
|
101
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${
|
|
116
|
+
}), y = `
|
|
117
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${v} {
|
|
102
118
|
shop {
|
|
103
119
|
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
104
120
|
value
|
|
@@ -132,7 +148,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
132
148
|
}
|
|
133
149
|
variants(first: 250) {
|
|
134
150
|
nodes {
|
|
135
|
-
${
|
|
151
|
+
${p}
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
154
|
collections(first: 50) {
|
|
@@ -158,6 +174,9 @@ var e = (e, { language: n, country: s }) => {
|
|
|
158
174
|
reviewsRatingCount: metafield(namespace: "reviews", key: "rating_count") @include(if: $includeProductRating) {
|
|
159
175
|
value
|
|
160
176
|
}
|
|
177
|
+
subtitle: metafield(namespace: $subtitleNamespace, key: $subtitleKey) @include(if: $includeProductSubtitle) {
|
|
178
|
+
value
|
|
179
|
+
}
|
|
161
180
|
requiresSellingPlan
|
|
162
181
|
sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
|
|
163
182
|
nodes {
|
|
@@ -190,40 +209,43 @@ var e = (e, { language: n, country: s }) => {
|
|
|
190
209
|
}
|
|
191
210
|
}
|
|
192
211
|
}
|
|
193
|
-
`,
|
|
194
|
-
for (let e = 0; e <
|
|
195
|
-
let
|
|
196
|
-
let n = await e.query(
|
|
212
|
+
`, b = u ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", x = l.indexOf("."), S = l.slice(0, x), C = l.slice(x + 1), w = [], T = Math.min(d, 250);
|
|
213
|
+
for (let e = 0; e < _.length; e += T) w.push(_.slice(e, e + T));
|
|
214
|
+
let E = 1, D = async (t) => {
|
|
215
|
+
let n = await e.query(y, { variables: {
|
|
197
216
|
productGIDs: t,
|
|
198
217
|
includeSellingPlans: i,
|
|
199
218
|
includeAvailableQuantity: a,
|
|
200
219
|
includeProductRating: o,
|
|
201
|
-
|
|
202
|
-
|
|
220
|
+
includeProductSubtitle: c,
|
|
221
|
+
subtitleNamespace: S,
|
|
222
|
+
subtitleKey: C,
|
|
223
|
+
metafieldNamespace: b,
|
|
224
|
+
variantImageTransform: m
|
|
203
225
|
} });
|
|
204
|
-
return n.shop.currencyRateConstant && (
|
|
205
|
-
},
|
|
206
|
-
if (
|
|
207
|
-
let e = await Promise.allSettled(
|
|
208
|
-
for (let t of e) t.status === "rejected" &&
|
|
209
|
-
|
|
210
|
-
} else
|
|
211
|
-
let
|
|
212
|
-
if (
|
|
213
|
-
let t = await Promise.allSettled(
|
|
226
|
+
return n.shop.currencyRateConstant && (E = JSON.parse(n.shop.currencyRateConstant.value).amount / 1e6), n;
|
|
227
|
+
}, O;
|
|
228
|
+
if (f) {
|
|
229
|
+
let e = await Promise.allSettled(w.map(D));
|
|
230
|
+
for (let t of e) t.status === "rejected" && f(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
|
|
231
|
+
O = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
|
|
232
|
+
} else O = (await Promise.all(w.map(D))).flatMap((e) => e.nodes);
|
|
233
|
+
let k = O.filter((e) => e != null);
|
|
234
|
+
if (f) {
|
|
235
|
+
let t = await Promise.allSettled(k.map(async (t) => g(await h(e, t, {
|
|
214
236
|
includeSellingPlans: i,
|
|
215
237
|
includeAvailableQuantity: a,
|
|
216
|
-
variantImageTransform:
|
|
217
|
-
},
|
|
218
|
-
for (let e of t) e.status === "fulfilled" ? n.push(e.value) :
|
|
238
|
+
variantImageTransform: m
|
|
239
|
+
}, v), e.shopifyDomain, E))), n = [];
|
|
240
|
+
for (let e of t) e.status === "fulfilled" ? n.push(e.value) : f(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
|
|
219
241
|
return n;
|
|
220
242
|
}
|
|
221
|
-
return (await Promise.all(
|
|
243
|
+
return (await Promise.all(k.map((t) => h(e, t, {
|
|
222
244
|
includeSellingPlans: i,
|
|
223
245
|
includeAvailableQuantity: a,
|
|
224
|
-
variantImageTransform:
|
|
225
|
-
},
|
|
226
|
-
},
|
|
246
|
+
variantImageTransform: m
|
|
247
|
+
}, v)))).map((t) => g(t, e.shopifyDomain, E));
|
|
248
|
+
}, h = async (e, t, n, r = "") => {
|
|
227
249
|
if (t.variants.nodes.length < 250) return t;
|
|
228
250
|
let i = /* @__PURE__ */ new Set(), a = [], o = [], s = async (s) => {
|
|
229
251
|
let c = !0, l = null;
|
|
@@ -233,7 +255,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
233
255
|
product(id: $productGID) {
|
|
234
256
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
235
257
|
nodes {
|
|
236
|
-
${
|
|
258
|
+
${p}
|
|
237
259
|
}
|
|
238
260
|
pageInfo {
|
|
239
261
|
endCursor
|
|
@@ -259,7 +281,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
259
281
|
}
|
|
260
282
|
};
|
|
261
283
|
return await Promise.all([s(!1), s(!0)]), t.variants.nodes = [...a, ...o.reverse()], t;
|
|
262
|
-
},
|
|
284
|
+
}, g = (e, t, n) => {
|
|
263
285
|
let r = e.variants.nodes.map(({ unitPriceMeasurement: e, ...t }) => ({
|
|
264
286
|
id: Number(t.id.split("/").pop()),
|
|
265
287
|
availableForSale: t.availableForSale,
|
|
@@ -297,7 +319,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
297
319
|
defaultName: e.name,
|
|
298
320
|
name: e.name,
|
|
299
321
|
position: t + 1,
|
|
300
|
-
optionValues:
|
|
322
|
+
optionValues: y(n, t, r)
|
|
301
323
|
};
|
|
302
324
|
}), a = (e) => {
|
|
303
325
|
let t = e.priceAdjustments[0];
|
|
@@ -344,26 +366,27 @@ var e = (e, { language: n, country: s }) => {
|
|
|
344
366
|
text3: e.metafield3?.value || null,
|
|
345
367
|
text4: e.metafield4?.value || null
|
|
346
368
|
},
|
|
347
|
-
rating:
|
|
369
|
+
rating: _(e.reviewsRating, e.reviewsRatingCount),
|
|
370
|
+
subtitle: e.subtitle?.value || null
|
|
348
371
|
};
|
|
349
|
-
},
|
|
372
|
+
}, _ = (e, t) => {
|
|
350
373
|
if (!e) return null;
|
|
351
|
-
let n =
|
|
374
|
+
let n = v(e.value);
|
|
352
375
|
if (n === null) return null;
|
|
353
376
|
let r = Number(t?.value);
|
|
354
377
|
return {
|
|
355
378
|
value: n,
|
|
356
379
|
count: Number.isInteger(r) && r > 0 ? r : null
|
|
357
380
|
};
|
|
358
|
-
},
|
|
381
|
+
}, v = (e) => {
|
|
359
382
|
try {
|
|
360
383
|
let { value: t, scale_max: n } = JSON.parse(e), r = Number(t) / Number(n) * 5;
|
|
361
384
|
return Number.isFinite(r) && r > 0 ? Math.min(5, r) : null;
|
|
362
385
|
} catch {
|
|
363
386
|
return null;
|
|
364
387
|
}
|
|
365
|
-
},
|
|
366
|
-
let a = i ? `${
|
|
388
|
+
}, y = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0), b = "app--2935586817", x = async (t, { language: n, country: r, useExternalMetafieldNamespace: i }) => {
|
|
389
|
+
let a = i ? `${b}--kaching_bundles` : "$app:kaching_bundles", o = i ? b : "$app", c = s({ country: r }), { localization: { country: { currency: { isoCode: l } } }, shop: { moneyFormat: u, paymentSettings: { currencyCode: d }, currencyRateConstant: f, primaryDomain: p, settingsMetafield: m } } = await t.query(`
|
|
367
390
|
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${c} {
|
|
368
391
|
localization {
|
|
369
392
|
country {
|
|
@@ -394,7 +417,7 @@ var e = (e, { language: n, country: s }) => {
|
|
|
394
417
|
} }), h = l === d ? u : e(l, {
|
|
395
418
|
language: n,
|
|
396
419
|
country: r
|
|
397
|
-
}), g = f ?
|
|
420
|
+
}), g = f ? S(f.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
|
|
398
421
|
return {
|
|
399
422
|
shopifyDomain: p.host,
|
|
400
423
|
moneyFormat: h,
|
|
@@ -445,17 +468,17 @@ var e = (e, { language: n, country: s }) => {
|
|
|
445
468
|
"system.numbers_only": "Only numbers are allowed."
|
|
446
469
|
},
|
|
447
470
|
customSelectors: {
|
|
448
|
-
quantity:
|
|
449
|
-
addToCartButton:
|
|
450
|
-
variantPicker:
|
|
451
|
-
price:
|
|
452
|
-
priceCompare:
|
|
471
|
+
quantity: y.quantity ?? null,
|
|
472
|
+
addToCartButton: y.add_to_cart_button ?? null,
|
|
473
|
+
variantPicker: y.variant_picker ?? null,
|
|
474
|
+
price: y.price ?? null,
|
|
475
|
+
priceCompare: y.price_compare ?? null
|
|
453
476
|
},
|
|
454
477
|
shopCustomStyles: _?.shop_custom_styles ?? "",
|
|
455
478
|
featureFlags: v,
|
|
456
479
|
brandColors: _?.brand_colors ?? null
|
|
457
480
|
};
|
|
458
|
-
},
|
|
481
|
+
}, S = (e) => JSON.parse(e).amount / 1e6, C = async (e, t, n = 200) => {
|
|
459
482
|
let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
|
|
460
483
|
if (r.length === 0) return [];
|
|
461
484
|
let i = [];
|
|
@@ -467,93 +490,77 @@ var e = (e, { language: n, country: s }) => {
|
|
|
467
490
|
gid: e.id,
|
|
468
491
|
url: e.image.url
|
|
469
492
|
}] : []);
|
|
470
|
-
}
|
|
471
|
-
[
|
|
472
|
-
"primaryBackground",
|
|
473
|
-
"secondaryBackground",
|
|
474
|
-
"primaryText",
|
|
475
|
-
"secondaryText",
|
|
476
|
-
"border",
|
|
477
|
-
"overlay",
|
|
478
|
-
"primaryAccent",
|
|
479
|
-
"primaryAccentText",
|
|
480
|
-
"badgeBackground",
|
|
481
|
-
"badgeText",
|
|
482
|
-
"error"
|
|
483
|
-
].map((e) => `brand_${e}`);
|
|
484
|
-
var C = /* @__PURE__ */ function(e) {
|
|
485
|
-
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
486
|
-
}({}), w = (e) => [
|
|
487
|
-
...ee(e),
|
|
488
|
-
...te(e),
|
|
489
|
-
...ne(e),
|
|
490
|
-
...re(e),
|
|
491
|
-
...ie(e),
|
|
493
|
+
}, w = (e) => [
|
|
492
494
|
...T(e),
|
|
493
495
|
...E(e),
|
|
494
496
|
...D(e),
|
|
495
497
|
...O(e),
|
|
496
|
-
...ae(e),
|
|
497
|
-
...oe(e),
|
|
498
498
|
...k(e),
|
|
499
|
-
...A(e)
|
|
500
|
-
|
|
499
|
+
...A(e),
|
|
500
|
+
...j(e),
|
|
501
|
+
...ee(e),
|
|
502
|
+
...te(e),
|
|
503
|
+
...ne(e),
|
|
504
|
+
...re(e),
|
|
505
|
+
...ie(e),
|
|
506
|
+
...ae(e)
|
|
507
|
+
].filter((e) => e != null && !e.includes("placeholder")), T = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), E = (e) => e.dealBars.flatMap((e) => e.dealBarType === d.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), D = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), O = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), k = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), A = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
|
|
501
508
|
let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
|
|
502
509
|
return [...e, ...n];
|
|
503
|
-
}, []) : [],
|
|
510
|
+
}, []) : [], j = (e) => {
|
|
504
511
|
if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
|
|
505
512
|
let t = e.collectionBreaks.mediaImageGID;
|
|
506
513
|
return t ? [t] : [];
|
|
507
|
-
},
|
|
514
|
+
}, ee = (e) => e.progressiveGifts ? [
|
|
508
515
|
...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
|
|
509
516
|
e.progressiveGifts.style?.lockedMediaImageGID,
|
|
510
517
|
e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
|
|
511
|
-
].filter((e) => e != null) : [],
|
|
518
|
+
].filter((e) => e != null) : [], te = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ne = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), re = (e) => {
|
|
512
519
|
let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
|
|
513
520
|
return n ? [...t, n] : t;
|
|
514
|
-
},
|
|
521
|
+
}, ie = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), ae = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], oe = (e) => {
|
|
515
522
|
let t = [
|
|
523
|
+
...se(e),
|
|
524
|
+
...ce(e),
|
|
525
|
+
...le(e),
|
|
526
|
+
...ue(e),
|
|
516
527
|
...M(e),
|
|
517
528
|
...N(e),
|
|
518
529
|
...P(e),
|
|
519
|
-
...F(e)
|
|
520
|
-
...I(e),
|
|
521
|
-
...L(e),
|
|
522
|
-
...R(e),
|
|
523
|
-
...z(e)
|
|
530
|
+
...F(e)
|
|
524
531
|
];
|
|
525
532
|
return Array.from(new Set(t.filter((e) => e != null)));
|
|
526
|
-
},
|
|
533
|
+
}, se = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), ce = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), le = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], ue = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), M = (e) => e.dealBars.filter((e) => e.dealBarType === d.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), N = (e) => e.dealBars.filter((e) => e.dealBarType === d.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...e.selectedProducts?.map((e) => e.id) ?? []]) : []).filter((e) => e != null).filter((e) => e !== "default"), P = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), F = (e) => e.dealBars.filter((e) => e.dealBarType === d.Sku).flatMap(({ productGID: e }) => e ? [e] : []), I = class extends Error {
|
|
527
534
|
constructor({ status: e, operationName: t, graphqlErrors: n }) {
|
|
528
535
|
let r = n.length ? `: ${n.join("; ")}` : "";
|
|
529
536
|
super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
|
|
530
537
|
}
|
|
531
|
-
},
|
|
538
|
+
}, L = async (e, t) => {
|
|
532
539
|
let n = await e.text();
|
|
533
540
|
if (!n) throw Error("Empty graphql response");
|
|
534
541
|
let r;
|
|
535
542
|
try {
|
|
536
543
|
r = JSON.parse(n);
|
|
537
544
|
} catch (n) {
|
|
538
|
-
throw e.ok ? n : new
|
|
545
|
+
throw e.ok ? n : new I({
|
|
539
546
|
status: e.status,
|
|
540
547
|
operationName: t,
|
|
541
548
|
graphqlErrors: []
|
|
542
549
|
});
|
|
543
550
|
}
|
|
544
|
-
if (!e.ok || r.data === null || r.data === void 0) throw new
|
|
551
|
+
if (!e.ok || r.data === null || r.data === void 0) throw new I({
|
|
545
552
|
status: e.status,
|
|
546
553
|
operationName: t,
|
|
547
554
|
graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
|
|
548
555
|
});
|
|
549
556
|
return r.data;
|
|
550
|
-
},
|
|
557
|
+
}, R = class {
|
|
551
558
|
constructor(e, t) {
|
|
552
559
|
this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
|
|
553
560
|
}
|
|
554
561
|
async query(e, t) {
|
|
555
562
|
let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
|
|
556
|
-
return i && (r += `?operation_name=${i}`),
|
|
563
|
+
return i && (r += `?operation_name=${i}`), L(await fetch(r, {
|
|
557
564
|
method: "POST",
|
|
558
565
|
headers: {
|
|
559
566
|
"Content-Type": "application/json",
|
|
@@ -565,7 +572,7 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
565
572
|
})
|
|
566
573
|
}), i);
|
|
567
574
|
}
|
|
568
|
-
},
|
|
575
|
+
}, z = (e, t) => {
|
|
569
576
|
let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
|
|
570
577
|
for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
|
|
571
578
|
let i = e.filter((e) => e.blockVisibility === "selected-collections");
|
|
@@ -575,18 +582,18 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
575
582
|
let o = e.filter((e) => e.blockVisibility === "all-products");
|
|
576
583
|
for (let e of o) n.push(e);
|
|
577
584
|
return n;
|
|
578
|
-
},
|
|
585
|
+
}, B = async (e, t, { country: n, language: r }) => {
|
|
579
586
|
let i = t.collectionBreaks;
|
|
580
587
|
if (!t.collectionBreaksEnabled || !i) return;
|
|
581
588
|
let a;
|
|
582
|
-
a = i.visibility === "deal-products" ? await
|
|
589
|
+
a = i.visibility === "deal-products" ? await f(e, {
|
|
583
590
|
country: n,
|
|
584
591
|
language: r,
|
|
585
592
|
blockVisibility: t.blockVisibility,
|
|
586
593
|
excludedProductGIDs: (t.excludedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
|
|
587
594
|
selectedProductGIDs: (t.selectedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
|
|
588
595
|
selectedCollectionGIDs: (t.selectedCollectionIds || []).map((e) => `gid://shopify/Collection/${e}`)
|
|
589
|
-
}) : await
|
|
596
|
+
}) : await f(e, {
|
|
590
597
|
country: n,
|
|
591
598
|
language: r,
|
|
592
599
|
blockVisibility: i.visibility,
|
|
@@ -594,14 +601,14 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
594
601
|
selectedProductGIDs: (i.selectedProducts || []).map(({ id: e }) => e),
|
|
595
602
|
selectedCollectionGIDs: (i.selectedCollections || []).map(({ id: e }) => e)
|
|
596
603
|
});
|
|
597
|
-
let o = await
|
|
604
|
+
let o = await m(e, {
|
|
598
605
|
country: n,
|
|
599
606
|
language: r,
|
|
600
607
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
601
608
|
useExternalMetafieldNamespace: !0
|
|
602
609
|
});
|
|
603
610
|
return o = o.filter((e) => e.availableForSale), o;
|
|
604
|
-
},
|
|
611
|
+
}, V = ({ language: e, dealBlockId: t }) => {
|
|
605
612
|
let n = {
|
|
606
613
|
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
607
614
|
"system.invalid_variant": "Sorry, this is not currently available.",
|
|
@@ -627,13 +634,13 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
627
634
|
"system.letters_only": "Only letters are allowed.",
|
|
628
635
|
"system.numbers_only": "Only numbers are allowed.",
|
|
629
636
|
"system.personalisation_required_alert": "Please add personalisation for every item to continue."
|
|
630
|
-
}, r = e ?
|
|
637
|
+
}, r = e ? H(e) : void 0;
|
|
631
638
|
return {
|
|
632
639
|
...n,
|
|
633
640
|
...r?.system,
|
|
634
641
|
...r?.dealBlocks[t]
|
|
635
642
|
};
|
|
636
|
-
},
|
|
643
|
+
}, H = (e) => {
|
|
637
644
|
if (typeof document > "u") return;
|
|
638
645
|
let t = document.querySelector("script#kaching-bundles-translations");
|
|
639
646
|
if (!t?.textContent) return;
|
|
@@ -643,19 +650,19 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
643
650
|
} catch {
|
|
644
651
|
return;
|
|
645
652
|
}
|
|
646
|
-
let r =
|
|
647
|
-
return n.find((e) =>
|
|
648
|
-
},
|
|
653
|
+
let r = U(e);
|
|
654
|
+
return n.find((e) => U(e.locale) === r)?.translations;
|
|
655
|
+
}, U = (e) => e.toLowerCase().replace(/_/g, "-"), de = "2026-07", W = async (e, { productId: t, dealBlockId: n, country: r = void 0, language: i = void 0 }) => {
|
|
649
656
|
try {
|
|
650
|
-
let a = [Number(t.split("/").pop())], o = new
|
|
657
|
+
let a = [Number(t.split("/").pop())], o = new fe(e);
|
|
651
658
|
r ||= o.i18n?.country, i ||= o.i18n?.language;
|
|
652
|
-
let s = await
|
|
659
|
+
let s = await x(o, {
|
|
653
660
|
language: i,
|
|
654
661
|
country: r,
|
|
655
662
|
useExternalMetafieldNamespace: !0
|
|
656
663
|
});
|
|
657
664
|
o.shopifyDomain = s.shopifyDomain;
|
|
658
|
-
let l = s.storefrontAccessToken ? new
|
|
665
|
+
let l = s.storefrontAccessToken ? new R(s.shopifyDomain, s.storefrontAccessToken) : o, [u, d] = await Promise.all([m(l, {
|
|
659
666
|
country: r,
|
|
660
667
|
language: i,
|
|
661
668
|
productIds: a,
|
|
@@ -665,21 +672,21 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
665
672
|
useMetaobjects: s.featureFlags.storefront_metaobjects
|
|
666
673
|
})]), f = u[0];
|
|
667
674
|
if (!f) return null;
|
|
668
|
-
let
|
|
669
|
-
if (n ? (h =
|
|
670
|
-
let g = w(h), _ =
|
|
671
|
-
|
|
675
|
+
let p = z(d, f), h;
|
|
676
|
+
if (n ? (h = p.find((e) => e.id === n || e.nanoId === n), h ||= p[0]) : h = p[0], !h) return null;
|
|
677
|
+
let g = w(h), _ = oe(h), [v, y, b, S] = await Promise.all([
|
|
678
|
+
m(l, {
|
|
672
679
|
country: r,
|
|
673
680
|
language: i,
|
|
674
681
|
productIds: _,
|
|
675
682
|
useExternalMetafieldNamespace: !0
|
|
676
683
|
}),
|
|
677
|
-
|
|
678
|
-
|
|
684
|
+
C(l, g, 300),
|
|
685
|
+
B(l, h, {
|
|
679
686
|
country: r,
|
|
680
687
|
language: i
|
|
681
688
|
}),
|
|
682
|
-
|
|
689
|
+
V({
|
|
683
690
|
language: i,
|
|
684
691
|
dealBlockId: h.id
|
|
685
692
|
})
|
|
@@ -690,13 +697,13 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
690
697
|
config: s,
|
|
691
698
|
otherProducts: v,
|
|
692
699
|
mediaImages: y,
|
|
693
|
-
collectionBreaksProducts:
|
|
694
|
-
translations:
|
|
700
|
+
collectionBreaksProducts: b ?? [],
|
|
701
|
+
translations: S
|
|
695
702
|
};
|
|
696
703
|
} catch (e) {
|
|
697
704
|
return console.error(e), null;
|
|
698
705
|
}
|
|
699
|
-
},
|
|
706
|
+
}, fe = class {
|
|
700
707
|
constructor(e) {
|
|
701
708
|
this.storefront = e, this.shopifyDomain = "";
|
|
702
709
|
}
|
|
@@ -709,7 +716,7 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
709
716
|
}
|
|
710
717
|
if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
|
|
711
718
|
if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
|
|
712
|
-
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${
|
|
719
|
+
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${de}/graphql.json`, {
|
|
713
720
|
body: JSON.stringify({
|
|
714
721
|
query: e,
|
|
715
722
|
variables: t?.variables
|
|
@@ -739,30 +746,45 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
739
746
|
get i18n() {
|
|
740
747
|
if ("i18n" in this.storefront) return this.storefront.i18n;
|
|
741
748
|
}
|
|
742
|
-
},
|
|
749
|
+
}, G = "kaching-bundles-block", K = 1e4, q = "/kaching-bundles-block.js", pe = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", me = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", J = /* @__PURE__ */ new WeakSet(), Y = async (e) => {
|
|
743
750
|
let t = e.document;
|
|
744
|
-
if (!e.customElements.get(
|
|
745
|
-
if (
|
|
746
|
-
|
|
751
|
+
if (!e.customElements.get(G)) {
|
|
752
|
+
if (J.has(t)) return Q(e, G);
|
|
753
|
+
J.add(t);
|
|
747
754
|
try {
|
|
748
|
-
await
|
|
755
|
+
await _e(e);
|
|
749
756
|
} catch (e) {
|
|
750
|
-
throw
|
|
757
|
+
throw J.delete(t), e;
|
|
751
758
|
}
|
|
752
759
|
}
|
|
753
|
-
},
|
|
754
|
-
let t = e.document;
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
760
|
+
}, he = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, ge = () => he() ? pe : me, _e = async (e) => {
|
|
761
|
+
let t = e.document, n = ge();
|
|
762
|
+
if (t.querySelector(`script[src="${n}"]`)) return Q(e, G);
|
|
763
|
+
let r = ve(t);
|
|
764
|
+
if (r && await X(t, r)) return Q(e, G);
|
|
765
|
+
let i = t.createElement("script");
|
|
766
|
+
return i.src = n, await Z(t, i), Q(e, G);
|
|
767
|
+
}, ve = (e) => {
|
|
768
|
+
let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);
|
|
769
|
+
return Array.from(t, (e) => e.href).find(ye);
|
|
770
|
+
}, ye = (e) => {
|
|
771
|
+
try {
|
|
772
|
+
return new URL(e).pathname.endsWith(q);
|
|
773
|
+
} catch {
|
|
774
|
+
return !1;
|
|
775
|
+
}
|
|
776
|
+
}, X = async (e, t) => {
|
|
777
|
+
let n = e.createElement("script");
|
|
778
|
+
n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
|
|
779
|
+
try {
|
|
780
|
+
return await Z(e, n), !0;
|
|
781
|
+
} catch {
|
|
782
|
+
return n.remove(), !1;
|
|
783
|
+
}
|
|
784
|
+
}, Z = (e, t) => new Promise((n, r) => {
|
|
785
|
+
t.onload = () => n(), t.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), e.head.appendChild(t);
|
|
786
|
+
}), Q = (e, t) => new Promise((n, r) => {
|
|
787
|
+
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);
|
|
766
788
|
});
|
|
767
789
|
[
|
|
768
790
|
"primaryBackground",
|
|
@@ -779,7 +801,7 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
779
801
|
].map((e) => `brand_${e}`);
|
|
780
802
|
var $ = /* @__PURE__ */ function(e) {
|
|
781
803
|
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
782
|
-
}({}),
|
|
804
|
+
}({}), be = {
|
|
783
805
|
config: {
|
|
784
806
|
shopifyDomain: "",
|
|
785
807
|
moneyFormat: "${{amount}}",
|
|
@@ -1178,7 +1200,7 @@ var $ = /* @__PURE__ */ function(e) {
|
|
|
1178
1200
|
mediaImages: [],
|
|
1179
1201
|
collectionBreaksProducts: [],
|
|
1180
1202
|
translations: {}
|
|
1181
|
-
},
|
|
1203
|
+
}, xe = class extends HTMLElement {
|
|
1182
1204
|
constructor(...e) {
|
|
1183
1205
|
super(...e), this.innerElement = null, this.handleItemsChanged = null, this.initializeId = 0;
|
|
1184
1206
|
}
|
|
@@ -1196,13 +1218,13 @@ var $ = /* @__PURE__ */ function(e) {
|
|
|
1196
1218
|
async initialize() {
|
|
1197
1219
|
let e = ++this.initializeId;
|
|
1198
1220
|
if (this.cleanup(), this.hasAttribute("demo")) {
|
|
1199
|
-
if (await
|
|
1200
|
-
this.renderInnerElement(
|
|
1221
|
+
if (await Y(window), e !== this.initializeId) return;
|
|
1222
|
+
this.renderInnerElement(be);
|
|
1201
1223
|
return;
|
|
1202
1224
|
}
|
|
1203
1225
|
let t = this.getAttribute("shop-domain"), n = this.getAttribute("storefront-token"), r = this.getAttribute("product-id");
|
|
1204
1226
|
if (!t || !n || !r) return;
|
|
1205
|
-
let [i] = await Promise.all([
|
|
1227
|
+
let [i] = await Promise.all([W({
|
|
1206
1228
|
shopifyDomain: t,
|
|
1207
1229
|
storefrontAccessToken: n
|
|
1208
1230
|
}, {
|
|
@@ -1210,7 +1232,7 @@ var $ = /* @__PURE__ */ function(e) {
|
|
|
1210
1232
|
dealBlockId: this.getAttribute("deal-block-id") ?? void 0,
|
|
1211
1233
|
country: this.getAttribute("country")?.toUpperCase() ?? void 0,
|
|
1212
1234
|
language: this.getAttribute("language")?.toUpperCase() ?? void 0
|
|
1213
|
-
}),
|
|
1235
|
+
}), Y(window)]);
|
|
1214
1236
|
i && e === this.initializeId && this.renderInnerElement(i);
|
|
1215
1237
|
}
|
|
1216
1238
|
renderInnerElement(e) {
|
|
@@ -1247,5 +1269,5 @@ var $ = /* @__PURE__ */ function(e) {
|
|
|
1247
1269
|
this.cleanup(), this.initializeId++;
|
|
1248
1270
|
}
|
|
1249
1271
|
};
|
|
1250
|
-
customElements.define("kaching-bundle-component",
|
|
1251
|
-
export {
|
|
1272
|
+
customElements.define("kaching-bundle-component", xe);
|
|
1273
|
+
export { W as fetchKachingBundlesData };
|