@kachingappz/bundles-js 0.2.2 → 0.3.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/README.md CHANGED
@@ -35,7 +35,7 @@ npm install @kachingappz/bundles-js
35
35
  | `selected-variant-id` | No | Currently selected variant ID (plain ID or full GID) |
36
36
  | `country` | No | Country code for localization (e.g. `US`) |
37
37
  | `language` | No | Language code for localization (e.g. `EN`) |
38
- | `deal-bars-only` | No | Show only deal bars, hiding title, timer, gifts, upsells, etc. |
38
+ | `compact` | No | Compact mode — hides block title, timer, and checkbox upsells |
39
39
  | `demo` | No | Render with placeholder data (no credentials needed) |
40
40
 
41
41
  ## Events
@@ -1,4 +1,4 @@
1
- (function(){"use strict";const N={config:{shopifyDomain:"",moneyFormat:"${{amount}}",locale:"en",country:"US",currencyRate:1,marketId:0,productId:null,storefrontAccessToken:null,accessScopes:[],customApiHost:null,keepQuantityInput:!1,ignoreDeselect:!1,ignoreUnitPrice:!1,requireCustomerLogin:!1,abTestsRunning:!1,webPixel:!1,b2bCustomer:!1,isLoggedIn:!1,preview:!0,previewAlerts:!1,defaultTranslations:{"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"},customSelectors:{quantity:null,addToCartButton:null,variantPicker:null,price:null,priceCompare:null},featureFlags:{},shopCustomStyles:""},dealBlock:{id:"example",nanoId:"example",blockName:"Bundle",discountName:"",blockTitle:"BUNDLE & SAVE",blockLayout:"vertical",blockVisibility:"all-products",marketId:null,currency:null,excludeB2bCustomers:!1,excludePos:!1,startTimestamp:0,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!0,disableVariantOptionSync:!1,hideUnavailableOptions:!1,showPricesPerItem:!1,showBothPrices:!1,unitLabel:"",useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:".00",updateNativePrice:!1,updateNativePriceType:"item",skipCart:!1,showVariantsForSingleQuantity:!1,preselectedDealBarId:"duo",cornerRadius:8,spacing:1,selectedProductIds:[],selectedCollectionIds:[],excludedProductIds:[],excludedCollectionIds:[],colors:{background:{red:255,green:255,blue:255,alpha:1},selectedBackground:{red:255,green:255,blue:255,alpha:1},border:{red:0,green:0,blue:0,alpha:1},blockTitle:{red:0,green:0,blue:0,alpha:1},title:{red:0,green:0,blue:0,alpha:1},subtitle:{red:85,green:85,blue:85,alpha:1},price:{red:0,green:0,blue:0,alpha:1},fullPrice:{red:85,green:85,blue:85,alpha:1},labelBackground:{red:238,green:238,blue:238,alpha:1},label:{red:0,green:0,blue:0,alpha:1},badgeBackground:{red:0,green:0,blue:0,alpha:1},badgeText:{red:255,green:255,blue:255,alpha:1},freeGiftBackground:{red:0,green:0,blue:0,alpha:.3},freeGiftText:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedBackground:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedText:{red:255,green:255,blue:255,alpha:1},upsellBackground:{red:0,green:0,blue:0,alpha:.2},upsellText:{red:0,green:0,blue:0,alpha:1},upsellSelectedBackground:{red:0,green:0,blue:0,alpha:.2},upsellSelectedText:{red:0,green:0,blue:0,alpha:1}},fonts:{blockTitle:{size:"14",style:"bold"},title:{size:"20",style:"medium"},subtitle:{size:"14",style:"regular"},label:{size:"12",style:"regular"},freeGift:{size:"13",style:"bold"},upsell:{size:"13",style:"bold"},unitLabel:{size:"14",style:"regular"}},dealBars:[{id:"single",dealBarType:"quantity-break",quantitySelector:!1,title:"Single",subtitle:"Standard price",label:"",quantity:1,discountType:"default",discountValue:"",badgeStyle:"simple",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null},{id:"duo",dealBarType:"quantity-break",quantitySelector:!1,title:"Duo",subtitle:"You save 20%",label:"SAVE $32",quantity:2,discountType:"percentage",discountValue:"20",badgeStyle:"most-popular",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null},{id:"trio",dealBarType:"quantity-break",quantitySelector:!1,title:"Trio",subtitle:"You save 25%",label:"SAVE $60",quantity:3,discountType:"percentage",discountValue:"25",badgeStyle:"simple",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null}],swatchOptions:[],swatchSize:18,swatchShape:"circle",imageSize:48,imageCornerRadius:6,defaultVariantsV2:[],collectionBreaksEnabled:!1,collectionBreaks:null,chooseProductModal:null,timerEnabled:!1,timer:null,subscriptionsEnabled:!1,subscriptions:null,stickyAtcEnabled:!1,stickyAtc:null,progressiveGiftsEnabled:!1,progressiveGifts:null,checkboxUpsellsEnabled:!1,checkboxUpsells:null,customStylesEnabled:!1,shopCustomStyles:"",customStyles:"",lowStockAlertEnabled:!1,lowStockAlert:null},product:{id:1,handle:"example-product",url:null,availableForSale:!0,title:"Example product",image:null,collectionIds:[],options:[],selectedVariantId:1,variants:[{id:1,availableForSale:!0,price:8e3,compareAtPrice:null,options:["Default Title"],imageId:null,image:null,unitPriceMeasurement:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50}],metafields:{text:null,text2:null,text3:null,text4:null},requiresSellingPlan:!1,sellingPlans:[],isNativeBundle:!1},otherProducts:[],mediaImages:[],collectionBreaksProducts:[],translations:{}},v=({country:t,language:e})=>{const l=[];return t&&l.push(`country: ${t}`),e&&l.push(`language: ${e}`),l.length>0?`@inContext(${l.join(", ")})`:""},x=async(t,{useExternalMetafieldNamespace:e,useMetaobjects:l})=>l?T(t):B(t),B=async(t,e)=>{var a;const l=(a=(await t.query(`
1
+ (function(){"use strict";const N={config:{shopifyDomain:"",moneyFormat:"${{amount}}",locale:"en",country:"US",currencyRate:1,marketId:0,productId:null,storefrontAccessToken:null,accessScopes:[],customApiHost:null,keepQuantityInput:!1,ignoreDeselect:!1,ignoreUnitPrice:!1,requireCustomerLogin:!1,abTestsRunning:!1,webPixel:!1,b2bCustomer:!1,isLoggedIn:!1,preview:!0,previewAlerts:!1,defaultTranslations:{"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"},customSelectors:{quantity:null,addToCartButton:null,variantPicker:null,price:null,priceCompare:null},featureFlags:{},shopCustomStyles:""},dealBlock:{id:"example",nanoId:"example",blockName:"Bundle",discountName:"",blockTitle:"BUNDLE & SAVE",blockLayout:"vertical",blockVisibility:"all-products",marketId:null,currency:null,excludeB2bCustomers:!1,excludePos:!1,startTimestamp:0,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!0,disableVariantOptionSync:!1,hideUnavailableOptions:!1,showPricesPerItem:!1,showBothPrices:!1,unitLabel:"",useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:".00",updateNativePrice:!1,updateNativePriceType:"item",skipCart:!1,showVariantsForSingleQuantity:!1,preselectedDealBarId:"duo",cornerRadius:8,spacing:1,selectedProductIds:[],selectedCollectionIds:[],excludedProductIds:[],excludedCollectionIds:[],colors:{background:{red:255,green:255,blue:255,alpha:1},selectedBackground:{red:255,green:255,blue:255,alpha:1},border:{red:0,green:0,blue:0,alpha:1},blockTitle:{red:0,green:0,blue:0,alpha:1},title:{red:0,green:0,blue:0,alpha:1},subtitle:{red:85,green:85,blue:85,alpha:1},price:{red:0,green:0,blue:0,alpha:1},fullPrice:{red:85,green:85,blue:85,alpha:1},labelBackground:{red:238,green:238,blue:238,alpha:1},label:{red:0,green:0,blue:0,alpha:1},badgeBackground:{red:0,green:0,blue:0,alpha:1},badgeText:{red:255,green:255,blue:255,alpha:1},freeGiftBackground:{red:0,green:0,blue:0,alpha:.3},freeGiftText:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedBackground:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedText:{red:255,green:255,blue:255,alpha:1},upsellBackground:{red:0,green:0,blue:0,alpha:.2},upsellText:{red:0,green:0,blue:0,alpha:1},upsellSelectedBackground:{red:0,green:0,blue:0,alpha:.2},upsellSelectedText:{red:0,green:0,blue:0,alpha:1}},fonts:{blockTitle:{size:"14",style:"bold"},title:{size:"20",style:"medium"},subtitle:{size:"14",style:"regular"},label:{size:"12",style:"regular"},freeGift:{size:"13",style:"bold"},upsell:{size:"13",style:"bold"},unitLabel:{size:"14",style:"regular"}},dealBars:[{id:"single",dealBarType:"quantity-break",quantitySelector:!1,title:"Single",subtitle:"Standard price",label:"",quantity:1,discountType:"default",discountValue:"",badgeStyle:"simple",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null},{id:"duo",dealBarType:"quantity-break",quantitySelector:!1,title:"Duo",subtitle:"You save 20%",label:"SAVE $32",quantity:2,discountType:"percentage",discountValue:"20",badgeStyle:"most-popular",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null},{id:"trio",dealBarType:"quantity-break",quantitySelector:!1,title:"Trio",subtitle:"You save 25%",label:"SAVE $60",quantity:3,discountType:"percentage",discountValue:"25",badgeStyle:"simple",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null}],swatchOptions:[],swatchSize:18,swatchShape:"circle",imageSize:48,imageCornerRadius:6,defaultVariantsV2:[],collectionBreaksEnabled:!1,collectionBreaks:null,chooseProductModal:null,timerEnabled:!1,timer:null,subscriptionsEnabled:!1,subscriptions:null,stickyAtcEnabled:!1,stickyAtc:null,progressiveGiftsEnabled:!1,progressiveGifts:null,checkboxUpsellsEnabled:!1,checkboxUpsells:null,customStylesEnabled:!1,shopCustomStyles:"",customStyles:"",lowStockAlertEnabled:!1,lowStockAlert:null},product:{id:1,handle:"example-product",url:null,availableForSale:!0,title:"Example product",image:null,collectionIds:[],options:[],selectedVariantId:1,variants:[{id:1,availableForSale:!0,price:8e3,compareAtPrice:null,options:["Default Title"],imageId:null,image:null,unitPriceMeasurement:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50}],metafields:{text:null,text2:null,text3:null,text4:null},requiresSellingPlan:!1,sellingPlans:[],isNativeBundle:!1},otherProducts:[],mediaImages:[],collectionBreaksProducts:[],translations:{}},P=({country:t,language:e})=>{const l=[];return t&&l.push(`country: ${t}`),e&&l.push(`language: ${e}`),l.length>0?`@inContext(${l.join(", ")})`:""},x=async(t,{useExternalMetafieldNamespace:e,useMetaobjects:l})=>l?T(t):B(t),B=async(t,e)=>{var a;const l=(a=(await t.query(`
2
2
  query FetchDealBlocks($metafieldNamespace: String!) {
3
3
  shop {
4
4
  metafield(namespace: $metafieldNamespace, key: "deal_blocks") {
@@ -21,7 +21,7 @@
21
21
  }
22
22
  }
23
23
  }
24
- `,{variables:{type:l,cursor:n}});for(const c of o.metaobjects.nodes){const s=c.fields.find(m=>m.key==="settings");s!=null&&s.value&&a.push(JSON.parse(s.value))}if(!o.metaobjects.pageInfo.hasNextPage)break;n=o.metaobjects.pageInfo.endCursor}return a},S="app--2935586817",q=async(t,{language:e,country:l,useExternalMetafieldNamespace:a})=>{const n=`${S}--kaching_bundles`,o=S,{shop:{moneyFormat:c,currencyRateConstant:s,primaryDomain:m,settingsMetafield:p}}=await t.query(`
24
+ `,{variables:{type:l,cursor:n}});for(const c of o.metaobjects.nodes){const s=c.fields.find(m=>m.key==="settings");s!=null&&s.value&&a.push(JSON.parse(s.value))}if(!o.metaobjects.pageInfo.hasNextPage)break;n=o.metaobjects.pageInfo.endCursor}return a},E="app--2935586817",q=async(t,{language:e,country:l,useExternalMetafieldNamespace:a})=>{const n=`${E}--kaching_bundles`,o=E,{shop:{moneyFormat:c,currencyRateConstant:s,primaryDomain:m,settingsMetafield:p}}=await t.query(`
25
25
  query config($metafieldNamespace: String!, $settingsNamespace: String!) {
26
26
  shop {
27
27
  moneyFormat
@@ -47,7 +47,7 @@
47
47
  }
48
48
  }
49
49
  }
50
- `,{variables:{mediaImageIds:e,size:l}})).nodes.filter(Boolean).map(a=>({gid:a.id,url:a.image.url}))),E=async(t,{country:e,language:l,blockVisibility:a,excludedProductGIDs:n,selectedProductGIDs:o,selectedCollectionGIDs:c,limit:s=250})=>{switch(a){case"selected-products":return o.slice(0,s);case"all-products":case"excluded-products":{const m=v({country:e,language:l});let p=(await t.query(`
50
+ `,{variables:{mediaImageIds:e,size:l}})).nodes.filter(Boolean).map(a=>({gid:a.id,url:a.image.url}))),A=async(t,{country:e,language:l,blockVisibility:a,excludedProductGIDs:n,selectedProductGIDs:o,selectedCollectionGIDs:c,limit:s=250})=>{switch(a){case"selected-products":return o.slice(0,s);case"all-products":case"excluded-products":{const m=P({country:e,language:l});let p=(await t.query(`
51
51
  query FetchProductGIDs($limit: Int!) ${m} {
52
52
  products(first: $limit) {
53
53
  nodes {
@@ -55,7 +55,7 @@
55
55
  }
56
56
  }
57
57
  }
58
- `,{variables:{limit:s}})).products.nodes.map(d=>d.id);return a==="excluded-products"&&(p=p.filter(d=>!n.includes(d))),p}case"selected-collections":{const m=v({country:e,language:l}),p=(await t.query(`
58
+ `,{variables:{limit:s}})).products.nodes.map(d=>d.id);return a==="excluded-products"&&(p=p.filter(d=>!n.includes(d))),p}case"selected-collections":{const m=P({country:e,language:l}),p=(await t.query(`
59
59
  query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${m} {
60
60
  nodes(ids: $collectionGIDs) {
61
61
  ... on Collection {
@@ -67,7 +67,7 @@
67
67
  }
68
68
  }
69
69
  }
70
- `,{variables:{collectionGIDs:c,limit:s}})).nodes.filter(d=>d!==null).flatMap(d=>d.products.nodes.map(i=>i.id));return Array.from(new Set(p)).slice(0,s)}}},A=`
70
+ `,{variables:{collectionGIDs:c,limit:s}})).nodes.filter(d=>d!==null).flatMap(d=>d.products.nodes.map(i=>i.id));return Array.from(new Set(p)).slice(0,s)}}},w=`
71
71
  id
72
72
  availableForSale
73
73
  price {
@@ -104,7 +104,7 @@
104
104
  }
105
105
  }
106
106
  quantityAvailable @include(if: $includeAvailableQuantity)
107
- `,P=async(t,{country:e,language:l,productIds:a,includeSellingPlans:n=!0,includeAvailableQuantity:o=!0,useExternalMetafieldNamespace:c=!1})=>{if(!a.length)return[];const s=a.map(d=>typeof d=="string"&&d.startsWith("gid://")?d:`gid://shopify/Product/${d}`),m=v({country:e,language:l});let p=(await t.query(`
107
+ `,_=async(t,{country:e,language:l,productIds:a,includeSellingPlans:n=!0,includeAvailableQuantity:o=!0,useExternalMetafieldNamespace:c=!1})=>{if(!a.length)return[];const s=a.map(d=>typeof d=="string"&&d.startsWith("gid://")?d:`gid://shopify/Product/${d}`),m=P({country:e,language:l});let p=(await t.query(`
108
108
  query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${m} {
109
109
  nodes(ids: $productGIDs) {
110
110
  ... on Product {
@@ -134,7 +134,7 @@
134
134
  }
135
135
  variants(first: 250) {
136
136
  nodes {
137
- ${A}
137
+ ${w}
138
138
  }
139
139
  }
140
140
  collections(first: 50) {
@@ -191,7 +191,7 @@
191
191
  product(id: $productGID) {
192
192
  variants(first: 250, after: $cursor, reverse: $reverse) {
193
193
  nodes {
194
- ${A}
194
+ ${w}
195
195
  }
196
196
  pageInfo {
197
197
  endCursor
@@ -200,4 +200,4 @@
200
200
  }
201
201
  }
202
202
  }
203
- `,{variables:{productGID:e.id,cursor:p,reverse:s,...l}}),{nodes:i,pageInfo:u}=d.product.variants;for(const r of i){if(a.has(r.id)){m=!1;break}a.add(r.id),s?o.push(r):n.push(r)}u.hasNextPage||(m=!1),p=u.endCursor}};return await Promise.all([c(!1),c(!0)]),e.variants.nodes=[...n,...o.reverse()],e},U=t=>{var c,s,m,p,d,i;const e=t.variants.nodes.map(({unitPriceMeasurement:u,...r})=>{var f,h;return{id:Number(r.id.split("/").pop()),availableForSale:r.availableForSale,price:Math.round(Number(r.price.amount)*100),compareAtPrice:r.compareAtPrice?Math.round(Number(r.compareAtPrice.amount)*100):null,options:r.selectedOptions.map(g=>g.value),imageId:r.image?Number(r.image.id.split("/").pop()):null,image:((f=r.image)==null?void 0:f.url)||null,sellingPlans:((h=r.sellingPlanAllocations)==null?void 0:h.nodes.map(g=>({id:Number(g.sellingPlan.id.split("/").pop()),price:g.priceAdjustments.length>0?Math.round(Number(g.priceAdjustments[0].price.amount)*100):Math.round(Number(r.price.amount)*100)})))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:r.quantityAvailable??null,unitPriceMeasurement:u!=null&&u.quantityUnit&&(u!=null&&u.referenceUnit)?{quantityValue:u.quantityValue,quantityUnit:u.quantityUnit.toLowerCase(),referenceValue:u.referenceValue,referenceUnit:u.referenceUnit.toLowerCase()}:null}}),l=t.options.map((u,r)=>{const f=u.optionValues.map(h=>{var g,b,y,I;return{id:Number(h.id.split("/").pop()),defaultName:h.name,name:h.name,swatch:{color:((g=h.swatch)==null?void 0:g.color)||null,image:((I=(y=(b=h.swatch)==null?void 0:b.image)==null?void 0:y.previewImage)==null?void 0:I.url)||null}}});return{defaultName:u.name,name:u.name,position:r+1,optionValues:V(f,r,e)}}),a=u=>{const r=u.priceAdjustments[0];if(!r)return null;const f=r.adjustmentValue;switch(f.__typename){case"SellingPlanPercentagePriceAdjustment":return{type:"percentage",value:f.adjustmentPercentage};case"SellingPlanFixedAmountPriceAdjustment":return{type:"fixed_amount",value:Number(f.adjustmentAmount.amount)*100};case"SellingPlanFixedPriceAdjustment":return{type:"price",value:Number(f.price.amount)*100};default:throw new Error(`Unknown price adjustment type: ${f.__typename}`)}},n=((c=t.sellingPlanGroups)==null?void 0:c.nodes.flatMap(u=>u.sellingPlans.nodes.map(r=>({id:Number(r.id.split("/").pop()),name:r.name,priceAdjustment:a(r)}))))||[],o=t.variants.nodes.some(u=>u.requiresComponents);return{id:Number(t.id.split("/").pop()),handle:t.handle,url:t.onlineStoreUrl,availableForSale:t.availableForSale,createdAt:t.createdAt,title:t.title,image:((s=t.featuredImage)==null?void 0:s.url)||null,collectionIds:t.collections.nodes.map(u=>Number(u.id.split("/").pop())),options:l,selectedVariantId:Number(t.variants.nodes[0].id.split("/").pop()),variants:e,requiresSellingPlan:t.requiresSellingPlan,sellingPlans:n,isNativeBundle:o,metafields:{text:((m=t.metafield)==null?void 0:m.value)||null,text2:((p=t.metafield2)==null?void 0:p.value)||null,text3:((d=t.metafield3)==null?void 0:d.value)||null,text4:((i=t.metafield4)==null?void 0:i.value)||null}}},V=(t,e,l)=>t.filter(a=>l.filter(n=>n.options[e]===a.name).length>0),F=(t,e)=>{const l=[],a=t.filter(s=>s.blockVisibility==="selected-products");for(const s of a)s.selectedProductIds.map(Number).includes(e.id)&&l.push(s);const n=t.filter(s=>s.blockVisibility==="selected-collections");for(const s of n)e.collectionIds.some(m=>s.selectedCollectionIds.map(Number).includes(m))&&l.push(s);const o=t.filter(s=>s.blockVisibility==="excluded-products");for(const s of o)!s.excludedProductIds.map(Number).includes(e.id)&&!(s.excludedCollectionIds||[]).some(m=>e.collectionIds.includes(m))&&l.push(s);const c=t.filter(s=>s.blockVisibility==="all-products");for(const s of c)l.push(s);return l},j=t=>[...z(t),...R(t),...H(t),...J(t),...Q(t),...X(t),...W(t),...K(t),...Y(t),...Z(t)].filter(e=>e!=null&&!e.includes("placeholder")),z=t=>t.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),R=t=>t.dealBars.map(({freeGifts:e})=>(e||[]).map(l=>l.mediaImageGID)).reduce((e,l)=>e.concat(l),[]).filter(e=>e!=null),H=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(l=>l.mediaImageGID)).filter(e=>e!=null),J=t=>t.dealBars.map(({upsells:e})=>(e||[]).map(l=>l.mediaImageGID)).reduce((e,l)=>e.concat(l),[]).filter(e=>e!=null),Q=t=>t.swatchOptions?t.swatchOptions.reduce((e,l)=>{const a=l.images.map(n=>n.mediaImageGID).filter(n=>n!=null);return[...e,...a]},[]):[],X=t=>{if(!t.collectionBreaksEnabled||!t.collectionBreaks)return[];const e=t.collectionBreaks.mediaImageGID;return e?[e]:[]},W=t=>{var e,l,a;return t.progressiveGifts?[...((e=t.progressiveGifts.gifts)==null?void 0:e.map(n=>n.mediaImageGID))||[],(l=t.progressiveGifts.style)==null?void 0:l.lockedMediaImageGID,(a=t.progressiveGifts.dealBarStyle)==null?void 0:a.lockedMediaImageGID].filter(n=>n!=null):[]},K=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.mediaImageGID).filter(e=>e!=null),Y=t=>t.dealBars.map(e=>{var l;return(l=e.productPersonalisation)==null?void 0:l.mediaImageGID}).filter(e=>e!=null),Z=t=>t.dealBars.map(e=>{var l;return(l=e.highlights)==null?void 0:l.customIconGID}).filter(e=>e!=null),ee=t=>{const e=[...te(t),...le(t),...se(t),...ae(t),...ne(t),...ie(t),...re(t)];return Array.from(new Set(e.filter(l=>l!=null)))},te=t=>t.dealBars.flatMap(({freeGifts:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null),le=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(l=>l.products?l.products.map(a=>a.id):[]):[]).filter(e=>e!=null),se=t=>{var e;return t.progressiveGiftsEnabled?((e=t.progressiveGifts)==null?void 0:e.gifts.map(l=>l.productGID).filter(l=>l!=null))||[]:[]},ae=t=>t.dealBars.flatMap(({upsells:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null),ne=t=>t.dealBars.filter(e=>e.dealBarType==="bundle").flatMap(({bundleProducts:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),ie=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),re=t=>t.dealBars.filter(e=>e.dealBarType==="sku").flatMap(({productGID:e})=>e?[e]:[]);class w{constructor(e,l){this.storefrontApiVersion="2025-10",this.storefrontAccessToken=l,this.shopifyDomain=e}async query(e,l){var s;const a=(l==null?void 0:l.variables)??{};let n=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const o=(s=e.match(/query\s+(\w+)/))==null?void 0:s[1];o&&(n+=`?operation_name=${o}`);const c=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:a})})).text();if(!c)throw new Error("Empty graphql response");return JSON.parse(c).data}}const oe=async(t,e,{country:l,language:a})=>{const n=e.collectionBreaks;if(!e.collectionBreaksEnabled||!n)return;let o;n.visibility==="deal-products"?o=await E(t,{country:l,language:a,blockVisibility:e.blockVisibility,excludedProductGIDs:(e.excludedProductIds||[]).map(s=>`gid://shopify/Product/${s}`),selectedProductGIDs:(e.selectedProductIds||[]).map(s=>`gid://shopify/Product/${s}`),selectedCollectionGIDs:(e.selectedCollectionIds||[]).map(s=>`gid://shopify/Collection/${s}`)}):o=await E(t,{country:l,language:a,blockVisibility:n.visibility,excludedProductGIDs:(n.excludedProducts||[]).map(({id:s})=>s),selectedProductGIDs:(n.selectedProducts||[]).map(({id:s})=>s),selectedCollectionGIDs:(n.selectedCollections||[]).map(({id:s})=>s)}),o=o.slice(0,250);let c=await P(t,{country:l,language:a,productIds:o.map(s=>Number(s.split("/").pop())),useExternalMetafieldNamespace:!0});return c=c.filter(s=>s.availableForSale),c},ce=()=>({"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"}),ue=async(t,{productId:e,dealBlockId:l,country:a,language:n})=>{try{const o=[Number(e.split("/").pop())],c=new w(t.shopifyDomain,t.storefrontAccessToken),s=await q(c,{language:n,country:a,useExternalMetafieldNamespace:!0}),m=s.storefrontAccessToken?new w(s.shopifyDomain,s.storefrontAccessToken):c,[p,d]=await Promise.all([P(m,{country:a,language:n,productIds:o,useExternalMetafieldNamespace:!0}),x(m,{useExternalMetafieldNamespace:!0,useMetaobjects:s.featureFlags.storefront_metaobjects})]),i=p[0];if(!i)return null;const u=F(d,i);let r;if(l?(r=u.find($=>$.id===l||$.nanoId===l),r||(r=u[0])):r=u[0],!r)return null;const f=j(r),h=ee(r),[g,b,y,I]=await Promise.all([P(m,{country:a,language:n,productIds:h,useExternalMetafieldNamespace:!0}),L(m,f,300),oe(m,r,{country:a,language:n}),ce()]);return{product:i,dealBlock:r,config:s,otherProducts:g,mediaImages:b,collectionBreaksProducts:y??[],translations:I}}catch(o){return console.error(o),null}},_="kaching-bundles-block",D=1e4,de="https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js",me="https://bundles-integrations.kachingappz.app/kaching-bundles-block.js",k=new WeakSet,C=async t=>{const e=t.document;if(!t.customElements.get(_)){if(k.has(e))return G(t,_);k.add(e);try{await he(t)}catch(l){throw k.delete(e),l}}},pe=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",fe=()=>pe()?de:me,he=t=>{const e=t.document;return new Promise((l,a)=>{const n=fe();if(e.querySelector(`script[src="${n}"]`)){l();return}const c=e.createElement("script");c.src=n,c.onload=()=>G(t,_).then(l).catch(a),c.onerror=()=>a(new Error("Failed to load script")),e.head.appendChild(c)})},G=(t,e)=>new Promise((l,a)=>{if(t.customElements.get(e)){l();return}Promise.race([t.customElements.whenDefined(e),new Promise((n,o)=>setTimeout(()=>o(new Error(`Custom element "${e}" failed to register within ${D}ms`)),D))]).then(()=>l()).catch(a)});class ge extends HTMLElement{constructor(){super(...arguments),this.innerElement=null,this.handleItemsChanged=null,this.initializeId=0}static get observedAttributes(){return["selected-variant-id","product-id"]}async connectedCallback(){await this.initialize()}async initialize(){var c,s;const e=++this.initializeId;if(this.cleanup(),this.hasAttribute("demo")){if(await C(window),e!==this.initializeId)return;this.renderInnerElement(N);return}const l=this.getAttribute("shop-domain"),a=this.getAttribute("storefront-token"),n=this.getAttribute("product-id");if(!l||!a||!n)return;const[o]=await Promise.all([ue({shopifyDomain:l,storefrontAccessToken:a},{productId:n,dealBlockId:this.getAttribute("deal-block-id")??void 0,country:((c=this.getAttribute("country"))==null?void 0:c.toUpperCase())??void 0,language:((s=this.getAttribute("language"))==null?void 0:s.toUpperCase())??void 0}),C(window)]);!o||e!==this.initializeId||this.renderInnerElement(o)}renderInnerElement(e){const{config:l,dealBlock:a,product:n,otherProducts:o,mediaImages:c,collectionBreaksProducts:s,translations:m}=e;this.innerElement=document.createElement("kaching-bundles-block"),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("media-images",JSON.stringify(c??[])),this.innerElement.setAttribute("product",JSON.stringify(n)),this.innerElement.setAttribute("other-products",JSON.stringify(o??[])),this.innerElement.setAttribute("collection-breaks-products",JSON.stringify(s??[])),this.innerElement.setAttribute("translations",JSON.stringify(m??{}));const p=this.getAttribute("selected-variant-id");this.innerElement.setAttribute("current-variant-id",String(p?p.split("/").pop():n.variants[0].id)),this.hasAttribute("deal-bars-only")&&this.innerElement.setAttribute("deal-bars-only",""),this.appendChild(this.innerElement);const d=this.innerElement,i=()=>{if(this.innerElement!==d)return;const r=d.items();r&&this.dispatchEvent(new CustomEvent("items-changed",{detail:{items:r},bubbles:!0}))};this.handleItemsChanged=r=>{r.stopPropagation(),i()};const u=this.handleItemsChanged;d.addEventListener("kaching-bundles-block-loaded",()=>{this.innerElement===d&&(d.addEventListener("items-changed",u),i(),this.dispatchEvent(new CustomEvent("loaded",{bubbles:!0})))},{once:!0})}cleanup(){this.handleItemsChanged&&this.innerElement&&(this.innerElement.removeEventListener("items-changed",this.handleItemsChanged),this.handleItemsChanged=null),this.innerElement&&(this.innerElement.remove(),this.innerElement=null)}attributeChangedCallback(e,l,a){l!==a&&this.isConnected&&(e==="product-id"?this.initialize():e==="selected-variant-id"&&this.innerElement&&a&&this.innerElement.setAttribute("current-variant-id",a.includes("/")?String(a.split("/").pop()):a))}items(){return this.innerElement?this.innerElement.items():[]}disconnectedCallback(){this.cleanup(),this.initializeId++}}customElements.define("kaching-bundle-component",ge)})();
203
+ `,{variables:{productGID:e.id,cursor:p,reverse:s,...l}}),{nodes:i,pageInfo:u}=d.product.variants;for(const r of i){if(a.has(r.id)){m=!1;break}a.add(r.id),s?o.push(r):n.push(r)}u.hasNextPage||(m=!1),p=u.endCursor}};return await Promise.all([c(!1),c(!0)]),e.variants.nodes=[...n,...o.reverse()],e},U=t=>{var c,s,m,p,d,i;const e=t.variants.nodes.map(({unitPriceMeasurement:u,...r})=>{var f,h;return{id:Number(r.id.split("/").pop()),availableForSale:r.availableForSale,price:Math.round(Number(r.price.amount)*100),compareAtPrice:r.compareAtPrice?Math.round(Number(r.compareAtPrice.amount)*100):null,options:r.selectedOptions.map(g=>g.value),imageId:r.image?Number(r.image.id.split("/").pop()):null,image:((f=r.image)==null?void 0:f.url)||null,sellingPlans:((h=r.sellingPlanAllocations)==null?void 0:h.nodes.map(g=>({id:Number(g.sellingPlan.id.split("/").pop()),price:g.priceAdjustments.length>0?Math.round(Number(g.priceAdjustments[0].price.amount)*100):Math.round(Number(r.price.amount)*100)})))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:r.quantityAvailable??null,unitPriceMeasurement:u!=null&&u.quantityUnit&&(u!=null&&u.referenceUnit)?{quantityValue:u.quantityValue,quantityUnit:u.quantityUnit.toLowerCase(),referenceValue:u.referenceValue,referenceUnit:u.referenceUnit.toLowerCase()}:null}}),l=t.options.map((u,r)=>{const f=u.optionValues.map(h=>{var g,y,I,v;return{id:Number(h.id.split("/").pop()),defaultName:h.name,name:h.name,swatch:{color:((g=h.swatch)==null?void 0:g.color)||null,image:((v=(I=(y=h.swatch)==null?void 0:y.image)==null?void 0:I.previewImage)==null?void 0:v.url)||null}}});return{defaultName:u.name,name:u.name,position:r+1,optionValues:V(f,r,e)}}),a=u=>{const r=u.priceAdjustments[0];if(!r)return null;const f=r.adjustmentValue;switch(f.__typename){case"SellingPlanPercentagePriceAdjustment":return{type:"percentage",value:f.adjustmentPercentage};case"SellingPlanFixedAmountPriceAdjustment":return{type:"fixed_amount",value:Number(f.adjustmentAmount.amount)*100};case"SellingPlanFixedPriceAdjustment":return{type:"price",value:Number(f.price.amount)*100};default:throw new Error(`Unknown price adjustment type: ${f.__typename}`)}},n=((c=t.sellingPlanGroups)==null?void 0:c.nodes.flatMap(u=>u.sellingPlans.nodes.map(r=>({id:Number(r.id.split("/").pop()),name:r.name,priceAdjustment:a(r)}))))||[],o=t.variants.nodes.some(u=>u.requiresComponents);return{id:Number(t.id.split("/").pop()),handle:t.handle,url:t.onlineStoreUrl,availableForSale:t.availableForSale,createdAt:t.createdAt,title:t.title,image:((s=t.featuredImage)==null?void 0:s.url)||null,collectionIds:t.collections.nodes.map(u=>Number(u.id.split("/").pop())),options:l,selectedVariantId:Number(t.variants.nodes[0].id.split("/").pop()),variants:e,requiresSellingPlan:t.requiresSellingPlan,sellingPlans:n,isNativeBundle:o,metafields:{text:((m=t.metafield)==null?void 0:m.value)||null,text2:((p=t.metafield2)==null?void 0:p.value)||null,text3:((d=t.metafield3)==null?void 0:d.value)||null,text4:((i=t.metafield4)==null?void 0:i.value)||null}}},V=(t,e,l)=>t.filter(a=>l.filter(n=>n.options[e]===a.name).length>0),F=(t,e)=>{const l=[],a=t.filter(s=>s.blockVisibility==="selected-products");for(const s of a)s.selectedProductIds.map(Number).includes(e.id)&&l.push(s);const n=t.filter(s=>s.blockVisibility==="selected-collections");for(const s of n)e.collectionIds.some(m=>s.selectedCollectionIds.map(Number).includes(m))&&l.push(s);const o=t.filter(s=>s.blockVisibility==="excluded-products");for(const s of o)!s.excludedProductIds.map(Number).includes(e.id)&&!(s.excludedCollectionIds||[]).some(m=>e.collectionIds.includes(m))&&l.push(s);const c=t.filter(s=>s.blockVisibility==="all-products");for(const s of c)l.push(s);return l},j=t=>[...z(t),...R(t),...H(t),...J(t),...Q(t),...X(t),...K(t),...W(t),...Y(t),...Z(t)].filter(e=>e!=null&&!e.includes("placeholder")),z=t=>t.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),R=t=>t.dealBars.map(({freeGifts:e})=>(e||[]).map(l=>l.mediaImageGID)).reduce((e,l)=>e.concat(l),[]).filter(e=>e!=null),H=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(l=>l.mediaImageGID)).filter(e=>e!=null),J=t=>t.dealBars.map(({upsells:e})=>(e||[]).map(l=>l.mediaImageGID)).reduce((e,l)=>e.concat(l),[]).filter(e=>e!=null),Q=t=>t.swatchOptions?t.swatchOptions.reduce((e,l)=>{const a=l.images.map(n=>n.mediaImageGID).filter(n=>n!=null);return[...e,...a]},[]):[],X=t=>{if(!t.collectionBreaksEnabled||!t.collectionBreaks)return[];const e=t.collectionBreaks.mediaImageGID;return e?[e]:[]},K=t=>{var e,l,a;return t.progressiveGifts?[...((e=t.progressiveGifts.gifts)==null?void 0:e.map(n=>n.mediaImageGID))||[],(l=t.progressiveGifts.style)==null?void 0:l.lockedMediaImageGID,(a=t.progressiveGifts.dealBarStyle)==null?void 0:a.lockedMediaImageGID].filter(n=>n!=null):[]},W=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.mediaImageGID).filter(e=>e!=null),Y=t=>t.dealBars.map(e=>{var l;return(l=e.productPersonalisation)==null?void 0:l.mediaImageGID}).filter(e=>e!=null),Z=t=>t.dealBars.map(e=>{var l;return(l=e.highlights)==null?void 0:l.customIconGID}).filter(e=>e!=null),ee=t=>{const e=[...te(t),...le(t),...se(t),...ae(t),...ne(t),...ie(t),...re(t)];return Array.from(new Set(e.filter(l=>l!=null)))},te=t=>t.dealBars.flatMap(({freeGifts:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null),le=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(l=>l.products?l.products.map(a=>a.id):[]):[]).filter(e=>e!=null),se=t=>{var e;return t.progressiveGiftsEnabled?((e=t.progressiveGifts)==null?void 0:e.gifts.map(l=>l.productGID).filter(l=>l!=null))||[]:[]},ae=t=>t.dealBars.flatMap(({upsells:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null),ne=t=>t.dealBars.filter(e=>e.dealBarType==="bundle").flatMap(({bundleProducts:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),ie=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),re=t=>t.dealBars.filter(e=>e.dealBarType==="sku").flatMap(({productGID:e})=>e?[e]:[]);class D{constructor(e,l){this.storefrontApiVersion="2025-10",this.storefrontAccessToken=l,this.shopifyDomain=e}async query(e,l){var s;const a=(l==null?void 0:l.variables)??{};let n=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const o=(s=e.match(/query\s+(\w+)/))==null?void 0:s[1];o&&(n+=`?operation_name=${o}`);const c=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:a})})).text();if(!c)throw new Error("Empty graphql response");return JSON.parse(c).data}}const oe=async(t,e,{country:l,language:a})=>{const n=e.collectionBreaks;if(!e.collectionBreaksEnabled||!n)return;let o;n.visibility==="deal-products"?o=await A(t,{country:l,language:a,blockVisibility:e.blockVisibility,excludedProductGIDs:(e.excludedProductIds||[]).map(s=>`gid://shopify/Product/${s}`),selectedProductGIDs:(e.selectedProductIds||[]).map(s=>`gid://shopify/Product/${s}`),selectedCollectionGIDs:(e.selectedCollectionIds||[]).map(s=>`gid://shopify/Collection/${s}`)}):o=await A(t,{country:l,language:a,blockVisibility:n.visibility,excludedProductGIDs:(n.excludedProducts||[]).map(({id:s})=>s),selectedProductGIDs:(n.selectedProducts||[]).map(({id:s})=>s),selectedCollectionGIDs:(n.selectedCollections||[]).map(({id:s})=>s)}),o=o.slice(0,250);let c=await _(t,{country:l,language:a,productIds:o.map(s=>Number(s.split("/").pop())),useExternalMetafieldNamespace:!0});return c=c.filter(s=>s.availableForSale),c},ce=()=>({"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"}),ue=async(t,{productId:e,dealBlockId:l,country:a,language:n})=>{try{const o=[Number(e.split("/").pop())],c=new D(t.shopifyDomain,t.storefrontAccessToken),s=await q(c,{language:n,country:a,useExternalMetafieldNamespace:!0}),m=s.storefrontAccessToken?new D(s.shopifyDomain,s.storefrontAccessToken):c,[p,d]=await Promise.all([_(m,{country:a,language:n,productIds:o,useExternalMetafieldNamespace:!0}),x(m,{useExternalMetafieldNamespace:!0,useMetaobjects:s.featureFlags.storefront_metaobjects})]),i=p[0];if(!i)return null;const u=F(d,i);let r;if(l?(r=u.find($=>$.id===l||$.nanoId===l),r||(r=u[0])):r=u[0],!r)return null;const f=j(r),h=ee(r),[g,y,I,v]=await Promise.all([_(m,{country:a,language:n,productIds:h,useExternalMetafieldNamespace:!0}),L(m,f,300),oe(m,r,{country:a,language:n}),ce()]);return{product:i,dealBlock:r,config:s,otherProducts:g,mediaImages:y,collectionBreaksProducts:I??[],translations:v}}catch(o){return console.error(o),null}},b="kaching-bundles-block",C=1e4,de="https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js",me="https://bundles-integrations.kachingappz.app/kaching-bundles-block.js",k=new WeakSet,G=async t=>{const e=t.document;if(!t.customElements.get(b)){if(k.has(e))return S(t,b);k.add(e);try{await he(t)}catch(l){throw k.delete(e),l}}},pe=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",fe=()=>pe()?de:me,he=t=>{const e=t.document;return new Promise((l,a)=>{const n=fe();if(e.querySelector(`script[src="${n}"]`)){S(t,b).then(l).catch(a);return}const c=e.createElement("script");c.src=n,c.onload=()=>S(t,b).then(l).catch(a),c.onerror=()=>a(new Error("Failed to load script")),e.head.appendChild(c)})},S=(t,e)=>new Promise((l,a)=>{if(t.customElements.get(e)){l();return}Promise.race([t.customElements.whenDefined(e),new Promise((n,o)=>setTimeout(()=>o(new Error(`Custom element "${e}" failed to register within ${C}ms`)),C))]).then(()=>l()).catch(a)});class ge extends HTMLElement{constructor(){super(...arguments),this.innerElement=null,this.handleItemsChanged=null,this.initializeId=0}static get observedAttributes(){return["selected-variant-id","product-id"]}async connectedCallback(){await this.initialize()}async initialize(){var c,s;const e=++this.initializeId;if(this.cleanup(),this.hasAttribute("demo")){if(await G(window),e!==this.initializeId)return;this.renderInnerElement(N);return}const l=this.getAttribute("shop-domain"),a=this.getAttribute("storefront-token"),n=this.getAttribute("product-id");if(!l||!a||!n)return;const[o]=await Promise.all([ue({shopifyDomain:l,storefrontAccessToken:a},{productId:n,dealBlockId:this.getAttribute("deal-block-id")??void 0,country:((c=this.getAttribute("country"))==null?void 0:c.toUpperCase())??void 0,language:((s=this.getAttribute("language"))==null?void 0:s.toUpperCase())??void 0}),G(window)]);!o||e!==this.initializeId||this.renderInnerElement(o)}renderInnerElement(e){const{config:l,dealBlock:a,product:n,otherProducts:o,mediaImages:c,collectionBreaksProducts:s,translations:m}=e;this.innerElement=document.createElement("kaching-bundles-block"),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("media-images",JSON.stringify(c??[])),this.innerElement.setAttribute("product",JSON.stringify(n)),this.innerElement.setAttribute("other-products",JSON.stringify(o??[])),this.innerElement.setAttribute("collection-breaks-products",JSON.stringify(s??[])),this.innerElement.setAttribute("translations",JSON.stringify(m??{}));const p=this.getAttribute("selected-variant-id");this.innerElement.setAttribute("current-variant-id",String(p?p.split("/").pop():n.variants[0].id)),this.hasAttribute("deal-bars-only")&&this.innerElement.setAttribute("deal-bars-only","");const d=this.innerElement,i=()=>{if(this.innerElement!==d)return;const r=d.items();r&&this.dispatchEvent(new CustomEvent("items-changed",{detail:{items:r},bubbles:!0}))};this.handleItemsChanged=r=>{r.stopPropagation(),i()};const u=this.handleItemsChanged;d.addEventListener("kaching-bundles-block-loaded",()=>{this.innerElement===d&&(d.addEventListener("items-changed",u),i(),this.dispatchEvent(new CustomEvent("loaded",{bubbles:!0})))},{once:!0}),this.appendChild(this.innerElement)}cleanup(){this.handleItemsChanged&&this.innerElement&&(this.innerElement.removeEventListener("items-changed",this.handleItemsChanged),this.handleItemsChanged=null),this.innerElement&&(this.innerElement.remove(),this.innerElement=null)}attributeChangedCallback(e,l,a){l!==a&&this.isConnected&&(e==="product-id"?this.initialize():e==="selected-variant-id"&&this.innerElement&&a&&this.innerElement.setAttribute("current-variant-id",a.includes("/")?String(a.split("/").pop()):a))}items(){return this.innerElement?this.innerElement.items():[]}disconnectedCallback(){this.cleanup(),this.initializeId++}}customElements.define("kaching-bundle-component",ge)})();
@@ -249,7 +249,7 @@ const N = {
249
249
  mediaImages: [],
250
250
  collectionBreaksProducts: [],
251
251
  translations: {}
252
- }, P = ({
252
+ }, _ = ({
253
253
  country: t,
254
254
  language: e
255
255
  }) => {
@@ -318,12 +318,12 @@ const N = {
318
318
  n = o.metaobjects.pageInfo.endCursor;
319
319
  }
320
320
  return a;
321
- }, E = "app--2935586817", L = async (t, {
321
+ }, A = "app--2935586817", L = async (t, {
322
322
  language: e,
323
323
  country: l,
324
324
  useExternalMetafieldNamespace: a
325
325
  }) => {
326
- const n = `${E}--kaching_bundles`, o = E, {
326
+ const n = `${A}--kaching_bundles`, o = A, {
327
327
  shop: {
328
328
  moneyFormat: c,
329
329
  currencyRateConstant: s,
@@ -426,7 +426,7 @@ const N = {
426
426
  )).nodes.filter(Boolean).map((a) => ({
427
427
  gid: a.id,
428
428
  url: a.image.url
429
- }))), A = async (t, {
429
+ }))), w = async (t, {
430
430
  country: e,
431
431
  language: l,
432
432
  blockVisibility: a,
@@ -440,7 +440,7 @@ const N = {
440
440
  return o.slice(0, s);
441
441
  case "all-products":
442
442
  case "excluded-products": {
443
- const m = P({ country: e, language: l });
443
+ const m = _({ country: e, language: l });
444
444
  let p = (await t.query(
445
445
  `
446
446
  query FetchProductGIDs($limit: Int!) ${m} {
@@ -462,7 +462,7 @@ const N = {
462
462
  )), p;
463
463
  }
464
464
  case "selected-collections": {
465
- const m = P({ country: e, language: l }), p = (await t.query(
465
+ const m = _({ country: e, language: l }), p = (await t.query(
466
466
  `
467
467
  query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${m} {
468
468
  nodes(ids: $collectionGIDs) {
@@ -488,7 +488,7 @@ const N = {
488
488
  return Array.from(new Set(p)).slice(0, s);
489
489
  }
490
490
  }
491
- }, $ = `
491
+ }, G = `
492
492
  id
493
493
  availableForSale
494
494
  price {
@@ -525,7 +525,7 @@ const N = {
525
525
  }
526
526
  }
527
527
  quantityAvailable @include(if: $includeAvailableQuantity)
528
- `, _ = async (t, {
528
+ `, k = async (t, {
529
529
  country: e,
530
530
  language: l,
531
531
  productIds: a,
@@ -535,7 +535,7 @@ const N = {
535
535
  }) => {
536
536
  if (!a.length)
537
537
  return [];
538
- const s = a.map((d) => typeof d == "string" && d.startsWith("gid://") ? d : `gid://shopify/Product/${d}`), m = P({ country: e, language: l });
538
+ const s = a.map((d) => typeof d == "string" && d.startsWith("gid://") ? d : `gid://shopify/Product/${d}`), m = _({ country: e, language: l });
539
539
  let p = (await t.query(
540
540
  `
541
541
  query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${m} {
@@ -567,7 +567,7 @@ const N = {
567
567
  }
568
568
  variants(first: 250) {
569
569
  nodes {
570
- ${$}
570
+ ${G}
571
571
  }
572
572
  }
573
573
  collections(first: 50) {
@@ -651,7 +651,7 @@ const N = {
651
651
  product(id: $productGID) {
652
652
  variants(first: 250, after: $cursor, reverse: $reverse) {
653
653
  nodes {
654
- ${$}
654
+ ${G}
655
655
  }
656
656
  pageInfo {
657
657
  endCursor
@@ -881,7 +881,7 @@ const N = {
881
881
  }, re = (t) => t.dealBars.flatMap(({ upsells: e }) => e ? e.map((l) => l.productGID) : []).filter((e) => e != null), oe = (t) => t.dealBars.filter((e) => e.dealBarType === "bundle").flatMap(
882
882
  ({ bundleProducts: e }) => e ? e.map((l) => l.productGID) : []
883
883
  ).filter((e) => e != null).filter((e) => e !== "default"), ce = (t) => !t.checkboxUpsellsEnabled || !t.checkboxUpsells ? [] : t.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), ue = (t) => t.dealBars.filter((e) => e.dealBarType === "sku").flatMap(({ productGID: e }) => e ? [e] : []);
884
- class w {
884
+ class D {
885
885
  constructor(e, l) {
886
886
  this.storefrontApiVersion = "2025-10", this.storefrontAccessToken = l, this.shopifyDomain = e;
887
887
  }
@@ -911,7 +911,7 @@ const de = async (t, e, { country: l, language: a }) => {
911
911
  const n = e.collectionBreaks;
912
912
  if (!e.collectionBreaksEnabled || !n) return;
913
913
  let o;
914
- n.visibility === "deal-products" ? o = await A(t, {
914
+ n.visibility === "deal-products" ? o = await w(t, {
915
915
  country: l,
916
916
  language: a,
917
917
  blockVisibility: e.blockVisibility,
@@ -924,7 +924,7 @@ const de = async (t, e, { country: l, language: a }) => {
924
924
  selectedCollectionGIDs: (e.selectedCollectionIds || []).map(
925
925
  (s) => `gid://shopify/Collection/${s}`
926
926
  )
927
- }) : o = await A(t, {
927
+ }) : o = await w(t, {
928
928
  country: l,
929
929
  language: a,
930
930
  blockVisibility: n.visibility,
@@ -938,7 +938,7 @@ const de = async (t, e, { country: l, language: a }) => {
938
938
  ({ id: s }) => s
939
939
  )
940
940
  }), o = o.slice(0, 250);
941
- let c = await _(t, {
941
+ let c = await k(t, {
942
942
  country: l,
943
943
  language: a,
944
944
  productIds: o.map((s) => Number(s.split("/").pop())),
@@ -971,18 +971,18 @@ const de = async (t, e, { country: l, language: a }) => {
971
971
  language: n
972
972
  }) => {
973
973
  try {
974
- const o = [Number(e.split("/").pop())], c = new w(
974
+ const o = [Number(e.split("/").pop())], c = new D(
975
975
  t.shopifyDomain,
976
976
  t.storefrontAccessToken
977
977
  ), s = await L(c, {
978
978
  language: n,
979
979
  country: a,
980
980
  useExternalMetafieldNamespace: !0
981
- }), m = s.storefrontAccessToken ? new w(
981
+ }), m = s.storefrontAccessToken ? new D(
982
982
  s.shopifyDomain,
983
983
  s.storefrontAccessToken
984
984
  ) : c, [p, d] = await Promise.all([
985
- _(m, {
985
+ k(m, {
986
986
  country: a,
987
987
  language: n,
988
988
  productIds: o,
@@ -998,11 +998,11 @@ const de = async (t, e, { country: l, language: a }) => {
998
998
  const u = R(d, i);
999
999
  let r;
1000
1000
  if (l ? (r = u.find(
1001
- (S) => S.id === l || S.nanoId === l
1001
+ (E) => E.id === l || E.nanoId === l
1002
1002
  ), r || (r = u[0])) : r = u[0], !r)
1003
1003
  return null;
1004
1004
  const f = H(r), h = se(r), [g, b, y, I] = await Promise.all([
1005
- _(m, {
1005
+ k(m, {
1006
1006
  country: a,
1007
1007
  language: n,
1008
1008
  productIds: h,
@@ -1027,16 +1027,16 @@ const de = async (t, e, { country: l, language: a }) => {
1027
1027
  } catch (o) {
1028
1028
  return console.error(o), null;
1029
1029
  }
1030
- }, k = "kaching-bundles-block", D = 1e4, fe = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", he = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", v = /* @__PURE__ */ new WeakSet(), C = async (t) => {
1030
+ }, v = "kaching-bundles-block", C = 1e4, fe = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", he = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", P = /* @__PURE__ */ new WeakSet(), $ = async (t) => {
1031
1031
  const e = t.document;
1032
- if (!t.customElements.get(k)) {
1033
- if (v.has(e))
1034
- return G(t, k);
1035
- v.add(e);
1032
+ if (!t.customElements.get(v)) {
1033
+ if (P.has(e))
1034
+ return S(t, v);
1035
+ P.add(e);
1036
1036
  try {
1037
1037
  await ye(t);
1038
1038
  } catch (l) {
1039
- throw v.delete(e), l;
1039
+ throw P.delete(e), l;
1040
1040
  }
1041
1041
  }
1042
1042
  }, ge = () => typeof window < "u" && typeof window.__KACHING_DEV__ < "u", be = () => ge() ? fe : he, ye = (t) => {
@@ -1046,13 +1046,13 @@ const de = async (t, e, { country: l, language: a }) => {
1046
1046
  if (e.querySelector(
1047
1047
  `script[src="${n}"]`
1048
1048
  )) {
1049
- l();
1049
+ S(t, v).then(l).catch(a);
1050
1050
  return;
1051
1051
  }
1052
1052
  const c = e.createElement("script");
1053
- c.src = n, c.onload = () => G(t, k).then(l).catch(a), c.onerror = () => a(new Error("Failed to load script")), e.head.appendChild(c);
1053
+ c.src = n, c.onload = () => S(t, v).then(l).catch(a), c.onerror = () => a(new Error("Failed to load script")), e.head.appendChild(c);
1054
1054
  });
1055
- }, G = (t, e) => new Promise((l, a) => {
1055
+ }, S = (t, e) => new Promise((l, a) => {
1056
1056
  if (t.customElements.get(e)) {
1057
1057
  l();
1058
1058
  return;
@@ -1063,10 +1063,10 @@ const de = async (t, e, { country: l, language: a }) => {
1063
1063
  (n, o) => setTimeout(
1064
1064
  () => o(
1065
1065
  new Error(
1066
- `Custom element "${e}" failed to register within ${D}ms`
1066
+ `Custom element "${e}" failed to register within ${C}ms`
1067
1067
  )
1068
1068
  ),
1069
- D
1069
+ C
1070
1070
  )
1071
1071
  )
1072
1072
  ]).then(() => l()).catch(a);
@@ -1085,7 +1085,7 @@ class Ie extends HTMLElement {
1085
1085
  var c, s;
1086
1086
  const e = ++this.initializeId;
1087
1087
  if (this.cleanup(), this.hasAttribute("demo")) {
1088
- if (await C(window), e !== this.initializeId) return;
1088
+ if (await $(window), e !== this.initializeId) return;
1089
1089
  this.renderInnerElement(T);
1090
1090
  return;
1091
1091
  }
@@ -1104,7 +1104,7 @@ class Ie extends HTMLElement {
1104
1104
  language: ((s = this.getAttribute("language")) == null ? void 0 : s.toUpperCase()) ?? void 0
1105
1105
  }
1106
1106
  ),
1107
- C(window)
1107
+ $(window)
1108
1108
  ]);
1109
1109
  !o || e !== this.initializeId || this.renderInnerElement(o);
1110
1110
  }
@@ -1137,7 +1137,7 @@ class Ie extends HTMLElement {
1137
1137
  this.innerElement.setAttribute(
1138
1138
  "current-variant-id",
1139
1139
  String(p ? p.split("/").pop() : n.variants[0].id)
1140
- ), this.hasAttribute("deal-bars-only") && this.innerElement.setAttribute("deal-bars-only", ""), this.appendChild(this.innerElement);
1140
+ ), this.hasAttribute("deal-bars-only") && this.innerElement.setAttribute("deal-bars-only", "");
1141
1141
  const d = this.innerElement, i = () => {
1142
1142
  if (this.innerElement !== d) return;
1143
1143
  const r = d.items();
@@ -1158,7 +1158,7 @@ class Ie extends HTMLElement {
1158
1158
  this.innerElement === d && (d.addEventListener("items-changed", u), i(), this.dispatchEvent(new CustomEvent("loaded", { bubbles: !0 })));
1159
1159
  },
1160
1160
  { once: !0 }
1161
- );
1161
+ ), this.appendChild(this.innerElement);
1162
1162
  }
1163
1163
  cleanup() {
1164
1164
  this.handleItemsChanged && this.innerElement && (this.innerElement.removeEventListener(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kachingappz/bundles-js",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/bundles-js.js",
6
6
  "module": "./dist/bundles-js.js",