@kachingappz/bundles-js 1.1.8 → 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.
- package/dist/bundles-js.iife.js +39 -7
- package/dist/index.d.ts +31 -7
- package/dist/index.js +237 -94
- package/dist/kaching-bundle-component/index.d.ts +31 -7
- package/dist/kaching-bundle-component/index.js +288 -156
- package/dist/react/index.cjs +39 -7
- package/dist/react/index.d.ts +31 -7
- package/dist/react/index.js +277 -148
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -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
|
...M(e),
|
|
502
569
|
...N(e),
|
|
570
|
+
...ee(e),
|
|
571
|
+
...te(e),
|
|
503
572
|
...P(e),
|
|
504
573
|
...F(e),
|
|
505
574
|
...I(e),
|
|
506
|
-
...L(e)
|
|
507
|
-
|
|
575
|
+
...L(e),
|
|
576
|
+
...R(e)
|
|
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), M = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), N = (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
|
+
}, []) : [], ee = (e) => {
|
|
511
581
|
if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
|
|
512
582
|
let t = e.collectionBreaks.mediaImageGID;
|
|
513
583
|
return t ? [t] : [];
|
|
514
|
-
},
|
|
584
|
+
}, te = (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) : [], P = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), F = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), I = (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
|
-
},
|
|
522
|
-
let
|
|
523
|
-
...z(e),
|
|
591
|
+
}, L = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), R = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], z = (e, { includeMixAndMatchSwapProducts: t = !0 } = {}) => {
|
|
592
|
+
let n = [
|
|
524
593
|
...B(e),
|
|
525
594
|
...V(e),
|
|
526
595
|
...H(e),
|
|
527
596
|
...U(e),
|
|
528
597
|
...W(e),
|
|
529
|
-
...G(e),
|
|
530
|
-
...K(e)
|
|
598
|
+
...G(e, t),
|
|
599
|
+
...K(e),
|
|
600
|
+
...q(e)
|
|
531
601
|
];
|
|
532
|
-
return Array.from(new Set(
|
|
533
|
-
},
|
|
602
|
+
return Array.from(new Set(n.filter((e) => e != null)));
|
|
603
|
+
}, B = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), V = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), H = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], U = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), W = (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"), G = (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"), K = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), q = (e) => e.dealBars.filter((e) => e.dealBarType === d.Sku).flatMap(({ productGID: e }) => e ? [e] : []), J = 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
|
+
}, Y = 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 J({
|
|
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 J({
|
|
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
|
+
}, X = 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}`), Y(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
|
+
}, Z = (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,23 @@ 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
|
+
};
|
|
656
|
+
[
|
|
657
|
+
"primaryBackground",
|
|
658
|
+
"secondaryBackground",
|
|
659
|
+
"primaryText",
|
|
660
|
+
"secondaryText",
|
|
661
|
+
"border",
|
|
662
|
+
"overlay",
|
|
663
|
+
"primaryAccent",
|
|
664
|
+
"primaryAccentText",
|
|
665
|
+
"badgeBackground",
|
|
666
|
+
"badgeText",
|
|
667
|
+
"error"
|
|
668
|
+
].map((e) => `brand_${e}`);
|
|
669
|
+
var ne = /* @__PURE__ */ function(e) {
|
|
670
|
+
return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
|
|
671
|
+
}({}), re = async (e, t, { country: n, language: r }) => {
|
|
586
672
|
let i = t.collectionBreaks;
|
|
587
673
|
if (!t.collectionBreaksEnabled || !i) return;
|
|
588
674
|
let a;
|
|
@@ -607,8 +693,8 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
607
693
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
608
694
|
useExternalMetafieldNamespace: !0
|
|
609
695
|
}), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
|
|
610
|
-
return o = o.filter((e) => e.availableForSale && (!s ||
|
|
611
|
-
},
|
|
696
|
+
return o = o.filter((e) => e.availableForSale && (!s || Z([t], e).length > 0)), o;
|
|
697
|
+
}, ie = ({ language: e, dealBlockId: t }) => {
|
|
612
698
|
let n = {
|
|
613
699
|
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
614
700
|
"system.invalid_variant": "Sorry, this is not currently available.",
|
|
@@ -635,13 +721,13 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
635
721
|
"system.numbers_only": "Only numbers are allowed.",
|
|
636
722
|
"system.personalisation_required_alert": "Please add personalisation for every item to continue.",
|
|
637
723
|
"system.gifts_required_alert": "Please choose your free gifts"
|
|
638
|
-
}, r = e ?
|
|
724
|
+
}, r = e ? ae(e) : void 0;
|
|
639
725
|
return {
|
|
640
726
|
...n,
|
|
641
727
|
...r?.system,
|
|
642
728
|
...r?.dealBlocks[t]
|
|
643
729
|
};
|
|
644
|
-
},
|
|
730
|
+
}, ae = (e) => {
|
|
645
731
|
if (typeof document > "u") return;
|
|
646
732
|
let t = document.querySelector("script#kaching-bundles-translations");
|
|
647
733
|
if (!t?.textContent) return;
|
|
@@ -651,19 +737,19 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
651
737
|
} catch {
|
|
652
738
|
return;
|
|
653
739
|
}
|
|
654
|
-
let r =
|
|
655
|
-
return n.find((e) =>
|
|
656
|
-
},
|
|
740
|
+
let r = Q(e);
|
|
741
|
+
return n.find((e) => Q(e.locale) === r)?.translations;
|
|
742
|
+
}, Q = (e) => e.toLowerCase().replace(/_/g, "-"), oe = "2026-07", $ = async (e, { productId: t, dealBlockId: n, abTestVariantId: r, country: i = void 0, language: a = void 0 }) => {
|
|
657
743
|
try {
|
|
658
|
-
let o = [Number(t.split("/").pop())], s = new
|
|
744
|
+
let o = [Number(t.split("/").pop())], s = new de(e);
|
|
659
745
|
i ||= s.i18n?.country, a ||= s.i18n?.language;
|
|
660
|
-
let l = await
|
|
746
|
+
let l = await S(s, {
|
|
661
747
|
language: a,
|
|
662
748
|
country: i,
|
|
663
749
|
useExternalMetafieldNamespace: !0
|
|
664
750
|
});
|
|
665
751
|
s.shopifyDomain = l.shopifyDomain;
|
|
666
|
-
let u = l.storefrontAccessToken ? new
|
|
752
|
+
let u = l.storefrontAccessToken ? new X(l.shopifyDomain, l.storefrontAccessToken) : s, [d, f] = await Promise.all([m(u, {
|
|
667
753
|
country: i,
|
|
668
754
|
language: a,
|
|
669
755
|
productIds: o,
|
|
@@ -673,38 +759,77 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
673
759
|
useMetaobjects: l.featureFlags.storefront_metaobjects
|
|
674
760
|
})]), p = d[0];
|
|
675
761
|
if (!p) return null;
|
|
676
|
-
let h =
|
|
762
|
+
let h = Z(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
763
|
if (!_) return null;
|
|
678
|
-
let v =
|
|
764
|
+
let v = z(_, { includeMixAndMatchSwapProducts: !1 }), y = se(u, _, {
|
|
765
|
+
otherProductGIDs: v,
|
|
766
|
+
country: i,
|
|
767
|
+
language: a
|
|
768
|
+
}), [b, x, C] = await Promise.all([
|
|
679
769
|
m(u, {
|
|
680
770
|
country: i,
|
|
681
771
|
language: a,
|
|
682
|
-
productIds:
|
|
772
|
+
productIds: v,
|
|
683
773
|
useExternalMetafieldNamespace: !0
|
|
684
774
|
}),
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
country: i,
|
|
688
|
-
language: a
|
|
689
|
-
}),
|
|
690
|
-
Q({
|
|
775
|
+
w(u, D(_), 300),
|
|
776
|
+
ie({
|
|
691
777
|
language: a,
|
|
692
778
|
dealBlockId: _.id
|
|
693
779
|
})
|
|
694
780
|
]);
|
|
695
781
|
return {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
782
|
+
data: {
|
|
783
|
+
config: l,
|
|
784
|
+
dealBlock: _,
|
|
785
|
+
product: p,
|
|
786
|
+
otherProducts: b,
|
|
787
|
+
mediaImages: x,
|
|
788
|
+
translations: C
|
|
789
|
+
},
|
|
790
|
+
modalProducts: y
|
|
703
791
|
};
|
|
704
792
|
} catch (e) {
|
|
705
793
|
return console.error(e), null;
|
|
706
794
|
}
|
|
707
|
-
},
|
|
795
|
+
}, se = async (e, t, n) => {
|
|
796
|
+
let [r, i] = await Promise.all([ce(e, t, n), ue(e, t, n)]);
|
|
797
|
+
return {
|
|
798
|
+
mixAndMatchSwapProducts: r,
|
|
799
|
+
collectionBreaksProducts: i
|
|
800
|
+
};
|
|
801
|
+
}, ce = async (e, t, { otherProductGIDs: n, country: r, language: i }) => {
|
|
802
|
+
try {
|
|
803
|
+
let a = [];
|
|
804
|
+
try {
|
|
805
|
+
a = await E(e, {
|
|
806
|
+
dealBlock: t,
|
|
807
|
+
country: r,
|
|
808
|
+
language: i
|
|
809
|
+
});
|
|
810
|
+
} catch (e) {
|
|
811
|
+
console.error(e);
|
|
812
|
+
}
|
|
813
|
+
let o = new Set(n), s = [.../* @__PURE__ */ new Set([...le(t), ...a])].filter((e) => !o.has(e));
|
|
814
|
+
return s.length ? await m(e, {
|
|
815
|
+
country: r,
|
|
816
|
+
language: i,
|
|
817
|
+
productIds: s,
|
|
818
|
+
useExternalMetafieldNamespace: !0
|
|
819
|
+
}) : [];
|
|
820
|
+
} catch (e) {
|
|
821
|
+
return console.error(e), [];
|
|
822
|
+
}
|
|
823
|
+
}, le = (e) => e.dealBars.flatMap((e) => e.dealBarType === ne.MixAndMatch ? e.bundleProducts.flatMap((e) => (e.selectedProducts ?? []).map((e) => e.id)) : []), ue = async (e, t, { country: n, language: r }) => {
|
|
824
|
+
try {
|
|
825
|
+
return await re(e, t, {
|
|
826
|
+
country: n,
|
|
827
|
+
language: r
|
|
828
|
+
}) ?? [];
|
|
829
|
+
} catch (e) {
|
|
830
|
+
return console.error(e), [];
|
|
831
|
+
}
|
|
832
|
+
}, de = class {
|
|
708
833
|
constructor(e) {
|
|
709
834
|
this.storefront = e, this.shopifyDomain = "";
|
|
710
835
|
}
|
|
@@ -717,7 +842,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
717
842
|
}
|
|
718
843
|
if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
|
|
719
844
|
if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
|
|
720
|
-
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${
|
|
845
|
+
let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${oe}/graphql.json`, {
|
|
721
846
|
body: JSON.stringify({
|
|
722
847
|
query: e,
|
|
723
848
|
variables: t?.variables
|
|
@@ -747,5 +872,23 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
747
872
|
get i18n() {
|
|
748
873
|
if ("i18n" in this.storefront) return this.storefront.i18n;
|
|
749
874
|
}
|
|
875
|
+
}, fe = async (e, t) => {
|
|
876
|
+
try {
|
|
877
|
+
let n = await $(e, t);
|
|
878
|
+
if (!n) return null;
|
|
879
|
+
let { config: r, dealBlock: i, product: a, otherProducts: o, mediaImages: s, translations: c } = n.data, { mixAndMatchSwapProducts: l, collectionBreaksProducts: u } = await n.modalProducts;
|
|
880
|
+
return {
|
|
881
|
+
config: r,
|
|
882
|
+
dealBlock: i,
|
|
883
|
+
product: a,
|
|
884
|
+
otherProducts: o,
|
|
885
|
+
mixAndMatchSwapProducts: l,
|
|
886
|
+
mediaImages: s,
|
|
887
|
+
collectionBreaksProducts: u,
|
|
888
|
+
translations: c
|
|
889
|
+
};
|
|
890
|
+
} catch (e) {
|
|
891
|
+
return console.error(e), null;
|
|
892
|
+
}
|
|
750
893
|
};
|
|
751
|
-
export {
|
|
894
|
+
export { fe as fetchKachingBundlesData };
|