@kachingappz/bundles-js 0.3.7 → 1.0.0

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/index.js ADDED
@@ -0,0 +1,980 @@
1
+ const q = (e, t) => {
2
+ const a = [], r = e.filter(
3
+ (n) => n.blockVisibility === "selected-products"
4
+ );
5
+ for (const n of r)
6
+ n.selectedProductIds.map(Number).includes(t.id) && a.push(n);
7
+ const l = e.filter(
8
+ (n) => n.blockVisibility === "selected-collections"
9
+ );
10
+ for (const n of l)
11
+ t.collectionIds.some(
12
+ (d) => n.selectedCollectionIds.map(Number).includes(d)
13
+ ) && a.push(n);
14
+ const o = e.filter(
15
+ (n) => n.blockVisibility === "excluded-products"
16
+ );
17
+ for (const n of o)
18
+ !n.excludedProductIds.map(Number).includes(t.id) && !(n.excludedCollectionIds || []).some(
19
+ (d) => t.collectionIds.includes(d)
20
+ ) && a.push(n);
21
+ const u = e.filter(
22
+ (n) => n.blockVisibility === "all-products"
23
+ );
24
+ for (const n of u)
25
+ a.push(n);
26
+ return a;
27
+ }, j = (e, { language: t, country: a }) => {
28
+ var b, g;
29
+ const r = B(t, a), l = new Intl.NumberFormat(r, {
30
+ style: "currency",
31
+ currency: e,
32
+ currencyDisplay: "narrowSymbol"
33
+ }).formatToParts(123456789e-2), o = (b = l.find((f) => f.type === "decimal")) == null ? void 0 : b.value, u = T(
34
+ (g = l.find((f) => f.type === "group")) == null ? void 0 : g.value
35
+ ), n = l.some((f) => f.type === "fraction"), d = E(
36
+ u,
37
+ o,
38
+ n
39
+ ), m = l.findIndex(N), p = l.findLastIndex(N);
40
+ return [
41
+ ...l.slice(0, m).map(D),
42
+ d,
43
+ ...l.slice(p + 1).map(D)
44
+ ].join("");
45
+ }, D = (e) => M(e.value), M = (e) => e.replace(/\s/g, " "), N = (e) => e.type === "integer" || e.type === "group" || e.type === "decimal" || e.type === "fraction", B = (e, t) => e && t ? `${e}-${t.toUpperCase()}` : e || (t ? t.toUpperCase() : "en"), T = (e) => e === void 0 ? void 0 : M(e).replace(/’/g, "'"), E = (e, t, a) => t === "," && e === "." ? a ? "{{amount_with_comma_separator}}" : "{{amount_no_decimals_with_comma_separator}}" : t === "," && e === " " ? a ? "{{amount_with_space_separator}}" : "{{amount_no_decimals_with_space_separator}}" : t === "." && e === " " ? "{{amount_with_period_and_space_separator}}" : t === "." && e === "'" ? "{{amount_with_apostrophe_separator}}" : a ? "{{amount}}" : "{{amount_no_decimals}}", w = ({
46
+ country: e,
47
+ language: t
48
+ }) => {
49
+ const a = [];
50
+ return e && a.push(`country: ${e}`), t && a.push(`language: ${t}`), a.length > 0 ? `@inContext(${a.join(", ")})` : "";
51
+ }, F = async (e, {
52
+ useExternalMetafieldNamespace: t,
53
+ useMetaobjects: a
54
+ }) => a ? U(
55
+ e
56
+ ) : O(e), O = async (e, t) => {
57
+ var r;
58
+ const a = (r = (await e.query(
59
+ `
60
+ query FetchDealBlocks($metafieldNamespace: String!) {
61
+ shop {
62
+ metafield(namespace: $metafieldNamespace, key: "deal_blocks") {
63
+ value
64
+ }
65
+ }
66
+ }
67
+ `,
68
+ {
69
+ variables: {
70
+ metafieldNamespace: "app--2935586817--kaching_bundles"
71
+ }
72
+ }
73
+ )).shop.metafield) == null ? void 0 : r.value;
74
+ return a ? JSON.parse(a) : [];
75
+ }, U = async (e, t) => {
76
+ const a = "app--2935586817--deal_block", r = [];
77
+ let l = null;
78
+ for (; ; ) {
79
+ const o = await e.query(
80
+ `
81
+ query FetchDealBlockMetaobjects($type: String!, $cursor: String) {
82
+ metaobjects(type: $type, first: 250, after: $cursor) {
83
+ nodes {
84
+ fields {
85
+ key
86
+ value
87
+ }
88
+ }
89
+ pageInfo {
90
+ hasNextPage
91
+ endCursor
92
+ }
93
+ }
94
+ }
95
+ `,
96
+ {
97
+ variables: {
98
+ type: a,
99
+ cursor: l
100
+ }
101
+ }
102
+ );
103
+ for (const u of o.metaobjects.nodes) {
104
+ const n = u.fields.find(
105
+ (d) => d.key === "settings"
106
+ );
107
+ n != null && n.value && r.push(JSON.parse(n.value));
108
+ }
109
+ if (!o.metaobjects.pageInfo.hasNextPage)
110
+ break;
111
+ l = o.metaobjects.pageInfo.endCursor;
112
+ }
113
+ return r;
114
+ }, k = async (e, {
115
+ country: t,
116
+ language: a,
117
+ blockVisibility: r,
118
+ excludedProductGIDs: l,
119
+ selectedProductGIDs: o,
120
+ selectedCollectionGIDs: u,
121
+ limit: n = 1e3
122
+ }) => {
123
+ switch (r) {
124
+ case "selected-products":
125
+ return o.slice(0, n);
126
+ case "all-products":
127
+ case "excluded-products": {
128
+ const d = w({ country: t, language: a });
129
+ let m = [], p = null;
130
+ for (; m.length < n; ) {
131
+ const b = Math.min(n - m.length, 250), g = await e.query(
132
+ `
133
+ query FetchProductGIDs($limit: Int!, $cursor: String) ${d} {
134
+ products(first: $limit, after: $cursor) {
135
+ nodes {
136
+ id
137
+ }
138
+ pageInfo {
139
+ hasNextPage
140
+ endCursor
141
+ }
142
+ }
143
+ }
144
+ `,
145
+ {
146
+ variables: {
147
+ limit: b,
148
+ cursor: p
149
+ }
150
+ }
151
+ );
152
+ if (m.push(...g.products.nodes.map((f) => f.id)), !g.products.pageInfo.hasNextPage) break;
153
+ p = g.products.pageInfo.endCursor;
154
+ }
155
+ if (r === "excluded-products") {
156
+ const b = new Set(l);
157
+ m = m.filter((g) => !b.has(g));
158
+ }
159
+ return m;
160
+ }
161
+ case "selected-collections": {
162
+ const d = w({ country: t, language: a }), m = (await e.query(
163
+ `
164
+ query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${d} {
165
+ nodes(ids: $collectionGIDs) {
166
+ ... on Collection {
167
+ products(first: $limit) {
168
+ nodes {
169
+ id
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ `,
176
+ {
177
+ variables: {
178
+ collectionGIDs: u,
179
+ limit: Math.min(n, 250)
180
+ }
181
+ }
182
+ )).nodes.filter((p) => p !== null).flatMap(
183
+ (p) => p.products.nodes.map((b) => b.id)
184
+ );
185
+ return Array.from(new Set(m)).slice(0, n);
186
+ }
187
+ }
188
+ }, C = `
189
+ id
190
+ availableForSale
191
+ price {
192
+ amount
193
+ }
194
+ compareAtPrice {
195
+ amount
196
+ }
197
+ selectedOptions {
198
+ name
199
+ value
200
+ }
201
+ image {
202
+ id
203
+ url(transform: { maxWidth: 200, maxHeight: 200 })
204
+ }
205
+ unitPriceMeasurement {
206
+ quantityUnit
207
+ quantityValue
208
+ referenceUnit
209
+ referenceValue
210
+ }
211
+ requiresComponents
212
+ sellingPlanAllocations(first: 100) @include(if: $includeSellingPlans) {
213
+ nodes {
214
+ sellingPlan {
215
+ id
216
+ }
217
+ priceAdjustments {
218
+ price {
219
+ amount
220
+ }
221
+ compareAtPrice {
222
+ amount
223
+ }
224
+ perDeliveryPrice {
225
+ amount
226
+ }
227
+ }
228
+ }
229
+ }
230
+ quantityAvailable @include(if: $includeAvailableQuantity)
231
+ `, S = async (e, {
232
+ country: t,
233
+ language: a,
234
+ productIds: r,
235
+ includeSellingPlans: l = !0,
236
+ includeAvailableQuantity: o = !0,
237
+ useExternalMetafieldNamespace: u = !1,
238
+ batchSize: n = 250,
239
+ onBatchError: d
240
+ }) => {
241
+ if (!r.length)
242
+ return [];
243
+ const m = r.map((i) => typeof i == "string" && i.startsWith("gid://") ? i : `gid://shopify/Product/${i}`), p = w({ country: t, language: a }), b = `
244
+ query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${p} {
245
+ shop {
246
+ currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
247
+ value
248
+ }
249
+ }
250
+ nodes(ids: $productGIDs) {
251
+ ... on Product {
252
+ id
253
+ handle
254
+ onlineStoreUrl
255
+ availableForSale
256
+ createdAt
257
+ title
258
+ featuredImage {
259
+ url
260
+ }
261
+ options {
262
+ name
263
+ optionValues {
264
+ id
265
+ name
266
+ swatch {
267
+ color
268
+ image {
269
+ previewImage {
270
+ url(transform: { maxWidth: 200, maxHeight: 200 })
271
+ }
272
+ }
273
+ }
274
+ }
275
+ }
276
+ variants(first: 250) {
277
+ nodes {
278
+ ${C}
279
+ }
280
+ }
281
+ collections(first: 50) {
282
+ nodes {
283
+ id
284
+ }
285
+ }
286
+ metafield: metafield(namespace: $metafieldNamespace, key: "text") {
287
+ value
288
+ }
289
+ metafield2: metafield(namespace: $metafieldNamespace, key: "text2") {
290
+ value
291
+ }
292
+ metafield3: metafield(namespace: $metafieldNamespace, key: "text3") {
293
+ value
294
+ }
295
+ metafield4: metafield(namespace: $metafieldNamespace, key: "text4") {
296
+ value
297
+ }
298
+ requiresSellingPlan
299
+ sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
300
+ nodes {
301
+ sellingPlans(first: 100) {
302
+ nodes {
303
+ id
304
+ name
305
+ priceAdjustments {
306
+ adjustmentValue {
307
+ __typename
308
+ ... on SellingPlanPercentagePriceAdjustment {
309
+ adjustmentPercentage
310
+ }
311
+ ... on SellingPlanFixedAmountPriceAdjustment {
312
+ adjustmentAmount {
313
+ amount
314
+ }
315
+ }
316
+ ... on SellingPlanFixedPriceAdjustment {
317
+ price {
318
+ amount
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+ }
325
+ }
326
+ }
327
+ }
328
+ }
329
+ }
330
+ `, g = u ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", f = [], v = Math.min(n, 250);
331
+ for (let i = 0; i < m.length; i += v)
332
+ f.push(m.slice(i, i + v));
333
+ let s = 1;
334
+ const c = async (i) => {
335
+ const h = await e.query(b, {
336
+ variables: {
337
+ productGIDs: i,
338
+ includeSellingPlans: l,
339
+ includeAvailableQuantity: o,
340
+ metafieldNamespace: g
341
+ }
342
+ });
343
+ return h.shop.currencyRateConstant && (s = JSON.parse(h.shop.currencyRateConstant.value).amount / 1e6), h;
344
+ };
345
+ let y;
346
+ if (d) {
347
+ const i = await Promise.allSettled(f.map(c));
348
+ for (const h of i)
349
+ h.status === "rejected" && d(
350
+ h.reason instanceof Error ? h.reason : new Error(String(h.reason))
351
+ );
352
+ y = i.filter(
353
+ (h) => h.status === "fulfilled"
354
+ ).flatMap((h) => h.value.nodes);
355
+ } else
356
+ y = (await Promise.all(f.map(c))).flatMap((i) => i.nodes);
357
+ const _ = y.filter((i) => i != null);
358
+ if (d) {
359
+ const i = await Promise.allSettled(
360
+ _.map(async (I) => {
361
+ const P = await G(
362
+ e,
363
+ I,
364
+ { includeSellingPlans: l, includeAvailableQuantity: o },
365
+ p
366
+ );
367
+ return x(
368
+ P,
369
+ e.shopifyDomain,
370
+ s
371
+ );
372
+ })
373
+ ), h = [];
374
+ for (const I of i)
375
+ I.status === "fulfilled" ? h.push(I.value) : d(
376
+ I.reason instanceof Error ? I.reason : new Error(String(I.reason))
377
+ );
378
+ return h;
379
+ }
380
+ return (await Promise.all(
381
+ _.map(
382
+ (i) => G(
383
+ e,
384
+ i,
385
+ {
386
+ includeSellingPlans: l,
387
+ includeAvailableQuantity: o
388
+ },
389
+ p
390
+ )
391
+ )
392
+ )).map(
393
+ (i) => x(i, e.shopifyDomain, s)
394
+ );
395
+ }, G = async (e, t, a, r = "") => {
396
+ if (t.variants.nodes.length < 250)
397
+ return t;
398
+ const l = /* @__PURE__ */ new Set(), o = [], u = [], n = async (d) => {
399
+ let m = !0, p = null;
400
+ for (; m; ) {
401
+ const b = await e.query(
402
+ `
403
+ query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!) ${r} {
404
+ product(id: $productGID) {
405
+ variants(first: 250, after: $cursor, reverse: $reverse) {
406
+ nodes {
407
+ ${C}
408
+ }
409
+ pageInfo {
410
+ endCursor
411
+ hasNextPage
412
+ }
413
+ }
414
+ }
415
+ }
416
+ `,
417
+ {
418
+ variables: {
419
+ productGID: t.id,
420
+ cursor: p,
421
+ reverse: d,
422
+ ...a
423
+ }
424
+ }
425
+ ), { nodes: g, pageInfo: f } = b.product.variants;
426
+ for (const v of g) {
427
+ if (l.has(v.id)) {
428
+ m = !1;
429
+ break;
430
+ }
431
+ l.add(v.id), d ? u.push(v) : o.push(v);
432
+ }
433
+ f.hasNextPage || (m = !1), p = f.endCursor;
434
+ }
435
+ };
436
+ return await Promise.all([
437
+ n(!1),
438
+ n(!0)
439
+ ]), t.variants.nodes = [...o, ...u.reverse()], t;
440
+ }, x = (e, t, a) => {
441
+ var m, p, b, g, f, v;
442
+ const r = e.variants.nodes.map(
443
+ ({ unitPriceMeasurement: s, ...c }) => {
444
+ var y, _;
445
+ return {
446
+ id: Number(c.id.split("/").pop()),
447
+ availableForSale: c.availableForSale,
448
+ price: Math.round(Number(c.price.amount) * 100),
449
+ compareAtPrice: c.compareAtPrice ? Math.round(Number(c.compareAtPrice.amount) * 100) : null,
450
+ options: c.selectedOptions.map((i) => i.value),
451
+ imageId: c.image ? Number(c.image.id.split("/").pop()) : null,
452
+ image: ((y = c.image) == null ? void 0 : y.url) || null,
453
+ sellingPlans: ((_ = c.sellingPlanAllocations) == null ? void 0 : _.nodes.map((i) => ({
454
+ id: Number(i.sellingPlan.id.split("/").pop()),
455
+ price: i.priceAdjustments.length > 0 ? Math.round(Number(i.priceAdjustments[0].price.amount) * 100) : Math.round(Number(c.price.amount) * 100),
456
+ compareAtPrice: i.priceAdjustments.length > 0 ? Math.round(
457
+ Number(i.priceAdjustments[0].compareAtPrice.amount) * 100
458
+ ) : Math.round(Number(c.price.amount) * 100),
459
+ perDeliveryPrice: i.priceAdjustments.length > 0 ? Math.round(
460
+ Number(i.priceAdjustments[0].perDeliveryPrice.amount) * 100
461
+ ) : Math.round(Number(c.price.amount) * 100)
462
+ }))) || [],
463
+ inventoryManagement: null,
464
+ // Storefront API does not return inventory management, only available in liquid
465
+ inventoryPolicy: null,
466
+ // Storefront API does not return inventory policy, only available in liquid
467
+ inventoryQuantity: c.quantityAvailable ?? null,
468
+ unitPriceMeasurement: s != null && s.quantityUnit && (s != null && s.referenceUnit) ? {
469
+ quantityValue: s.quantityValue,
470
+ quantityUnit: s.quantityUnit.toLowerCase(),
471
+ referenceValue: s.referenceValue,
472
+ referenceUnit: s.referenceUnit.toLowerCase()
473
+ } : null
474
+ };
475
+ }
476
+ ), l = e.options.map((s, c) => {
477
+ const y = s.optionValues.map((_) => {
478
+ var i, h, I, P;
479
+ return {
480
+ id: Number(_.id.split("/").pop()),
481
+ defaultName: _.name,
482
+ name: _.name,
483
+ swatch: {
484
+ color: ((i = _.swatch) == null ? void 0 : i.color) || null,
485
+ image: ((P = (I = (h = _.swatch) == null ? void 0 : h.image) == null ? void 0 : I.previewImage) == null ? void 0 : P.url) || null
486
+ }
487
+ };
488
+ });
489
+ return {
490
+ defaultName: s.name,
491
+ name: s.name,
492
+ position: c + 1,
493
+ optionValues: V(y, c, r)
494
+ };
495
+ }), o = (s) => {
496
+ const c = s.priceAdjustments[0];
497
+ if (!c)
498
+ return null;
499
+ const y = c.adjustmentValue;
500
+ switch (y.__typename) {
501
+ case "SellingPlanPercentagePriceAdjustment":
502
+ return {
503
+ type: "percentage",
504
+ value: y.adjustmentPercentage
505
+ };
506
+ case "SellingPlanFixedAmountPriceAdjustment":
507
+ return {
508
+ type: "fixed_amount",
509
+ value: u(y.adjustmentAmount.amount)
510
+ };
511
+ case "SellingPlanFixedPriceAdjustment":
512
+ return {
513
+ type: "price",
514
+ value: u(y.price.amount)
515
+ };
516
+ default:
517
+ throw new Error(
518
+ `Unknown price adjustment type: ${y.__typename}`
519
+ );
520
+ }
521
+ }, u = (s) => a === 1 ? Number(s) * 100 : Math.round(Number(s) * 100 * a), n = ((m = e.sellingPlanGroups) == null ? void 0 : m.nodes.flatMap(
522
+ (s) => s.sellingPlans.nodes.map((c) => ({
523
+ id: Number(c.id.split("/").pop()),
524
+ name: c.name,
525
+ priceAdjustment: o(c)
526
+ }))
527
+ )) || [], d = e.variants.nodes.some(
528
+ (s) => s.requiresComponents
529
+ );
530
+ return {
531
+ id: Number(e.id.split("/").pop()),
532
+ handle: e.handle,
533
+ url: e.onlineStoreUrl || `https://${t}/products/${e.handle}`,
534
+ availableForSale: e.availableForSale,
535
+ createdAt: e.createdAt,
536
+ title: e.title,
537
+ image: ((p = e.featuredImage) == null ? void 0 : p.url) || null,
538
+ collectionIds: e.collections.nodes.map(
539
+ (s) => Number(s.id.split("/").pop())
540
+ ),
541
+ options: l,
542
+ selectedVariantId: Number(
543
+ e.variants.nodes[0].id.split("/").pop()
544
+ ),
545
+ variants: r,
546
+ requiresSellingPlan: e.requiresSellingPlan,
547
+ sellingPlans: n,
548
+ isNativeBundle: d,
549
+ metafields: {
550
+ text: ((b = e.metafield) == null ? void 0 : b.value) || null,
551
+ text2: ((g = e.metafield2) == null ? void 0 : g.value) || null,
552
+ text3: ((f = e.metafield3) == null ? void 0 : f.value) || null,
553
+ text4: ((v = e.metafield4) == null ? void 0 : v.value) || null
554
+ }
555
+ };
556
+ }, V = (e, t, a) => e.filter((r) => a.filter(
557
+ (l) => l.options[t] === r.name
558
+ ).length > 0), A = "app--2935586817", R = async (e, {
559
+ language: t,
560
+ country: a,
561
+ useExternalMetafieldNamespace: r
562
+ }) => {
563
+ const l = `${A}--kaching_bundles`, o = A, u = w({ country: a }), {
564
+ localization: {
565
+ country: {
566
+ currency: { isoCode: n }
567
+ }
568
+ },
569
+ shop: {
570
+ moneyFormat: d,
571
+ paymentSettings: { currencyCode: m },
572
+ currencyRateConstant: p,
573
+ primaryDomain: b,
574
+ settingsMetafield: g
575
+ }
576
+ } = await e.query(
577
+ `
578
+ query config($metafieldNamespace: String!, $settingsNamespace: String!) ${u} {
579
+ localization {
580
+ country {
581
+ currency {
582
+ isoCode
583
+ }
584
+ }
585
+ }
586
+ shop {
587
+ moneyFormat
588
+ paymentSettings {
589
+ currencyCode
590
+ }
591
+ primaryDomain {
592
+ host
593
+ }
594
+ currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
595
+ value
596
+ }
597
+ settingsMetafield: metafield(namespace: $settingsNamespace, key: "config") {
598
+ value
599
+ }
600
+ }
601
+ }
602
+ `,
603
+ {
604
+ variables: {
605
+ metafieldNamespace: l,
606
+ settingsNamespace: o
607
+ }
608
+ }
609
+ ), f = n === m ? d : j(n, { language: t, country: a }), v = p ? Q(p.value) : 1, s = g ? JSON.parse(g.value) : null, c = (s == null ? void 0 : s.feature_flags) ?? {}, y = (s == null ? void 0 : s.custom_selectors) ?? {};
610
+ return {
611
+ shopifyDomain: b.host,
612
+ moneyFormat: f,
613
+ locale: (t == null ? void 0 : t.toLowerCase()) || "en",
614
+ liquidLocale: (t == null ? void 0 : t.toLowerCase()) || "en",
615
+ country: a ?? "US",
616
+ currencyRate: v,
617
+ marketId: 0,
618
+ productId: null,
619
+ storefrontAccessToken: (s == null ? void 0 : s.storefront_access_token) ?? null,
620
+ includeSellingPlans: (s == null ? void 0 : s.include_selling_plans) ?? !1,
621
+ includeAvailableQuantity: (s == null ? void 0 : s.include_available_quantity) ?? !1,
622
+ customApiHost: (s == null ? void 0 : s.custom_api_host) ?? null,
623
+ keepQuantityInput: (s == null ? void 0 : s.keep_quantity_input) ?? !1,
624
+ ignoreDeselect: (s == null ? void 0 : s.ignore_deselect) ?? !1,
625
+ ignoreUnitPrice: (s == null ? void 0 : s.ignore_unit_price) ?? !1,
626
+ requireCustomerLogin: (s == null ? void 0 : s.require_customer_login) ?? !1,
627
+ abTestsRunning: (s == null ? void 0 : s.ab_tests_running) ?? !1,
628
+ webPixel: (s == null ? void 0 : s.web_pixel) ?? !1,
629
+ b2bCustomer: !1,
630
+ isLoggedIn: !1,
631
+ preview: !1,
632
+ previewAlerts: !1,
633
+ previewScratchOff: !1,
634
+ defaultTranslations: {
635
+ "system.out_of_stock": "Out of stock",
636
+ "system.invalid_variant": "Invalid variant",
637
+ "system.unavailable_option_value": "Unavailable option value",
638
+ "system.confirm": "Confirm",
639
+ "system.cancel": "Cancel",
640
+ "system.free": "FREE",
641
+ "system.search": "Search",
642
+ "system.quantity": "Quantity",
643
+ "system.subscription_plan": "Subscription plan",
644
+ "system.remove": "Remove",
645
+ "system.sort_by": "Sort by",
646
+ "system.sort_relevance": "Relevance",
647
+ "system.sort_newest_first": "Newest first",
648
+ "system.sort_price_low_to_high": "Price: Low → High",
649
+ "system.sort_price_high_to_low": "Price: High → Low",
650
+ "system.no_results_found": "No results found",
651
+ "system.no_results_description": "We can't find any item matching your search.",
652
+ "system.clear_search": "Clear search",
653
+ "system.no_products_available": "No products available",
654
+ "system.original_price": "Original price:",
655
+ "system.price": "Price:",
656
+ "system.letters_only": "Only letters are allowed.",
657
+ "system.numbers_only": "Only numbers are allowed."
658
+ },
659
+ customSelectors: {
660
+ quantity: y.quantity ?? null,
661
+ addToCartButton: y.add_to_cart_button ?? null,
662
+ variantPicker: y.variant_picker ?? null,
663
+ price: y.price ?? null,
664
+ priceCompare: y.price_compare ?? null
665
+ },
666
+ shopCustomStyles: (s == null ? void 0 : s.shop_custom_styles) ?? "",
667
+ featureFlags: c,
668
+ brandColors: (s == null ? void 0 : s.brand_colors) ?? null
669
+ };
670
+ }, Q = (e) => JSON.parse(e).amount / 1e6, L = async (e, t, a = 200) => (t = t.filter(Boolean).filter((r) => !r.startsWith("placeholder")), t.length === 0 ? [] : (await e.query(
671
+ `
672
+ query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
673
+ nodes(ids: $mediaImageIds) {
674
+ ... on MediaImage {
675
+ id
676
+ image {
677
+ url(transform: { maxWidth: $size, maxHeight: $size })
678
+ }
679
+ }
680
+ }
681
+ }
682
+ `,
683
+ {
684
+ variables: {
685
+ mediaImageIds: t,
686
+ size: a
687
+ }
688
+ }
689
+ )).nodes.filter(Boolean).map((r) => ({
690
+ gid: r.id,
691
+ url: r.image.url
692
+ })));
693
+ var $ = /* @__PURE__ */ ((e) => (e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e))($ || {});
694
+ const H = (e) => [
695
+ ...J(e),
696
+ ...z(e),
697
+ ...W(e),
698
+ ...X(e),
699
+ ...K(e),
700
+ ...Y(e),
701
+ ...Z(e),
702
+ ...ee(e),
703
+ ...te(e),
704
+ ...ae(e),
705
+ ...se(e),
706
+ ...ne(e),
707
+ ...re(e)
708
+ ].filter((t) => t != null && !t.includes("placeholder")), J = (e) => e.dealBars.flatMap((t) => [t.mediaImageGID, t.badgeImageGID]).filter((t) => t != null), z = (e) => e.dealBars.flatMap(
709
+ (t) => t.dealBarType === $.Bundle ? t.bundleProducts.map(
710
+ (a) => a.mediaImageGID
711
+ ) : []
712
+ ).filter((t) => t != null), W = (e) => e.dealBars.map(
713
+ ({ freeGifts: t }) => (t || []).map((a) => a.mediaImageGID)
714
+ ).reduce((t, a) => t.concat(a), []).filter((t) => t != null), X = (e) => e.dealBars.flatMap(
715
+ ({ multipleGiftsSelectors: t }) => (t || []).map((a) => a.mediaImageGID)
716
+ ).filter((t) => t != null), K = (e) => e.dealBars.map(({ upsells: t }) => (t || []).map((a) => a.mediaImageGID)).reduce((t, a) => t.concat(a), []).filter((t) => t != null), Y = (e) => e.swatchOptions ? e.swatchOptions.reduce((t, a) => {
717
+ const r = a.images.map((l) => l.mediaImageGID).filter((l) => l != null);
718
+ return [...t, ...r];
719
+ }, []) : [], Z = (e) => {
720
+ if (!e.collectionBreaksEnabled || !e.collectionBreaks)
721
+ return [];
722
+ const t = e.collectionBreaks.mediaImageGID;
723
+ return t ? [t] : [];
724
+ }, ee = (e) => {
725
+ var t, a, r;
726
+ return e.progressiveGifts ? [
727
+ ...((t = e.progressiveGifts.gifts) == null ? void 0 : t.map((l) => l.mediaImageGID)) || [],
728
+ (a = e.progressiveGifts.style) == null ? void 0 : a.lockedMediaImageGID,
729
+ (r = e.progressiveGifts.dealBarStyle) == null ? void 0 : r.lockedMediaImageGID
730
+ ].filter((l) => l != null) : [];
731
+ }, te = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((t) => [t.mediaImageGID, t.badgeImageGID]).filter((t) => t != null), ae = (e) => e.dealBars.map((t) => {
732
+ var a;
733
+ return (a = t.productPersonalisation) == null ? void 0 : a.mediaImageGID;
734
+ }).filter((t) => t != null), se = (e) => {
735
+ var r, l;
736
+ const t = e.dealBars.map((o) => {
737
+ var u;
738
+ return (u = o.highlights) == null ? void 0 : u.customIconGID;
739
+ }).filter((o) => o != null), a = (l = (r = e.subscriptions) == null ? void 0 : r.highlights) == null ? void 0 : l.customIconGID;
740
+ return a ? [...t, a] : t;
741
+ }, ne = (e) => (e.badges || []).flatMap(
742
+ (t) => t.badgeType === "custom" && t.imageGID ? [t.imageGID] : []
743
+ ), re = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], le = (e) => {
744
+ const t = [
745
+ ...ie(e),
746
+ ...oe(e),
747
+ ...ce(e),
748
+ ...ue(e),
749
+ ...de(e),
750
+ ...me(e),
751
+ ...pe(e),
752
+ ...fe(e)
753
+ ];
754
+ return Array.from(new Set(t.filter((a) => a != null)));
755
+ }, ie = (e) => e.dealBars.flatMap(
756
+ ({ freeGifts: t }) => t ? t.map((a) => a.productGID) : []
757
+ ).filter((t) => t != null), oe = (e) => e.dealBars.flatMap(
758
+ ({ multipleGiftsSelectors: t }) => t ? t.flatMap(
759
+ (a) => a.products ? a.products.map((r) => r.id) : []
760
+ ) : []
761
+ ).filter((t) => t != null), ce = (e) => {
762
+ var t;
763
+ return e.progressiveGiftsEnabled ? ((t = e.progressiveGifts) == null ? void 0 : t.gifts.map((a) => a.productGID).filter((a) => a != null)) || [] : [];
764
+ }, ue = (e) => e.dealBars.flatMap(({ upsells: t }) => t ? t.map((a) => a.productGID) : []).filter((t) => t != null), de = (e) => e.dealBars.filter((t) => t.dealBarType === $.Bundle).flatMap(
765
+ ({ bundleProducts: t }) => t ? t.map((a) => a.productGID) : []
766
+ ).filter((t) => t != null).filter((t) => t !== "default"), me = (e) => e.dealBars.filter((t) => t.dealBarType === $.MixAndMatch).flatMap(
767
+ ({ bundleProducts: t }) => t ? t.flatMap((a) => {
768
+ var r;
769
+ return [
770
+ a.productGID,
771
+ ...((r = a.selectedProducts) == null ? void 0 : r.map((l) => l.id)) ?? []
772
+ ];
773
+ }) : []
774
+ ).filter((t) => t != null).filter((t) => t !== "default"), pe = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((t) => t.productGID).filter((t) => t != null), fe = (e) => e.dealBars.filter((t) => t.dealBarType === $.Sku).flatMap(({ productGID: t }) => t ? [t] : []);
775
+ class ye {
776
+ constructor(t, a) {
777
+ this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = a, this.shopifyDomain = t;
778
+ }
779
+ async query(t, a) {
780
+ var n;
781
+ const r = (a == null ? void 0 : a.variables) ?? {};
782
+ let l = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;
783
+ const o = (n = t.match(/query\s+(\w+)/)) == null ? void 0 : n[1];
784
+ o && (l += `?operation_name=${o}`);
785
+ const u = await (await fetch(l, {
786
+ method: "POST",
787
+ headers: {
788
+ "Content-Type": "application/json",
789
+ "X-Shopify-Storefront-Access-Token": this.storefrontAccessToken
790
+ },
791
+ body: JSON.stringify({
792
+ query: t,
793
+ variables: r
794
+ })
795
+ })).text();
796
+ if (!u)
797
+ throw new Error("Empty graphql response");
798
+ return JSON.parse(u).data;
799
+ }
800
+ }
801
+ const ge = async (e, t, { country: a, language: r }) => {
802
+ const l = t.collectionBreaks;
803
+ if (!t.collectionBreaksEnabled || !l) return;
804
+ let o;
805
+ l.visibility === "deal-products" ? o = await k(e, {
806
+ country: a,
807
+ language: r,
808
+ blockVisibility: t.blockVisibility,
809
+ excludedProductGIDs: (t.excludedProductIds || []).map(
810
+ (n) => `gid://shopify/Product/${n}`
811
+ ),
812
+ selectedProductGIDs: (t.selectedProductIds || []).map(
813
+ (n) => `gid://shopify/Product/${n}`
814
+ ),
815
+ selectedCollectionGIDs: (t.selectedCollectionIds || []).map(
816
+ (n) => `gid://shopify/Collection/${n}`
817
+ )
818
+ }) : o = await k(e, {
819
+ country: a,
820
+ language: r,
821
+ blockVisibility: l.visibility,
822
+ excludedProductGIDs: (l.excludedProducts || []).map(
823
+ ({ id: n }) => n
824
+ ),
825
+ selectedProductGIDs: (l.selectedProducts || []).map(
826
+ ({ id: n }) => n
827
+ ),
828
+ selectedCollectionGIDs: (l.selectedCollections || []).map(
829
+ ({ id: n }) => n
830
+ )
831
+ });
832
+ let u = await S(e, {
833
+ country: a,
834
+ language: r,
835
+ productIds: o.map((n) => Number(n.split("/").pop())),
836
+ useExternalMetafieldNamespace: !0
837
+ });
838
+ return u = u.filter(
839
+ (n) => n.availableForSale
840
+ ), u;
841
+ }, he = () => ({
842
+ "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
843
+ "system.invalid_variant": "Sorry, this is not currently available.",
844
+ "system.unavailable_option_value": "Unavailable",
845
+ "system.confirm": "Confirm",
846
+ "system.cancel": "Cancel",
847
+ "system.free": "FREE",
848
+ "system.search": "Search",
849
+ "system.quantity": "Quantity",
850
+ "system.subscription_plan": "Subscription plan",
851
+ "system.remove": "Remove",
852
+ "system.sort_by": "Sort by",
853
+ "system.sort_relevance": "Relevance",
854
+ "system.sort_newest_first": "Newest first",
855
+ "system.sort_price_low_to_high": "Price: Low → High",
856
+ "system.sort_price_high_to_low": "Price: High → Low",
857
+ "system.no_results_found": "No results found",
858
+ "system.no_results_description": "We can't find any item matching your search.",
859
+ "system.clear_search": "Clear search",
860
+ "system.no_products_available": "No products available",
861
+ "system.original_price": "Original price:",
862
+ "system.price": "Price:",
863
+ "system.letters_only": "Only letters are allowed.",
864
+ "system.numbers_only": "Only numbers are allowed.",
865
+ "system.personalisation_required_alert": "Please add personalisation for every item to continue."
866
+ }), be = "2026-07", _e = async (e, {
867
+ productId: t,
868
+ dealBlockId: a,
869
+ country: r = void 0,
870
+ language: l = void 0
871
+ }) => {
872
+ var o, u;
873
+ try {
874
+ const n = [Number(t.split("/").pop())], d = new ve(e);
875
+ r = r || ((o = d.i18n) == null ? void 0 : o.country), l = l || ((u = d.i18n) == null ? void 0 : u.language);
876
+ const m = await R(d, {
877
+ language: l,
878
+ country: r,
879
+ useExternalMetafieldNamespace: !0
880
+ });
881
+ d.shopifyDomain = m.shopifyDomain;
882
+ const p = m.storefrontAccessToken ? new ye(
883
+ m.shopifyDomain,
884
+ m.storefrontAccessToken
885
+ ) : d, [b, g] = await Promise.all([
886
+ S(p, {
887
+ country: r,
888
+ language: l,
889
+ productIds: n,
890
+ useExternalMetafieldNamespace: !0
891
+ }),
892
+ F(p, {
893
+ useExternalMetafieldNamespace: !0,
894
+ useMetaobjects: m.featureFlags.storefront_metaobjects
895
+ })
896
+ ]), f = b[0];
897
+ if (!f)
898
+ return null;
899
+ const v = q(g, f);
900
+ let s;
901
+ if (a ? (s = v.find(
902
+ (P) => P.id === a || P.nanoId === a
903
+ ), s || (s = v[0])) : s = v[0], !s)
904
+ return null;
905
+ const c = H(s), y = le(s), [_, i, h, I] = await Promise.all([
906
+ S(p, {
907
+ country: r,
908
+ language: l,
909
+ productIds: y,
910
+ useExternalMetafieldNamespace: !0
911
+ }),
912
+ L(p, c, 300),
913
+ ge(p, s, {
914
+ country: r,
915
+ language: l
916
+ }),
917
+ he()
918
+ ]);
919
+ return {
920
+ product: f,
921
+ dealBlock: s,
922
+ config: m,
923
+ otherProducts: _,
924
+ mediaImages: i,
925
+ collectionBreaksProducts: h ?? [],
926
+ translations: I
927
+ };
928
+ } catch (n) {
929
+ return console.error(n), null;
930
+ }
931
+ };
932
+ class ve {
933
+ constructor(t) {
934
+ this.storefront = t, this.shopifyDomain = "";
935
+ }
936
+ async query(t, a) {
937
+ if ("query" in this.storefront && "i18n" in this.storefront)
938
+ return await this.storefront.query(t, a);
939
+ if ("request" in this.storefront)
940
+ return (await this.storefront.request(t, a)).data;
941
+ if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
942
+ const r = await fetch(
943
+ `https://${this.storefront.shopifyDomain}/api/${be}/graphql.json`,
944
+ {
945
+ body: JSON.stringify({
946
+ query: t,
947
+ variables: a == null ? void 0 : a.variables
948
+ }),
949
+ headers: {
950
+ "Content-Type": "application/json",
951
+ "X-Shopify-Storefront-Access-Token": this.storefront.storefrontAccessToken
952
+ },
953
+ method: "POST"
954
+ }
955
+ );
956
+ if (!r.ok)
957
+ throw new Error(r.statusText);
958
+ return (await r.json()).data;
959
+ } else {
960
+ const r = await fetch(this.storefront.getStorefrontApiUrl(), {
961
+ body: JSON.stringify({
962
+ query: t,
963
+ variables: a == null ? void 0 : a.variables
964
+ }),
965
+ headers: this.storefront.getPublicTokenHeaders(),
966
+ method: "POST"
967
+ });
968
+ if (!r.ok)
969
+ throw new Error(r.statusText);
970
+ return (await r.json()).data;
971
+ }
972
+ }
973
+ get i18n() {
974
+ if ("i18n" in this.storefront)
975
+ return this.storefront.i18n;
976
+ }
977
+ }
978
+ export {
979
+ _e as fetchKachingBundlesData
980
+ };