@kachingappz/bundles-js 0.3.7 → 1.0.1

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.
@@ -1,1202 +0,0 @@
1
- const N = {
2
- id: 1,
3
- handle: "example-product",
4
- url: null,
5
- availableForSale: !0,
6
- title: "Example product",
7
- image: null,
8
- collectionIds: [],
9
- options: [],
10
- selectedVariantId: 1,
11
- variants: [
12
- {
13
- id: 1,
14
- availableForSale: !0,
15
- price: 8e3,
16
- compareAtPrice: null,
17
- options: ["Default Title"],
18
- imageId: null,
19
- image: null,
20
- unitPriceMeasurement: null,
21
- sellingPlans: [],
22
- inventoryManagement: null,
23
- inventoryPolicy: null,
24
- inventoryQuantity: 50
25
- }
26
- ],
27
- metafields: { text: null, text2: null, text3: null, text4: null },
28
- requiresSellingPlan: !1,
29
- sellingPlans: [],
30
- isNativeBundle: !1
31
- }, x = {
32
- id: "example",
33
- nanoId: "example",
34
- blockName: "Bundle",
35
- discountName: "",
36
- blockTitle: "BUNDLE & SAVE",
37
- blockLayout: "vertical",
38
- blockVisibility: "all-products",
39
- marketId: null,
40
- currency: null,
41
- excludeB2bCustomers: !1,
42
- excludePos: !1,
43
- startTimestamp: 0,
44
- endTimestamp: null,
45
- differentVariantsEnabled: !0,
46
- hideVariantPicker: !0,
47
- disableVariantOptionSync: !1,
48
- hideUnavailableOptions: !1,
49
- showPricesPerItem: !1,
50
- showBothPrices: !1,
51
- unitLabel: "",
52
- useProductCompareAtPrice: !0,
53
- showPricesWithoutDecimals: !1,
54
- priceRounding: !1,
55
- priceRoundingPrecision: ".00",
56
- updateNativePrice: !1,
57
- updateNativePriceType: "item",
58
- skipCart: !1,
59
- showVariantsForSingleQuantity: !1,
60
- preselectedDealBarId: "duo",
61
- cornerRadius: 16,
62
- spacing: 1,
63
- selectedProductIds: [],
64
- selectedCollectionIds: [],
65
- excludedProductIds: [],
66
- excludedCollectionIds: [],
67
- colors: {
68
- background: { red: 245, green: 245, blue: 245, alpha: 1 },
69
- selectedBackground: { red: 255, green: 255, blue: 255, alpha: 1 },
70
- border: { red: 0, green: 0, blue: 0, alpha: 1 },
71
- blockTitle: { red: 0, green: 0, blue: 0, alpha: 1 },
72
- title: { red: 0, green: 0, blue: 0, alpha: 1 },
73
- subtitle: { red: 85, green: 85, blue: 85, alpha: 1 },
74
- price: { red: 0, green: 0, blue: 0, alpha: 1 },
75
- fullPrice: { red: 85, green: 85, blue: 85, alpha: 1 },
76
- labelBackground: { red: 171, green: 239, blue: 198, alpha: 1 },
77
- label: { red: 0, green: 0, blue: 0, alpha: 1 },
78
- badgeBackground: { red: 0, green: 0, blue: 0, alpha: 1 },
79
- badgeText: { red: 255, green: 255, blue: 255, alpha: 1 },
80
- freeGiftBackground: { red: 0, green: 0, blue: 0, alpha: 0.3 },
81
- freeGiftText: { red: 0, green: 0, blue: 0, alpha: 1 },
82
- freeGiftSelectedBackground: { red: 0, green: 0, blue: 0, alpha: 1 },
83
- freeGiftSelectedText: { red: 255, green: 255, blue: 255, alpha: 1 },
84
- upsellBackground: { red: 0, green: 0, blue: 0, alpha: 0.2 },
85
- upsellText: { red: 0, green: 0, blue: 0, alpha: 1 },
86
- upsellSelectedBackground: { red: 0, green: 0, blue: 0, alpha: 0.2 },
87
- upsellSelectedText: { red: 0, green: 0, blue: 0, alpha: 1 }
88
- },
89
- fonts: {
90
- blockTitle: { size: "14", style: "bold" },
91
- title: { size: "20", style: "bold" },
92
- subtitle: { size: "14", style: "regular" },
93
- label: { size: "12", style: "bold" },
94
- freeGift: { size: "13", style: "bold" },
95
- upsell: { size: "13", style: "bold" },
96
- unitLabel: { size: "14", style: "regular" }
97
- },
98
- dealBars: [
99
- {
100
- id: "single",
101
- dealBarType: "quantity-break",
102
- quantitySelector: !1,
103
- title: "Single",
104
- subtitle: "Standard price",
105
- label: "",
106
- quantity: 1,
107
- discountType: "default",
108
- discountValue: "",
109
- badgeStyle: "simple",
110
- badgeText: "",
111
- badgeImageGID: null,
112
- mediaImageGID: null,
113
- freeGifts: [],
114
- multipleGiftsSelectors: [],
115
- upsells: [],
116
- showAsSoldOutEnabled: !1,
117
- showAsSoldOut: null,
118
- productPersonalisation: null,
119
- highlights: null,
120
- sellingPlanEnabled: !1,
121
- sellingPlanGid: null
122
- },
123
- {
124
- id: "duo",
125
- dealBarType: "quantity-break",
126
- quantitySelector: !1,
127
- title: "Duo",
128
- subtitle: "You save 20%",
129
- label: "SAVE $32",
130
- quantity: 2,
131
- discountType: "percentage",
132
- discountValue: "20",
133
- badgeStyle: "most-popular",
134
- badgeText: "",
135
- badgeImageGID: null,
136
- mediaImageGID: null,
137
- freeGifts: [],
138
- multipleGiftsSelectors: [],
139
- upsells: [],
140
- showAsSoldOutEnabled: !1,
141
- showAsSoldOut: null,
142
- productPersonalisation: null,
143
- highlights: null,
144
- sellingPlanEnabled: !1,
145
- sellingPlanGid: null
146
- },
147
- {
148
- id: "trio",
149
- dealBarType: "quantity-break",
150
- quantitySelector: !1,
151
- title: "Trio",
152
- subtitle: "You save 25%",
153
- label: "SAVE $60",
154
- quantity: 3,
155
- discountType: "percentage",
156
- discountValue: "25",
157
- badgeStyle: "simple",
158
- badgeText: "",
159
- badgeImageGID: null,
160
- mediaImageGID: null,
161
- freeGifts: [],
162
- multipleGiftsSelectors: [],
163
- upsells: [],
164
- showAsSoldOutEnabled: !1,
165
- showAsSoldOut: null,
166
- productPersonalisation: null,
167
- highlights: null,
168
- sellingPlanEnabled: !1,
169
- sellingPlanGid: null
170
- }
171
- ],
172
- swatchOptions: [],
173
- swatchSize: 18,
174
- swatchShape: "circle",
175
- imageSize: 48,
176
- imageCornerRadius: 6,
177
- defaultVariantsV2: [],
178
- collectionBreaksEnabled: !1,
179
- collectionBreaks: null,
180
- chooseProductModal: null,
181
- timerEnabled: !1,
182
- timer: null,
183
- subscriptionsEnabled: !1,
184
- subscriptions: null,
185
- stickyAtcEnabled: !1,
186
- stickyAtc: null,
187
- progressiveGiftsEnabled: !1,
188
- progressiveGifts: null,
189
- checkboxUpsellsEnabled: !1,
190
- checkboxUpsells: null,
191
- customStylesEnabled: !1,
192
- shopCustomStyles: "",
193
- customStyles: "",
194
- lowStockAlertEnabled: !1,
195
- lowStockAlert: null
196
- }, B = {
197
- shopifyDomain: "",
198
- moneyFormat: "${{amount}}",
199
- locale: "en",
200
- country: "US",
201
- currencyRate: 1,
202
- marketId: 0,
203
- productId: null,
204
- storefrontAccessToken: null,
205
- accessScopes: [],
206
- customApiHost: null,
207
- keepQuantityInput: !1,
208
- ignoreDeselect: !1,
209
- ignoreUnitPrice: !1,
210
- requireCustomerLogin: !1,
211
- abTestsRunning: !1,
212
- webPixel: !1,
213
- b2bCustomer: !1,
214
- isLoggedIn: !1,
215
- preview: !0,
216
- previewAlerts: !1,
217
- defaultTranslations: {
218
- "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
219
- "system.invalid_variant": "Sorry, this is not currently available.",
220
- "system.unavailable_option_value": "Unavailable",
221
- "system.confirm": "Confirm",
222
- "system.cancel": "Cancel",
223
- "system.free": "FREE",
224
- "system.search": "Search",
225
- "system.sort_by": "Sort by",
226
- "system.sort_relevance": "Relevance",
227
- "system.sort_newest_first": "Newest first",
228
- "system.sort_price_low_to_high": "Price: Low → High",
229
- "system.sort_price_high_to_low": "Price: High → Low",
230
- "system.no_results_found": "No results found",
231
- "system.no_results_description": "We can't find any item matching your search.",
232
- "system.clear_search": "Clear search",
233
- "system.no_products_available": "No products available"
234
- },
235
- customSelectors: {
236
- quantity: null,
237
- addToCartButton: null,
238
- variantPicker: null,
239
- price: null,
240
- priceCompare: null
241
- },
242
- featureFlags: {},
243
- shopCustomStyles: ""
244
- }, T = {
245
- config: B,
246
- dealBlock: x,
247
- product: N,
248
- otherProducts: [],
249
- mediaImages: [],
250
- collectionBreaksProducts: [],
251
- translations: {}
252
- }, v = ({
253
- country: t,
254
- language: e
255
- }) => {
256
- const l = [];
257
- return t && l.push(`country: ${t}`), e && l.push(`language: ${e}`), l.length > 0 ? `@inContext(${l.join(", ")})` : "";
258
- }, q = async (t, {
259
- useExternalMetafieldNamespace: e,
260
- useMetaobjects: l
261
- }) => l ? U(
262
- t
263
- ) : M(t), M = async (t, e) => {
264
- var a;
265
- const l = (a = (await t.query(
266
- `
267
- query FetchDealBlocks($metafieldNamespace: String!) {
268
- shop {
269
- metafield(namespace: $metafieldNamespace, key: "deal_blocks") {
270
- value
271
- }
272
- }
273
- }
274
- `,
275
- {
276
- variables: {
277
- metafieldNamespace: "app--2935586817--kaching_bundles"
278
- }
279
- }
280
- )).shop.metafield) == null ? void 0 : a.value;
281
- return l ? JSON.parse(l) : [];
282
- }, U = async (t, e) => {
283
- const l = "app--2935586817--deal_block", a = [];
284
- let n = null;
285
- for (; ; ) {
286
- const o = await t.query(
287
- `
288
- query FetchDealBlockMetaobjects($type: String!, $cursor: String) {
289
- metaobjects(type: $type, first: 250, after: $cursor) {
290
- nodes {
291
- fields {
292
- key
293
- value
294
- }
295
- }
296
- pageInfo {
297
- hasNextPage
298
- endCursor
299
- }
300
- }
301
- }
302
- `,
303
- {
304
- variables: {
305
- type: l,
306
- cursor: n
307
- }
308
- }
309
- );
310
- for (const c of o.metaobjects.nodes) {
311
- const s = c.fields.find(
312
- (m) => m.key === "settings"
313
- );
314
- s != null && s.value && a.push(JSON.parse(s.value));
315
- }
316
- if (!o.metaobjects.pageInfo.hasNextPage)
317
- break;
318
- n = o.metaobjects.pageInfo.endCursor;
319
- }
320
- return a;
321
- }, w = "app--2935586817", L = async (t, {
322
- language: e,
323
- country: l,
324
- useExternalMetafieldNamespace: a
325
- }) => {
326
- const n = `${w}--kaching_bundles`, o = w, c = v({ country: l }), {
327
- localization: {
328
- country: {
329
- currency: { isoCode: s }
330
- }
331
- },
332
- shop: {
333
- moneyFormat: m,
334
- paymentSettings: { currencyCode: p },
335
- currencyRateConstant: d,
336
- primaryDomain: f,
337
- settingsMetafield: u
338
- }
339
- } = await t.query(
340
- `
341
- query config($metafieldNamespace: String!, $settingsNamespace: String!) ${c} {
342
- localization {
343
- country {
344
- currency {
345
- isoCode
346
- }
347
- }
348
- }
349
- shop {
350
- moneyFormat
351
- paymentSettings {
352
- currencyCode
353
- }
354
- primaryDomain {
355
- host
356
- }
357
- currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
358
- value
359
- }
360
- settingsMetafield: metafield(namespace: $settingsNamespace, key: "config") {
361
- value
362
- }
363
- }
364
- }
365
- `,
366
- {
367
- variables: {
368
- metafieldNamespace: n,
369
- settingsNamespace: o
370
- }
371
- }
372
- ), r = s === p ? m : V(s), g = d ? O(d.value) : 1, i = u ? JSON.parse(u.value) : null, h = (i == null ? void 0 : i.feature_flags) ?? {}, y = (i == null ? void 0 : i.custom_selectors) ?? {};
373
- return {
374
- shopifyDomain: f.host,
375
- moneyFormat: r,
376
- locale: (e == null ? void 0 : e.toLowerCase()) || "en",
377
- liquidLocale: (e == null ? void 0 : e.toLowerCase()) || "en",
378
- country: l ?? "US",
379
- currencyRate: g,
380
- marketId: 0,
381
- productId: null,
382
- storefrontAccessToken: (i == null ? void 0 : i.storefront_access_token) ?? null,
383
- accessScopes: (i == null ? void 0 : i.access_scopes) ?? [],
384
- customApiHost: (i == null ? void 0 : i.custom_api_host) ?? null,
385
- keepQuantityInput: (i == null ? void 0 : i.keep_quantity_input) ?? !1,
386
- ignoreDeselect: (i == null ? void 0 : i.ignore_deselect) ?? !1,
387
- ignoreUnitPrice: (i == null ? void 0 : i.ignore_unit_price) ?? !1,
388
- requireCustomerLogin: (i == null ? void 0 : i.require_customer_login) ?? !1,
389
- abTestsRunning: (i == null ? void 0 : i.ab_tests_running) ?? !1,
390
- webPixel: (i == null ? void 0 : i.web_pixel) ?? !1,
391
- b2bCustomer: !1,
392
- isLoggedIn: !1,
393
- preview: !1,
394
- previewAlerts: !1,
395
- defaultTranslations: {
396
- "system.out_of_stock": "Out of stock",
397
- "system.invalid_variant": "Invalid variant",
398
- "system.unavailable_option_value": "Unavailable option value",
399
- "system.confirm": "Confirm",
400
- "system.cancel": "Cancel",
401
- "system.free": "FREE",
402
- "system.search": "Search",
403
- "system.sort_by": "Sort by",
404
- "system.sort_relevance": "Relevance",
405
- "system.sort_newest_first": "Newest first",
406
- "system.sort_price_low_to_high": "Price: Low → High",
407
- "system.sort_price_high_to_low": "Price: High → Low",
408
- "system.no_results_found": "No results found",
409
- "system.no_results_description": "We can't find any item matching your search.",
410
- "system.clear_search": "Clear search",
411
- "system.no_products_available": "No products available"
412
- },
413
- customSelectors: {
414
- quantity: y.quantity ?? null,
415
- addToCartButton: y.add_to_cart_button ?? null,
416
- variantPicker: y.variant_picker ?? null,
417
- price: y.price ?? null,
418
- priceCompare: y.price_compare ?? null
419
- },
420
- shopCustomStyles: (i == null ? void 0 : i.shop_custom_styles) ?? "",
421
- featureFlags: h
422
- };
423
- }, O = (t) => JSON.parse(t).amount / 1e6, V = (t) => new Intl.NumberFormat("en", {
424
- style: "currency",
425
- currency: t,
426
- currencyDisplay: "narrowSymbol"
427
- }).format(1).replace(/1(\.0+)?/, "{{amount}}"), F = async (t, e, l = 200) => (e = e.filter(Boolean).filter((a) => !a.startsWith("placeholder")), e.length === 0 ? [] : (await t.query(
428
- `
429
- query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
430
- nodes(ids: $mediaImageIds) {
431
- ... on MediaImage {
432
- id
433
- image {
434
- url(transform: { maxWidth: $size, maxHeight: $size })
435
- }
436
- }
437
- }
438
- }
439
- `,
440
- {
441
- variables: {
442
- mediaImageIds: e,
443
- size: l
444
- }
445
- }
446
- )).nodes.filter(Boolean).map((a) => ({
447
- gid: a.id,
448
- url: a.image.url
449
- }))), A = async (t, {
450
- country: e,
451
- language: l,
452
- blockVisibility: a,
453
- excludedProductGIDs: n,
454
- selectedProductGIDs: o,
455
- selectedCollectionGIDs: c,
456
- limit: s = 250
457
- }) => {
458
- switch (a) {
459
- case "selected-products":
460
- return o.slice(0, s);
461
- case "all-products":
462
- case "excluded-products": {
463
- const m = v({ country: e, language: l });
464
- let p = (await t.query(
465
- `
466
- query FetchProductGIDs($limit: Int!) ${m} {
467
- products(first: $limit) {
468
- nodes {
469
- id
470
- }
471
- }
472
- }
473
- `,
474
- {
475
- variables: {
476
- limit: s
477
- }
478
- }
479
- )).products.nodes.map((d) => d.id);
480
- return a === "excluded-products" && (p = p.filter(
481
- (d) => !n.includes(d)
482
- )), p;
483
- }
484
- case "selected-collections": {
485
- const m = v({ country: e, language: l }), p = (await t.query(
486
- `
487
- query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${m} {
488
- nodes(ids: $collectionGIDs) {
489
- ... on Collection {
490
- products(first: $limit) {
491
- nodes {
492
- id
493
- }
494
- }
495
- }
496
- }
497
- }
498
- `,
499
- {
500
- variables: {
501
- collectionGIDs: c,
502
- limit: s
503
- }
504
- }
505
- )).nodes.filter((d) => d !== null).flatMap(
506
- (d) => d.products.nodes.map((f) => f.id)
507
- );
508
- return Array.from(new Set(p)).slice(0, s);
509
- }
510
- }
511
- }, G = `
512
- id
513
- availableForSale
514
- price {
515
- amount
516
- }
517
- compareAtPrice {
518
- amount
519
- }
520
- selectedOptions {
521
- name
522
- value
523
- }
524
- image {
525
- id
526
- url(transform: { maxWidth: 200, maxHeight: 200 })
527
- }
528
- unitPriceMeasurement {
529
- quantityUnit
530
- quantityValue
531
- referenceUnit
532
- referenceValue
533
- }
534
- requiresComponents
535
- sellingPlanAllocations(first: 100) @include(if: $includeSellingPlans) {
536
- nodes {
537
- sellingPlan {
538
- id
539
- }
540
- priceAdjustments {
541
- price {
542
- amount
543
- }
544
- }
545
- }
546
- }
547
- quantityAvailable @include(if: $includeAvailableQuantity)
548
- `, k = async (t, {
549
- country: e,
550
- language: l,
551
- productIds: a,
552
- includeSellingPlans: n = !0,
553
- includeAvailableQuantity: o = !0,
554
- useExternalMetafieldNamespace: c = !1
555
- }) => {
556
- if (!a.length)
557
- return [];
558
- const s = a.map((d) => typeof d == "string" && d.startsWith("gid://") ? d : `gid://shopify/Product/${d}`), m = v({ country: e, language: l });
559
- let p = (await t.query(
560
- `
561
- query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${m} {
562
- nodes(ids: $productGIDs) {
563
- ... on Product {
564
- id
565
- handle
566
- onlineStoreUrl
567
- availableForSale
568
- createdAt
569
- title
570
- featuredImage {
571
- url
572
- }
573
- options {
574
- name
575
- optionValues {
576
- id
577
- name
578
- swatch {
579
- color
580
- image {
581
- previewImage {
582
- url(transform: { maxWidth: 200, maxHeight: 200 })
583
- }
584
- }
585
- }
586
- }
587
- }
588
- variants(first: 250) {
589
- nodes {
590
- ${G}
591
- }
592
- }
593
- collections(first: 50) {
594
- nodes {
595
- id
596
- }
597
- }
598
- metafield: metafield(namespace: $metafieldNamespace, key: "text") {
599
- value
600
- }
601
- metafield2: metafield(namespace: $metafieldNamespace, key: "text2") {
602
- value
603
- }
604
- metafield3: metafield(namespace: $metafieldNamespace, key: "text3") {
605
- value
606
- }
607
- metafield4: metafield(namespace: $metafieldNamespace, key: "text4") {
608
- value
609
- }
610
- requiresSellingPlan
611
- sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
612
- nodes {
613
- sellingPlans(first: 100) {
614
- nodes {
615
- id
616
- name
617
- priceAdjustments {
618
- adjustmentValue {
619
- __typename
620
- ... on SellingPlanPercentagePriceAdjustment {
621
- adjustmentPercentage
622
- }
623
- ... on SellingPlanFixedAmountPriceAdjustment {
624
- adjustmentAmount {
625
- amount
626
- }
627
- }
628
- ... on SellingPlanFixedPriceAdjustment {
629
- price {
630
- amount
631
- }
632
- }
633
- }
634
- }
635
- }
636
- }
637
- }
638
- }
639
- }
640
- }
641
- }
642
- `,
643
- {
644
- variables: {
645
- productGIDs: s,
646
- includeSellingPlans: n,
647
- includeAvailableQuantity: o,
648
- metafieldNamespace: c ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles"
649
- }
650
- }
651
- )).nodes.filter(
652
- (d) => d != null
653
- );
654
- return p = await Promise.all(
655
- p.map(
656
- (d) => j(t, d, {
657
- includeSellingPlans: n,
658
- includeAvailableQuantity: o
659
- })
660
- )
661
- ), p.map(z);
662
- }, j = async (t, e, l) => {
663
- if (e.variants.nodes.length < 250)
664
- return e;
665
- const a = /* @__PURE__ */ new Set(), n = [], o = [], c = async (s) => {
666
- let m = !0, p = null;
667
- for (; m; ) {
668
- const d = await t.query(
669
- `
670
- query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!) {
671
- product(id: $productGID) {
672
- variants(first: 250, after: $cursor, reverse: $reverse) {
673
- nodes {
674
- ${G}
675
- }
676
- pageInfo {
677
- endCursor
678
- hasNextPage
679
- }
680
- }
681
- }
682
- }
683
- `,
684
- {
685
- variables: {
686
- productGID: e.id,
687
- cursor: p,
688
- reverse: s,
689
- ...l
690
- }
691
- }
692
- ), { nodes: f, pageInfo: u } = d.product.variants;
693
- for (const r of f) {
694
- if (a.has(r.id)) {
695
- m = !1;
696
- break;
697
- }
698
- a.add(r.id), s ? o.push(r) : n.push(r);
699
- }
700
- u.hasNextPage || (m = !1), p = u.endCursor;
701
- }
702
- };
703
- return await Promise.all([
704
- c(!1),
705
- c(!0)
706
- ]), e.variants.nodes = [...n, ...o.reverse()], e;
707
- }, z = (t) => {
708
- var c, s, m, p, d, f;
709
- const e = t.variants.nodes.map(
710
- ({ unitPriceMeasurement: u, ...r }) => {
711
- var g, i;
712
- return {
713
- id: Number(r.id.split("/").pop()),
714
- availableForSale: r.availableForSale,
715
- price: Math.round(Number(r.price.amount) * 100),
716
- compareAtPrice: r.compareAtPrice ? Math.round(Number(r.compareAtPrice.amount) * 100) : null,
717
- options: r.selectedOptions.map((h) => h.value),
718
- imageId: r.image ? Number(r.image.id.split("/").pop()) : null,
719
- image: ((g = r.image) == null ? void 0 : g.url) || null,
720
- sellingPlans: ((i = r.sellingPlanAllocations) == null ? void 0 : i.nodes.map((h) => ({
721
- id: Number(h.sellingPlan.id.split("/").pop()),
722
- price: h.priceAdjustments.length > 0 ? Math.round(Number(h.priceAdjustments[0].price.amount) * 100) : Math.round(Number(r.price.amount) * 100)
723
- }))) || [],
724
- inventoryManagement: null,
725
- // Storefront API does not return inventory management, only available in liquid
726
- inventoryPolicy: null,
727
- // Storefront API does not return inventory policy, only available in liquid
728
- inventoryQuantity: r.quantityAvailable ?? null,
729
- unitPriceMeasurement: u != null && u.quantityUnit && (u != null && u.referenceUnit) ? {
730
- quantityValue: u.quantityValue,
731
- quantityUnit: u.quantityUnit.toLowerCase(),
732
- referenceValue: u.referenceValue,
733
- referenceUnit: u.referenceUnit.toLowerCase()
734
- } : null
735
- };
736
- }
737
- ), l = t.options.map((u, r) => {
738
- const g = u.optionValues.map((i) => {
739
- var h, y, b, I;
740
- return {
741
- id: Number(i.id.split("/").pop()),
742
- defaultName: i.name,
743
- name: i.name,
744
- swatch: {
745
- color: ((h = i.swatch) == null ? void 0 : h.color) || null,
746
- image: ((I = (b = (y = i.swatch) == null ? void 0 : y.image) == null ? void 0 : b.previewImage) == null ? void 0 : I.url) || null
747
- }
748
- };
749
- });
750
- return {
751
- defaultName: u.name,
752
- name: u.name,
753
- position: r + 1,
754
- optionValues: R(g, r, e)
755
- };
756
- }), a = (u) => {
757
- const r = u.priceAdjustments[0];
758
- if (!r)
759
- return null;
760
- const g = r.adjustmentValue;
761
- switch (g.__typename) {
762
- case "SellingPlanPercentagePriceAdjustment":
763
- return {
764
- type: "percentage",
765
- value: g.adjustmentPercentage
766
- };
767
- case "SellingPlanFixedAmountPriceAdjustment":
768
- return {
769
- type: "fixed_amount",
770
- value: Number(g.adjustmentAmount.amount) * 100
771
- };
772
- case "SellingPlanFixedPriceAdjustment":
773
- return {
774
- type: "price",
775
- value: Number(g.price.amount) * 100
776
- };
777
- default:
778
- throw new Error(
779
- `Unknown price adjustment type: ${g.__typename}`
780
- );
781
- }
782
- }, n = ((c = t.sellingPlanGroups) == null ? void 0 : c.nodes.flatMap(
783
- (u) => u.sellingPlans.nodes.map((r) => ({
784
- id: Number(r.id.split("/").pop()),
785
- name: r.name,
786
- priceAdjustment: a(r)
787
- }))
788
- )) || [], o = t.variants.nodes.some(
789
- (u) => u.requiresComponents
790
- );
791
- return {
792
- id: Number(t.id.split("/").pop()),
793
- handle: t.handle,
794
- url: t.onlineStoreUrl,
795
- availableForSale: t.availableForSale,
796
- createdAt: t.createdAt,
797
- title: t.title,
798
- image: ((s = t.featuredImage) == null ? void 0 : s.url) || null,
799
- collectionIds: t.collections.nodes.map(
800
- (u) => Number(u.id.split("/").pop())
801
- ),
802
- options: l,
803
- selectedVariantId: Number(
804
- t.variants.nodes[0].id.split("/").pop()
805
- ),
806
- variants: e,
807
- requiresSellingPlan: t.requiresSellingPlan,
808
- sellingPlans: n,
809
- isNativeBundle: o,
810
- metafields: {
811
- text: ((m = t.metafield) == null ? void 0 : m.value) || null,
812
- text2: ((p = t.metafield2) == null ? void 0 : p.value) || null,
813
- text3: ((d = t.metafield3) == null ? void 0 : d.value) || null,
814
- text4: ((f = t.metafield4) == null ? void 0 : f.value) || null
815
- }
816
- };
817
- }, R = (t, e, l) => t.filter((a) => l.filter(
818
- (n) => n.options[e] === a.name
819
- ).length > 0), H = (t, e) => {
820
- const l = [], a = t.filter(
821
- (s) => s.blockVisibility === "selected-products"
822
- );
823
- for (const s of a)
824
- s.selectedProductIds.map(Number).includes(e.id) && l.push(s);
825
- const n = t.filter(
826
- (s) => s.blockVisibility === "selected-collections"
827
- );
828
- for (const s of n)
829
- e.collectionIds.some(
830
- (m) => s.selectedCollectionIds.map(Number).includes(m)
831
- ) && l.push(s);
832
- const o = t.filter(
833
- (s) => s.blockVisibility === "excluded-products"
834
- );
835
- for (const s of o)
836
- !s.excludedProductIds.map(Number).includes(e.id) && !(s.excludedCollectionIds || []).some(
837
- (m) => e.collectionIds.includes(m)
838
- ) && l.push(s);
839
- const c = t.filter(
840
- (s) => s.blockVisibility === "all-products"
841
- );
842
- for (const s of c)
843
- l.push(s);
844
- return l;
845
- }, J = (t) => [
846
- ...Q(t),
847
- ...W(t),
848
- ...X(t),
849
- ...K(t),
850
- ...Y(t),
851
- ...Z(t),
852
- ...ee(t),
853
- ...te(t),
854
- ...le(t),
855
- ...se(t)
856
- ].filter((e) => e != null && !e.includes("placeholder")), Q = (t) => t.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), W = (t) => t.dealBars.map(
857
- ({ freeGifts: e }) => (e || []).map((l) => l.mediaImageGID)
858
- ).reduce((e, l) => e.concat(l), []).filter((e) => e != null), X = (t) => t.dealBars.flatMap(
859
- ({ multipleGiftsSelectors: e }) => (e || []).map((l) => l.mediaImageGID)
860
- ).filter((e) => e != null), K = (t) => t.dealBars.map(({ upsells: e }) => (e || []).map((l) => l.mediaImageGID)).reduce((e, l) => e.concat(l), []).filter((e) => e != null), Y = (t) => t.swatchOptions ? t.swatchOptions.reduce((e, l) => {
861
- const a = l.images.map((n) => n.mediaImageGID).filter((n) => n != null);
862
- return [...e, ...a];
863
- }, []) : [], Z = (t) => {
864
- if (!t.collectionBreaksEnabled || !t.collectionBreaks)
865
- return [];
866
- const e = t.collectionBreaks.mediaImageGID;
867
- return e ? [e] : [];
868
- }, ee = (t) => {
869
- var e, l, a;
870
- return t.progressiveGifts ? [
871
- ...((e = t.progressiveGifts.gifts) == null ? void 0 : e.map((n) => n.mediaImageGID)) || [],
872
- (l = t.progressiveGifts.style) == null ? void 0 : l.lockedMediaImageGID,
873
- (a = t.progressiveGifts.dealBarStyle) == null ? void 0 : a.lockedMediaImageGID
874
- ].filter((n) => n != null) : [];
875
- }, te = (t) => !t.checkboxUpsellsEnabled || !t.checkboxUpsells ? [] : t.checkboxUpsells.upsells.map((e) => e.mediaImageGID).filter((e) => e != null), le = (t) => t.dealBars.map((e) => {
876
- var l;
877
- return (l = e.productPersonalisation) == null ? void 0 : l.mediaImageGID;
878
- }).filter((e) => e != null), se = (t) => t.dealBars.map((e) => {
879
- var l;
880
- return (l = e.highlights) == null ? void 0 : l.customIconGID;
881
- }).filter((e) => e != null), ae = (t) => {
882
- const e = [
883
- ...ne(t),
884
- ...ie(t),
885
- ...re(t),
886
- ...oe(t),
887
- ...ce(t),
888
- ...ue(t),
889
- ...de(t)
890
- ];
891
- return Array.from(new Set(e.filter((l) => l != null)));
892
- }, ne = (t) => t.dealBars.flatMap(
893
- ({ freeGifts: e }) => e ? e.map((l) => l.productGID) : []
894
- ).filter((e) => e != null), ie = (t) => t.dealBars.flatMap(
895
- ({ multipleGiftsSelectors: e }) => e ? e.flatMap(
896
- (l) => l.products ? l.products.map((a) => a.id) : []
897
- ) : []
898
- ).filter((e) => e != null), re = (t) => {
899
- var e;
900
- return t.progressiveGiftsEnabled ? ((e = t.progressiveGifts) == null ? void 0 : e.gifts.map((l) => l.productGID).filter((l) => l != null)) || [] : [];
901
- }, oe = (t) => t.dealBars.flatMap(({ upsells: e }) => e ? e.map((l) => l.productGID) : []).filter((e) => e != null), ce = (t) => t.dealBars.filter((e) => e.dealBarType === "bundle").flatMap(
902
- ({ bundleProducts: e }) => e ? e.map((l) => l.productGID) : []
903
- ).filter((e) => e != null).filter((e) => e !== "default"), ue = (t) => !t.checkboxUpsellsEnabled || !t.checkboxUpsells ? [] : t.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), de = (t) => t.dealBars.filter((e) => e.dealBarType === "sku").flatMap(({ productGID: e }) => e ? [e] : []);
904
- class C {
905
- constructor(e, l) {
906
- this.storefrontApiVersion = "2025-10", this.storefrontAccessToken = l, this.shopifyDomain = e;
907
- }
908
- async query(e, l) {
909
- var s;
910
- const a = (l == null ? void 0 : l.variables) ?? {};
911
- let n = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;
912
- const o = (s = e.match(/query\s+(\w+)/)) == null ? void 0 : s[1];
913
- o && (n += `?operation_name=${o}`);
914
- const c = await (await fetch(n, {
915
- method: "POST",
916
- headers: {
917
- "Content-Type": "application/json",
918
- "X-Shopify-Storefront-Access-Token": this.storefrontAccessToken
919
- },
920
- body: JSON.stringify({
921
- query: e,
922
- variables: a
923
- })
924
- })).text();
925
- if (!c)
926
- throw new Error("Empty graphql response");
927
- return JSON.parse(c).data;
928
- }
929
- }
930
- const me = async (t, e, { country: l, language: a }) => {
931
- const n = e.collectionBreaks;
932
- if (!e.collectionBreaksEnabled || !n) return;
933
- let o;
934
- n.visibility === "deal-products" ? o = await A(t, {
935
- country: l,
936
- language: a,
937
- blockVisibility: e.blockVisibility,
938
- excludedProductGIDs: (e.excludedProductIds || []).map(
939
- (s) => `gid://shopify/Product/${s}`
940
- ),
941
- selectedProductGIDs: (e.selectedProductIds || []).map(
942
- (s) => `gid://shopify/Product/${s}`
943
- ),
944
- selectedCollectionGIDs: (e.selectedCollectionIds || []).map(
945
- (s) => `gid://shopify/Collection/${s}`
946
- )
947
- }) : o = await A(t, {
948
- country: l,
949
- language: a,
950
- blockVisibility: n.visibility,
951
- excludedProductGIDs: (n.excludedProducts || []).map(
952
- ({ id: s }) => s
953
- ),
954
- selectedProductGIDs: (n.selectedProducts || []).map(
955
- ({ id: s }) => s
956
- ),
957
- selectedCollectionGIDs: (n.selectedCollections || []).map(
958
- ({ id: s }) => s
959
- )
960
- }), o = o.slice(0, 250);
961
- let c = await k(t, {
962
- country: l,
963
- language: a,
964
- productIds: o.map((s) => Number(s.split("/").pop())),
965
- useExternalMetafieldNamespace: !0
966
- });
967
- return c = c.filter(
968
- (s) => s.availableForSale
969
- ), c;
970
- }, pe = () => ({
971
- "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
972
- "system.invalid_variant": "Sorry, this is not currently available.",
973
- "system.unavailable_option_value": "Unavailable",
974
- "system.confirm": "Confirm",
975
- "system.cancel": "Cancel",
976
- "system.free": "FREE",
977
- "system.search": "Search",
978
- "system.sort_by": "Sort by",
979
- "system.sort_relevance": "Relevance",
980
- "system.sort_newest_first": "Newest first",
981
- "system.sort_price_low_to_high": "Price: Low → High",
982
- "system.sort_price_high_to_low": "Price: High → Low",
983
- "system.no_results_found": "No results found",
984
- "system.no_results_description": "We can't find any item matching your search.",
985
- "system.clear_search": "Clear search",
986
- "system.no_products_available": "No products available"
987
- }), fe = async (t, {
988
- productId: e,
989
- dealBlockId: l,
990
- country: a,
991
- language: n
992
- }) => {
993
- try {
994
- const o = [Number(e.split("/").pop())], c = new C(
995
- t.shopifyDomain,
996
- t.storefrontAccessToken
997
- ), s = await L(c, {
998
- language: n,
999
- country: a,
1000
- useExternalMetafieldNamespace: !0
1001
- }), m = s.storefrontAccessToken ? new C(
1002
- s.shopifyDomain,
1003
- s.storefrontAccessToken
1004
- ) : c, [p, d] = await Promise.all([
1005
- k(m, {
1006
- country: a,
1007
- language: n,
1008
- productIds: o,
1009
- useExternalMetafieldNamespace: !0
1010
- }),
1011
- q(m, {
1012
- useExternalMetafieldNamespace: !0,
1013
- useMetaobjects: s.featureFlags.storefront_metaobjects
1014
- })
1015
- ]), f = p[0];
1016
- if (!f)
1017
- return null;
1018
- const u = H(d, f);
1019
- let r;
1020
- if (l ? (r = u.find(
1021
- (E) => E.id === l || E.nanoId === l
1022
- ), r || (r = u[0])) : r = u[0], !r)
1023
- return null;
1024
- const g = J(r), i = ae(r), [h, y, b, I] = await Promise.all([
1025
- k(m, {
1026
- country: a,
1027
- language: n,
1028
- productIds: i,
1029
- useExternalMetafieldNamespace: !0
1030
- }),
1031
- F(m, g, 300),
1032
- me(m, r, {
1033
- country: a,
1034
- language: n
1035
- }),
1036
- pe()
1037
- ]);
1038
- return {
1039
- product: f,
1040
- dealBlock: r,
1041
- config: s,
1042
- otherProducts: h,
1043
- mediaImages: y,
1044
- collectionBreaksProducts: b ?? [],
1045
- translations: I
1046
- };
1047
- } catch (o) {
1048
- return console.error(o), null;
1049
- }
1050
- }, P = "kaching-bundles-block", D = 1e4, ge = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", he = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", _ = /* @__PURE__ */ new WeakSet(), $ = async (t) => {
1051
- const e = t.document;
1052
- if (!t.customElements.get(P)) {
1053
- if (_.has(e))
1054
- return S(t, P);
1055
- _.add(e);
1056
- try {
1057
- await Ie(t);
1058
- } catch (l) {
1059
- throw _.delete(e), l;
1060
- }
1061
- }
1062
- }, ye = () => typeof window < "u" && typeof window.__KACHING_DEV__ < "u", be = () => ye() ? ge : he, Ie = (t) => {
1063
- const e = t.document;
1064
- return new Promise((l, a) => {
1065
- const n = be();
1066
- if (e.querySelector(
1067
- `script[src="${n}"]`
1068
- )) {
1069
- S(t, P).then(l).catch(a);
1070
- return;
1071
- }
1072
- const c = e.createElement("script");
1073
- c.src = n, c.onload = () => S(t, P).then(l).catch(a), c.onerror = () => a(new Error("Failed to load script")), e.head.appendChild(c);
1074
- });
1075
- }, S = (t, e) => new Promise((l, a) => {
1076
- if (t.customElements.get(e)) {
1077
- l();
1078
- return;
1079
- }
1080
- Promise.race([
1081
- t.customElements.whenDefined(e),
1082
- new Promise(
1083
- (n, o) => setTimeout(
1084
- () => o(
1085
- new Error(
1086
- `Custom element "${e}" failed to register within ${D}ms`
1087
- )
1088
- ),
1089
- D
1090
- )
1091
- )
1092
- ]).then(() => l()).catch(a);
1093
- });
1094
- class ve extends HTMLElement {
1095
- constructor() {
1096
- super(...arguments), this.innerElement = null, this.handleItemsChanged = null, this.initializeId = 0;
1097
- }
1098
- static get observedAttributes() {
1099
- return ["selected-variant-id", "product-id", "country", "language"];
1100
- }
1101
- async connectedCallback() {
1102
- await this.initialize();
1103
- }
1104
- async initialize() {
1105
- var c, s;
1106
- const e = ++this.initializeId;
1107
- if (this.cleanup(), this.hasAttribute("demo")) {
1108
- if (await $(window), e !== this.initializeId) return;
1109
- this.renderInnerElement(T);
1110
- return;
1111
- }
1112
- const l = this.getAttribute("shop-domain"), a = this.getAttribute("storefront-token"), n = this.getAttribute("product-id");
1113
- if (!l || !a || !n) return;
1114
- const [o] = await Promise.all([
1115
- fe(
1116
- {
1117
- shopifyDomain: l,
1118
- storefrontAccessToken: a
1119
- },
1120
- {
1121
- productId: n,
1122
- dealBlockId: this.getAttribute("deal-block-id") ?? void 0,
1123
- country: ((c = this.getAttribute("country")) == null ? void 0 : c.toUpperCase()) ?? void 0,
1124
- language: ((s = this.getAttribute("language")) == null ? void 0 : s.toUpperCase()) ?? void 0
1125
- }
1126
- ),
1127
- $(window)
1128
- ]);
1129
- !o || e !== this.initializeId || this.renderInnerElement(o);
1130
- }
1131
- renderInnerElement(e) {
1132
- const {
1133
- config: l,
1134
- dealBlock: a,
1135
- product: n,
1136
- otherProducts: o,
1137
- mediaImages: c,
1138
- collectionBreaksProducts: s,
1139
- translations: m
1140
- } = e;
1141
- this.innerElement = document.createElement(
1142
- "kaching-bundles-block"
1143
- ), this.innerElement.setAttribute("deal-block-id", a.id), this.innerElement.setAttribute("config", JSON.stringify(l)), this.innerElement.setAttribute("deal-block", JSON.stringify(a)), this.innerElement.setAttribute(
1144
- "media-images",
1145
- JSON.stringify(c ?? [])
1146
- ), this.innerElement.setAttribute("product", JSON.stringify(n)), this.innerElement.setAttribute(
1147
- "other-products",
1148
- JSON.stringify(o ?? [])
1149
- ), this.innerElement.setAttribute(
1150
- "collection-breaks-products",
1151
- JSON.stringify(s ?? [])
1152
- ), this.innerElement.setAttribute(
1153
- "translations",
1154
- JSON.stringify(m ?? {})
1155
- );
1156
- const p = this.getAttribute("selected-variant-id");
1157
- this.innerElement.setAttribute(
1158
- "current-variant-id",
1159
- String(p ? p.split("/").pop() : n.variants[0].id)
1160
- ), this.hasAttribute("compact") && this.innerElement.setAttribute("compact", "");
1161
- const d = this.innerElement, f = () => {
1162
- if (this.innerElement !== d) return;
1163
- const r = d.items();
1164
- r && this.dispatchEvent(
1165
- new CustomEvent("items-changed", {
1166
- detail: { items: r },
1167
- bubbles: !0
1168
- })
1169
- );
1170
- };
1171
- this.handleItemsChanged = (r) => {
1172
- r.stopPropagation(), f();
1173
- };
1174
- const u = this.handleItemsChanged;
1175
- d.addEventListener(
1176
- "kaching-bundles-block-loaded",
1177
- () => {
1178
- this.innerElement === d && (d.addEventListener("items-changed", u), this.dispatchEvent(new CustomEvent("loaded", { bubbles: !0 })));
1179
- },
1180
- { once: !0 }
1181
- ), this.appendChild(this.innerElement);
1182
- }
1183
- cleanup() {
1184
- this.handleItemsChanged && this.innerElement && (this.innerElement.removeEventListener(
1185
- "items-changed",
1186
- this.handleItemsChanged
1187
- ), this.handleItemsChanged = null), this.innerElement && (this.innerElement.remove(), this.innerElement = null);
1188
- }
1189
- attributeChangedCallback(e, l, a) {
1190
- l !== a && this.isConnected && (e === "product-id" || e === "country" || e === "language" ? this.initialize() : e === "selected-variant-id" && this.innerElement && a && this.innerElement.setAttribute(
1191
- "current-variant-id",
1192
- a.includes("/") ? String(a.split("/").pop()) : a
1193
- ));
1194
- }
1195
- items() {
1196
- return this.innerElement ? this.innerElement.items() : [];
1197
- }
1198
- disconnectedCallback() {
1199
- this.cleanup(), this.initializeId++;
1200
- }
1201
- }
1202
- customElements.define("kaching-bundle-component", ve);