@kachingappz/bundles-js 1.1.7 → 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.
- package/dist/bundles-js.iife.js +39 -7
- package/dist/index.d.ts +19 -0
- package/dist/index.js +177 -95
- package/dist/kaching-bundle-component/index.d.ts +19 -0
- package/dist/kaching-bundle-component/index.js +202 -120
- package/dist/react/index.cjs +39 -7
- package/dist/react/index.d.ts +19 -0
- package/dist/react/index.js +197 -115
- package/package.json +3 -3
|
@@ -105,16 +105,16 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
105
105
|
return Array.from(new Set(i)).slice(0, c);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
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,
|
|
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, includeProductTabFields: l = !1, productSubtitleMetafield: u = "descriptors.subtitle", useExternalMetafieldNamespace: d = !1, batchSize: f = 250, onBatchError: m, variantImageTransform: v = {
|
|
109
109
|
maxWidth: 200,
|
|
110
110
|
maxHeight: 200
|
|
111
111
|
} }) => {
|
|
112
112
|
if (!r.length) return [];
|
|
113
|
-
let
|
|
113
|
+
let y = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), b = s({
|
|
114
114
|
country: t,
|
|
115
115
|
language: n
|
|
116
|
-
}),
|
|
117
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${
|
|
116
|
+
}), x = `
|
|
117
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $includeProductTabFields: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${b} {
|
|
118
118
|
shop {
|
|
119
119
|
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
120
120
|
value
|
|
@@ -177,6 +177,10 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
177
177
|
subtitle: metafield(namespace: $subtitleNamespace, key: $subtitleKey) @include(if: $includeProductSubtitle) {
|
|
178
178
|
value
|
|
179
179
|
}
|
|
180
|
+
category @include(if: $includeProductTabFields) {
|
|
181
|
+
id
|
|
182
|
+
}
|
|
183
|
+
tags @include(if: $includeProductTabFields)
|
|
180
184
|
requiresSellingPlan
|
|
181
185
|
sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
|
|
182
186
|
nodes {
|
|
@@ -184,6 +188,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
184
188
|
nodes {
|
|
185
189
|
id
|
|
186
190
|
name
|
|
191
|
+
recurringDeliveries
|
|
187
192
|
priceAdjustments {
|
|
188
193
|
adjustmentValue {
|
|
189
194
|
__typename
|
|
@@ -209,43 +214,63 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
209
214
|
}
|
|
210
215
|
}
|
|
211
216
|
}
|
|
212
|
-
`,
|
|
213
|
-
for (let e = 0; e <
|
|
214
|
-
let
|
|
215
|
-
let
|
|
216
|
-
productGIDs:
|
|
217
|
+
`, S = d ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", C = u.indexOf("."), w = u.slice(0, C), T = u.slice(C + 1), E = [], D = Math.min(f, 250);
|
|
218
|
+
for (let e = 0; e < y.length; e += D) E.push(y.slice(e, e + D));
|
|
219
|
+
let O = 1, k = async (n) => {
|
|
220
|
+
let [r, s] = await Promise.all([e.query(x, { variables: {
|
|
221
|
+
productGIDs: n,
|
|
217
222
|
includeSellingPlans: i,
|
|
218
223
|
includeAvailableQuantity: a,
|
|
219
224
|
includeProductRating: o,
|
|
220
225
|
includeProductSubtitle: c,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
226
|
+
includeProductTabFields: l,
|
|
227
|
+
subtitleNamespace: w,
|
|
228
|
+
subtitleKey: T,
|
|
229
|
+
metafieldNamespace: S,
|
|
230
|
+
variantImageTransform: v
|
|
231
|
+
} }), l ? h(e, t, n) : null]);
|
|
232
|
+
return r.shop.currencyRateConstant && (O = JSON.parse(r.shop.currencyRateConstant.value).amount / 1e6), s ? { nodes: r.nodes.map((e) => e && {
|
|
233
|
+
...e,
|
|
234
|
+
productType: s.get(e.id)
|
|
235
|
+
}) } : r;
|
|
236
|
+
}, A;
|
|
237
|
+
if (m) {
|
|
238
|
+
let e = await Promise.allSettled(E.map(k));
|
|
239
|
+
for (let t of e) t.status === "rejected" && m(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
|
|
240
|
+
A = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
|
|
241
|
+
} else A = (await Promise.all(E.map(k))).flatMap((e) => e.nodes);
|
|
242
|
+
let j = A.filter((e) => e != null);
|
|
243
|
+
if (m) {
|
|
244
|
+
let t = await Promise.allSettled(j.map(async (t) => _(await g(e, t, {
|
|
236
245
|
includeSellingPlans: i,
|
|
237
246
|
includeAvailableQuantity: a,
|
|
238
|
-
variantImageTransform:
|
|
239
|
-
},
|
|
240
|
-
for (let e of t) e.status === "fulfilled" ? n.push(e.value) :
|
|
247
|
+
variantImageTransform: v
|
|
248
|
+
}, b), e.shopifyDomain, O))), n = [];
|
|
249
|
+
for (let e of t) e.status === "fulfilled" ? n.push(e.value) : m(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
|
|
241
250
|
return n;
|
|
242
251
|
}
|
|
243
|
-
return (await Promise.all(
|
|
252
|
+
return (await Promise.all(j.map((t) => g(e, t, {
|
|
244
253
|
includeSellingPlans: i,
|
|
245
254
|
includeAvailableQuantity: a,
|
|
246
|
-
variantImageTransform:
|
|
247
|
-
},
|
|
248
|
-
}, h = async (e, t, n
|
|
255
|
+
variantImageTransform: v
|
|
256
|
+
}, b)))).map((t) => _(t, e.shopifyDomain, O));
|
|
257
|
+
}, h = async (e, t, n) => {
|
|
258
|
+
try {
|
|
259
|
+
let r = await e.query(`
|
|
260
|
+
query FetchProductTypes($productGIDs: [ID!]!) ${s({ country: t })} {
|
|
261
|
+
nodes(ids: $productGIDs) {
|
|
262
|
+
... on Product {
|
|
263
|
+
id
|
|
264
|
+
productType
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
`, { variables: { productGIDs: n } });
|
|
269
|
+
return new Map(r.nodes.filter((e) => e != null).map((e) => [e.id, e.productType]));
|
|
270
|
+
} catch (e) {
|
|
271
|
+
return console.error(e), null;
|
|
272
|
+
}
|
|
273
|
+
}, g = async (e, t, n, r = "") => {
|
|
249
274
|
if (t.variants.nodes.length < 250) return t;
|
|
250
275
|
let i = /* @__PURE__ */ new Set(), a = [], o = [], s = async (s) => {
|
|
251
276
|
let c = !0, l = null;
|
|
@@ -281,7 +306,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
281
306
|
}
|
|
282
307
|
};
|
|
283
308
|
return await Promise.all([s(!1), s(!0)]), t.variants.nodes = [...a, ...o.reverse()], t;
|
|
284
|
-
},
|
|
309
|
+
}, _ = (e, t, n) => {
|
|
285
310
|
let r = e.variants.nodes.map(({ unitPriceMeasurement: e, ...t }) => ({
|
|
286
311
|
id: Number(t.id.split("/").pop()),
|
|
287
312
|
availableForSale: t.availableForSale,
|
|
@@ -319,7 +344,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
319
344
|
defaultName: e.name,
|
|
320
345
|
name: e.name,
|
|
321
346
|
position: t + 1,
|
|
322
|
-
optionValues:
|
|
347
|
+
optionValues: b(n, t, r)
|
|
323
348
|
};
|
|
324
349
|
}), a = (e) => {
|
|
325
350
|
let t = e.priceAdjustments[0];
|
|
@@ -343,6 +368,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
343
368
|
}, o = (e) => n === 1 ? Number(e) * 100 : Math.round(Number(e) * 100 * n), s = e.sellingPlanGroups?.nodes.flatMap((e) => e.sellingPlans.nodes.map((e) => ({
|
|
344
369
|
id: Number(e.id.split("/").pop()),
|
|
345
370
|
name: e.name,
|
|
371
|
+
recurringDeliveries: e.recurringDeliveries,
|
|
346
372
|
priceAdjustment: a(e)
|
|
347
373
|
}))) || [], c = e.variants.nodes.some((e) => e.requiresComponents);
|
|
348
374
|
return {
|
|
@@ -366,27 +392,45 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
366
392
|
text3: e.metafield3?.value || null,
|
|
367
393
|
text4: e.metafield4?.value || null
|
|
368
394
|
},
|
|
369
|
-
rating:
|
|
370
|
-
subtitle: e.subtitle?.value || null
|
|
395
|
+
rating: v(e.reviewsRating, e.reviewsRatingCount),
|
|
396
|
+
subtitle: e.subtitle?.value || null,
|
|
397
|
+
productType: e.productType || null,
|
|
398
|
+
categoryGid: e.category?.id ?? null,
|
|
399
|
+
tags: e.tags ?? []
|
|
371
400
|
};
|
|
372
|
-
},
|
|
401
|
+
}, v = (e, t) => {
|
|
373
402
|
if (!e) return null;
|
|
374
|
-
let n =
|
|
403
|
+
let n = y(e.value);
|
|
375
404
|
if (n === null) return null;
|
|
376
405
|
let r = Number(t?.value);
|
|
377
406
|
return {
|
|
378
407
|
value: n,
|
|
379
408
|
count: Number.isInteger(r) && r > 0 ? r : null
|
|
380
409
|
};
|
|
381
|
-
},
|
|
410
|
+
}, y = (e) => {
|
|
382
411
|
try {
|
|
383
412
|
let { value: t, scale_max: n } = JSON.parse(e), r = Number(t) / Number(n) * 5;
|
|
384
413
|
return Number.isFinite(r) && r > 0 ? Math.min(5, r) : null;
|
|
385
414
|
} catch {
|
|
386
415
|
return null;
|
|
387
416
|
}
|
|
388
|
-
},
|
|
389
|
-
|
|
417
|
+
}, b = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0);
|
|
418
|
+
[
|
|
419
|
+
"primaryBackground",
|
|
420
|
+
"secondaryBackground",
|
|
421
|
+
"primaryText",
|
|
422
|
+
"secondaryText",
|
|
423
|
+
"border",
|
|
424
|
+
"overlay",
|
|
425
|
+
"primaryAccent",
|
|
426
|
+
"primaryAccentText",
|
|
427
|
+
"badgeBackground",
|
|
428
|
+
"badgeText",
|
|
429
|
+
"error"
|
|
430
|
+
].map((e) => `brand_${e}`);
|
|
431
|
+
// ../bundles-storefront-api/dist/fetchGlobalConfig.js
|
|
432
|
+
var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalMetafieldNamespace: i }) => {
|
|
433
|
+
let a = i ? `${x}--kaching_bundles` : "$app:kaching_bundles", o = i ? x : "$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(`
|
|
390
434
|
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${c} {
|
|
391
435
|
localization {
|
|
392
436
|
country {
|
|
@@ -417,7 +461,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
417
461
|
} }), h = l === d ? u : e(l, {
|
|
418
462
|
language: n,
|
|
419
463
|
country: r
|
|
420
|
-
}), g = f ?
|
|
464
|
+
}), g = f ? C(f.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
|
|
421
465
|
return {
|
|
422
466
|
shopifyDomain: p.host,
|
|
423
467
|
moneyFormat: h,
|
|
@@ -478,7 +522,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
478
522
|
featureFlags: v,
|
|
479
523
|
brandColors: _?.brand_colors ?? null
|
|
480
524
|
};
|
|
481
|
-
},
|
|
525
|
+
}, C = (e) => JSON.parse(e).amount / 1e6, w = async (e, t, n = 200) => {
|
|
482
526
|
let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
|
|
483
527
|
if (r.length === 0) return [];
|
|
484
528
|
let i = [];
|
|
@@ -490,77 +534,103 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
490
534
|
gid: e.id,
|
|
491
535
|
url: e.image.url
|
|
492
536
|
}] : []);
|
|
493
|
-
},
|
|
494
|
-
...
|
|
495
|
-
|
|
496
|
-
|
|
537
|
+
}, T = 100, E = async (e, { dealBlock: t, country: n, language: r }) => {
|
|
538
|
+
let i = [...new Set(t.dealBars.flatMap((e) => e.dealBarType === d.MixAndMatch ? e.bundleProducts : []).flatMap((e) => (e.selectedCollections ?? []).map((e) => e.id)))];
|
|
539
|
+
if (i.length === 0) return [];
|
|
540
|
+
let a = s({
|
|
541
|
+
country: n,
|
|
542
|
+
language: r
|
|
543
|
+
}), o = await e.query(`
|
|
544
|
+
query FetchMixAndMatchCollectionProductGIDs($collectionGIDs: [ID!]!) ${a} {
|
|
545
|
+
nodes(ids: $collectionGIDs) {
|
|
546
|
+
... on Collection {
|
|
547
|
+
id
|
|
548
|
+
products(first: ${T}) {
|
|
549
|
+
nodes {
|
|
550
|
+
id
|
|
551
|
+
variants(first: 1) {
|
|
552
|
+
nodes {
|
|
553
|
+
requiresComponents
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
`, { variables: { collectionGIDs: i } });
|
|
562
|
+
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))];
|
|
563
|
+
}, D = (e) => [
|
|
497
564
|
...O(e),
|
|
498
565
|
...k(e),
|
|
499
566
|
...A(e),
|
|
500
567
|
...j(e),
|
|
501
568
|
...ee(e),
|
|
502
569
|
...te(e),
|
|
570
|
+
...M(e),
|
|
503
571
|
...ne(e),
|
|
572
|
+
...N(e),
|
|
573
|
+
...P(e),
|
|
504
574
|
...re(e),
|
|
505
575
|
...ie(e),
|
|
506
576
|
...ae(e)
|
|
507
|
-
].filter((e) => e != null && !e.includes("placeholder")),
|
|
577
|
+
].filter((e) => e != null && !e.includes("placeholder")), O = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), k = (e) => e.dealBars.flatMap((e) => e.dealBarType === d.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), A = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), j = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), ee = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), te = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
|
|
508
578
|
let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
|
|
509
579
|
return [...e, ...n];
|
|
510
|
-
}, []) : [],
|
|
580
|
+
}, []) : [], M = (e) => {
|
|
511
581
|
if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
|
|
512
582
|
let t = e.collectionBreaks.mediaImageGID;
|
|
513
583
|
return t ? [t] : [];
|
|
514
|
-
},
|
|
584
|
+
}, ne = (e) => e.progressiveGifts ? [
|
|
515
585
|
...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
|
|
516
586
|
e.progressiveGifts.style?.lockedMediaImageGID,
|
|
517
587
|
e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
|
|
518
|
-
].filter((e) => e != null) : [],
|
|
588
|
+
].filter((e) => e != null) : [], N = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), P = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), re = (e) => {
|
|
519
589
|
let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
|
|
520
590
|
return n ? [...t, n] : t;
|
|
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) => {
|
|
522
|
-
let
|
|
591
|
+
}, 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, { includeMixAndMatchSwapProducts: t = !0 } = {}) => {
|
|
592
|
+
let n = [
|
|
523
593
|
...se(e),
|
|
524
594
|
...ce(e),
|
|
525
595
|
...le(e),
|
|
526
596
|
...ue(e),
|
|
527
|
-
...
|
|
528
|
-
...
|
|
529
|
-
...
|
|
530
|
-
...
|
|
597
|
+
...F(e),
|
|
598
|
+
...I(e, t),
|
|
599
|
+
...L(e),
|
|
600
|
+
...R(e)
|
|
531
601
|
];
|
|
532
|
-
return Array.from(new Set(
|
|
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),
|
|
602
|
+
return Array.from(new Set(n.filter((e) => e != null)));
|
|
603
|
+
}, 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), F = (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"), I = (e, t) => e.dealBars.filter((e) => e.dealBarType === d.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"), L = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), R = (e) => e.dealBars.filter((e) => e.dealBarType === d.Sku).flatMap(({ productGID: e }) => e ? [e] : []), z = class extends Error {
|
|
534
604
|
constructor({ status: e, operationName: t, graphqlErrors: n }) {
|
|
535
605
|
let r = n.length ? `: ${n.join("; ")}` : "";
|
|
536
606
|
super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
|
|
537
607
|
}
|
|
538
|
-
},
|
|
608
|
+
}, B = async (e, t) => {
|
|
539
609
|
let n = await e.text();
|
|
540
610
|
if (!n) throw Error("Empty graphql response");
|
|
541
611
|
let r;
|
|
542
612
|
try {
|
|
543
613
|
r = JSON.parse(n);
|
|
544
614
|
} catch (n) {
|
|
545
|
-
throw e.ok ? n : new
|
|
615
|
+
throw e.ok ? n : new z({
|
|
546
616
|
status: e.status,
|
|
547
617
|
operationName: t,
|
|
548
618
|
graphqlErrors: []
|
|
549
619
|
});
|
|
550
620
|
}
|
|
551
|
-
if (!e.ok || r.data === null || r.data === void 0) throw new
|
|
621
|
+
if (!e.ok || r.data === null || r.data === void 0) throw new z({
|
|
552
622
|
status: e.status,
|
|
553
623
|
operationName: t,
|
|
554
624
|
graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
|
|
555
625
|
});
|
|
556
626
|
return r.data;
|
|
557
|
-
},
|
|
627
|
+
}, V = class {
|
|
558
628
|
constructor(e, t) {
|
|
559
629
|
this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
|
|
560
630
|
}
|
|
561
631
|
async query(e, t) {
|
|
562
632
|
let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
|
|
563
|
-
return i && (r += `?operation_name=${i}`),
|
|
633
|
+
return i && (r += `?operation_name=${i}`), B(await fetch(r, {
|
|
564
634
|
method: "POST",
|
|
565
635
|
headers: {
|
|
566
636
|
"Content-Type": "application/json",
|
|
@@ -572,7 +642,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
572
642
|
})
|
|
573
643
|
}), i);
|
|
574
644
|
}
|
|
575
|
-
},
|
|
645
|
+
}, H = (e, t) => {
|
|
576
646
|
let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
|
|
577
647
|
for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
|
|
578
648
|
let i = e.filter((e) => e.blockVisibility === "selected-collections");
|
|
@@ -582,7 +652,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
582
652
|
let o = e.filter((e) => e.blockVisibility === "all-products");
|
|
583
653
|
for (let e of o) n.push(e);
|
|
584
654
|
return n;
|
|
585
|
-
},
|
|
655
|
+
}, U = async (e, t, { country: n, language: r }) => {
|
|
586
656
|
let i = t.collectionBreaks;
|
|
587
657
|
if (!t.collectionBreaksEnabled || !i) return;
|
|
588
658
|
let a;
|
|
@@ -606,9 +676,9 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
606
676
|
language: r,
|
|
607
677
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
608
678
|
useExternalMetafieldNamespace: !0
|
|
609
|
-
});
|
|
610
|
-
return o = o.filter((e) => e.availableForSale), o;
|
|
611
|
-
},
|
|
679
|
+
}), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
|
|
680
|
+
return o = o.filter((e) => e.availableForSale && (!s || H([t], e).length > 0)), o;
|
|
681
|
+
}, de = ({ language: e, dealBlockId: t }) => {
|
|
612
682
|
let n = {
|
|
613
683
|
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
614
684
|
"system.invalid_variant": "Sorry, this is not currently available.",
|
|
@@ -635,13 +705,13 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
635
705
|
"system.numbers_only": "Only numbers are allowed.",
|
|
636
706
|
"system.personalisation_required_alert": "Please add personalisation for every item to continue.",
|
|
637
707
|
"system.gifts_required_alert": "Please choose your free gifts"
|
|
638
|
-
}, r = e ?
|
|
708
|
+
}, r = e ? fe(e) : void 0;
|
|
639
709
|
return {
|
|
640
710
|
...n,
|
|
641
711
|
...r?.system,
|
|
642
712
|
...r?.dealBlocks[t]
|
|
643
713
|
};
|
|
644
|
-
},
|
|
714
|
+
}, fe = (e) => {
|
|
645
715
|
if (typeof document > "u") return;
|
|
646
716
|
let t = document.querySelector("script#kaching-bundles-translations");
|
|
647
717
|
if (!t?.textContent) return;
|
|
@@ -651,19 +721,19 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
651
721
|
} catch {
|
|
652
722
|
return;
|
|
653
723
|
}
|
|
654
|
-
let r =
|
|
655
|
-
return n.find((e) =>
|
|
656
|
-
},
|
|
724
|
+
let r = W(e);
|
|
725
|
+
return n.find((e) => W(e.locale) === r)?.translations;
|
|
726
|
+
}, W = (e) => e.toLowerCase().replace(/_/g, "-"), pe = "2026-07", G = async (e, { productId: t, dealBlockId: n, abTestVariantId: r, country: i = void 0, language: a = void 0 }) => {
|
|
657
727
|
try {
|
|
658
|
-
let o = [Number(t.split("/").pop())], s = new
|
|
728
|
+
let o = [Number(t.split("/").pop())], s = new me(e);
|
|
659
729
|
i ||= s.i18n?.country, a ||= s.i18n?.language;
|
|
660
|
-
let l = await
|
|
730
|
+
let l = await S(s, {
|
|
661
731
|
language: a,
|
|
662
732
|
country: i,
|
|
663
733
|
useExternalMetafieldNamespace: !0
|
|
664
734
|
});
|
|
665
735
|
s.shopifyDomain = l.shopifyDomain;
|
|
666
|
-
let u = l.storefrontAccessToken ? new
|
|
736
|
+
let u = l.storefrontAccessToken ? new V(l.shopifyDomain, l.storefrontAccessToken) : s, [d, f] = await Promise.all([m(u, {
|
|
667
737
|
country: i,
|
|
668
738
|
language: a,
|
|
669
739
|
productIds: o,
|
|
@@ -673,21 +743,33 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
673
743
|
useMetaobjects: l.featureFlags.storefront_metaobjects
|
|
674
744
|
})]), p = d[0];
|
|
675
745
|
if (!p) return null;
|
|
676
|
-
let h =
|
|
746
|
+
let h = H(f, p), g = n ? h.filter((e) => e.id === n || e.nanoId === n) : h, _ = (r ? g.find((e) => e.abTestVariantId === r) : void 0) ?? g[0] ?? h[0];
|
|
677
747
|
if (!_) return null;
|
|
678
|
-
let v =
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
748
|
+
let v = D(_), [y, b, x, C] = await Promise.all([
|
|
749
|
+
(async () => {
|
|
750
|
+
let e = [];
|
|
751
|
+
try {
|
|
752
|
+
e = await E(u, {
|
|
753
|
+
dealBlock: _,
|
|
754
|
+
country: i,
|
|
755
|
+
language: a
|
|
756
|
+
});
|
|
757
|
+
} catch (e) {
|
|
758
|
+
console.error(e);
|
|
759
|
+
}
|
|
760
|
+
return m(u, {
|
|
761
|
+
country: i,
|
|
762
|
+
language: a,
|
|
763
|
+
productIds: [.../* @__PURE__ */ new Set([...oe(_), ...e])],
|
|
764
|
+
useExternalMetafieldNamespace: !0
|
|
765
|
+
});
|
|
766
|
+
})(),
|
|
767
|
+
w(u, v, 300),
|
|
768
|
+
U(u, _, {
|
|
687
769
|
country: i,
|
|
688
770
|
language: a
|
|
689
771
|
}),
|
|
690
|
-
|
|
772
|
+
de({
|
|
691
773
|
language: a,
|
|
692
774
|
dealBlockId: _.id
|
|
693
775
|
})
|
|
@@ -696,15 +778,15 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
696
778
|
product: p,
|
|
697
779
|
dealBlock: _,
|
|
698
780
|
config: l,
|
|
699
|
-
otherProducts:
|
|
700
|
-
mediaImages:
|
|
701
|
-
collectionBreaksProducts:
|
|
702
|
-
translations:
|
|
781
|
+
otherProducts: y,
|
|
782
|
+
mediaImages: b,
|
|
783
|
+
collectionBreaksProducts: x ?? [],
|
|
784
|
+
translations: C
|
|
703
785
|
};
|
|
704
786
|
} catch (e) {
|
|
705
787
|
return console.error(e), null;
|
|
706
788
|
}
|
|
707
|
-
},
|
|
789
|
+
}, me = class {
|
|
708
790
|
constructor(e) {
|
|
709
791
|
this.storefront = e, this.shopifyDomain = "";
|
|
710
792
|
}
|
|
@@ -717,7 +799,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
717
799
|
}
|
|
718
800
|
if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
|
|
719
801
|
if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
|
|
720
|
-
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${
|
|
802
|
+
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${pe}/graphql.json`, {
|
|
721
803
|
body: JSON.stringify({
|
|
722
804
|
query: e,
|
|
723
805
|
variables: t?.variables
|
|
@@ -747,34 +829,34 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
747
829
|
get i18n() {
|
|
748
830
|
if ("i18n" in this.storefront) return this.storefront.i18n;
|
|
749
831
|
}
|
|
750
|
-
},
|
|
832
|
+
}, K = "kaching-bundles-block", q = 1e4, J = "/kaching-bundles-block.js", he = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", ge = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", Y = /* @__PURE__ */ new WeakSet(), X = async (e) => {
|
|
751
833
|
let t = e.document;
|
|
752
|
-
if (!e.customElements.get(
|
|
753
|
-
if (
|
|
754
|
-
|
|
834
|
+
if (!e.customElements.get(K)) {
|
|
835
|
+
if (Y.has(t)) return Q(e, K);
|
|
836
|
+
Y.add(t);
|
|
755
837
|
try {
|
|
756
|
-
await
|
|
838
|
+
await ye(e);
|
|
757
839
|
} catch (e) {
|
|
758
|
-
throw
|
|
840
|
+
throw Y.delete(t), e;
|
|
759
841
|
}
|
|
760
842
|
}
|
|
761
|
-
},
|
|
762
|
-
let t = e.document, n =
|
|
763
|
-
if (t.querySelector(`script[src="${n}"]`)) return Q(e,
|
|
764
|
-
let r =
|
|
765
|
-
if (r && await
|
|
843
|
+
}, _e = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, ve = () => _e() ? he : ge, ye = async (e) => {
|
|
844
|
+
let t = e.document, n = ve();
|
|
845
|
+
if (t.querySelector(`script[src="${n}"]`)) return Q(e, K);
|
|
846
|
+
let r = be(t);
|
|
847
|
+
if (r && await Se(t, r)) return Q(e, K);
|
|
766
848
|
let i = t.createElement("script");
|
|
767
|
-
return i.src = n, await Z(t, i), Q(e,
|
|
768
|
-
},
|
|
769
|
-
let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${
|
|
770
|
-
return Array.from(t, (e) => e.href).find(
|
|
771
|
-
},
|
|
849
|
+
return i.src = n, await Z(t, i), Q(e, K);
|
|
850
|
+
}, be = (e) => {
|
|
851
|
+
let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${J}"]`);
|
|
852
|
+
return Array.from(t, (e) => e.href).find(xe);
|
|
853
|
+
}, xe = (e) => {
|
|
772
854
|
try {
|
|
773
|
-
return new URL(e).pathname.endsWith(
|
|
855
|
+
return new URL(e).pathname.endsWith(J);
|
|
774
856
|
} catch {
|
|
775
857
|
return !1;
|
|
776
858
|
}
|
|
777
|
-
},
|
|
859
|
+
}, Se = async (e, t) => {
|
|
778
860
|
let n = e.createElement("script");
|
|
779
861
|
n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
|
|
780
862
|
try {
|
|
@@ -785,7 +867,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
785
867
|
}, Z = (e, t) => new Promise((n, r) => {
|
|
786
868
|
t.onload = () => n(), t.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), e.head.appendChild(t);
|
|
787
869
|
}), Q = (e, t) => new Promise((n, r) => {
|
|
788
|
-
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 ${
|
|
870
|
+
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);
|
|
789
871
|
});
|
|
790
872
|
[
|
|
791
873
|
"primaryBackground",
|
|
@@ -802,7 +884,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
802
884
|
].map((e) => `brand_${e}`);
|
|
803
885
|
var $ = /* @__PURE__ */ function(e) {
|
|
804
886
|
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
805
|
-
}({}),
|
|
887
|
+
}({}), Ce = {
|
|
806
888
|
config: {
|
|
807
889
|
shopifyDomain: "",
|
|
808
890
|
moneyFormat: "${{amount}}",
|
|
@@ -1201,7 +1283,7 @@ var $ = /* @__PURE__ */ function(e) {
|
|
|
1201
1283
|
mediaImages: [],
|
|
1202
1284
|
collectionBreaksProducts: [],
|
|
1203
1285
|
translations: {}
|
|
1204
|
-
},
|
|
1286
|
+
}, we = class extends HTMLElement {
|
|
1205
1287
|
constructor(...e) {
|
|
1206
1288
|
super(...e), this.innerElement = null, this.handleItemsChanged = null, this.initializeId = 0;
|
|
1207
1289
|
}
|
|
@@ -1219,13 +1301,13 @@ var $ = /* @__PURE__ */ function(e) {
|
|
|
1219
1301
|
async initialize() {
|
|
1220
1302
|
let e = ++this.initializeId;
|
|
1221
1303
|
if (this.cleanup(), this.hasAttribute("demo")) {
|
|
1222
|
-
if (await
|
|
1223
|
-
this.renderInnerElement(
|
|
1304
|
+
if (await X(window), e !== this.initializeId) return;
|
|
1305
|
+
this.renderInnerElement(Ce);
|
|
1224
1306
|
return;
|
|
1225
1307
|
}
|
|
1226
1308
|
let t = this.getAttribute("shop-domain"), n = this.getAttribute("storefront-token"), r = this.getAttribute("product-id");
|
|
1227
1309
|
if (!t || !n || !r) return;
|
|
1228
|
-
let [i] = await Promise.all([
|
|
1310
|
+
let [i] = await Promise.all([G({
|
|
1229
1311
|
shopifyDomain: t,
|
|
1230
1312
|
storefrontAccessToken: n
|
|
1231
1313
|
}, {
|
|
@@ -1234,7 +1316,7 @@ var $ = /* @__PURE__ */ function(e) {
|
|
|
1234
1316
|
abTestVariantId: this.getAttribute("ab-test-variant-id") ?? void 0,
|
|
1235
1317
|
country: this.getAttribute("country")?.toUpperCase() ?? void 0,
|
|
1236
1318
|
language: this.getAttribute("language")?.toUpperCase() ?? void 0
|
|
1237
|
-
}),
|
|
1319
|
+
}), X(window)]);
|
|
1238
1320
|
i && e === this.initializeId && this.renderInnerElement(i);
|
|
1239
1321
|
}
|
|
1240
1322
|
renderInnerElement(e) {
|
|
@@ -1271,5 +1353,5 @@ var $ = /* @__PURE__ */ function(e) {
|
|
|
1271
1353
|
this.cleanup(), this.initializeId++;
|
|
1272
1354
|
}
|
|
1273
1355
|
};
|
|
1274
|
-
customElements.define("kaching-bundle-component",
|
|
1275
|
-
export {
|
|
1356
|
+
customElements.define("kaching-bundle-component", we);
|
|
1357
|
+
export { G as fetchKachingBundlesData };
|