@kachingappz/bundles-js 1.1.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles-js.iife.js +19 -19
- package/dist/index.d.ts +18 -9
- package/dist/index.js +305 -213
- package/dist/kaching-bundle-component/index.d.ts +18 -9
- package/dist/kaching-bundle-component/index.js +354 -273
- package/dist/react/index.cjs +19 -19
- package/dist/react/index.d.ts +18 -9
- package/dist/react/index.js +328 -250
- package/package.json +3 -2
package/dist/react/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");var n=(e,{
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime");[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var n=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),r=(e,t)=>e.selectedVariants?.find(e=>e.productId===t)?.variantIds,i=(e,t)=>r(e,t)!==void 0,a=(e,t,n)=>r(e,t)?.includes(n)??!0,o=(e,t)=>i(e,t.id)?t.variants.filter(n=>a(e,t.id,n.id)).map(e=>e.id):void 0,s=(e,t)=>{if(!t)return e;let n=e.variants.filter(e=>t.includes(e.id)),r=e.options.map((e,t)=>({...e,optionValues:e.optionValues.filter(e=>n.some(n=>n.options[t]===e.name))})),i=n.some(t=>t.id===e.selectedVariantId)?e.selectedVariantId:n[0]?.id??e.selectedVariantId;return{...e,variants:n,options:r,selectedVariantId:i}},c=(e,t)=>l(e)?u(e,t,d(e)):t,l=e=>!!e.selectedVariants?.length,u=(e,t,n)=>t.flatMap(t=>{let r=o(e,t);if(!r)return[t];let i=s(t,[...r,...t.variants.map(e=>e.id).filter(e=>n.has(e))]);return i.variants.length?[i]:[]}),d=e=>new Set([...e.dealBars.flatMap(f),...(e.progressiveGifts?.gifts??[]).flatMap(e=>e.variantGIDs??[]),...(e.checkboxUpsells?.upsells??[]).flatMap(e=>e.variantGIDs??[])].map(m)),f=e=>[...e.freeGifts.flatMap(e=>e.variantGIDs??[]),...e.upsells.flatMap(e=>e.variantGIDs??[]),...(e.multipleGiftsSelectors??[]).flatMap(e=>e.products.flatMap(e=>e.variantGIDs??[])),...p(e)],p=e=>{switch(e.dealBarType){case n.Bundle:return e.bundleProducts.flatMap(e=>e.productGID==="default"?[]:e.variantGIDs??[]);case n.MixAndMatch:return e.bundleProducts.flatMap(e=>[...e.productGID==="default"?[]:e.variantGIDs??[],...(e.selectedProducts??[]).flatMap(e=>e.variantGIDs??[])]);default:return[]}},m=e=>Number(e.split(`/`).pop()),h=(e,t,n)=>{let i=e=>n!==void 0&&a(e,t.id,n),o=e.filter(e=>r(e,t.id)?.some(e=>t.variants.some(t=>t.id===e))),s=o.filter(i),c=[...s],l=o.filter(e=>!s.includes(e)),u=e.filter(e=>e.blockVisibility===`selected-products`);for(let e of u)e.selectedProductIds.map(Number).includes(t.id)&&c.push(e);let d=e.filter(e=>e.blockVisibility===`selected-collections`);for(let e of d)t.collectionIds.some(t=>e.selectedCollectionIds.map(Number).includes(t))&&c.push(e);let f=e.filter(e=>e.blockVisibility===`excluded-products`);for(let e of f)!e.excludedProductIds.map(Number).includes(t.id)&&!(e.excludedCollectionIds||[]).some(e=>t.collectionIds.includes(e))&&c.push(e);let p=e.filter(e=>e.blockVisibility===`all-products`);for(let e of p)c.push(e);return n===void 0?c:[...c,...l]},g=(e,{language:t,country:n})=>{let r=b(t,n),i=new Intl.NumberFormat(r,{style:`currency`,currency:e,currencyDisplay:`narrowSymbol`}).formatToParts(1234567.89),a=i.find(e=>e.type===`decimal`)?.value,o=S(x(i.find(e=>e.type===`group`)?.value),a,i.some(e=>e.type===`fraction`)),s=i.findIndex(y),c=i.findLastIndex(y);return[...i.slice(0,s).map(_),o,...i.slice(c+1).map(_)].join(``)},_=e=>v(e.value),v=e=>e.replace(/\s/g,` `),y=e=>e.type===`integer`||e.type===`group`||e.type===`decimal`||e.type===`fraction`,b=(e,t)=>e&&t?`${e}-${t.toUpperCase()}`:e||(t?t.toUpperCase():`en`),x=e=>e===void 0?void 0:v(e).replace(/’/g,`'`),S=(e,t,n)=>t===`,`&&e===`.`?n?`{{amount_with_comma_separator}}`:`{{amount_no_decimals_with_comma_separator}}`:t===`,`&&e===` `?n?`{{amount_with_space_separator}}`:`{{amount_no_decimals_with_space_separator}}`:t===`.`&&e===` `?`{{amount_with_period_and_space_separator}}`:t===`.`&&e===`'`?`{{amount_with_apostrophe_separator}}`:n?`{{amount}}`:`{{amount_no_decimals}}`,C=({country:e,language:t})=>{let n=[];return e&&n.push(`country: ${e}`),t&&n.push(`language: ${t}`),n.length>0?`@inContext(${n.join(`, `)})`:``},w=async(e,{useExternalMetafieldNamespace:t,useMetaobjects:n})=>n?E(e,t):T(e,t),T=async(e,t)=>{let 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 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
`,{variables:{metafieldNamespace:t?`app--2935586817--kaching_bundles`:`$app:kaching_bundles`}})).shop.metafield?.value;return n?JSON.parse(n):[]},
|
|
9
|
+
`,{variables:{metafieldNamespace:t?`app--2935586817--kaching_bundles`:`$app:kaching_bundles`}})).shop.metafield?.value;return n?JSON.parse(n):[]},E=async(e,t)=>{let n=t?`app--2935586817--deal_block`:`$app:deal_block`,r=[],i=null;for(;;){let t=await e.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 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
`,{variables:{type:n,cursor:i}});for(let e of t.metaobjects.nodes){let t=e.fields.find(e=>e.key===`settings`);t?.value&&r.push(JSON.parse(t.value))}if(!t.metaobjects.pageInfo.hasNextPage)break;i=t.metaobjects.pageInfo.endCursor}return r};[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var
|
|
24
|
+
`,{variables:{type:n,cursor:i}});for(let e of t.metaobjects.nodes){let t=e.fields.find(e=>e.key===`settings`);t?.value&&r.push(JSON.parse(t.value))}if(!t.metaobjects.pageInfo.hasNextPage)break;i=t.metaobjects.pageInfo.endCursor}return r};[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var D=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),O=async(e,{country:t,language:n,blockVisibility:r,excludedProductGIDs:i,selectedProductGIDs:a,selectedCollectionGIDs:o,limit:s=1e3})=>{switch(r){case`selected-products`:return a.slice(0,s);case`all-products`:case`excluded-products`:{let a=C({country:t,language:n}),o=[],c=null;for(;o.length<s;){let t=Math.min(s-o.length,250),n=await e.query(`
|
|
25
25
|
query FetchProductGIDs($limit: Int!, $cursor: String) ${a} {
|
|
26
26
|
products(first: $limit, after: $cursor) {
|
|
27
27
|
nodes {
|
|
@@ -33,7 +33,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
`,{variables:{limit:t,cursor:c}});if(o.push(...n.products.nodes.map(e=>e.id)),!n.products.pageInfo.hasNextPage)break;c=n.products.pageInfo.endCursor}if(r===`excluded-products`){let e=new Set(i);o=o.filter(t=>!e.has(t))}return o}case`selected-collections`:{let r=
|
|
36
|
+
`,{variables:{limit:t,cursor:c}});if(o.push(...n.products.nodes.map(e=>e.id)),!n.products.pageInfo.hasNextPage)break;c=n.products.pageInfo.endCursor}if(r===`excluded-products`){let e=new Set(i);o=o.filter(t=>!e.has(t))}return o}case`selected-collections`:{let r=C({country:t,language:n}),i=(await e.query(`
|
|
37
37
|
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${r} {
|
|
38
38
|
nodes(ids: $collectionGIDs) {
|
|
39
39
|
... on Collection {
|
|
@@ -45,7 +45,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
`,{variables:{collectionGIDs:o,limit:Math.min(s,250)}})).nodes.filter(e=>e!==null).flatMap(e=>e.products.nodes.map(e=>e.id));return Array.from(new Set(i)).slice(0,s)}}},
|
|
48
|
+
`,{variables:{collectionGIDs:o,limit:Math.min(s,250)}})).nodes.filter(e=>e!==null).flatMap(e=>e.products.nodes.map(e=>e.id));return Array.from(new Set(i)).slice(0,s)}}},k=`
|
|
49
49
|
id
|
|
50
50
|
availableForSale
|
|
51
51
|
price {
|
|
@@ -88,8 +88,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
quantityAvailable @include(if: $includeAvailableQuantity)
|
|
91
|
-
`,
|
|
92
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $includeProductTabFields: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${
|
|
91
|
+
`,A=async(e,{country:t,language:n,productIds:r,includeSellingPlans:i=!0,includeAvailableQuantity:a=!0,includeProductRating:o=!1,includeProductSubtitle:s=!1,includeProductTabFields:c=!1,productSubtitleMetafield:l=`descriptors.subtitle`,useExternalMetafieldNamespace:u=!1,batchSize:d=250,onBatchError:f,variantImageTransform:p={maxWidth:200,maxHeight:200}})=>{if(!r.length)return[];let m=r.map(e=>typeof e==`string`&&e.startsWith(`gid://`)?e:`gid://shopify/Product/${e}`),h=C({country:t,language:n}),g=`
|
|
92
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $includeProductTabFields: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${h} {
|
|
93
93
|
shop {
|
|
94
94
|
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
95
95
|
value
|
|
@@ -123,7 +123,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
123
123
|
}
|
|
124
124
|
variants(first: 250) {
|
|
125
125
|
nodes {
|
|
126
|
-
${
|
|
126
|
+
${k}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
collections(first: 50) {
|
|
@@ -189,8 +189,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
`,
|
|
193
|
-
query FetchProductTypes($productGIDs: [ID!]!) ${
|
|
192
|
+
`,_=u?`app--2935586817--kaching_bundles`:`$app:kaching_bundles`,v=l.indexOf(`.`),y=l.slice(0,v),b=l.slice(v+1),x=[],S=Math.min(d,250);for(let e=0;e<m.length;e+=S)x.push(m.slice(e,e+S));let w=1,T=async n=>{let[r,l]=await Promise.all([e.query(g,{variables:{productGIDs:n,includeSellingPlans:i,includeAvailableQuantity:a,includeProductRating:o,includeProductSubtitle:s,includeProductTabFields:c,subtitleNamespace:y,subtitleKey:b,metafieldNamespace:_,variantImageTransform:p}}),c?ee(e,t,n):null]);return r.shop.currencyRateConstant&&(w=JSON.parse(r.shop.currencyRateConstant.value).amount/1e6),l?{nodes:r.nodes.map(e=>e&&{...e,productType:l.get(e.id)})}:r},E;if(f){let e=await Promise.allSettled(x.map(T));for(let t of e)t.status===`rejected`&&f(t.reason instanceof Error?t.reason:Error(String(t.reason)));E=e.filter(e=>e.status===`fulfilled`).flatMap(e=>e.value.nodes)}else E=(await Promise.all(x.map(T))).flatMap(e=>e.nodes);let D=E.filter(e=>e!=null);if(f){let t=await Promise.allSettled(D.map(async t=>M(await j(e,t,{includeSellingPlans:i,includeAvailableQuantity:a,variantImageTransform:p},h),e.shopifyDomain,w))),n=[];for(let e of t)e.status===`fulfilled`?n.push(e.value):f(e.reason instanceof Error?e.reason:Error(String(e.reason)));return n}return(await Promise.all(D.map(t=>j(e,t,{includeSellingPlans:i,includeAvailableQuantity:a,variantImageTransform:p},h)))).map(t=>M(t,e.shopifyDomain,w))},ee=async(e,t,n)=>{try{let r=await e.query(`
|
|
193
|
+
query FetchProductTypes($productGIDs: [ID!]!) ${C({country:t})} {
|
|
194
194
|
nodes(ids: $productGIDs) {
|
|
195
195
|
... on Product {
|
|
196
196
|
id
|
|
@@ -198,12 +198,12 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
`,{variables:{productGIDs:n}});return new Map(r.nodes.filter(e=>e!=null).map(e=>[e.id,e.productType]))}catch(e){return console.error(e),null}},
|
|
201
|
+
`,{variables:{productGIDs:n}});return new Map(r.nodes.filter(e=>e!=null).map(e=>[e.id,e.productType]))}catch(e){return console.error(e),null}},j=async(e,t,n,r=``)=>{if(t.variants.nodes.length<250)return t;let i=new Set,a=[],o=[],s=async s=>{let c=!0,l=null;for(;c;){let{nodes:u,pageInfo:d}=(await e.query(`
|
|
202
202
|
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $variantImageTransform: ImageTransformInput) ${r} {
|
|
203
203
|
product(id: $productGID) {
|
|
204
204
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
205
205
|
nodes {
|
|
206
|
-
${
|
|
206
|
+
${k}
|
|
207
207
|
}
|
|
208
208
|
pageInfo {
|
|
209
209
|
endCursor
|
|
@@ -212,8 +212,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
`,{variables:{productGID:t.id,cursor:l,reverse:s,...n}})).product.variants;for(let e of u){if(i.has(e.id)){c=!1;break}i.add(e.id),s?o.push(e):a.push(e)}d.hasNextPage||(c=!1),l=d.endCursor}};return await Promise.all([s(!1),s(!0)]),t.variants.nodes=[...a,...o.reverse()],t},
|
|
216
|
-
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${
|
|
215
|
+
`,{variables:{productGID:t.id,cursor:l,reverse:s,...n}})).product.variants;for(let e of u){if(i.has(e.id)){c=!1;break}i.add(e.id),s?o.push(e):a.push(e)}d.hasNextPage||(c=!1),l=d.endCursor}};return await Promise.all([s(!1),s(!0)]),t.variants.nodes=[...a,...o.reverse()],t},M=(e,t,n)=>{let r=e.variants.nodes.map(({unitPriceMeasurement:e,...t})=>({id:Number(t.id.split(`/`).pop()),availableForSale:t.availableForSale,price:Math.round(Number(t.price.amount)*100),compareAtPrice:t.compareAtPrice?Math.round(Number(t.compareAtPrice.amount)*100):null,options:t.selectedOptions.map(e=>e.value),imageId:t.image?Number(t.image.id.split(`/`).pop()):null,image:t.image?.url||null,sellingPlans:t.sellingPlanAllocations?.nodes.map(e=>({id:Number(e.sellingPlan.id.split(`/`).pop()),price:e.priceAdjustments.length>0?Math.round(Number(e.priceAdjustments[0].price.amount)*100):Math.round(Number(t.price.amount)*100),compareAtPrice:e.priceAdjustments.length>0?Math.round(Number(e.priceAdjustments[0].compareAtPrice.amount)*100):Math.round(Number(t.price.amount)*100),perDeliveryPrice:e.priceAdjustments.length>0?Math.round(Number(e.priceAdjustments[0].perDeliveryPrice.amount)*100):Math.round(Number(t.price.amount)*100)}))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:t.quantityAvailable??null,unitPriceMeasurement:e?.quantityUnit&&e?.referenceUnit?{quantityValue:e.quantityValue,quantityUnit:e.quantityUnit.toLowerCase(),referenceValue:e.referenceValue,referenceUnit:e.referenceUnit.toLowerCase()}:null})),i=e.options.map((e,t)=>{let n=e.optionValues.map(e=>({id:Number(e.id.split(`/`).pop()),defaultName:e.name,name:e.name,swatch:{color:e.swatch?.color||null,image:e.swatch?.image?.previewImage?.url||null}}));return{defaultName:e.name,name:e.name,position:t+1,optionValues:re(n,t,r)}}),a=e=>{let t=e.priceAdjustments[0];if(!t)return null;let n=t.adjustmentValue;switch(n.__typename){case`SellingPlanPercentagePriceAdjustment`:return{type:`percentage`,value:n.adjustmentPercentage};case`SellingPlanFixedAmountPriceAdjustment`:return{type:`fixed_amount`,value:o(n.adjustmentAmount.amount)};case`SellingPlanFixedPriceAdjustment`:return{type:`price`,value:o(n.price.amount)};default:throw Error(`Unknown price adjustment type: ${n.__typename}`)}},o=e=>n===1?Number(e)*100:Math.round(Number(e)*100*n),s=e.sellingPlanGroups?.nodes.flatMap(e=>e.sellingPlans.nodes.map(e=>({id:Number(e.id.split(`/`).pop()),name:e.name,recurringDeliveries:e.recurringDeliveries,priceAdjustment:a(e)})))||[],c=e.variants.nodes.some(e=>e.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:e.featuredImage?.url||null,collectionIds:e.collections.nodes.map(e=>Number(e.id.split(`/`).pop())),options:i,selectedVariantId:Number(e.variants.nodes[0].id.split(`/`).pop()),variants:r,requiresSellingPlan:e.requiresSellingPlan,sellingPlans:s,isNativeBundle:c,metafields:{text:e.metafield?.value||null,text2:e.metafield2?.value||null,text3:e.metafield3?.value||null,text4:e.metafield4?.value||null},rating:te(e.reviewsRating,e.reviewsRatingCount),subtitle:e.subtitle?.value||null,productType:e.productType||null,categoryGid:e.category?.id??null,tags:e.tags??[]}},te=(e,t)=>{if(!e)return null;let n=ne(e.value);if(n===null)return null;let r=Number(t?.value);return{value:n,count:Number.isInteger(r)&&r>0?r:null}},ne=e=>{try{let{value:t,scale_max:n}=JSON.parse(e),r=Number(t)/Number(n)*5;return Number.isFinite(r)&&r>0?Math.min(5,r):null}catch{return null}},re=(e,t,n)=>e.filter(e=>n.filter(n=>n.options[t]===e.name).length>0),N=`app--2935586817`,ie=async(e,{language:t,country:n,useExternalMetafieldNamespace:r})=>{let i=r?`${N}--kaching_bundles`:`$app:kaching_bundles`,a=r?N:`$app`,o=C({country:n}),{localization:{country:{currency:{isoCode:s}}},shop:{moneyFormat:c,paymentSettings:{currencyCode:l},currencyRateConstant:u,primaryDomain:d,settingsMetafield:f}}=await e.query(`
|
|
216
|
+
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${o} {
|
|
217
217
|
localization {
|
|
218
218
|
country {
|
|
219
219
|
currency {
|
|
@@ -237,7 +237,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
`,{variables:{metafieldNamespace:
|
|
240
|
+
`,{variables:{metafieldNamespace:i,settingsNamespace:a}}),p=s===l?c:g(s,{language:t,country:n}),m=u?ae(u.value):1,h=f?JSON.parse(f.value):null,_=h?.feature_flags??{},v=h?.custom_selectors??{};return{shopifyDomain:d.host,moneyFormat:p,locale:t?.toLowerCase()||`en`,liquidLocale:t?.toLowerCase()||`en`,country:n??`US`,currencyRate:m,marketId:0,productId:null,storefrontAccessToken:h?.storefront_access_token??null,includeSellingPlans:h?.include_selling_plans??!1,includeAvailableQuantity:h?.include_available_quantity??!1,customApiHost:h?.custom_api_host??null,keepQuantityInput:h?.keep_quantity_input??!1,ignoreDeselect:h?.ignore_deselect??!1,ignoreUnitPrice:h?.ignore_unit_price??!1,requireCustomerLogin:h?.require_customer_login??!1,abTestsRunning:h?.ab_tests_running??!1,webPixel:h?.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:v.quantity??null,addToCartButton:v.add_to_cart_button??null,variantPicker:v.variant_picker??null,price:v.price??null,priceCompare:v.price_compare??null},shopCustomStyles:h?.shop_custom_styles??``,featureFlags:_,brandColors:h?.brand_colors??null}},ae=e=>JSON.parse(e).amount/1e6,oe=async(e,t,n=200)=>{let r=[...new Set(t.filter(Boolean).filter(e=>!e.startsWith(`placeholder`)))];if(r.length===0)return[];let i=[];for(let e=0;e<r.length;e+=250)i.push(r.slice(e,e+250));return(await Promise.all(i.map(t=>e.query(`
|
|
241
241
|
query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
|
|
242
242
|
nodes(ids: $mediaImageIds) {
|
|
243
243
|
... on MediaImage {
|
|
@@ -248,12 +248,12 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
`,{variables:{mediaImageIds:t,size:n}})))).flatMap(e=>e.nodes).flatMap(e=>e?.image?[{gid:e.id,url:e.image.url}]:[])},
|
|
251
|
+
`,{variables:{mediaImageIds:t,size:n}})))).flatMap(e=>e.nodes).flatMap(e=>e?.image?[{gid:e.id,url:e.image.url}]:[])},se=100,ce=async(e,{dealBlock:t,country:n,language:r})=>{let i=[...new Set(t.dealBars.flatMap(e=>e.dealBarType===D.MixAndMatch?e.bundleProducts:[]).flatMap(e=>(e.selectedCollections??[]).map(e=>e.id)))];if(i.length===0)return[];let a=C({country:n,language:r}),o=await e.query(`
|
|
252
252
|
query FetchMixAndMatchCollectionProductGIDs($collectionGIDs: [ID!]!) ${a} {
|
|
253
253
|
nodes(ids: $collectionGIDs) {
|
|
254
254
|
... on Collection {
|
|
255
255
|
id
|
|
256
|
-
products(first: ${
|
|
256
|
+
products(first: ${se}) {
|
|
257
257
|
nodes {
|
|
258
258
|
id
|
|
259
259
|
variants(first: 1) {
|
|
@@ -266,5 +266,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
-
`,{variables:{collectionGIDs:i}});return[...new Set(o.nodes.filter(e=>e!==null).flatMap(e=>e.products.nodes).filter(e=>!e.variants.nodes.some(e=>e.requiresComponents)).map(e=>e.id))]},
|
|
270
|
-
`));return n.data}if(`request`in this.storefront)return(await this.storefront.request(e,t)).data;if(`shopifyDomain`in this.storefront&&`storefrontAccessToken`in this.storefront){let n=await fetch(`https://${this.storefront.shopifyDomain}/api/${he}/graphql.json`,{body:JSON.stringify({query:e,variables:t?.variables}),headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}{let n=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:e,variables:t?.variables}),headers:this.storefront.getPublicTokenHeaders(),method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}}get i18n(){if(`i18n`in this.storefront)return this.storefront.i18n}},ve=ge,G=`kaching-bundles-block`,K=1e4,q=`/kaching-bundles-block.js`,ye=`https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js`,be=`https://bundles-integrations.kachingappz.app/kaching-bundles-block.js`,J=new WeakSet,xe=async e=>{let t=e.document;if(!e.customElements.get(G)){if(J.has(t))return X(e,G);J.add(t);try{await we(e)}catch(e){throw J.delete(t),e}}},Se=()=>typeof window<`u`&&window.__KACHING_DEV__!==void 0,Ce=()=>Se()?ye:be,we=async e=>{let t=e.document,n=Ce();if(t.querySelector(`script[src="${n}"]`))return X(e,G);let r=Te(t);if(r&&await De(t,r))return X(e,G);let i=t.createElement(`script`);return i.src=n,await Y(t,i),X(e,G)},Te=e=>{let t=e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);return Array.from(t,e=>e.href).find(Ee)},Ee=e=>{try{return new URL(e).pathname.endsWith(q)}catch{return!1}},De=async(e,t)=>{let n=e.createElement(`script`);n.type=`module`,n.setAttribute(`crossorigin`,`anonymous`),n.src=t;try{return await Y(e,n),!0}catch{return n.remove(),!1}},Y=(e,t)=>new Promise((n,r)=>{t.onload=()=>n(),t.onerror=()=>r(Error(`Failed to load script`)),e.head.appendChild(t)}),X=(e,t)=>new Promise((n,r)=>{e.customElements.get(t)?n():Promise.race([e.customElements.whenDefined(t),new Promise((e,n)=>setTimeout(()=>n(Error(`Custom element "${t}" failed to register within ${K}ms`)),K))]).then(()=>n()).catch(r)});[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var Z=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),Q=`a-f\\d`,Oe=`#?[${Q}]{3}[${Q}]?`,ke=`#?[${Q}]{6}([${Q}]{2})?`,Ae=RegExp(`[^#${Q}]`,`gi`),$=RegExp(`^${Oe}$|^${ke}$`,`i`);function je(e,t={}){if(typeof e!=`string`||Ae.test(e)||!$.test(e))throw TypeError(`Expected a valid hex string`);e=e.replace(/^#/,``);let n=1;e.length===8&&(n=Number.parseInt(e.slice(6,8),16)/255,e=e.slice(0,6)),e.length===4&&(n=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]);let r=Number.parseInt(e,16),i=r>>16,a=r>>8&255,o=r&255,s=typeof t.alpha==`number`?t.alpha:n;return t.format===`array`?[i,a,o,s]:t.format===`css`?`rgb(${i} ${a} ${o}${s===1?``:` / ${Number((s*100).toFixed(2))}%`})`:{red:i,green:a,blue:o,alpha:s}}var Me=({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}),Ne=()=>({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:{}}),Pe=({color:e,cornerRadius:t})=>{let n={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:Z.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:Z.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&&(n.colors.border={...je(e),alpha:1}),n},Fe=({data:n,selectedVariantId:r,preview:i,onLinesChange:a,targetWindow:o})=>{let s=(0,e.useRef)(null),[c,l]=(0,e.useState)(!1),u=(0,e.useRef)(!1);(0,e.useEffect)(()=>{s.current&&!c&&(async()=>{await xe(o??window),l(!0)})()},[c,o]),(0,e.useEffect)(()=>{let e=s.current;if(!c||!e)return;let t=()=>{let t=e.items().map(e=>({merchandiseId:`gid://shopify/ProductVariant/${e.id}`,quantity:e.quantity,attributes:Object.entries(e.properties).map(([e,t])=>({key:e,value:String(t)})),sellingPlanId:e.selling_plan?`gid://shopify/SellingPlan/${e.selling_plan}`:void 0}));a?.(t)};return u.current||=(typeof e.items==`function`?t():e.addEventListener(`kaching-bundles-block-loaded`,t),!0),e.addEventListener(`variants-changed`,t),()=>{e.removeEventListener(`kaching-bundles-block-loaded`,t),e.removeEventListener(`variants-changed`,t)}},[c,a]);let d=n?Le(n,r):i?Re(i):null;return Ie(()=>{let e=s.current;if(e&&d)for(let[t,n]of Object.entries(d.jsonAttributes))e.getAttribute(t)!==n&&e.setAttribute(t,n)}),d?(0,t.jsx)(`kaching-bundles-block`,{ref:s,"deal-block-id":d.dealBlockId,...d.jsonAttributes,"current-variant-id":d.currentVariantId}):null},Ie=typeof window>`u`?e.useEffect:e.useLayoutEffect,Le=({config:e,dealBlock:t,product:n,otherProducts:r,mediaImages:i,collectionBreaksProducts:a,translations:o},s)=>({dealBlockId:t.id,currentVariantId:s?s.split(`/`).pop():String(n.variants[0].id),jsonAttributes:{config:JSON.stringify(e),"deal-block":JSON.stringify(t),"media-images":JSON.stringify(i),product:JSON.stringify(n),"other-products":JSON.stringify(r),"collection-breaks-products":JSON.stringify(a),translations:JSON.stringify(o)}}),Re=({cornerRadius:e,color:t,price:n})=>{let r=Me({price:n}),i=Ne(),a=Pe({color:t,cornerRadius:e});return{dealBlockId:a.id,currentVariantId:String(r.variants[0].id),jsonAttributes:{config:JSON.stringify(i),"deal-block":JSON.stringify(a),"media-images":JSON.stringify([]),product:JSON.stringify(r),"other-products":JSON.stringify([]),"collection-breaks-products":JSON.stringify([]),translations:JSON.stringify({})}}};exports.KachingBundle=Fe,exports.fetchKachingBundlesData=ve;
|
|
269
|
+
`,{variables:{collectionGIDs:i}});return[...new Set(o.nodes.filter(e=>e!==null).flatMap(e=>e.products.nodes).filter(e=>!e.variants.nodes.some(e=>e.requiresComponents)).map(e=>e.id))]},le=e=>[...ue(e),...de(e),...P(e),...F(e),...I(e),...L(e),...R(e),...z(e),...B(e),...V(e),...H(e),...fe(e),...pe(e)].filter(e=>e!=null&&!e.includes(`placeholder`)),ue=e=>e.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),de=e=>e.dealBars.flatMap(e=>e.dealBarType===D.Bundle?e.bundleProducts.map(e=>e.mediaImageGID):[]).filter(e=>e!=null),P=e=>e.dealBars.map(({freeGifts:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),F=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(e=>e.mediaImageGID)).filter(e=>e!=null),I=e=>e.dealBars.map(({upsells:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),L=e=>e.swatchOptions?e.swatchOptions.reduce((e,t)=>{let n=t.images.map(e=>e.mediaImageGID).filter(e=>e!=null);return[...e,...n]},[]):[],R=e=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];let t=e.collectionBreaks.mediaImageGID;return t?[t]:[]},z=e=>e.progressiveGifts?[...e.progressiveGifts.gifts?.map(e=>e.mediaImageGID)||[],e.progressiveGifts.style?.lockedMediaImageGID,e.progressiveGifts.dealBarStyle?.lockedMediaImageGID].filter(e=>e!=null):[],B=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),V=e=>e.dealBars.map(e=>e.productPersonalisation?.mediaImageGID).filter(e=>e!=null),H=e=>{let t=e.dealBars.map(e=>e.highlights?.customIconGID).filter(e=>e!=null),n=e.subscriptions?.highlights?.customIconGID;return n?[...t,n]:t},fe=e=>(e.badges||[]).flatMap(e=>e.badgeType===`custom`&&e.imageGID?[e.imageGID]:[]),pe=e=>!e.savingsSummaryEnabled||!e.savingsSummary?[]:e.savingsSummary.customIconGID?[e.savingsSummary.customIconGID]:[],me=(e,{includeMixAndMatchSwapProducts:t=!0}={})=>{let n=[...he(e),...ge(e),..._e(e),...ve(e),...ye(e),...be(e,t),...xe(e),...Se(e)];return Array.from(new Set(n.filter(e=>e!=null)))},he=e=>e.dealBars.flatMap(({freeGifts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),ge=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(e=>e.products?e.products.map(e=>e.id):[]):[]).filter(e=>e!=null),_e=e=>e.progressiveGiftsEnabled&&e.progressiveGifts?.gifts.map(e=>e.productGID).filter(e=>e!=null)||[],ve=e=>e.dealBars.flatMap(({upsells:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),ye=e=>e.dealBars.filter(e=>e.dealBarType===D.Bundle).flatMap(({bundleProducts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),be=(e,t)=>e.dealBars.filter(e=>e.dealBarType===D.MixAndMatch).flatMap(({bundleProducts:e})=>e?e.flatMap(e=>[e.productGID,...t?e.selectedProducts?.map(e=>e.id)??[]:[]]):[]).filter(e=>e!=null).filter(e=>e!=="default"),xe=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),Se=e=>e.dealBars.filter(e=>e.dealBarType===D.Sku).flatMap(({productGID:e})=>e?[e]:[]),U=class extends Error{constructor({status:e,operationName:t,graphqlErrors:n}){let r=n.length?`: ${n.join(`; `)}`:``;super(`Storefront API ${t??`query`} failed (HTTP ${e})${r}`),this.name=`StorefrontApiError`,this.status=e,this.operationName=t,this.graphqlErrors=n}},Ce=async(e,t)=>{let n=await e.text();if(!n)throw Error(`Empty graphql response`);let r;try{r=JSON.parse(n)}catch(n){throw e.ok?n:new U({status:e.status,operationName:t,graphqlErrors:[]})}if(!e.ok||r.data===null||r.data===void 0)throw new U({status:e.status,operationName:t,graphqlErrors:(r.errors??[]).map(({message:e})=>e).filter(Boolean)});return r.data},we=class{constructor(e,t){this.storefrontApiVersion=`2026-07`,this.storefrontAccessToken=t,this.shopifyDomain=e}async query(e,t){let n=t?.variables??{},r=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`,i=e.match(/query\s+(\w+)/)?.[1];return i&&(r+=`?operation_name=${i}`),Ce(await fetch(r,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:n})}),i)}};[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var W=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),Te=async(e,t,{country:n,language:r})=>{let i=t.collectionBreaks;if(!t.collectionBreaksEnabled||!i)return;let a;a=i.visibility===`deal-products`?await O(e,{country:n,language:r,blockVisibility:t.blockVisibility,excludedProductGIDs:(t.excludedProductIds||[]).map(e=>`gid://shopify/Product/${e}`),selectedProductGIDs:(t.selectedProductIds||[]).map(e=>`gid://shopify/Product/${e}`),selectedCollectionGIDs:(t.selectedCollectionIds||[]).map(e=>`gid://shopify/Collection/${e}`)}):await O(e,{country:n,language:r,blockVisibility:i.visibility,excludedProductGIDs:(i.excludedProducts||[]).map(({id:e})=>e),selectedProductGIDs:(i.selectedProducts||[]).map(({id:e})=>e),selectedCollectionGIDs:(i.selectedCollections||[]).map(({id:e})=>e)});let o=await A(e,{country:n,language:r,productIds:a.map(e=>Number(e.split(`/`).pop())),useExternalMetafieldNamespace:!0}),s=i.visibility===`deal-products`&&t.blockVisibility===`excluded-products`;return o=o.filter(e=>e.availableForSale&&(!s||h([t],e).length>0)),o},Ee=({language:e,dealBlockId:t})=>{let n={"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.`,"system.gifts_required_alert":`Please choose your free gifts`},r=e?De(e):void 0;return{...n,...r?.system,...r?.dealBlocks[t]}},De=e=>{if(typeof document>`u`)return;let t=document.querySelector(`script#kaching-bundles-translations`);if(!t?.textContent)return;let n;try{n=JSON.parse(t.textContent)}catch{return}let r=G(e);return n.find(e=>G(e.locale)===r)?.translations},G=e=>e.toLowerCase().replace(/_/g,`-`),Oe=`2026-07`,ke=async(e,{productId:t,dealBlockId:n,abTestVariantId:r,country:i=void 0,language:a=void 0})=>{try{let o=[Number(t.split(`/`).pop())],s=new Pe(e);i||=s.i18n?.country,a||=s.i18n?.language;let l=await ie(s,{language:a,country:i,useExternalMetafieldNamespace:!0});s.shopifyDomain=l.shopifyDomain;let u=l.storefrontAccessToken?new we(l.shopifyDomain,l.storefrontAccessToken):s,[d,f]=await Promise.all([A(u,{country:i,language:a,productIds:o,useExternalMetafieldNamespace:!0}),w(u,{useExternalMetafieldNamespace:!0,useMetaobjects:l.featureFlags.storefront_metaobjects})]),p=d[0];if(!p)return null;let m=h(f,p),g=n?m.filter(e=>e.id===n||e.nanoId===n):m,_=(r?g.find(e=>e.abTestVariantId===r):void 0)??g[0]??m[0];if(!_)return null;let v=me(_,{includeMixAndMatchSwapProducts:!1}),y=Ae(u,_,{otherProductGIDs:v,country:i,language:a}),[b,x,S]=await Promise.all([A(u,{country:i,language:a,productIds:v,useExternalMetafieldNamespace:!0}),oe(u,le(_),300),Ee({language:a,dealBlockId:_.id})]);return{data:{config:l,dealBlock:_,product:p,otherProducts:c(_,b),mediaImages:x,translations:S},modalProducts:y}}catch(e){return console.error(e),null}},Ae=async(e,t,n)=>{let[r,i]=await Promise.all([je(e,t,n),Ne(e,t,n)]);return{mixAndMatchSwapProducts:r,collectionBreaksProducts:i}},je=async(e,t,{otherProductGIDs:n,country:r,language:i})=>{try{let a=[];try{a=await ce(e,{dealBlock:t,country:r,language:i})}catch(e){console.error(e)}let o=new Set(n),s=[...new Set([...Me(t),...a])].filter(e=>!o.has(e));return s.length?c(t,await A(e,{country:r,language:i,productIds:s,useExternalMetafieldNamespace:!0})):[]}catch(e){return console.error(e),[]}},Me=e=>e.dealBars.flatMap(e=>e.dealBarType===W.MixAndMatch?e.bundleProducts.flatMap(e=>(e.selectedProducts??[]).map(e=>e.id)):[]),Ne=async(e,t,{country:n,language:r})=>{try{return await Te(e,t,{country:n,language:r})??[]}catch(e){return console.error(e),[]}},Pe=class{constructor(e){this.storefront=e,this.shopifyDomain=``}async query(e,t){if(`query`in this.storefront&&`i18n`in this.storefront)return await this.storefront.query(e,t);if(`graphql`in this.storefront){let n=await this.storefront.graphql(e,t);if(n.errors?.length)throw Error(n.errors.map(e=>e.message).join(`
|
|
270
|
+
`));return n.data}if(`request`in this.storefront)return(await this.storefront.request(e,t)).data;if(`shopifyDomain`in this.storefront&&`storefrontAccessToken`in this.storefront){let n=await fetch(`https://${this.storefront.shopifyDomain}/api/${Oe}/graphql.json`,{body:JSON.stringify({query:e,variables:t?.variables}),headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}{let n=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:e,variables:t?.variables}),headers:this.storefront.getPublicTokenHeaders(),method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}}get i18n(){if(`i18n`in this.storefront)return this.storefront.i18n}},Fe=async(e,t)=>{try{let n=await ke(e,t);if(!n)return null;let{config:r,dealBlock:i,product:a,otherProducts:o,mediaImages:s,translations:c}=n.data,{mixAndMatchSwapProducts:l,collectionBreaksProducts:u}=await n.modalProducts;return{config:r,dealBlock:i,product:a,otherProducts:o,mixAndMatchSwapProducts:l,mediaImages:s,collectionBreaksProducts:u,translations:c}}catch(e){return console.error(e),null}},K=`kaching-bundles-block`,q=1e4,J=`/kaching-bundles-block.js`,Ie=`https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js`,Le=`https://bundles-integrations.kachingappz.app/kaching-bundles-block.js`,Y=new WeakSet,Re=async e=>{let t=e.document;if(!e.customElements.get(K)){if(Y.has(t))return Z(e,K);Y.add(t);try{await Ve(e)}catch(e){throw Y.delete(t),e}}},ze=()=>typeof window<`u`&&window.__KACHING_DEV__!==void 0,Be=()=>ze()?Ie:Le,Ve=async e=>{let t=e.document,n=Be();if(t.querySelector(`script[src="${n}"]`))return Z(e,K);let r=He(t);if(r&&await We(t,r))return Z(e,K);let i=t.createElement(`script`);return i.src=n,await X(t,i),Z(e,K)},He=e=>{let t=e.querySelectorAll(`link[rel="modulepreload"][href$="${J}"]`);return Array.from(t,e=>e.href).find(Ue)},Ue=e=>{try{return new URL(e).pathname.endsWith(J)}catch{return!1}},We=async(e,t)=>{let n=e.createElement(`script`);n.type=`module`,n.setAttribute(`crossorigin`,`anonymous`),n.src=t;try{return await X(e,n),!0}catch{return n.remove(),!1}},X=(e,t)=>new Promise((n,r)=>{t.onload=()=>n(),t.onerror=()=>r(Error(`Failed to load script`)),e.head.appendChild(t)}),Z=(e,t)=>new Promise((n,r)=>{e.customElements.get(t)?n():Promise.race([e.customElements.whenDefined(t),new Promise((e,n)=>setTimeout(()=>n(Error(`Custom element "${t}" failed to register within ${q}ms`)),q))]).then(()=>n()).catch(r)}),Q=`a-f\\d`,$=`#?[${Q}]{3}[${Q}]?`,Ge=`#?[${Q}]{6}([${Q}]{2})?`,Ke=RegExp(`[^#${Q}]`,`gi`),qe=RegExp(`^${$}$|^${Ge}$`,`i`);function Je(e,t={}){if(typeof e!=`string`||Ke.test(e)||!qe.test(e))throw TypeError(`Expected a valid hex string`);e=e.replace(/^#/,``);let n=1;e.length===8&&(n=Number.parseInt(e.slice(6,8),16)/255,e=e.slice(0,6)),e.length===4&&(n=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]);let r=Number.parseInt(e,16),i=r>>16,a=r>>8&255,o=r&255,s=typeof t.alpha==`number`?t.alpha:n;return t.format===`array`?[i,a,o,s]:t.format===`css`?`rgb(${i} ${a} ${o}${s===1?``:` / ${Number((s*100).toFixed(2))}%`})`:{red:i,green:a,blue:o,alpha:s}}var Ye=({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}),Xe=()=>({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:{}}),Ze=({color:e,cornerRadius:t})=>{let n={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:W.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:W.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&&(n.colors.border={...Je(e),alpha:1}),n},Qe=({data:n,selectedVariantId:r,preview:i,onLinesChange:a,targetWindow:o})=>{let s=(0,e.useRef)(null),[c,l]=(0,e.useState)(!1),u=(0,e.useRef)(!1);(0,e.useEffect)(()=>{s.current&&!c&&(async()=>{await Re(o??window),l(!0)})()},[c,o]),(0,e.useEffect)(()=>{let e=s.current;if(!c||!e)return;let t=()=>{let t=e.items().map(e=>({merchandiseId:`gid://shopify/ProductVariant/${e.id}`,quantity:e.quantity,attributes:Object.entries(e.properties).map(([e,t])=>({key:e,value:String(t)})),sellingPlanId:e.selling_plan?`gid://shopify/SellingPlan/${e.selling_plan}`:void 0}));a?.(t)};return u.current||=(typeof e.items==`function`?t():e.addEventListener(`kaching-bundles-block-loaded`,t),!0),e.addEventListener(`variants-changed`,t),()=>{e.removeEventListener(`kaching-bundles-block-loaded`,t),e.removeEventListener(`variants-changed`,t)}},[c,a]);let d=n?et(n,r):i?tt(i):null;return $e(()=>{let e=s.current;if(e&&d)for(let[t,n]of Object.entries(d.jsonAttributes))e.getAttribute(t)!==n&&e.setAttribute(t,n)}),d?(0,t.jsx)(`kaching-bundles-block`,{ref:s,"deal-block-id":d.dealBlockId,...d.jsonAttributes,"current-variant-id":d.currentVariantId}):null},$e=typeof window>`u`?e.useEffect:e.useLayoutEffect,et=({config:e,dealBlock:t,product:n,otherProducts:r,mixAndMatchSwapProducts:i,mediaImages:a,collectionBreaksProducts:o,translations:s},c)=>({dealBlockId:t.id,currentVariantId:c?c.split(`/`).pop():String(n.variants[0].id),jsonAttributes:{config:JSON.stringify(e),"deal-block":JSON.stringify(t),"media-images":JSON.stringify(a),product:JSON.stringify(n),"other-products":JSON.stringify(r),"mix-and-match-swap-products":JSON.stringify(i??[]),"collection-breaks-products":JSON.stringify(o),translations:JSON.stringify(s)}}),tt=({cornerRadius:e,color:t,price:n})=>{let r=Ye({price:n}),i=Xe(),a=Ze({color:t,cornerRadius:e});return{dealBlockId:a.id,currentVariantId:String(r.variants[0].id),jsonAttributes:{config:JSON.stringify(i),"deal-block":JSON.stringify(a),"media-images":JSON.stringify([]),product:JSON.stringify(r),"other-products":JSON.stringify([]),"mix-and-match-swap-products":JSON.stringify([]),"collection-breaks-products":JSON.stringify([]),translations:JSON.stringify({})}}};exports.KachingBundle=Qe,exports.fetchKachingBundlesData=Fe;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -323,6 +323,10 @@ declare type DealBlock = {
|
|
|
323
323
|
cornerRadius: number;
|
|
324
324
|
spacing?: number;
|
|
325
325
|
selectedProductIds: number[];
|
|
326
|
+
selectedVariants?: {
|
|
327
|
+
productId: number;
|
|
328
|
+
variantIds: number[];
|
|
329
|
+
}[];
|
|
326
330
|
selectedCollectionIds: number[];
|
|
327
331
|
excludedProductIds: number[];
|
|
328
332
|
excludedCollectionIds?: number[];
|
|
@@ -417,13 +421,7 @@ declare type DiscountType = "default" | "percentage" | "amount" | "specific";
|
|
|
417
421
|
|
|
418
422
|
export declare const fetchKachingBundlesData: (...args: Parameters<typeof fetchKachingBundlesData_2>) => Promise<KachingBundlesData | null>;
|
|
419
423
|
|
|
420
|
-
declare const fetchKachingBundlesData_2: (storefront:
|
|
421
|
-
productId: string;
|
|
422
|
-
dealBlockId?: string;
|
|
423
|
-
abTestVariantId?: string;
|
|
424
|
-
country?: string;
|
|
425
|
-
language?: string;
|
|
426
|
-
}) => Promise<KachingBundlesData_2 | null>;
|
|
424
|
+
declare const fetchKachingBundlesData_2: (storefront: KachingBundlesStorefront, options: KachingBundlesDataOptions) => Promise<KachingBundlesData_2 | null>;
|
|
427
425
|
|
|
428
426
|
declare type Font = {
|
|
429
427
|
size: string | number;
|
|
@@ -594,6 +592,7 @@ declare interface GlobalConfig {
|
|
|
594
592
|
"system.deal_page_remove_subscription_only_items"?: string;
|
|
595
593
|
"system.deal_page_items_range"?: string;
|
|
596
594
|
"system.deal_page_tip_box_size"?: string;
|
|
595
|
+
"system.deal_page_tip_price_per_item"?: string;
|
|
597
596
|
"system.deal_page_about_this_price"?: string;
|
|
598
597
|
"system.deal_page_rating"?: string;
|
|
599
598
|
"system.deal_page_rating_count_one"?: string;
|
|
@@ -666,7 +665,6 @@ declare interface GlobalConfig {
|
|
|
666
665
|
low_priority_scripts?: boolean;
|
|
667
666
|
native_swatches_disabled?: boolean;
|
|
668
667
|
observe_external_selling_plan?: boolean;
|
|
669
|
-
observe_form_selling_plan?: boolean;
|
|
670
668
|
percentage_cents_rounding_workaround?: boolean;
|
|
671
669
|
preserve_variant_selections?: boolean;
|
|
672
670
|
price_rounding_v2?: boolean;
|
|
@@ -674,6 +672,7 @@ declare interface GlobalConfig {
|
|
|
674
672
|
propagate_picker_option_changes?: boolean;
|
|
675
673
|
remove_variant_change_delay?: boolean;
|
|
676
674
|
rever_non_returnable?: boolean;
|
|
675
|
+
selected_variants?: boolean;
|
|
677
676
|
show_single_variant_name?: boolean;
|
|
678
677
|
split_bxgy_items?: boolean;
|
|
679
678
|
split_quantity_break_items?: boolean;
|
|
@@ -681,7 +680,6 @@ declare interface GlobalConfig {
|
|
|
681
680
|
pos_extension?: boolean;
|
|
682
681
|
variant_gallery_switch?: boolean;
|
|
683
682
|
variant_images?: boolean;
|
|
684
|
-
widget_scroll_guard?: boolean;
|
|
685
683
|
};
|
|
686
684
|
shopCustomStyles: string;
|
|
687
685
|
shopDealPageCustomStyles?: string;
|
|
@@ -752,6 +750,7 @@ declare interface KachingBundlesData_2 {
|
|
|
752
750
|
dealBlock: DealBlock;
|
|
753
751
|
product: Product;
|
|
754
752
|
otherProducts: Product[];
|
|
753
|
+
mixAndMatchSwapProducts: Product[];
|
|
755
754
|
mediaImages: {
|
|
756
755
|
gid: string;
|
|
757
756
|
url: string;
|
|
@@ -762,6 +761,16 @@ declare interface KachingBundlesData_2 {
|
|
|
762
761
|
};
|
|
763
762
|
}
|
|
764
763
|
|
|
764
|
+
declare interface KachingBundlesDataOptions {
|
|
765
|
+
productId: string;
|
|
766
|
+
dealBlockId?: string;
|
|
767
|
+
abTestVariantId?: string;
|
|
768
|
+
country?: string;
|
|
769
|
+
language?: string;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
declare type KachingBundlesStorefront = HydrogenV2Storefront | HydrogenStorefrontClient | ReactHydrogenStorefront | ShopifyStorefrontApiClient | StorefrontCredentials;
|
|
773
|
+
|
|
765
774
|
declare type LowStockAlert = {
|
|
766
775
|
threshold: number;
|
|
767
776
|
message: string;
|