@kachingappz/bundles-js 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles-js.iife.js +24 -24
- package/dist/index.d.ts +8 -9
- package/dist/index.js +479 -400
- package/dist/kaching-bundle-component/index.d.ts +8 -9
- package/dist/kaching-bundle-component/index.js +615 -536
- package/dist/react/index.cjs +26 -26
- package/dist/react/index.d.ts +8 -9
- package/dist/react/index.js +450 -371
- package/package.json +5 -5
package/dist/react/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("react/jsx-runtime"),S=require("react"),J=(e,t)=>{const a=[],n=e.filter(l=>l.blockVisibility==="selected-products");for(const l of n)l.selectedProductIds.map(Number).includes(t.id)&&a.push(l);const s=e.filter(l=>l.blockVisibility==="selected-collections");for(const l of s)t.collectionIds.some(d=>l.selectedCollectionIds.map(Number).includes(d))&&a.push(l);const i=e.filter(l=>l.blockVisibility==="excluded-products");for(const l of i)!l.excludedProductIds.map(Number).includes(t.id)&&!(l.excludedCollectionIds||[]).some(d=>t.collectionIds.includes(d))&&a.push(l);const o=e.filter(l=>l.blockVisibility==="all-products");for(const l of o)a.push(l);return a},z=(e,{language:t,country:a})=>{var p,g;const n=Q(t,a),s=new Intl.NumberFormat(n,{style:"currency",currency:e,currencyDisplay:"narrowSymbol"}).formatToParts(123456789e-2),i=(p=s.find(y=>y.type==="decimal"))==null?void 0:p.value,o=H((g=s.find(y=>y.type==="group"))==null?void 0:g.value),l=s.some(y=>y.type==="fraction"),d=K(o,i,l),u=s.findIndex(G),c=s.findLastIndex(G);return[...s.slice(0,u).map(B),d,...s.slice(c+1).map(B)].join("")},B=e=>U(e.value),U=e=>e.replace(/\s/g," "),G=e=>e.type==="integer"||e.type==="group"||e.type==="decimal"||e.type==="fraction",Q=(e,t)=>e&&t?`${e}-${t.toUpperCase()}`:e||(t?t.toUpperCase():"en"),H=e=>e===void 0?void 0:U(e).replace(/’/g,"'"),K=(e,t,a)=>t===","&&e==="."?a?"{{amount_with_comma_separator}}":"{{amount_no_decimals_with_comma_separator}}":t===","&&e===" "?a?"{{amount_with_space_separator}}":"{{amount_no_decimals_with_space_separator}}":t==="."&&e===" "?"{{amount_with_period_and_space_separator}}":t==="."&&e==="'"?"{{amount_with_apostrophe_separator}}":a?"{{amount}}":"{{amount_no_decimals}}",$=({country:e,language:t})=>{const a=[];return e&&a.push(`country: ${e}`),t&&a.push(`language: ${t}`),a.length>0?`@inContext(${a.join(", ")})`:""},W=async(e,{useExternalMetafieldNamespace:t,useMetaobjects:a})=>a?Y(e):X(e),X=async(e,t)=>{var n;const a=(n=(await e.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:
|
|
9
|
+
`,{variables:{metafieldNamespace:"app--2935586817--kaching_bundles"}})).shop.metafield)==null?void 0:n.value;return a?JSON.parse(a):[]},Y=async(e,t)=>{const a="app--2935586817--deal_block",n=[];let s=null;for(;;){const i=await e.query(`
|
|
10
10
|
query FetchDealBlockMetaobjects($type: String!, $cursor: String) {
|
|
11
11
|
metaobjects(type: $type, first: 250, after: $cursor) {
|
|
12
12
|
nodes {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
`,{variables:{type:a,cursor:s}});for(const o of i.metaobjects.nodes){const
|
|
25
|
-
query FetchProductGIDs($limit: Int!, $cursor: String) ${
|
|
24
|
+
`,{variables:{type:a,cursor:s}});for(const o of i.metaobjects.nodes){const l=o.fields.find(d=>d.key==="settings");l!=null&&l.value&&n.push(JSON.parse(l.value))}if(!i.metaobjects.pageInfo.hasNextPage)break;s=i.metaobjects.pageInfo.endCursor}return n},C=async(e,{country:t,language:a,blockVisibility:n,excludedProductGIDs:s,selectedProductGIDs:i,selectedCollectionGIDs:o,limit:l=1e3})=>{switch(n){case"selected-products":return i.slice(0,l);case"all-products":case"excluded-products":{const d=$({country:t,language:a});let u=[],c=null;for(;u.length<l;){const p=Math.min(l-u.length,250),g=await e.query(`
|
|
25
|
+
query FetchProductGIDs($limit: Int!, $cursor: String) ${d} {
|
|
26
26
|
products(first: $limit, after: $cursor) {
|
|
27
27
|
nodes {
|
|
28
28
|
id
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
`,{variables:{limit:
|
|
37
|
-
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${
|
|
36
|
+
`,{variables:{limit:p,cursor:c}});if(u.push(...g.products.nodes.map(y=>y.id)),!g.products.pageInfo.hasNextPage)break;c=g.products.pageInfo.endCursor}if(n==="excluded-products"){const p=new Set(s);u=u.filter(g=>!p.has(g))}return u}case"selected-collections":{const d=$({country:t,language:a}),u=(await e.query(`
|
|
37
|
+
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${d} {
|
|
38
38
|
nodes(ids: $collectionGIDs) {
|
|
39
39
|
... on Collection {
|
|
40
40
|
products(first: $limit) {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
`,{variables:{collectionGIDs:o,limit:Math.min(
|
|
48
|
+
`,{variables:{collectionGIDs:o,limit:Math.min(l,250)}})).nodes.filter(c=>c!==null).flatMap(c=>c.products.nodes.map(p=>p.id));return Array.from(new Set(u)).slice(0,l)}}},F=`
|
|
49
49
|
id
|
|
50
50
|
availableForSale
|
|
51
51
|
price {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
}
|
|
61
61
|
image {
|
|
62
62
|
id
|
|
63
|
-
url(transform:
|
|
63
|
+
url(transform: $variantImageTransform)
|
|
64
64
|
}
|
|
65
65
|
unitPriceMeasurement {
|
|
66
66
|
quantityUnit
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
quantityAvailable @include(if: $includeAvailableQuantity)
|
|
91
|
-
`,A=async(e,{country:t,language:a,productIds:
|
|
92
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String
|
|
91
|
+
`,A=async(e,{country:t,language:a,productIds:n,includeSellingPlans:s=!0,includeAvailableQuantity:i=!0,useExternalMetafieldNamespace:o=!1,batchSize:l=250,onBatchError:d,variantImageTransform:u={maxWidth:200,maxHeight:200}})=>{if(!n.length)return[];const c=n.map(f=>typeof f=="string"&&f.startsWith("gid://")?f:`gid://shopify/Product/${f}`),p=$({country:t,language:a}),g=`
|
|
92
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${p} {
|
|
93
93
|
shop {
|
|
94
94
|
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
95
95
|
value
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
}
|
|
124
124
|
variants(first: 250) {
|
|
125
125
|
nodes {
|
|
126
|
-
${
|
|
126
|
+
${F}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
collections(first: 50) {
|
|
@@ -175,12 +175,12 @@
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
`,
|
|
179
|
-
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean
|
|
178
|
+
`,y=o?"app--2935586817--kaching_bundles":"$app:kaching_bundles",h=[],r=Math.min(l,250);for(let f=0;f<c.length;f+=r)h.push(c.slice(f,f+r));let m=1;const b=async f=>{const v=await e.query(g,{variables:{productGIDs:f,includeSellingPlans:s,includeAvailableQuantity:i,metafieldNamespace:y,variantImageTransform:u}});return v.shop.currencyRateConstant&&(m=JSON.parse(v.shop.currencyRateConstant.value).amount/1e6),v};let I;if(d){const f=await Promise.allSettled(h.map(b));for(const v of f)v.status==="rejected"&&d(v.reason instanceof Error?v.reason:new Error(String(v.reason)));I=f.filter(v=>v.status==="fulfilled").flatMap(v=>v.value.nodes)}else I=(await Promise.all(h.map(b))).flatMap(f=>f.nodes);const _=I.filter(f=>f!=null);if(d){const f=await Promise.allSettled(_.map(async P=>{const L=await T(e,P,{includeSellingPlans:s,includeAvailableQuantity:i,variantImageTransform:u},p);return q(L,e.shopifyDomain,m)})),v=[];for(const P of f)P.status==="fulfilled"?v.push(P.value):d(P.reason instanceof Error?P.reason:new Error(String(P.reason)));return v}return(await Promise.all(_.map(f=>T(e,f,{includeSellingPlans:s,includeAvailableQuantity:i,variantImageTransform:u},p)))).map(f=>q(f,e.shopifyDomain,m))},T=async(e,t,a,n="")=>{if(t.variants.nodes.length<250)return t;const s=new Set,i=[],o=[],l=async d=>{let u=!0,c=null;for(;u;){const p=await e.query(`
|
|
179
|
+
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $variantImageTransform: ImageTransformInput) ${n} {
|
|
180
180
|
product(id: $productGID) {
|
|
181
181
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
182
182
|
nodes {
|
|
183
|
-
${
|
|
183
|
+
${F}
|
|
184
184
|
}
|
|
185
185
|
pageInfo {
|
|
186
186
|
endCursor
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
`,{variables:{productGID:t.id,cursor:c,reverse:
|
|
192
|
+
`,{variables:{productGID:t.id,cursor:c,reverse:d,...a}}),{nodes:g,pageInfo:y}=p.product.variants;for(const h of g){if(s.has(h.id)){u=!1;break}s.add(h.id),d?o.push(h):i.push(h)}y.hasNextPage||(u=!1),c=y.endCursor}};return await Promise.all([l(!1),l(!0)]),t.variants.nodes=[...i,...o.reverse()],t},q=(e,t,a)=>{var u,c,p,g,y,h;const n=e.variants.nodes.map(({unitPriceMeasurement:r,...m})=>{var b,I;return{id:Number(m.id.split("/").pop()),availableForSale:m.availableForSale,price:Math.round(Number(m.price.amount)*100),compareAtPrice:m.compareAtPrice?Math.round(Number(m.compareAtPrice.amount)*100):null,options:m.selectedOptions.map(_=>_.value),imageId:m.image?Number(m.image.id.split("/").pop()):null,image:((b=m.image)==null?void 0:b.url)||null,sellingPlans:((I=m.sellingPlanAllocations)==null?void 0:I.nodes.map(_=>({id:Number(_.sellingPlan.id.split("/").pop()),price:_.priceAdjustments.length>0?Math.round(Number(_.priceAdjustments[0].price.amount)*100):Math.round(Number(m.price.amount)*100),compareAtPrice:_.priceAdjustments.length>0?Math.round(Number(_.priceAdjustments[0].compareAtPrice.amount)*100):Math.round(Number(m.price.amount)*100),perDeliveryPrice:_.priceAdjustments.length>0?Math.round(Number(_.priceAdjustments[0].perDeliveryPrice.amount)*100):Math.round(Number(m.price.amount)*100)})))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:m.quantityAvailable??null,unitPriceMeasurement:r!=null&&r.quantityUnit&&(r!=null&&r.referenceUnit)?{quantityValue:r.quantityValue,quantityUnit:r.quantityUnit.toLowerCase(),referenceValue:r.referenceValue,referenceUnit:r.referenceUnit.toLowerCase()}:null}}),s=e.options.map((r,m)=>{const b=r.optionValues.map(I=>{var _,f,v,P;return{id:Number(I.id.split("/").pop()),defaultName:I.name,name:I.name,swatch:{color:((_=I.swatch)==null?void 0:_.color)||null,image:((P=(v=(f=I.swatch)==null?void 0:f.image)==null?void 0:v.previewImage)==null?void 0:P.url)||null}}});return{defaultName:r.name,name:r.name,position:m+1,optionValues:Z(b,m,n)}}),i=r=>{const m=r.priceAdjustments[0];if(!m)return null;const b=m.adjustmentValue;switch(b.__typename){case"SellingPlanPercentagePriceAdjustment":return{type:"percentage",value:b.adjustmentPercentage};case"SellingPlanFixedAmountPriceAdjustment":return{type:"fixed_amount",value:o(b.adjustmentAmount.amount)};case"SellingPlanFixedPriceAdjustment":return{type:"price",value:o(b.price.amount)};default:throw new Error(`Unknown price adjustment type: ${b.__typename}`)}},o=r=>a===1?Number(r)*100:Math.round(Number(r)*100*a),l=((u=e.sellingPlanGroups)==null?void 0:u.nodes.flatMap(r=>r.sellingPlans.nodes.map(m=>({id:Number(m.id.split("/").pop()),name:m.name,priceAdjustment:i(m)}))))||[],d=e.variants.nodes.some(r=>r.requiresComponents);return{id:Number(e.id.split("/").pop()),handle:e.handle,url:e.onlineStoreUrl||`https://${t}/products/${e.handle}`,availableForSale:e.availableForSale,createdAt:e.createdAt,title:e.title,image:((c=e.featuredImage)==null?void 0:c.url)||null,collectionIds:e.collections.nodes.map(r=>Number(r.id.split("/").pop())),options:s,selectedVariantId:Number(e.variants.nodes[0].id.split("/").pop()),variants:n,requiresSellingPlan:e.requiresSellingPlan,sellingPlans:l,isNativeBundle:d,metafields:{text:((p=e.metafield)==null?void 0:p.value)||null,text2:((g=e.metafield2)==null?void 0:g.value)||null,text3:((y=e.metafield3)==null?void 0:y.value)||null,text4:((h=e.metafield4)==null?void 0:h.value)||null}}},Z=(e,t,a)=>e.filter(n=>a.filter(s=>s.options[t]===n.name).length>0),M="app--2935586817",ee=async(e,{language:t,country:a,useExternalMetafieldNamespace:n})=>{const s=`${M}--kaching_bundles`,i=M,o=$({country:a}),{localization:{country:{currency:{isoCode:l}}},shop:{moneyFormat:d,paymentSettings:{currencyCode:u},currencyRateConstant:c,primaryDomain:p,settingsMetafield:g}}=await e.query(`
|
|
193
193
|
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${o} {
|
|
194
194
|
localization {
|
|
195
195
|
country {
|
|
@@ -214,16 +214,16 @@
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
`,{variables:{metafieldNamespace:s,settingsNamespace:i}}),y=
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
217
|
+
`,{variables:{metafieldNamespace:s,settingsNamespace:i}}),y=l===u?d:z(l,{language:t,country:a}),h=c?te(c.value):1,r=g?JSON.parse(g.value):null,m=(r==null?void 0:r.feature_flags)??{},b=(r==null?void 0:r.custom_selectors)??{};return{shopifyDomain:p.host,moneyFormat:y,locale:(t==null?void 0:t.toLowerCase())||"en",liquidLocale:(t==null?void 0:t.toLowerCase())||"en",country:a??"US",currencyRate:h,marketId:0,productId:null,storefrontAccessToken:(r==null?void 0:r.storefront_access_token)??null,includeSellingPlans:(r==null?void 0:r.include_selling_plans)??!1,includeAvailableQuantity:(r==null?void 0:r.include_available_quantity)??!1,customApiHost:(r==null?void 0:r.custom_api_host)??null,keepQuantityInput:(r==null?void 0:r.keep_quantity_input)??!1,ignoreDeselect:(r==null?void 0:r.ignore_deselect)??!1,ignoreUnitPrice:(r==null?void 0:r.ignore_unit_price)??!1,requireCustomerLogin:(r==null?void 0:r.require_customer_login)??!1,abTestsRunning:(r==null?void 0:r.ab_tests_running)??!1,webPixel:(r==null?void 0:r.web_pixel)??!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,previewScratchOff:!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.quantity":"Quantity","system.subscription_plan":"Subscription plan","system.remove":"Remove","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","system.original_price":"Original price:","system.price":"Price:","system.letters_only":"Only letters are allowed.","system.numbers_only":"Only numbers are allowed."},customSelectors:{quantity:b.quantity??null,addToCartButton:b.add_to_cart_button??null,variantPicker:b.variant_picker??null,price:b.price??null,priceCompare:b.price_compare??null},shopCustomStyles:(r==null?void 0:r.shop_custom_styles)??"",featureFlags:m,brandColors:(r==null?void 0:r.brand_colors)??null}},te=e=>JSON.parse(e).amount/1e6,ae=async(e,t,a=200)=>{const n=[...new Set(t.filter(Boolean).filter(i=>!i.startsWith("placeholder")))];if(n.length===0)return[];const s=[];for(let i=0;i<n.length;i+=250)s.push(n.slice(i,i+250));return(await Promise.all(s.map(i=>e.query(`
|
|
218
|
+
query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
|
|
219
|
+
nodes(ids: $mediaImageIds) {
|
|
220
|
+
... on MediaImage {
|
|
221
|
+
id
|
|
222
|
+
image {
|
|
223
|
+
url(transform: { maxWidth: $size, maxHeight: $size })
|
|
224
|
+
}
|
|
225
|
+
}
|
|
224
226
|
}
|
|
225
227
|
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
`,{variables:{mediaImageIds:t,size:a}})).nodes.filter(Boolean).map(l=>({gid:l.id,url:l.image.url})));var w=(e=>(e.QuantityBreak="quantity-break",e.Bxgy="bxgy",e.Bundle="bundle",e.MixAndMatch="mix-and-match",e.Sku="sku",e))(w||{});const ee=e=>[...te(e),...ae(e),...se(e),...ne(e),...le(e),...re(e),...ie(e),...oe(e),...ce(e),...ue(e),...de(e),...me(e),...pe(e)].filter(t=>t!=null&&!t.includes("placeholder")),te=e=>e.dealBars.flatMap(t=>[t.mediaImageGID,t.badgeImageGID]).filter(t=>t!=null),ae=e=>e.dealBars.flatMap(t=>t.dealBarType===w.Bundle?t.bundleProducts.map(a=>a.mediaImageGID):[]).filter(t=>t!=null),se=e=>e.dealBars.map(({freeGifts:t})=>(t||[]).map(a=>a.mediaImageGID)).reduce((t,a)=>t.concat(a),[]).filter(t=>t!=null),ne=e=>e.dealBars.flatMap(({multipleGiftsSelectors:t})=>(t||[]).map(a=>a.mediaImageGID)).filter(t=>t!=null),le=e=>e.dealBars.map(({upsells:t})=>(t||[]).map(a=>a.mediaImageGID)).reduce((t,a)=>t.concat(a),[]).filter(t=>t!=null),re=e=>e.swatchOptions?e.swatchOptions.reduce((t,a)=>{const l=a.images.map(s=>s.mediaImageGID).filter(s=>s!=null);return[...t,...l]},[]):[],ie=e=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];const t=e.collectionBreaks.mediaImageGID;return t?[t]:[]},oe=e=>{var t,a,l;return e.progressiveGifts?[...((t=e.progressiveGifts.gifts)==null?void 0:t.map(s=>s.mediaImageGID))||[],(a=e.progressiveGifts.style)==null?void 0:a.lockedMediaImageGID,(l=e.progressiveGifts.dealBarStyle)==null?void 0:l.lockedMediaImageGID].filter(s=>s!=null):[]},ce=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.flatMap(t=>[t.mediaImageGID,t.badgeImageGID]).filter(t=>t!=null),ue=e=>e.dealBars.map(t=>{var a;return(a=t.productPersonalisation)==null?void 0:a.mediaImageGID}).filter(t=>t!=null),de=e=>{var l,s;const t=e.dealBars.map(i=>{var o;return(o=i.highlights)==null?void 0:o.customIconGID}).filter(i=>i!=null),a=(s=(l=e.subscriptions)==null?void 0:l.highlights)==null?void 0:s.customIconGID;return a?[...t,a]:t},me=e=>(e.badges||[]).flatMap(t=>t.badgeType==="custom"&&t.imageGID?[t.imageGID]:[]),pe=e=>!e.savingsSummaryEnabled||!e.savingsSummary?[]:e.savingsSummary.customIconGID?[e.savingsSummary.customIconGID]:[],fe=e=>{const t=[...ye(e),...ge(e),...he(e),...be(e),...ve(e),..._e(e),...Ie(e),...Pe(e)];return Array.from(new Set(t.filter(a=>a!=null)))},ye=e=>e.dealBars.flatMap(({freeGifts:t})=>t?t.map(a=>a.productGID):[]).filter(t=>t!=null),ge=e=>e.dealBars.flatMap(({multipleGiftsSelectors:t})=>t?t.flatMap(a=>a.products?a.products.map(l=>l.id):[]):[]).filter(t=>t!=null),he=e=>{var t;return e.progressiveGiftsEnabled?((t=e.progressiveGifts)==null?void 0:t.gifts.map(a=>a.productGID).filter(a=>a!=null))||[]:[]},be=e=>e.dealBars.flatMap(({upsells:t})=>t?t.map(a=>a.productGID):[]).filter(t=>t!=null),ve=e=>e.dealBars.filter(t=>t.dealBarType===w.Bundle).flatMap(({bundleProducts:t})=>t?t.map(a=>a.productGID):[]).filter(t=>t!=null).filter(t=>t!=="default"),_e=e=>e.dealBars.filter(t=>t.dealBarType===w.MixAndMatch).flatMap(({bundleProducts:t})=>t?t.flatMap(a=>{var l;return[a.productGID,...((l=a.selectedProducts)==null?void 0:l.map(s=>s.id))??[]]}):[]).filter(t=>t!=null).filter(t=>t!=="default"),Ie=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.map(t=>t.productGID).filter(t=>t!=null),Pe=e=>e.dealBars.filter(t=>t.dealBarType===w.Sku).flatMap(({productGID:t})=>t?[t]:[]);class Se{constructor(t,a){this.storefrontApiVersion="2026-07",this.storefrontAccessToken=a,this.shopifyDomain=t}async query(t,a){var r;const l=(a==null?void 0:a.variables)??{};let s=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const i=(r=t.match(/query\s+(\w+)/))==null?void 0:r[1];i&&(s+=`?operation_name=${i}`);const o=await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:t,variables:l})})).text();if(!o)throw new Error("Empty graphql response");return JSON.parse(o).data}}const ke=async(e,t,{country:a,language:l})=>{const s=t.collectionBreaks;if(!t.collectionBreaksEnabled||!s)return;let i;s.visibility==="deal-products"?i=await C(e,{country:a,language:l,blockVisibility:t.blockVisibility,excludedProductGIDs:(t.excludedProductIds||[]).map(r=>`gid://shopify/Product/${r}`),selectedProductGIDs:(t.selectedProductIds||[]).map(r=>`gid://shopify/Product/${r}`),selectedCollectionGIDs:(t.selectedCollectionIds||[]).map(r=>`gid://shopify/Collection/${r}`)}):i=await C(e,{country:a,language:l,blockVisibility:s.visibility,excludedProductGIDs:(s.excludedProducts||[]).map(({id:r})=>r),selectedProductGIDs:(s.selectedProducts||[]).map(({id:r})=>r),selectedCollectionGIDs:(s.selectedCollections||[]).map(({id:r})=>r)});let o=await A(e,{country:a,language:l,productIds:i.map(r=>Number(r.split("/").pop())),useExternalMetafieldNamespace:!0});return o=o.filter(r=>r.availableForSale),o},we=()=>({"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.quantity":"Quantity","system.subscription_plan":"Subscription plan","system.remove":"Remove","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","system.original_price":"Original price:","system.price":"Price:","system.letters_only":"Only letters are allowed.","system.numbers_only":"Only numbers are allowed.","system.personalisation_required_alert":"Please add personalisation for every item to continue."}),$e="2026-07",De=async(e,{productId:t,dealBlockId:a,country:l=void 0,language:s=void 0})=>{var i,o;try{const r=[Number(t.split("/").pop())],m=new Ne(e);l=l||((i=m.i18n)==null?void 0:i.country),s=s||((o=m.i18n)==null?void 0:o.language);const d=await X(m,{language:s,country:l,useExternalMetafieldNamespace:!0});m.shopifyDomain=d.shopifyDomain;const c=d.storefrontAccessToken?new Se(d.shopifyDomain,d.storefrontAccessToken):m,[f,g]=await Promise.all([A(c,{country:l,language:s,productIds:r,useExternalMetafieldNamespace:!0}),Q(c,{useExternalMetafieldNamespace:!0,useMetaobjects:d.featureFlags.storefront_metaobjects})]),y=f[0];if(!y)return null;const h=F(g,y);let n;if(a?(n=h.find(P=>P.id===a||P.nanoId===a),n||(n=h[0])):n=h[0],!n)return null;const p=ee(n),b=fe(n),[_,u,v,I]=await Promise.all([A(c,{country:l,language:s,productIds:b,useExternalMetafieldNamespace:!0}),Z(c,p,300),ke(c,n,{country:l,language:s}),we()]);return{product:y,dealBlock:n,config:d,otherProducts:_,mediaImages:u,collectionBreaksProducts:v??[],translations:I}}catch(r){return console.error(r),null}};class Ne{constructor(t){this.storefront=t,this.shopifyDomain=""}async query(t,a){var l;if("query"in this.storefront&&"i18n"in this.storefront)return await this.storefront.query(t,a);if("graphql"in this.storefront){const s=await this.storefront.graphql(t,a);if((l=s.errors)!=null&&l.length)throw new Error(s.errors.map(i=>i.message).join(`
|
|
229
|
-
`));return s.data}if("request"in this.storefront)return(await this.storefront.request(t,a)).data;if("shopifyDomain"in this.storefront&&"storefrontAccessToken"in this.storefront){const s=await fetch(`https://${this.storefront.shopifyDomain}/api/${$e}/graphql.json`,{body:JSON.stringify({query:t,variables:a==null?void 0:a.variables}),headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:"POST"});if(!s.ok)throw new Error(s.statusText);return(await s.json()).data}else{const s=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:t,variables:a==null?void 0:a.variables}),headers:this.storefront.getPublicTokenHeaders(),method:"POST"});if(!s.ok)throw new Error(s.statusText);return(await s.json()).data}}get i18n(){if("i18n"in this.storefront)return this.storefront.i18n}}const Ae=De,D="kaching-bundles-block",j=1e4,xe="https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js",Be="https://bundles-integrations.kachingappz.app/kaching-bundles-block.js",N=new WeakSet,Ge=async e=>{const t=e.document;if(!e.customElements.get(D)){if(N.has(t))return x(e,D);N.add(t);try{await Me(e)}catch(a){throw N.delete(t),a}}},Ee=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",Ce=()=>Ee()?xe:Be,Me=e=>{const t=e.document;return new Promise((a,l)=>{const s=Ce();if(t.querySelector(`script[src="${s}"]`)){x(e,D).then(a).catch(l);return}const o=t.createElement("script");o.src=s,o.onload=()=>x(e,D).then(a).catch(l),o.onerror=()=>l(new Error("Failed to load script")),t.head.appendChild(o)})},x=(e,t)=>new Promise((a,l)=>{if(e.customElements.get(t)){a();return}Promise.race([e.customElements.whenDefined(t),new Promise((s,i)=>setTimeout(()=>i(new Error(`Custom element "${t}" failed to register within ${j}ms`)),j))]).then(()=>a()).catch(l)});var B=(e=>(e.QuantityBreak="quantity-break",e.Bxgy="bxgy",e.Bundle="bundle",e.MixAndMatch="mix-and-match",e.Sku="sku",e))(B||{});const k="a-f\\d",Te=`#?[${k}]{3}[${k}]?`,qe=`#?[${k}]{6}([${k}]{2})?`,je=new RegExp(`[^#${k}]`,"gi"),Oe=new RegExp(`^${Te}$|^${qe}$`,"i");function Ve(e,t={}){if(typeof e!="string"||je.test(e)||!Oe.test(e))throw new TypeError("Expected a valid hex string");e=e.replace(/^#/,"");let a=1;e.length===8&&(a=Number.parseInt(e.slice(6,8),16)/255,e=e.slice(0,6)),e.length===4&&(a=Number.parseInt(e.slice(3,4).repeat(2),16)/255,e=e.slice(0,3)),e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]);const l=Number.parseInt(e,16),s=l>>16,i=l>>8&255,o=l&255,r=typeof t.alpha=="number"?t.alpha:a;if(t.format==="array")return[s,i,o,r];if(t.format==="css"){const m=r===1?"":` / ${Number((r*100).toFixed(2))}%`;return`rgb(${s} ${i} ${o}${m})`}return{red:s,green:i,blue:o,alpha:r}}const Ue=({price:e})=>({id:123,handle:"123",url:null,availableForSale:!0,requiresSellingPlan:!1,title:"",image:null,selectedVariantId:456,collectionIds:[],options:[],sellingPlans:[],variants:[{id:456,availableForSale:!0,price:Math.round((e??10)*100),compareAtPrice:null,options:[],imageId:null,image:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50,unitPriceMeasurement:null}],metafields:{text:null,text2:null,text3:null,text4:null},isNativeBundle:!1}),Fe=()=>({shopifyDomain:"",moneyFormat:"${{amount_with_comma_separator}}",locale:"en",liquidLocale:"en",country:"US",marketId:0,productId:null,storefrontAccessToken:null,includeSellingPlans:!1,includeAvailableQuantity:!1,customApiHost:null,keepQuantityInput:!1,ignoreDeselect:!1,ignoreUnitPrice:!1,requireCustomerLogin:!1,abTestsRunning:!1,webPixel:!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,previewScratchOff:!1,currencyRate:1,defaultTranslations:{"system.out_of_stock":"","system.invalid_variant":"","system.unavailable_option_value":"","system.confirm":"","system.cancel":"","system.free":"","system.search":"","system.quantity":"","system.subscription_plan":"","system.remove":"","system.sort_by":"","system.sort_relevance":"","system.sort_newest_first":"","system.sort_price_low_to_high":"","system.sort_price_high_to_low":"","system.no_results_found":"","system.no_results_description":"","system.clear_search":"","system.no_products_available":"","system.original_price":"","system.price":"","system.letters_only":"","system.numbers_only":""},customSelectors:{quantity:null,addToCartButton:null,variantPicker:null},shopCustomStyles:"",featureFlags:{}}),Re=({color:e,cornerRadius:t})=>{const a={id:"123",nanoId:"123",blockName:"Bundle",discountName:"",blockTitle:"BUNDLE & SAVE",blockLayout:"vertical",blockVisibility:"all-products",marketId:null,currency:null,excludedProductIds:[],excludedCollectionIds:[],selectedProductIds:[],selectedCollectionIds:[],excludeB2bCustomers:!1,excludePos:!1,startTimestamp:175811496e4,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!1,showPricesPerItem:!1,showBothPrices:!1,useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:".00",updateNativePrice:!1,updateNativePriceType:"item",skipCart:!1,showVariantsForSingleQuantity:!0,preselectedDealBarId:"1f-9",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,lowStockAlertEnabled:!1,lowStockAlert:null,dealBars:[{id:"PfFU",dealBarType:B.QuantityBreak,title:"1 pack",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},{id:"1f-9",dealBarType:B.QuantityBreak,title:"2 pack",subtitle:"You save {{saved_percentage}}",label:"SAVE {{saved_total}}",quantity:2,discountType:"percentage",discountValue:"15",badgeStyle:"most-popular",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null}],badgesEnabled:!0,badges:[{id:"bdg1",attachedTo:{type:"dealBar",dealBarId:"1f-9"},text:"MOST POPULAR",colors:null,badgeType:"most-popular",size:90}],cornerRadius:t??8,spacing:1,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:255,green:17,blue:17,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:"bold"},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"}},swatchOptions:[],swatchSize:18,swatchShape:"circle",imageSize:48,imageCornerRadius:6};return e!==void 0&&(a.colors.border={...Ve(e),alpha:1}),a},Le=({data:e,selectedVariantId:t,preview:a,onLinesChange:l,targetWindow:s})=>{const i=S.useRef(null),[o,r]=S.useState(!1),m=S.useRef(!1);S.useEffect(()=>{if(!i.current||o)return;(async()=>{await Ge(s??window),r(!0)})()},[o,s]),S.useEffect(()=>{const c=i.current;if(!o||!c)return;const f=()=>{const y=c.items().map(h=>({merchandiseId:`gid://shopify/ProductVariant/${h.id}`,quantity:h.quantity,attributes:Object.entries(h.properties).map(([n,p])=>({key:n,value:String(p)})),sellingPlanId:h.selling_plan?`gid://shopify/SellingPlan/${h.selling_plan}`:void 0}));l==null||l(y)};return m.current||(typeof c.items=="function"?f():c.addEventListener("kaching-bundles-block-loaded",f),m.current=!0),c.addEventListener("variants-changed",f),()=>{c.removeEventListener("kaching-bundles-block-loaded",f),c.removeEventListener("variants-changed",f)}},[o,l]);const d=e?ze(e,t):a?Qe(a):null;return Je(()=>{const c=i.current;if(!(!c||!d))for(const[f,g]of Object.entries(d.jsonAttributes))c.getAttribute(f)!==g&&c.setAttribute(f,g)}),d?U.jsx("kaching-bundles-block",{ref:i,"deal-block-id":d.dealBlockId,...d.jsonAttributes,"current-variant-id":d.currentVariantId}):null},Je=typeof window>"u"?S.useEffect:S.useLayoutEffect,ze=({config:e,dealBlock:t,product:a,otherProducts:l,mediaImages:s,collectionBreaksProducts:i,translations:o},r)=>({dealBlockId:t.id,currentVariantId:r?r.split("/").pop():String(a.variants[0].id),jsonAttributes:{config:JSON.stringify(e),"deal-block":JSON.stringify(t),"media-images":JSON.stringify(s),product:JSON.stringify(a),"other-products":JSON.stringify(l),"collection-breaks-products":JSON.stringify(i),translations:JSON.stringify(o)}}),Qe=({cornerRadius:e,color:t,price:a})=>{const l=Ue({price:a}),s=Fe(),i=Re({color:t,cornerRadius:e});return{dealBlockId:i.id,currentVariantId:String(l.variants[0].id),jsonAttributes:{config:JSON.stringify(s),"deal-block":JSON.stringify(i),"media-images":JSON.stringify([]),product:JSON.stringify(l),"other-products":JSON.stringify([]),"collection-breaks-products":JSON.stringify([]),translations:JSON.stringify({})}}};exports.KachingBundle=Le;exports.fetchKachingBundlesData=Ae;
|
|
228
|
+
`,{variables:{mediaImageIds:i,size:a}})))).flatMap(i=>i.nodes).filter(Boolean).map(i=>({gid:i.id,url:i.image.url}))};var w=(e=>(e.QuantityBreak="quantity-break",e.Bxgy="bxgy",e.Bundle="bundle",e.MixAndMatch="mix-and-match",e.Sku="sku",e))(w||{});const se=e=>[...ne(e),...re(e),...le(e),...ie(e),...oe(e),...ce(e),...ue(e),...de(e),...me(e),...pe(e),...fe(e),...ge(e),...ye(e)].filter(t=>t!=null&&!t.includes("placeholder")),ne=e=>e.dealBars.flatMap(t=>[t.mediaImageGID,t.badgeImageGID]).filter(t=>t!=null),re=e=>e.dealBars.flatMap(t=>t.dealBarType===w.Bundle?t.bundleProducts.map(a=>a.mediaImageGID):[]).filter(t=>t!=null),le=e=>e.dealBars.map(({freeGifts:t})=>(t||[]).map(a=>a.mediaImageGID)).reduce((t,a)=>t.concat(a),[]).filter(t=>t!=null),ie=e=>e.dealBars.flatMap(({multipleGiftsSelectors:t})=>(t||[]).map(a=>a.mediaImageGID)).filter(t=>t!=null),oe=e=>e.dealBars.map(({upsells:t})=>(t||[]).map(a=>a.mediaImageGID)).reduce((t,a)=>t.concat(a),[]).filter(t=>t!=null),ce=e=>e.swatchOptions?e.swatchOptions.reduce((t,a)=>{const n=a.images.map(s=>s.mediaImageGID).filter(s=>s!=null);return[...t,...n]},[]):[],ue=e=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];const t=e.collectionBreaks.mediaImageGID;return t?[t]:[]},de=e=>{var t,a,n;return e.progressiveGifts?[...((t=e.progressiveGifts.gifts)==null?void 0:t.map(s=>s.mediaImageGID))||[],(a=e.progressiveGifts.style)==null?void 0:a.lockedMediaImageGID,(n=e.progressiveGifts.dealBarStyle)==null?void 0:n.lockedMediaImageGID].filter(s=>s!=null):[]},me=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.flatMap(t=>[t.mediaImageGID,t.badgeImageGID]).filter(t=>t!=null),pe=e=>e.dealBars.map(t=>{var a;return(a=t.productPersonalisation)==null?void 0:a.mediaImageGID}).filter(t=>t!=null),fe=e=>{var n,s;const t=e.dealBars.map(i=>{var o;return(o=i.highlights)==null?void 0:o.customIconGID}).filter(i=>i!=null),a=(s=(n=e.subscriptions)==null?void 0:n.highlights)==null?void 0:s.customIconGID;return a?[...t,a]:t},ge=e=>(e.badges||[]).flatMap(t=>t.badgeType==="custom"&&t.imageGID?[t.imageGID]:[]),ye=e=>!e.savingsSummaryEnabled||!e.savingsSummary?[]:e.savingsSummary.customIconGID?[e.savingsSummary.customIconGID]:[],he=e=>{const t=[...be(e),...ve(e),..._e(e),...Ie(e),...Pe(e),...Se(e),...ke(e),...we(e)];return Array.from(new Set(t.filter(a=>a!=null)))},be=e=>e.dealBars.flatMap(({freeGifts:t})=>t?t.map(a=>a.productGID):[]).filter(t=>t!=null),ve=e=>e.dealBars.flatMap(({multipleGiftsSelectors:t})=>t?t.flatMap(a=>a.products?a.products.map(n=>n.id):[]):[]).filter(t=>t!=null),_e=e=>{var t;return e.progressiveGiftsEnabled?((t=e.progressiveGifts)==null?void 0:t.gifts.map(a=>a.productGID).filter(a=>a!=null))||[]:[]},Ie=e=>e.dealBars.flatMap(({upsells:t})=>t?t.map(a=>a.productGID):[]).filter(t=>t!=null),Pe=e=>e.dealBars.filter(t=>t.dealBarType===w.Bundle).flatMap(({bundleProducts:t})=>t?t.map(a=>a.productGID):[]).filter(t=>t!=null).filter(t=>t!=="default"),Se=e=>e.dealBars.filter(t=>t.dealBarType===w.MixAndMatch).flatMap(({bundleProducts:t})=>t?t.flatMap(a=>{var n;return[a.productGID,...((n=a.selectedProducts)==null?void 0:n.map(s=>s.id))??[]]}):[]).filter(t=>t!=null).filter(t=>t!=="default"),ke=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.map(t=>t.productGID).filter(t=>t!=null),we=e=>e.dealBars.filter(t=>t.dealBarType===w.Sku).flatMap(({productGID:t})=>t?[t]:[]);class j extends Error{constructor({status:t,operationName:a,graphqlErrors:n}){const s=n.length?`: ${n.join("; ")}`:"";super(`Storefront API ${a??"query"} failed (HTTP ${t})${s}`),this.name="StorefrontApiError",this.status=t,this.operationName=a,this.graphqlErrors=n}}const $e=async(e,t)=>{const a=await e.text();if(!a)throw new Error("Empty graphql response");let n;try{n=JSON.parse(a)}catch(s){throw e.ok?s:new j({status:e.status,operationName:t,graphqlErrors:[]})}if(!e.ok||n.data===null||n.data===void 0)throw new j({status:e.status,operationName:t,graphqlErrors:(n.errors??[]).map(({message:s})=>s).filter(Boolean)});return n.data};class Ne{constructor(t,a){this.storefrontApiVersion="2026-07",this.storefrontAccessToken=a,this.shopifyDomain=t}async query(t,a){var l;const n=(a==null?void 0:a.variables)??{};let s=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const i=(l=t.match(/query\s+(\w+)/))==null?void 0:l[1];i&&(s+=`?operation_name=${i}`);const o=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:t,variables:n})});return $e(o,i)}}const De=async(e,t,{country:a,language:n})=>{const s=t.collectionBreaks;if(!t.collectionBreaksEnabled||!s)return;let i;s.visibility==="deal-products"?i=await C(e,{country:a,language:n,blockVisibility:t.blockVisibility,excludedProductGIDs:(t.excludedProductIds||[]).map(l=>`gid://shopify/Product/${l}`),selectedProductGIDs:(t.selectedProductIds||[]).map(l=>`gid://shopify/Product/${l}`),selectedCollectionGIDs:(t.selectedCollectionIds||[]).map(l=>`gid://shopify/Collection/${l}`)}):i=await C(e,{country:a,language:n,blockVisibility:s.visibility,excludedProductGIDs:(s.excludedProducts||[]).map(({id:l})=>l),selectedProductGIDs:(s.selectedProducts||[]).map(({id:l})=>l),selectedCollectionGIDs:(s.selectedCollections||[]).map(({id:l})=>l)});let o=await A(e,{country:a,language:n,productIds:i.map(l=>Number(l.split("/").pop())),useExternalMetafieldNamespace:!0});return o=o.filter(l=>l.availableForSale),o},Ae=({language:e,dealBlockId:t})=>{const a={"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.quantity":"Quantity","system.subscription_plan":"Subscription plan","system.remove":"Remove","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","system.original_price":"Original price:","system.price":"Price:","system.letters_only":"Only letters are allowed.","system.numbers_only":"Only numbers are allowed.","system.personalisation_required_alert":"Please add personalisation for every item to continue."},n=e?Ee(e):void 0;return{...a,...n==null?void 0:n.system,...n==null?void 0:n.dealBlocks[t]}},Ee=e=>{var s;if(typeof document>"u")return;const t=document.querySelector("script#kaching-bundles-translations");if(!(t!=null&&t.textContent))return;let a;try{a=JSON.parse(t.textContent)}catch{return}const n=O(e);return(s=a.find(i=>O(i.locale)===n))==null?void 0:s.translations},O=e=>e.toLowerCase().replace(/_/g,"-"),xe="2026-07",Be=async(e,{productId:t,dealBlockId:a,country:n=void 0,language:s=void 0})=>{var i,o;try{const l=[Number(t.split("/").pop())],d=new Ge(e);n=n||((i=d.i18n)==null?void 0:i.country),s=s||((o=d.i18n)==null?void 0:o.language);const u=await ee(d,{language:s,country:n,useExternalMetafieldNamespace:!0});d.shopifyDomain=u.shopifyDomain;const c=u.storefrontAccessToken?new Ne(u.shopifyDomain,u.storefrontAccessToken):d,[p,g]=await Promise.all([A(c,{country:n,language:s,productIds:l,useExternalMetafieldNamespace:!0}),W(c,{useExternalMetafieldNamespace:!0,useMetaobjects:u.featureFlags.storefront_metaobjects})]),y=p[0];if(!y)return null;const h=J(g,y);let r;if(a?(r=h.find(P=>P.id===a||P.nanoId===a),r||(r=h[0])):r=h[0],!r)return null;const m=se(r),b=he(r),[I,_,f,v]=await Promise.all([A(c,{country:n,language:s,productIds:b,useExternalMetafieldNamespace:!0}),ae(c,m,300),De(c,r,{country:n,language:s}),Ae({language:s,dealBlockId:r.id})]);return{product:y,dealBlock:r,config:u,otherProducts:I,mediaImages:_,collectionBreaksProducts:f??[],translations:v}}catch(l){return console.error(l),null}};class Ge{constructor(t){this.storefront=t,this.shopifyDomain=""}async query(t,a){var n;if("query"in this.storefront&&"i18n"in this.storefront)return await this.storefront.query(t,a);if("graphql"in this.storefront){const s=await this.storefront.graphql(t,a);if((n=s.errors)!=null&&n.length)throw new Error(s.errors.map(i=>i.message).join(`
|
|
229
|
+
`));return s.data}if("request"in this.storefront)return(await this.storefront.request(t,a)).data;if("shopifyDomain"in this.storefront&&"storefrontAccessToken"in this.storefront){const s=await fetch(`https://${this.storefront.shopifyDomain}/api/${xe}/graphql.json`,{body:JSON.stringify({query:t,variables:a==null?void 0:a.variables}),headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:"POST"});if(!s.ok)throw new Error(s.statusText);return(await s.json()).data}else{const s=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:t,variables:a==null?void 0:a.variables}),headers:this.storefront.getPublicTokenHeaders(),method:"POST"});if(!s.ok)throw new Error(s.statusText);return(await s.json()).data}}get i18n(){if("i18n"in this.storefront)return this.storefront.i18n}}const Ce=Be,N="kaching-bundles-block",V=1e4,Te="https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js",qe="https://bundles-integrations.kachingappz.app/kaching-bundles-block.js",D=new WeakSet,Me=async e=>{const t=e.document;if(!e.customElements.get(N)){if(D.has(t))return E(e,N);D.add(t);try{await Ve(e)}catch(a){throw D.delete(t),a}}},je=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",Oe=()=>je()?Te:qe,Ve=e=>{const t=e.document;return new Promise((a,n)=>{const s=Oe();if(t.querySelector(`script[src="${s}"]`)){E(e,N).then(a).catch(n);return}const o=t.createElement("script");o.src=s,o.onload=()=>E(e,N).then(a).catch(n),o.onerror=()=>n(new Error("Failed to load script")),t.head.appendChild(o)})},E=(e,t)=>new Promise((a,n)=>{if(e.customElements.get(t)){a();return}Promise.race([e.customElements.whenDefined(t),new Promise((s,i)=>setTimeout(()=>i(new Error(`Custom element "${t}" failed to register within ${V}ms`)),V))]).then(()=>a()).catch(n)});var x=(e=>(e.QuantityBreak="quantity-break",e.Bxgy="bxgy",e.Bundle="bundle",e.MixAndMatch="mix-and-match",e.Sku="sku",e))(x||{});const k="a-f\\d",Ue=`#?[${k}]{3}[${k}]?`,Fe=`#?[${k}]{6}([${k}]{2})?`,Le=new RegExp(`[^#${k}]`,"gi"),Re=new RegExp(`^${Ue}$|^${Fe}$`,"i");function Je(e,t={}){if(typeof e!="string"||Le.test(e)||!Re.test(e))throw new TypeError("Expected a valid hex string");e=e.replace(/^#/,"");let a=1;e.length===8&&(a=Number.parseInt(e.slice(6,8),16)/255,e=e.slice(0,6)),e.length===4&&(a=Number.parseInt(e.slice(3,4).repeat(2),16)/255,e=e.slice(0,3)),e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]);const n=Number.parseInt(e,16),s=n>>16,i=n>>8&255,o=n&255,l=typeof t.alpha=="number"?t.alpha:a;if(t.format==="array")return[s,i,o,l];if(t.format==="css"){const d=l===1?"":` / ${Number((l*100).toFixed(2))}%`;return`rgb(${s} ${i} ${o}${d})`}return{red:s,green:i,blue:o,alpha:l}}const ze=({price:e})=>({id:123,handle:"123",url:null,availableForSale:!0,requiresSellingPlan:!1,title:"",image:null,selectedVariantId:456,collectionIds:[],options:[],sellingPlans:[],variants:[{id:456,availableForSale:!0,price:Math.round((e??10)*100),compareAtPrice:null,options:[],imageId:null,image:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50,unitPriceMeasurement:null}],metafields:{text:null,text2:null,text3:null,text4:null},isNativeBundle:!1}),Qe=()=>({shopifyDomain:"",moneyFormat:"${{amount_with_comma_separator}}",locale:"en",liquidLocale:"en",country:"US",marketId:0,productId:null,storefrontAccessToken:null,includeSellingPlans:!1,includeAvailableQuantity:!1,customApiHost:null,keepQuantityInput:!1,ignoreDeselect:!1,ignoreUnitPrice:!1,requireCustomerLogin:!1,abTestsRunning:!1,webPixel:!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,previewScratchOff:!1,currencyRate:1,defaultTranslations:{"system.out_of_stock":"","system.invalid_variant":"","system.unavailable_option_value":"","system.confirm":"","system.cancel":"","system.free":"","system.search":"","system.quantity":"","system.subscription_plan":"","system.remove":"","system.sort_by":"","system.sort_relevance":"","system.sort_newest_first":"","system.sort_price_low_to_high":"","system.sort_price_high_to_low":"","system.no_results_found":"","system.no_results_description":"","system.clear_search":"","system.no_products_available":"","system.original_price":"","system.price":"","system.letters_only":"","system.numbers_only":""},customSelectors:{quantity:null,addToCartButton:null,variantPicker:null},shopCustomStyles:"",featureFlags:{}}),He=({color:e,cornerRadius:t})=>{const a={id:"123",nanoId:"123",blockName:"Bundle",discountName:"",blockTitle:"BUNDLE & SAVE",blockLayout:"vertical",blockVisibility:"all-products",marketId:null,currency:null,excludedProductIds:[],excludedCollectionIds:[],selectedProductIds:[],selectedCollectionIds:[],excludeB2bCustomers:!1,excludePos:!1,startTimestamp:175811496e4,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!1,showPricesPerItem:!1,showBothPrices:!1,useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:".00",updateNativePrice:!1,updateNativePriceType:"item",skipCart:!1,showVariantsForSingleQuantity:!0,preselectedDealBarId:"1f-9",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,lowStockAlertEnabled:!1,lowStockAlert:null,dealBars:[{id:"PfFU",dealBarType:x.QuantityBreak,title:"1 pack",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},{id:"1f-9",dealBarType:x.QuantityBreak,title:"2 pack",subtitle:"You save {{saved_percentage}}",label:"SAVE {{saved_total}}",quantity:2,discountType:"percentage",discountValue:"15",badgeStyle:"most-popular",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null}],badgesEnabled:!0,badges:[{id:"bdg1",attachedTo:{type:"dealBar",dealBarId:"1f-9"},text:"MOST POPULAR",colors:null,badgeType:"most-popular",size:90}],cornerRadius:t??8,spacing:1,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:255,green:17,blue:17,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:"bold"},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"}},swatchOptions:[],swatchSize:18,swatchShape:"circle",imageSize:48,imageCornerRadius:6};return e!==void 0&&(a.colors.border={...Je(e),alpha:1}),a},Ke=({data:e,selectedVariantId:t,preview:a,onLinesChange:n,targetWindow:s})=>{const i=S.useRef(null),[o,l]=S.useState(!1),d=S.useRef(!1);S.useEffect(()=>{if(!i.current||o)return;(async()=>{await Me(s??window),l(!0)})()},[o,s]),S.useEffect(()=>{const c=i.current;if(!o||!c)return;const p=()=>{const y=c.items().map(h=>({merchandiseId:`gid://shopify/ProductVariant/${h.id}`,quantity:h.quantity,attributes:Object.entries(h.properties).map(([r,m])=>({key:r,value:String(m)})),sellingPlanId:h.selling_plan?`gid://shopify/SellingPlan/${h.selling_plan}`:void 0}));n==null||n(y)};return d.current||(typeof c.items=="function"?p():c.addEventListener("kaching-bundles-block-loaded",p),d.current=!0),c.addEventListener("variants-changed",p),()=>{c.removeEventListener("kaching-bundles-block-loaded",p),c.removeEventListener("variants-changed",p)}},[o,n]);const u=e?Xe(e,t):a?Ye(a):null;return We(()=>{const c=i.current;if(!(!c||!u))for(const[p,g]of Object.entries(u.jsonAttributes))c.getAttribute(p)!==g&&c.setAttribute(p,g)}),u?R.jsx("kaching-bundles-block",{ref:i,"deal-block-id":u.dealBlockId,...u.jsonAttributes,"current-variant-id":u.currentVariantId}):null},We=typeof window>"u"?S.useEffect:S.useLayoutEffect,Xe=({config:e,dealBlock:t,product:a,otherProducts:n,mediaImages:s,collectionBreaksProducts:i,translations:o},l)=>({dealBlockId:t.id,currentVariantId:l?l.split("/").pop():String(a.variants[0].id),jsonAttributes:{config:JSON.stringify(e),"deal-block":JSON.stringify(t),"media-images":JSON.stringify(s),product:JSON.stringify(a),"other-products":JSON.stringify(n),"collection-breaks-products":JSON.stringify(i),translations:JSON.stringify(o)}}),Ye=({cornerRadius:e,color:t,price:a})=>{const n=ze({price:a}),s=Qe(),i=He({color:t,cornerRadius:e});return{dealBlockId:i.id,currentVariantId:String(n.variants[0].id),jsonAttributes:{config:JSON.stringify(s),"deal-block":JSON.stringify(i),"media-images":JSON.stringify([]),product:JSON.stringify(n),"other-products":JSON.stringify([]),"collection-breaks-products":JSON.stringify([]),translations:JSON.stringify({})}}};exports.KachingBundle=Ke;exports.fetchKachingBundlesData=Ce;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -303,12 +303,14 @@ declare type DealBlock = {
|
|
|
303
303
|
showBothPrices: boolean;
|
|
304
304
|
unitLabel?: string;
|
|
305
305
|
useProductCompareAtPrice: boolean;
|
|
306
|
+
hideFullPrice?: boolean;
|
|
306
307
|
showPricesWithoutDecimals?: boolean;
|
|
307
308
|
priceRounding: boolean;
|
|
308
309
|
priceRoundingPrecision: PriceRoundingPrecision;
|
|
309
310
|
updateNativePrice?: boolean;
|
|
310
311
|
updateNativePriceType?: "item" | "bundle";
|
|
311
312
|
showTotalPriceInAddToCartButton?: boolean;
|
|
313
|
+
includeUpsellsInDealBarPrice?: boolean;
|
|
312
314
|
skipCart: boolean;
|
|
313
315
|
showVariantsForSingleQuantity: boolean;
|
|
314
316
|
preselectedDealBarId: string | null;
|
|
@@ -457,6 +459,7 @@ declare interface GlobalConfig {
|
|
|
457
459
|
includeSellingPlans: boolean;
|
|
458
460
|
includeAvailableQuantity: boolean;
|
|
459
461
|
customApiHost: string | null;
|
|
462
|
+
appEmbedCheckToken?: string | null;
|
|
460
463
|
keepQuantityInput: boolean;
|
|
461
464
|
ignoreDeselect: boolean;
|
|
462
465
|
ignoreUnitPrice: boolean;
|
|
@@ -519,11 +522,10 @@ declare interface GlobalConfig {
|
|
|
519
522
|
"system.deal_page_box_full"?: string;
|
|
520
523
|
"system.deal_page_sold_out"?: string;
|
|
521
524
|
"system.deal_page_start_your_box"?: string;
|
|
522
|
-
"system.
|
|
525
|
+
"system.deal_page_not_a_box_size"?: string;
|
|
523
526
|
"system.deal_page_full_price_for_now"?: string;
|
|
524
527
|
"system.deal_page_percentage_unlocked"?: string;
|
|
525
528
|
"system.deal_page_box_of"?: string;
|
|
526
|
-
"system.deal_page_no_box_price"?: string;
|
|
527
529
|
"system.deal_page_track_box_full"?: string;
|
|
528
530
|
"system.deal_page_nudge_start_percentage_one"?: string;
|
|
529
531
|
"system.deal_page_nudge_start_percentage_other"?: string;
|
|
@@ -541,12 +543,10 @@ declare interface GlobalConfig {
|
|
|
541
543
|
"system.deal_page_nudge_more_fixed_other"?: string;
|
|
542
544
|
"system.deal_page_nudge_more_fixed_few"?: string;
|
|
543
545
|
"system.deal_page_nudge_more_fixed_many"?: string;
|
|
544
|
-
"system.
|
|
545
|
-
"system.
|
|
546
|
-
"system.
|
|
547
|
-
"system.
|
|
548
|
-
"system.deal_page_nudge_below_minimum_few"?: string;
|
|
549
|
-
"system.deal_page_nudge_below_minimum_many"?: string;
|
|
546
|
+
"system.deal_page_nudge_not_a_box_size_one"?: string;
|
|
547
|
+
"system.deal_page_nudge_not_a_box_size_other"?: string;
|
|
548
|
+
"system.deal_page_nudge_not_a_box_size_few"?: string;
|
|
549
|
+
"system.deal_page_nudge_not_a_box_size_many"?: string;
|
|
550
550
|
"system.deal_page_subtotal"?: string;
|
|
551
551
|
"system.deal_page_box_discount"?: string;
|
|
552
552
|
"system.deal_page_box_price_saving"?: string;
|
|
@@ -574,7 +574,6 @@ declare interface GlobalConfig {
|
|
|
574
574
|
"system.deal_page_default_add_to_box"?: string;
|
|
575
575
|
"system.deal_page_default_add_box_to_cart"?: string;
|
|
576
576
|
"system.deal_page_items_range"?: string;
|
|
577
|
-
"system.deal_page_minimum"?: string;
|
|
578
577
|
"system.deal_page_tip_box_size"?: string;
|
|
579
578
|
"system.deal_page_tip_on_its_own"?: string;
|
|
580
579
|
"system.deal_page_about_this_price"?: string;
|