@kachingappz/bundles-js 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles-js.iife.js +15 -15
- package/dist/bundles-js.js +147 -147
- package/package.json +1 -1
package/dist/bundles-js.iife.js
CHANGED
|
@@ -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:{}},
|
|
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") {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
`,{variables:{metafieldNamespace:"app--2935586817--kaching_bundles"}})).shop.metafield)==null?void 0:a.value;return l?JSON.parse(l):[]},T=async(t,e)=>{const l="app--2935586817--deal_block",a=[];let
|
|
9
|
+
`,{variables:{metafieldNamespace:"app--2935586817--kaching_bundles"}})).shop.metafield)==null?void 0:a.value;return l?JSON.parse(l):[]},T=async(t,e)=>{const l="app--2935586817--deal_block",a=[];let n=null;for(;;){const o=await t.query(`
|
|
10
10
|
query FetchDealBlockMetaobjects($type: String!, $cursor: String) {
|
|
11
11
|
metaobjects(type: $type, first: 250, after: $cursor) {
|
|
12
12
|
nodes {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
`,{variables:{type:l,cursor:
|
|
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
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
`,{variables:{metafieldNamespace:
|
|
39
|
+
`,{variables:{metafieldNamespace:n,settingsNamespace:o}}),d=s?M(s.value):1,i=p?JSON.parse(p.value):null,u=(i==null?void 0:i.feature_flags)??{},r=(i==null?void 0:i.custom_selectors)??{};return{shopifyDomain:m.host,moneyFormat:c,locale:(e==null?void 0:e.toLowerCase())||"en",liquidLocale:(e==null?void 0:e.toLowerCase())||"en",country:l??"US",currencyRate:d,marketId:0,productId:null,storefrontAccessToken:(i==null?void 0:i.storefront_access_token)??null,accessScopes:(i==null?void 0:i.access_scopes)??[],customApiHost:(i==null?void 0:i.custom_api_host)??null,keepQuantityInput:(i==null?void 0:i.keep_quantity_input)??!1,ignoreDeselect:(i==null?void 0:i.ignore_deselect)??!1,ignoreUnitPrice:(i==null?void 0:i.ignore_unit_price)??!1,requireCustomerLogin:(i==null?void 0:i.require_customer_login)??!1,abTestsRunning:(i==null?void 0:i.ab_tests_running)??!1,webPixel:(i==null?void 0:i.web_pixel)??!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,defaultTranslations:{"system.out_of_stock":"Out of stock","system.invalid_variant":"Invalid variant","system.unavailable_option_value":"Unavailable option value","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:r.quantity??null,addToCartButton:r.add_to_cart_button??null,variantPicker:r.variant_picker??null,price:r.price??null,priceCompare:r.price_compare??null},shopCustomStyles:(i==null?void 0:i.shop_custom_styles)??"",featureFlags:u}},M=t=>JSON.parse(t).amount/1e6,L=async(t,e,l=200)=>(e=e.filter(Boolean).filter(a=>!a.startsWith("placeholder")),e.length===0?[]:(await t.query(`
|
|
40
40
|
query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
|
|
41
41
|
nodes(ids: $mediaImageIds) {
|
|
42
42
|
... on MediaImage {
|
|
@@ -47,16 +47,16 @@
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
`,{variables:{mediaImageIds:e,size:l}})).nodes.filter(Boolean).map(a=>({gid:a.id,url:a.image.url}))),
|
|
51
|
-
query FetchProductGIDs($limit: Int!) ${
|
|
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
|
+
query FetchProductGIDs($limit: Int!) ${m} {
|
|
52
52
|
products(first: $limit) {
|
|
53
53
|
nodes {
|
|
54
54
|
id
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
`,{variables:{limit:s}})).products.nodes.map(
|
|
59
|
-
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${
|
|
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
|
+
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${m} {
|
|
60
60
|
nodes(ids: $collectionGIDs) {
|
|
61
61
|
... on Collection {
|
|
62
62
|
products(first: $limit) {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
`,{variables:{collectionGIDs:c,limit:s}})).nodes.filter(
|
|
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,8 +104,8 @@
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
quantityAvailable @include(if: $includeAvailableQuantity)
|
|
107
|
-
`,
|
|
108
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${
|
|
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
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${m} {
|
|
109
109
|
nodes(ids: $productGIDs) {
|
|
110
110
|
... on Product {
|
|
111
111
|
id
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
}
|
|
135
135
|
variants(first: 250) {
|
|
136
136
|
nodes {
|
|
137
|
-
${
|
|
137
|
+
${w}
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
collections(first: 50) {
|
|
@@ -186,12 +186,12 @@
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
`,{variables:{productGIDs:s,includeSellingPlans:
|
|
189
|
+
`,{variables:{productGIDs:s,includeSellingPlans:n,includeAvailableQuantity:o,metafieldNamespace:c?"app--2935586817--kaching_bundles":"$app:kaching_bundles"}})).nodes.filter(d=>d!=null);return p=await Promise.all(p.map(d=>O(t,d,{includeSellingPlans:n,includeAvailableQuantity:o}))),p.map(U)},O=async(t,e,l)=>{if(e.variants.nodes.length<250)return e;const a=new Set,n=[],o=[],c=async s=>{let m=!0,p=null;for(;m;){const d=await t.query(`
|
|
190
190
|
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!) {
|
|
191
191
|
product(id: $productGID) {
|
|
192
192
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
193
193
|
nodes {
|
|
194
|
-
${
|
|
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:n,pageInfo:u}=m.product.variants;for(const r of n){if(a.has(r.id)){d=!1;break}a.add(r.id),s?o.push(r):i.push(r)}u.hasNextPage||(d=!1),p=u.endCursor}};return await Promise.all([c(!1),c(!0)]),e.variants.nodes=[...i,...o.reverse()],e},U=t=>{var c,s,d,p,m,n;const e=t.variants.nodes.map(({unitPriceMeasurement:u,...r})=>{var f,g;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(h=>h.value),imageId:r.image?Number(r.image.id.split("/").pop()):null,image:((f=r.image)==null?void 0:f.url)||null,sellingPlans:((g=r.sellingPlanAllocations)==null?void 0:g.nodes.map(h=>({id:Number(h.sellingPlan.id.split("/").pop()),price:h.priceAdjustments.length>0?Math.round(Number(h.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(g=>{var h,b,y,I;return{id:Number(g.id.split("/").pop()),defaultName:g.name,name:g.name,swatch:{color:((h=g.swatch)==null?void 0:h.color)||null,image:((I=(y=(b=g.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}`)}},i=((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:i,isNativeBundle:o,metafields:{text:((d=t.metafield)==null?void 0:d.value)||null,text2:((p=t.metafield2)==null?void 0:p.value)||null,text3:((m=t.metafield3)==null?void 0:m.value)||null,text4:((n=t.metafield4)==null?void 0:n.value)||null}}},V=(t,e,l)=>t.filter(a=>l.filter(i=>i.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 i=t.filter(s=>s.blockVisibility==="selected-collections");for(const s of i)e.collectionIds.some(d=>s.selectedCollectionIds.map(Number).includes(d))&&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(d=>e.collectionIds.includes(d))&&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(i=>i.mediaImageGID).filter(i=>i!=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(i=>i.mediaImageGID))||[],(l=t.progressiveGifts.style)==null?void 0:l.lockedMediaImageGID,(a=t.progressiveGifts.dealBarStyle)==null?void 0:a.lockedMediaImageGID].filter(i=>i!=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 i=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const o=(s=e.match(/query\s+(\w+)/))==null?void 0:s[1];o&&(i+=`?operation_name=${o}`);const c=await(await fetch(i,{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 i=e.collectionBreaks;if(!e.collectionBreaksEnabled||!i)return;let o;i.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:i.visibility,excludedProductGIDs:(i.excludedProducts||[]).map(({id:s})=>s),selectedProductGIDs:(i.selectedProducts||[]).map(({id:s})=>s),selectedCollectionGIDs:(i.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:i})=>{try{const o=[Number(e.split("/").pop())],c=new w(t.shopifyDomain,t.storefrontAccessToken),s=await q(c,{language:i,country:a,useExternalMetafieldNamespace:!0}),d=s.storefrontAccessToken?new w(s.shopifyDomain,s.storefrontAccessToken):c,[p,m]=await Promise.all([P(d,{country:a,language:i,productIds:o,useExternalMetafieldNamespace:!0}),x(d,{useExternalMetafieldNamespace:!0,useMetaobjects:s.featureFlags.storefront_metaobjects})]),n=p[0];if(!n)return null;const u=F(m,n);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),g=ee(r),[h,b,y,I]=await Promise.all([P(d,{country:a,language:i,productIds:g,useExternalMetafieldNamespace:!0}),L(d,f,300),oe(d,r,{country:a,language:i}),ce()]);return{product:n,dealBlock:r,config:s,otherProducts:h,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 ge(t)}catch(l){throw k.delete(e),l}}},pe=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",fe=()=>pe()?de:me,ge=t=>{const e=t.document;return new Promise((l,a)=>{const i=fe();if(e.querySelector(`script[src="${i}"]`)){l();return}const c=e.createElement("script");c.src=i,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((i,o)=>setTimeout(()=>o(new Error(`Custom element "${e}" failed to register within ${D}ms`)),D))]).then(()=>l()).catch(a)});class he 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"),i=this.getAttribute("product-id");if(!l||!a||!i)return;const[o]=await Promise.all([ue({shopifyDomain:l,storefrontAccessToken:a},{productId:i,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:i,otherProducts:o,mediaImages:c,collectionBreaksProducts:s,translations:d}=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(i)),this.innerElement.setAttribute("other-products",JSON.stringify(o??[])),this.innerElement.setAttribute("collection-breaks-products",JSON.stringify(s??[])),this.innerElement.setAttribute("translations",JSON.stringify(d??{}));const p=this.getAttribute("selected-variant-id");this.innerElement.setAttribute("current-variant-id",String(p?p.split("/").pop():i.variants[0].id)),this.hasAttribute("deal-bars-only")&&this.innerElement.setAttribute("deal-bars-only",""),this.appendChild(this.innerElement);const m=()=>{const n=this.innerElement.items();n&&this.dispatchEvent(new CustomEvent("items-changed",{detail:{items:n},bubbles:!0}))};this.handleItemsChanged=n=>{n.stopPropagation(),m()},this.innerElement.addEventListener("kaching-bundles-block-loaded",()=>{this.innerElement.addEventListener("items-changed",this.handleItemsChanged),m(),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&&(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",he)})();
|
|
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)})();
|
package/dist/bundles-js.js
CHANGED
|
@@ -249,7 +249,7 @@ const N = {
|
|
|
249
249
|
mediaImages: [],
|
|
250
250
|
collectionBreaksProducts: [],
|
|
251
251
|
translations: {}
|
|
252
|
-
},
|
|
252
|
+
}, _ = ({
|
|
253
253
|
country: t,
|
|
254
254
|
language: e
|
|
255
255
|
}) => {
|
|
@@ -281,7 +281,7 @@ const N = {
|
|
|
281
281
|
return l ? JSON.parse(l) : [];
|
|
282
282
|
}, U = async (t, e) => {
|
|
283
283
|
const l = "app--2935586817--deal_block", a = [];
|
|
284
|
-
let
|
|
284
|
+
let n = null;
|
|
285
285
|
for (; ; ) {
|
|
286
286
|
const o = await t.query(
|
|
287
287
|
`
|
|
@@ -303,31 +303,31 @@ const N = {
|
|
|
303
303
|
{
|
|
304
304
|
variables: {
|
|
305
305
|
type: l,
|
|
306
|
-
cursor:
|
|
306
|
+
cursor: n
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
);
|
|
310
310
|
for (const c of o.metaobjects.nodes) {
|
|
311
311
|
const s = c.fields.find(
|
|
312
|
-
(
|
|
312
|
+
(m) => m.key === "settings"
|
|
313
313
|
);
|
|
314
314
|
s != null && s.value && a.push(JSON.parse(s.value));
|
|
315
315
|
}
|
|
316
316
|
if (!o.metaobjects.pageInfo.hasNextPage)
|
|
317
317
|
break;
|
|
318
|
-
|
|
318
|
+
n = o.metaobjects.pageInfo.endCursor;
|
|
319
319
|
}
|
|
320
320
|
return a;
|
|
321
|
-
},
|
|
321
|
+
}, A = "app--2935586817", L = async (t, {
|
|
322
322
|
language: e,
|
|
323
323
|
country: l,
|
|
324
324
|
useExternalMetafieldNamespace: a
|
|
325
325
|
}) => {
|
|
326
|
-
const
|
|
326
|
+
const n = `${A}--kaching_bundles`, o = A, {
|
|
327
327
|
shop: {
|
|
328
328
|
moneyFormat: c,
|
|
329
329
|
currencyRateConstant: s,
|
|
330
|
-
primaryDomain:
|
|
330
|
+
primaryDomain: m,
|
|
331
331
|
settingsMetafield: p
|
|
332
332
|
}
|
|
333
333
|
} = await t.query(
|
|
@@ -349,29 +349,29 @@ const N = {
|
|
|
349
349
|
`,
|
|
350
350
|
{
|
|
351
351
|
variables: {
|
|
352
|
-
metafieldNamespace:
|
|
352
|
+
metafieldNamespace: n,
|
|
353
353
|
settingsNamespace: o
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
),
|
|
356
|
+
), d = s ? O(s.value) : 1, i = p ? JSON.parse(p.value) : null, u = (i == null ? void 0 : i.feature_flags) ?? {}, r = (i == null ? void 0 : i.custom_selectors) ?? {};
|
|
357
357
|
return {
|
|
358
|
-
shopifyDomain:
|
|
358
|
+
shopifyDomain: m.host,
|
|
359
359
|
moneyFormat: c,
|
|
360
360
|
locale: (e == null ? void 0 : e.toLowerCase()) || "en",
|
|
361
361
|
liquidLocale: (e == null ? void 0 : e.toLowerCase()) || "en",
|
|
362
362
|
country: l ?? "US",
|
|
363
|
-
currencyRate:
|
|
363
|
+
currencyRate: d,
|
|
364
364
|
marketId: 0,
|
|
365
365
|
productId: null,
|
|
366
|
-
storefrontAccessToken: (
|
|
367
|
-
accessScopes: (
|
|
368
|
-
customApiHost: (
|
|
369
|
-
keepQuantityInput: (
|
|
370
|
-
ignoreDeselect: (
|
|
371
|
-
ignoreUnitPrice: (
|
|
372
|
-
requireCustomerLogin: (
|
|
373
|
-
abTestsRunning: (
|
|
374
|
-
webPixel: (
|
|
366
|
+
storefrontAccessToken: (i == null ? void 0 : i.storefront_access_token) ?? null,
|
|
367
|
+
accessScopes: (i == null ? void 0 : i.access_scopes) ?? [],
|
|
368
|
+
customApiHost: (i == null ? void 0 : i.custom_api_host) ?? null,
|
|
369
|
+
keepQuantityInput: (i == null ? void 0 : i.keep_quantity_input) ?? !1,
|
|
370
|
+
ignoreDeselect: (i == null ? void 0 : i.ignore_deselect) ?? !1,
|
|
371
|
+
ignoreUnitPrice: (i == null ? void 0 : i.ignore_unit_price) ?? !1,
|
|
372
|
+
requireCustomerLogin: (i == null ? void 0 : i.require_customer_login) ?? !1,
|
|
373
|
+
abTestsRunning: (i == null ? void 0 : i.ab_tests_running) ?? !1,
|
|
374
|
+
webPixel: (i == null ? void 0 : i.web_pixel) ?? !1,
|
|
375
375
|
b2bCustomer: !1,
|
|
376
376
|
isLoggedIn: !1,
|
|
377
377
|
preview: !1,
|
|
@@ -401,7 +401,7 @@ const N = {
|
|
|
401
401
|
price: r.price ?? null,
|
|
402
402
|
priceCompare: r.price_compare ?? null
|
|
403
403
|
},
|
|
404
|
-
shopCustomStyles: (
|
|
404
|
+
shopCustomStyles: (i == null ? void 0 : i.shop_custom_styles) ?? "",
|
|
405
405
|
featureFlags: u
|
|
406
406
|
};
|
|
407
407
|
}, O = (t) => JSON.parse(t).amount / 1e6, V = async (t, e, l = 200) => (e = e.filter(Boolean).filter((a) => !a.startsWith("placeholder")), e.length === 0 ? [] : (await t.query(
|
|
@@ -426,11 +426,11 @@ const N = {
|
|
|
426
426
|
)).nodes.filter(Boolean).map((a) => ({
|
|
427
427
|
gid: a.id,
|
|
428
428
|
url: a.image.url
|
|
429
|
-
}))),
|
|
429
|
+
}))), w = async (t, {
|
|
430
430
|
country: e,
|
|
431
431
|
language: l,
|
|
432
432
|
blockVisibility: a,
|
|
433
|
-
excludedProductGIDs:
|
|
433
|
+
excludedProductGIDs: n,
|
|
434
434
|
selectedProductGIDs: o,
|
|
435
435
|
selectedCollectionGIDs: c,
|
|
436
436
|
limit: s = 250
|
|
@@ -440,10 +440,10 @@ const N = {
|
|
|
440
440
|
return o.slice(0, s);
|
|
441
441
|
case "all-products":
|
|
442
442
|
case "excluded-products": {
|
|
443
|
-
const
|
|
443
|
+
const m = _({ country: e, language: l });
|
|
444
444
|
let p = (await t.query(
|
|
445
445
|
`
|
|
446
|
-
query FetchProductGIDs($limit: Int!) ${
|
|
446
|
+
query FetchProductGIDs($limit: Int!) ${m} {
|
|
447
447
|
products(first: $limit) {
|
|
448
448
|
nodes {
|
|
449
449
|
id
|
|
@@ -456,15 +456,15 @@ const N = {
|
|
|
456
456
|
limit: s
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
|
-
)).products.nodes.map((
|
|
459
|
+
)).products.nodes.map((d) => d.id);
|
|
460
460
|
return a === "excluded-products" && (p = p.filter(
|
|
461
|
-
(
|
|
461
|
+
(d) => !n.includes(d)
|
|
462
462
|
)), p;
|
|
463
463
|
}
|
|
464
464
|
case "selected-collections": {
|
|
465
|
-
const
|
|
465
|
+
const m = _({ country: e, language: l }), p = (await t.query(
|
|
466
466
|
`
|
|
467
|
-
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${
|
|
467
|
+
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${m} {
|
|
468
468
|
nodes(ids: $collectionGIDs) {
|
|
469
469
|
... on Collection {
|
|
470
470
|
products(first: $limit) {
|
|
@@ -482,8 +482,8 @@ const N = {
|
|
|
482
482
|
limit: s
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
|
-
)).nodes.filter((
|
|
486
|
-
(
|
|
485
|
+
)).nodes.filter((d) => d !== null).flatMap(
|
|
486
|
+
(d) => d.products.nodes.map((i) => i.id)
|
|
487
487
|
);
|
|
488
488
|
return Array.from(new Set(p)).slice(0, s);
|
|
489
489
|
}
|
|
@@ -525,20 +525,20 @@ const N = {
|
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
527
|
quantityAvailable @include(if: $includeAvailableQuantity)
|
|
528
|
-
`,
|
|
528
|
+
`, k = async (t, {
|
|
529
529
|
country: e,
|
|
530
530
|
language: l,
|
|
531
531
|
productIds: a,
|
|
532
|
-
includeSellingPlans:
|
|
532
|
+
includeSellingPlans: n = !0,
|
|
533
533
|
includeAvailableQuantity: o = !0,
|
|
534
534
|
useExternalMetafieldNamespace: c = !1
|
|
535
535
|
}) => {
|
|
536
536
|
if (!a.length)
|
|
537
537
|
return [];
|
|
538
|
-
const s = a.map((
|
|
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
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${
|
|
541
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${m} {
|
|
542
542
|
nodes(ids: $productGIDs) {
|
|
543
543
|
... on Product {
|
|
544
544
|
id
|
|
@@ -623,18 +623,18 @@ const N = {
|
|
|
623
623
|
{
|
|
624
624
|
variables: {
|
|
625
625
|
productGIDs: s,
|
|
626
|
-
includeSellingPlans:
|
|
626
|
+
includeSellingPlans: n,
|
|
627
627
|
includeAvailableQuantity: o,
|
|
628
628
|
metafieldNamespace: c ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles"
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
631
|
)).nodes.filter(
|
|
632
|
-
(
|
|
632
|
+
(d) => d != null
|
|
633
633
|
);
|
|
634
634
|
return p = await Promise.all(
|
|
635
635
|
p.map(
|
|
636
|
-
(
|
|
637
|
-
includeSellingPlans:
|
|
636
|
+
(d) => F(t, d, {
|
|
637
|
+
includeSellingPlans: n,
|
|
638
638
|
includeAvailableQuantity: o
|
|
639
639
|
})
|
|
640
640
|
)
|
|
@@ -642,10 +642,10 @@ const N = {
|
|
|
642
642
|
}, F = async (t, e, l) => {
|
|
643
643
|
if (e.variants.nodes.length < 250)
|
|
644
644
|
return e;
|
|
645
|
-
const a = /* @__PURE__ */ new Set(),
|
|
646
|
-
let
|
|
647
|
-
for (;
|
|
648
|
-
const
|
|
645
|
+
const a = /* @__PURE__ */ new Set(), n = [], o = [], c = async (s) => {
|
|
646
|
+
let m = !0, p = null;
|
|
647
|
+
for (; m; ) {
|
|
648
|
+
const d = await t.query(
|
|
649
649
|
`
|
|
650
650
|
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!) {
|
|
651
651
|
product(id: $productGID) {
|
|
@@ -669,37 +669,37 @@ const N = {
|
|
|
669
669
|
...l
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
|
-
), { nodes:
|
|
673
|
-
for (const r of
|
|
672
|
+
), { nodes: i, pageInfo: u } = d.product.variants;
|
|
673
|
+
for (const r of i) {
|
|
674
674
|
if (a.has(r.id)) {
|
|
675
|
-
|
|
675
|
+
m = !1;
|
|
676
676
|
break;
|
|
677
677
|
}
|
|
678
|
-
a.add(r.id), s ? o.push(r) :
|
|
678
|
+
a.add(r.id), s ? o.push(r) : n.push(r);
|
|
679
679
|
}
|
|
680
|
-
u.hasNextPage || (
|
|
680
|
+
u.hasNextPage || (m = !1), p = u.endCursor;
|
|
681
681
|
}
|
|
682
682
|
};
|
|
683
683
|
return await Promise.all([
|
|
684
684
|
c(!1),
|
|
685
685
|
c(!0)
|
|
686
|
-
]), e.variants.nodes = [...
|
|
686
|
+
]), e.variants.nodes = [...n, ...o.reverse()], e;
|
|
687
687
|
}, j = (t) => {
|
|
688
|
-
var c, s,
|
|
688
|
+
var c, s, m, p, d, i;
|
|
689
689
|
const e = t.variants.nodes.map(
|
|
690
690
|
({ unitPriceMeasurement: u, ...r }) => {
|
|
691
|
-
var f,
|
|
691
|
+
var f, h;
|
|
692
692
|
return {
|
|
693
693
|
id: Number(r.id.split("/").pop()),
|
|
694
694
|
availableForSale: r.availableForSale,
|
|
695
695
|
price: Math.round(Number(r.price.amount) * 100),
|
|
696
696
|
compareAtPrice: r.compareAtPrice ? Math.round(Number(r.compareAtPrice.amount) * 100) : null,
|
|
697
|
-
options: r.selectedOptions.map((
|
|
697
|
+
options: r.selectedOptions.map((g) => g.value),
|
|
698
698
|
imageId: r.image ? Number(r.image.id.split("/").pop()) : null,
|
|
699
699
|
image: ((f = r.image) == null ? void 0 : f.url) || null,
|
|
700
|
-
sellingPlans: ((
|
|
701
|
-
id: Number(
|
|
702
|
-
price:
|
|
700
|
+
sellingPlans: ((h = r.sellingPlanAllocations) == null ? void 0 : h.nodes.map((g) => ({
|
|
701
|
+
id: Number(g.sellingPlan.id.split("/").pop()),
|
|
702
|
+
price: g.priceAdjustments.length > 0 ? Math.round(Number(g.priceAdjustments[0].price.amount) * 100) : Math.round(Number(r.price.amount) * 100)
|
|
703
703
|
}))) || [],
|
|
704
704
|
inventoryManagement: null,
|
|
705
705
|
// Storefront API does not return inventory management, only available in liquid
|
|
@@ -715,15 +715,15 @@ const N = {
|
|
|
715
715
|
};
|
|
716
716
|
}
|
|
717
717
|
), l = t.options.map((u, r) => {
|
|
718
|
-
const f = u.optionValues.map((
|
|
719
|
-
var
|
|
718
|
+
const f = u.optionValues.map((h) => {
|
|
719
|
+
var g, b, y, I;
|
|
720
720
|
return {
|
|
721
|
-
id: Number(
|
|
722
|
-
defaultName:
|
|
723
|
-
name:
|
|
721
|
+
id: Number(h.id.split("/").pop()),
|
|
722
|
+
defaultName: h.name,
|
|
723
|
+
name: h.name,
|
|
724
724
|
swatch: {
|
|
725
|
-
color: ((
|
|
726
|
-
image: ((I = (y = (b =
|
|
725
|
+
color: ((g = h.swatch) == null ? void 0 : g.color) || null,
|
|
726
|
+
image: ((I = (y = (b = h.swatch) == null ? void 0 : b.image) == null ? void 0 : y.previewImage) == null ? void 0 : I.url) || null
|
|
727
727
|
}
|
|
728
728
|
};
|
|
729
729
|
});
|
|
@@ -759,7 +759,7 @@ const N = {
|
|
|
759
759
|
`Unknown price adjustment type: ${f.__typename}`
|
|
760
760
|
);
|
|
761
761
|
}
|
|
762
|
-
},
|
|
762
|
+
}, n = ((c = t.sellingPlanGroups) == null ? void 0 : c.nodes.flatMap(
|
|
763
763
|
(u) => u.sellingPlans.nodes.map((r) => ({
|
|
764
764
|
id: Number(r.id.split("/").pop()),
|
|
765
765
|
name: r.name,
|
|
@@ -785,36 +785,36 @@ const N = {
|
|
|
785
785
|
),
|
|
786
786
|
variants: e,
|
|
787
787
|
requiresSellingPlan: t.requiresSellingPlan,
|
|
788
|
-
sellingPlans:
|
|
788
|
+
sellingPlans: n,
|
|
789
789
|
isNativeBundle: o,
|
|
790
790
|
metafields: {
|
|
791
|
-
text: ((
|
|
791
|
+
text: ((m = t.metafield) == null ? void 0 : m.value) || null,
|
|
792
792
|
text2: ((p = t.metafield2) == null ? void 0 : p.value) || null,
|
|
793
|
-
text3: ((
|
|
794
|
-
text4: ((
|
|
793
|
+
text3: ((d = t.metafield3) == null ? void 0 : d.value) || null,
|
|
794
|
+
text4: ((i = t.metafield4) == null ? void 0 : i.value) || null
|
|
795
795
|
}
|
|
796
796
|
};
|
|
797
797
|
}, z = (t, e, l) => t.filter((a) => l.filter(
|
|
798
|
-
(
|
|
798
|
+
(n) => n.options[e] === a.name
|
|
799
799
|
).length > 0), R = (t, e) => {
|
|
800
800
|
const l = [], a = t.filter(
|
|
801
801
|
(s) => s.blockVisibility === "selected-products"
|
|
802
802
|
);
|
|
803
803
|
for (const s of a)
|
|
804
804
|
s.selectedProductIds.map(Number).includes(e.id) && l.push(s);
|
|
805
|
-
const
|
|
805
|
+
const n = t.filter(
|
|
806
806
|
(s) => s.blockVisibility === "selected-collections"
|
|
807
807
|
);
|
|
808
|
-
for (const s of
|
|
808
|
+
for (const s of n)
|
|
809
809
|
e.collectionIds.some(
|
|
810
|
-
(
|
|
810
|
+
(m) => s.selectedCollectionIds.map(Number).includes(m)
|
|
811
811
|
) && l.push(s);
|
|
812
812
|
const o = t.filter(
|
|
813
813
|
(s) => s.blockVisibility === "excluded-products"
|
|
814
814
|
);
|
|
815
815
|
for (const s of o)
|
|
816
816
|
!s.excludedProductIds.map(Number).includes(e.id) && !(s.excludedCollectionIds || []).some(
|
|
817
|
-
(
|
|
817
|
+
(m) => e.collectionIds.includes(m)
|
|
818
818
|
) && l.push(s);
|
|
819
819
|
const c = t.filter(
|
|
820
820
|
(s) => s.blockVisibility === "all-products"
|
|
@@ -838,7 +838,7 @@ const N = {
|
|
|
838
838
|
).reduce((e, l) => e.concat(l), []).filter((e) => e != null), W = (t) => t.dealBars.flatMap(
|
|
839
839
|
({ multipleGiftsSelectors: e }) => (e || []).map((l) => l.mediaImageGID)
|
|
840
840
|
).filter((e) => e != null), X = (t) => t.dealBars.map(({ upsells: e }) => (e || []).map((l) => l.mediaImageGID)).reduce((e, l) => e.concat(l), []).filter((e) => e != null), K = (t) => t.swatchOptions ? t.swatchOptions.reduce((e, l) => {
|
|
841
|
-
const a = l.images.map((
|
|
841
|
+
const a = l.images.map((n) => n.mediaImageGID).filter((n) => n != null);
|
|
842
842
|
return [...e, ...a];
|
|
843
843
|
}, []) : [], Y = (t) => {
|
|
844
844
|
if (!t.collectionBreaksEnabled || !t.collectionBreaks)
|
|
@@ -848,10 +848,10 @@ const N = {
|
|
|
848
848
|
}, Z = (t) => {
|
|
849
849
|
var e, l, a;
|
|
850
850
|
return t.progressiveGifts ? [
|
|
851
|
-
...((e = t.progressiveGifts.gifts) == null ? void 0 : e.map((
|
|
851
|
+
...((e = t.progressiveGifts.gifts) == null ? void 0 : e.map((n) => n.mediaImageGID)) || [],
|
|
852
852
|
(l = t.progressiveGifts.style) == null ? void 0 : l.lockedMediaImageGID,
|
|
853
853
|
(a = t.progressiveGifts.dealBarStyle) == null ? void 0 : a.lockedMediaImageGID
|
|
854
|
-
].filter((
|
|
854
|
+
].filter((n) => n != null) : [];
|
|
855
855
|
}, ee = (t) => !t.checkboxUpsellsEnabled || !t.checkboxUpsells ? [] : t.checkboxUpsells.upsells.map((e) => e.mediaImageGID).filter((e) => e != null), te = (t) => t.dealBars.map((e) => {
|
|
856
856
|
var l;
|
|
857
857
|
return (l = e.productPersonalisation) == null ? void 0 : l.mediaImageGID;
|
|
@@ -881,17 +881,17 @@ 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
|
|
884
|
+
class D {
|
|
885
885
|
constructor(e, l) {
|
|
886
886
|
this.storefrontApiVersion = "2025-10", this.storefrontAccessToken = l, this.shopifyDomain = e;
|
|
887
887
|
}
|
|
888
888
|
async query(e, l) {
|
|
889
889
|
var s;
|
|
890
890
|
const a = (l == null ? void 0 : l.variables) ?? {};
|
|
891
|
-
let
|
|
891
|
+
let n = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;
|
|
892
892
|
const o = (s = e.match(/query\s+(\w+)/)) == null ? void 0 : s[1];
|
|
893
|
-
o && (
|
|
894
|
-
const c = await (await fetch(
|
|
893
|
+
o && (n += `?operation_name=${o}`);
|
|
894
|
+
const c = await (await fetch(n, {
|
|
895
895
|
method: "POST",
|
|
896
896
|
headers: {
|
|
897
897
|
"Content-Type": "application/json",
|
|
@@ -908,10 +908,10 @@ class w {
|
|
|
908
908
|
}
|
|
909
909
|
}
|
|
910
910
|
const de = async (t, e, { country: l, language: a }) => {
|
|
911
|
-
const
|
|
912
|
-
if (!e.collectionBreaksEnabled || !
|
|
911
|
+
const n = e.collectionBreaks;
|
|
912
|
+
if (!e.collectionBreaksEnabled || !n) return;
|
|
913
913
|
let o;
|
|
914
|
-
|
|
914
|
+
n.visibility === "deal-products" ? o = await w(t, {
|
|
915
915
|
country: l,
|
|
916
916
|
language: a,
|
|
917
917
|
blockVisibility: e.blockVisibility,
|
|
@@ -924,21 +924,21 @@ 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
|
|
927
|
+
}) : o = await w(t, {
|
|
928
928
|
country: l,
|
|
929
929
|
language: a,
|
|
930
|
-
blockVisibility:
|
|
931
|
-
excludedProductGIDs: (
|
|
930
|
+
blockVisibility: n.visibility,
|
|
931
|
+
excludedProductGIDs: (n.excludedProducts || []).map(
|
|
932
932
|
({ id: s }) => s
|
|
933
933
|
),
|
|
934
|
-
selectedProductGIDs: (
|
|
934
|
+
selectedProductGIDs: (n.selectedProducts || []).map(
|
|
935
935
|
({ id: s }) => s
|
|
936
936
|
),
|
|
937
|
-
selectedCollectionGIDs: (
|
|
937
|
+
selectedCollectionGIDs: (n.selectedCollections || []).map(
|
|
938
938
|
({ id: s }) => s
|
|
939
939
|
)
|
|
940
940
|
}), o = o.slice(0, 250);
|
|
941
|
-
let c = await
|
|
941
|
+
let c = await k(t, {
|
|
942
942
|
country: l,
|
|
943
943
|
language: a,
|
|
944
944
|
productIds: o.map((s) => Number(s.split("/").pop())),
|
|
@@ -968,58 +968,58 @@ const de = async (t, e, { country: l, language: a }) => {
|
|
|
968
968
|
productId: e,
|
|
969
969
|
dealBlockId: l,
|
|
970
970
|
country: a,
|
|
971
|
-
language:
|
|
971
|
+
language: n
|
|
972
972
|
}) => {
|
|
973
973
|
try {
|
|
974
|
-
const o = [Number(e.split("/").pop())], c = new
|
|
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
|
-
language:
|
|
978
|
+
language: n,
|
|
979
979
|
country: a,
|
|
980
980
|
useExternalMetafieldNamespace: !0
|
|
981
|
-
}),
|
|
981
|
+
}), m = s.storefrontAccessToken ? new D(
|
|
982
982
|
s.shopifyDomain,
|
|
983
983
|
s.storefrontAccessToken
|
|
984
|
-
) : c, [p,
|
|
985
|
-
|
|
984
|
+
) : c, [p, d] = await Promise.all([
|
|
985
|
+
k(m, {
|
|
986
986
|
country: a,
|
|
987
|
-
language:
|
|
987
|
+
language: n,
|
|
988
988
|
productIds: o,
|
|
989
989
|
useExternalMetafieldNamespace: !0
|
|
990
990
|
}),
|
|
991
|
-
q(
|
|
991
|
+
q(m, {
|
|
992
992
|
useExternalMetafieldNamespace: !0,
|
|
993
993
|
useMetaobjects: s.featureFlags.storefront_metaobjects
|
|
994
994
|
})
|
|
995
|
-
]),
|
|
996
|
-
if (!
|
|
995
|
+
]), i = p[0];
|
|
996
|
+
if (!i)
|
|
997
997
|
return null;
|
|
998
|
-
const u = R(
|
|
998
|
+
const u = R(d, i);
|
|
999
999
|
let r;
|
|
1000
1000
|
if (l ? (r = u.find(
|
|
1001
|
-
(
|
|
1001
|
+
(E) => E.id === l || E.nanoId === l
|
|
1002
1002
|
), r || (r = u[0])) : r = u[0], !r)
|
|
1003
1003
|
return null;
|
|
1004
|
-
const f = H(r),
|
|
1005
|
-
|
|
1004
|
+
const f = H(r), h = se(r), [g, b, y, I] = await Promise.all([
|
|
1005
|
+
k(m, {
|
|
1006
1006
|
country: a,
|
|
1007
|
-
language:
|
|
1008
|
-
productIds:
|
|
1007
|
+
language: n,
|
|
1008
|
+
productIds: h,
|
|
1009
1009
|
useExternalMetafieldNamespace: !0
|
|
1010
1010
|
}),
|
|
1011
|
-
V(
|
|
1012
|
-
de(
|
|
1011
|
+
V(m, f, 300),
|
|
1012
|
+
de(m, r, {
|
|
1013
1013
|
country: a,
|
|
1014
|
-
language:
|
|
1014
|
+
language: n
|
|
1015
1015
|
}),
|
|
1016
1016
|
me()
|
|
1017
1017
|
]);
|
|
1018
1018
|
return {
|
|
1019
|
-
product:
|
|
1019
|
+
product: i,
|
|
1020
1020
|
dealBlock: r,
|
|
1021
1021
|
config: s,
|
|
1022
|
-
otherProducts:
|
|
1022
|
+
otherProducts: g,
|
|
1023
1023
|
mediaImages: b,
|
|
1024
1024
|
collectionBreaksProducts: y ?? [],
|
|
1025
1025
|
translations: I
|
|
@@ -1027,32 +1027,32 @@ const de = async (t, e, { country: l, language: a }) => {
|
|
|
1027
1027
|
} catch (o) {
|
|
1028
1028
|
return console.error(o), null;
|
|
1029
1029
|
}
|
|
1030
|
-
},
|
|
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(
|
|
1033
|
-
if (
|
|
1034
|
-
return
|
|
1035
|
-
|
|
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
|
|
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) => {
|
|
1043
1043
|
const e = t.document;
|
|
1044
1044
|
return new Promise((l, a) => {
|
|
1045
|
-
const
|
|
1045
|
+
const n = be();
|
|
1046
1046
|
if (e.querySelector(
|
|
1047
|
-
`script[src="${
|
|
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 =
|
|
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
|
-
},
|
|
1055
|
+
}, S = (t, e) => new Promise((l, a) => {
|
|
1056
1056
|
if (t.customElements.get(e)) {
|
|
1057
1057
|
l();
|
|
1058
1058
|
return;
|
|
@@ -1060,13 +1060,13 @@ const de = async (t, e, { country: l, language: a }) => {
|
|
|
1060
1060
|
Promise.race([
|
|
1061
1061
|
t.customElements.whenDefined(e),
|
|
1062
1062
|
new Promise(
|
|
1063
|
-
(
|
|
1063
|
+
(n, o) => setTimeout(
|
|
1064
1064
|
() => o(
|
|
1065
1065
|
new Error(
|
|
1066
|
-
`Custom element "${e}" failed to register within ${
|
|
1066
|
+
`Custom element "${e}" failed to register within ${C}ms`
|
|
1067
1067
|
)
|
|
1068
1068
|
),
|
|
1069
|
-
|
|
1069
|
+
C
|
|
1070
1070
|
)
|
|
1071
1071
|
)
|
|
1072
1072
|
]).then(() => l()).catch(a);
|
|
@@ -1089,8 +1089,8 @@ class Ie extends HTMLElement {
|
|
|
1089
1089
|
this.renderInnerElement(T);
|
|
1090
1090
|
return;
|
|
1091
1091
|
}
|
|
1092
|
-
const l = this.getAttribute("shop-domain"), a = this.getAttribute("storefront-token"),
|
|
1093
|
-
if (!l || !a || !
|
|
1092
|
+
const l = this.getAttribute("shop-domain"), a = this.getAttribute("storefront-token"), n = this.getAttribute("product-id");
|
|
1093
|
+
if (!l || !a || !n) return;
|
|
1094
1094
|
const [o] = await Promise.all([
|
|
1095
1095
|
pe(
|
|
1096
1096
|
{
|
|
@@ -1098,7 +1098,7 @@ class Ie extends HTMLElement {
|
|
|
1098
1098
|
storefrontAccessToken: a
|
|
1099
1099
|
},
|
|
1100
1100
|
{
|
|
1101
|
-
productId:
|
|
1101
|
+
productId: n,
|
|
1102
1102
|
dealBlockId: this.getAttribute("deal-block-id") ?? void 0,
|
|
1103
1103
|
country: ((c = this.getAttribute("country")) == null ? void 0 : c.toUpperCase()) ?? void 0,
|
|
1104
1104
|
language: ((s = this.getAttribute("language")) == null ? void 0 : s.toUpperCase()) ?? void 0
|
|
@@ -1112,18 +1112,18 @@ class Ie extends HTMLElement {
|
|
|
1112
1112
|
const {
|
|
1113
1113
|
config: l,
|
|
1114
1114
|
dealBlock: a,
|
|
1115
|
-
product:
|
|
1115
|
+
product: n,
|
|
1116
1116
|
otherProducts: o,
|
|
1117
1117
|
mediaImages: c,
|
|
1118
1118
|
collectionBreaksProducts: s,
|
|
1119
|
-
translations:
|
|
1119
|
+
translations: m
|
|
1120
1120
|
} = e;
|
|
1121
1121
|
this.innerElement = document.createElement(
|
|
1122
1122
|
"kaching-bundles-block"
|
|
1123
1123
|
), 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(
|
|
1124
1124
|
"media-images",
|
|
1125
1125
|
JSON.stringify(c ?? [])
|
|
1126
|
-
), this.innerElement.setAttribute("product", JSON.stringify(
|
|
1126
|
+
), this.innerElement.setAttribute("product", JSON.stringify(n)), this.innerElement.setAttribute(
|
|
1127
1127
|
"other-products",
|
|
1128
1128
|
JSON.stringify(o ?? [])
|
|
1129
1129
|
), this.innerElement.setAttribute(
|
|
@@ -1131,34 +1131,34 @@ class Ie extends HTMLElement {
|
|
|
1131
1131
|
JSON.stringify(s ?? [])
|
|
1132
1132
|
), this.innerElement.setAttribute(
|
|
1133
1133
|
"translations",
|
|
1134
|
-
JSON.stringify(
|
|
1134
|
+
JSON.stringify(m ?? {})
|
|
1135
1135
|
);
|
|
1136
1136
|
const p = this.getAttribute("selected-variant-id");
|
|
1137
1137
|
this.innerElement.setAttribute(
|
|
1138
1138
|
"current-variant-id",
|
|
1139
|
-
String(p ? p.split("/").pop() :
|
|
1140
|
-
), this.hasAttribute("deal-bars-only") && this.innerElement.setAttribute("deal-bars-only", "")
|
|
1141
|
-
const
|
|
1142
|
-
|
|
1143
|
-
|
|
1139
|
+
String(p ? p.split("/").pop() : n.variants[0].id)
|
|
1140
|
+
), this.hasAttribute("deal-bars-only") && this.innerElement.setAttribute("deal-bars-only", "");
|
|
1141
|
+
const d = this.innerElement, i = () => {
|
|
1142
|
+
if (this.innerElement !== d) return;
|
|
1143
|
+
const r = d.items();
|
|
1144
|
+
r && this.dispatchEvent(
|
|
1144
1145
|
new CustomEvent("items-changed", {
|
|
1145
|
-
detail: { items:
|
|
1146
|
+
detail: { items: r },
|
|
1146
1147
|
bubbles: !0
|
|
1147
1148
|
})
|
|
1148
1149
|
);
|
|
1149
1150
|
};
|
|
1150
|
-
this.handleItemsChanged = (
|
|
1151
|
-
|
|
1152
|
-
}
|
|
1151
|
+
this.handleItemsChanged = (r) => {
|
|
1152
|
+
r.stopPropagation(), i();
|
|
1153
|
+
};
|
|
1154
|
+
const u = this.handleItemsChanged;
|
|
1155
|
+
d.addEventListener(
|
|
1153
1156
|
"kaching-bundles-block-loaded",
|
|
1154
1157
|
() => {
|
|
1155
|
-
this.innerElement.addEventListener(
|
|
1156
|
-
"items-changed",
|
|
1157
|
-
this.handleItemsChanged
|
|
1158
|
-
), m(), this.dispatchEvent(new CustomEvent("loaded", { bubbles: !0 }));
|
|
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(
|
|
@@ -1167,7 +1167,7 @@ class Ie extends HTMLElement {
|
|
|
1167
1167
|
), this.handleItemsChanged = null), this.innerElement && (this.innerElement.remove(), this.innerElement = null);
|
|
1168
1168
|
}
|
|
1169
1169
|
attributeChangedCallback(e, l, a) {
|
|
1170
|
-
l !== a && (e === "product-id" ? this.initialize() : e === "selected-variant-id" && this.innerElement && a && this.innerElement.setAttribute(
|
|
1170
|
+
l !== a && this.isConnected && (e === "product-id" ? this.initialize() : e === "selected-variant-id" && this.innerElement && a && this.innerElement.setAttribute(
|
|
1171
1171
|
"current-variant-id",
|
|
1172
1172
|
a.includes("/") ? String(a.split("/").pop()) : a
|
|
1173
1173
|
));
|