@kachingappz/bundles-js 1.1.7 → 1.1.8
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 +1 -1
- package/dist/index.js +25 -25
- package/dist/kaching-bundle-component/index.js +10 -10
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +16 -16
- package/package.json +1 -1
package/dist/bundles-js.iife.js
CHANGED
|
@@ -234,5 +234,5 @@ var BundlesJs=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Mo
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
`,{variables:{mediaImageIds:t,size:n}})))).flatMap(e=>e.nodes).flatMap(e=>e?.image?[{gid:e.id,url:e.image.url}]:[])},T=e=>[...E(e),...D(e),...O(e),...k(e),...A(e),...ee(e),...te(e),...ne(e),...re(e),...ie(e),...ae(e),...oe(e)
|
|
237
|
+
`,{variables:{mediaImageIds:t,size:n}})))).flatMap(e=>e.nodes).flatMap(e=>e?.image?[{gid:e.id,url:e.image.url}]:[])},T=e=>[...E(e),...D(e),...O(e),...k(e),...A(e),...j(e),...ee(e),...te(e),...ne(e),...re(e),...ie(e),...ae(e),...oe(e)].filter(e=>e!=null&&!e.includes(`placeholder`)),E=e=>e.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),D=e=>e.dealBars.flatMap(e=>e.dealBarType===f.Bundle?e.bundleProducts.map(e=>e.mediaImageGID):[]).filter(e=>e!=null),O=e=>e.dealBars.map(({freeGifts:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),k=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(e=>e.mediaImageGID)).filter(e=>e!=null),A=e=>e.dealBars.map(({upsells:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),j=e=>e.swatchOptions?e.swatchOptions.reduce((e,t)=>{let n=t.images.map(e=>e.mediaImageGID).filter(e=>e!=null);return[...e,...n]},[]):[],ee=e=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];let t=e.collectionBreaks.mediaImageGID;return t?[t]:[]},te=e=>e.progressiveGifts?[...e.progressiveGifts.gifts?.map(e=>e.mediaImageGID)||[],e.progressiveGifts.style?.lockedMediaImageGID,e.progressiveGifts.dealBarStyle?.lockedMediaImageGID].filter(e=>e!=null):[],ne=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),re=e=>e.dealBars.map(e=>e.productPersonalisation?.mediaImageGID).filter(e=>e!=null),ie=e=>{let t=e.dealBars.map(e=>e.highlights?.customIconGID).filter(e=>e!=null),n=e.subscriptions?.highlights?.customIconGID;return n?[...t,n]:t},ae=e=>(e.badges||[]).flatMap(e=>e.badgeType===`custom`&&e.imageGID?[e.imageGID]:[]),oe=e=>!e.savingsSummaryEnabled||!e.savingsSummary?[]:e.savingsSummary.customIconGID?[e.savingsSummary.customIconGID]:[],se=e=>{let t=[...ce(e),...le(e),...ue(e),...de(e),...M(e),...N(e),...P(e),...F(e)];return Array.from(new Set(t.filter(e=>e!=null)))},ce=e=>e.dealBars.flatMap(({freeGifts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),le=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(e=>e.products?e.products.map(e=>e.id):[]):[]).filter(e=>e!=null),ue=e=>e.progressiveGiftsEnabled&&e.progressiveGifts?.gifts.map(e=>e.productGID).filter(e=>e!=null)||[],de=e=>e.dealBars.flatMap(({upsells:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),M=e=>e.dealBars.filter(e=>e.dealBarType===f.Bundle).flatMap(({bundleProducts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),N=e=>e.dealBars.filter(e=>e.dealBarType===f.MixAndMatch).flatMap(({bundleProducts:e})=>e?e.flatMap(e=>[e.productGID,...e.selectedProducts?.map(e=>e.id)??[]]):[]).filter(e=>e!=null).filter(e=>e!=="default"),P=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),F=e=>e.dealBars.filter(e=>e.dealBarType===f.Sku).flatMap(({productGID:e})=>e?[e]:[]),I=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}},L=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 I({status:e.status,operationName:t,graphqlErrors:[]})}if(!e.ok||r.data===null||r.data===void 0)throw new I({status:e.status,operationName:t,graphqlErrors:(r.errors??[]).map(({message:e})=>e).filter(Boolean)});return r.data},R=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}`),L(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)}},z=(e,t)=>{let n=[],r=e.filter(e=>e.blockVisibility===`selected-products`);for(let e of r)e.selectedProductIds.map(Number).includes(t.id)&&n.push(e);let i=e.filter(e=>e.blockVisibility===`selected-collections`);for(let e of i)t.collectionIds.some(t=>e.selectedCollectionIds.map(Number).includes(t))&&n.push(e);let a=e.filter(e=>e.blockVisibility===`excluded-products`);for(let e of a)!e.excludedProductIds.map(Number).includes(t.id)&&!(e.excludedCollectionIds||[]).some(e=>t.collectionIds.includes(e))&&n.push(e);let o=e.filter(e=>e.blockVisibility===`all-products`);for(let e of o)n.push(e);return n},B=async(e,t,{country:n,language:r})=>{let i=t.collectionBreaks;if(!t.collectionBreaksEnabled||!i)return;let a;a=i.visibility===`deal-products`?await p(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 p(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 h(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||z([t],e).length>0)),o},V=({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?H(e):void 0;return{...n,...r?.system,...r?.dealBlocks[t]}},H=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=U(e);return n.find(e=>U(e.locale)===r)?.translations},U=e=>e.toLowerCase().replace(/_/g,`-`),fe=`2026-07`,W=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 c=await S(s,{language:a,country:i,useExternalMetafieldNamespace:!0});s.shopifyDomain=c.shopifyDomain;let u=c.storefrontAccessToken?new R(c.shopifyDomain,c.storefrontAccessToken):s,[d,f]=await Promise.all([h(u,{country:i,language:a,productIds:o,useExternalMetafieldNamespace:!0}),l(u,{useExternalMetafieldNamespace:!0,useMetaobjects:c.featureFlags.storefront_metaobjects})]),p=d[0];if(!p)return null;let m=z(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=T(_),y=se(_),[b,x,C,E]=await Promise.all([h(u,{country:i,language:a,productIds:y,useExternalMetafieldNamespace:!0}),w(u,v,300),B(u,_,{country:i,language:a}),V({language:a,dealBlockId:_.id})]);return{product:p,dealBlock:_,config:c,otherProducts:b,mediaImages:x,collectionBreaksProducts:C??[],translations:E}}catch(e){return console.error(e),null}},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(`
|
|
238
238
|
`));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/${fe}/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}},G=`kaching-bundles-block`,K=1e4,q=`/kaching-bundles-block.js`,me=`https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js`,he=`https://bundles-integrations.kachingappz.app/kaching-bundles-block.js`,J=new WeakSet,Y=async e=>{let t=e.document;if(!e.customElements.get(G)){if(J.has(t))return Q(e,G);J.add(t);try{await _e(e)}catch(e){throw J.delete(t),e}}},ge=()=>typeof window<`u`&&window.__KACHING_DEV__!==void 0,X=()=>ge()?me:he,_e=async e=>{let t=e.document,n=X();if(t.querySelector(`script[src="${n}"]`))return Q(e,G);let r=ve(t);if(r&&await be(t,r))return Q(e,G);let i=t.createElement(`script`);return i.src=n,await Z(t,i),Q(e,G)},ve=e=>{let t=e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);return Array.from(t,e=>e.href).find(ye)},ye=e=>{try{return new URL(e).pathname.endsWith(q)}catch{return!1}},be=async(e,t)=>{let n=e.createElement(`script`);n.type=`module`,n.setAttribute(`crossorigin`,`anonymous`),n.src=t;try{return await Z(e,n),!0}catch{return n.remove(),!1}},Z=(e,t)=>new Promise((n,r)=>{t.onload=()=>n(),t.onerror=()=>r(Error(`Failed to load script`)),e.head.appendChild(t)}),Q=(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 $=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),xe={config:{shopifyDomain:``,moneyFormat:"${{amount}}",locale:`en`,country:`US`,currencyRate:1,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:!0,previewAlerts:!1,previewScratchOff:!1,defaultTranslations:{"system.out_of_stock":`There's not enough items in our stock, please select smaller bundle.`,"system.invalid_variant":`Sorry, this is not currently available.`,"system.unavailable_option_value":`Unavailable`,"system.confirm":`Confirm`,"system.cancel":`Cancel`,"system.free":`FREE`,"system.search":`Search`,"system.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:null,addToCartButton:null,variantPicker:null,price:null,priceCompare:null},featureFlags:{},shopCustomStyles:``},dealBlock:{id:`example`,nanoId:`example`,blockName:`Bundle`,discountName:``,blockTitle:`BUNDLE & SAVE`,blockLayout:`vertical`,blockVisibility:`all-products`,marketId:null,currency:null,excludeB2bCustomers:!1,excludePos:!1,startTimestamp:0,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!0,disableVariantOptionSync:!1,hideUnavailableOptions:!1,showPricesPerItem:!1,showBothPrices:!1,unitLabel:``,useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:`.00`,updateNativePrice:!1,updateNativePriceType:`item`,skipCart:!1,showVariantsForSingleQuantity:!1,preselectedDealBarId:`duo`,cornerRadius:16,spacing:1,selectedProductIds:[],selectedCollectionIds:[],excludedProductIds:[],excludedCollectionIds:[],colors:{background:{red:245,green:245,blue:245,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:171,green:239,blue:198,alpha:1},label:{red:0,green:0,blue:0,alpha:1},badgeBackground:{red:0,green:0,blue:0,alpha:1},badgeText:{red:255,green:255,blue:255,alpha:1},freeGiftBackground:{red:0,green:0,blue:0,alpha:.3},freeGiftText:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedBackground:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedText:{red:255,green:255,blue:255,alpha:1},upsellBackground:{red:0,green:0,blue:0,alpha:.2},upsellText:{red:0,green:0,blue:0,alpha:1},upsellSelectedBackground:{red:0,green:0,blue:0,alpha:.2},upsellSelectedText:{red:0,green:0,blue:0,alpha:1}},fonts:{blockTitle:{size:`14`,style:`bold`},title:{size:`20`,style:`bold`},subtitle:{size:`14`,style:`regular`},label:{size:`12`,style:`bold`},freeGift:{size:`13`,style:`bold`},upsell:{size:`13`,style:`bold`},unitLabel:{size:`14`,style:`regular`}},dealBars:[{id:`single`,dealBarType:$.QuantityBreak,quantitySelector:!1,title:`Single`,subtitle:`Standard price`,label:``,quantity:1,discountType:`default`,discountValue:``,badgeStyle:`simple`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null,subscriptionMode:`customer-choice`},{id:`duo`,dealBarType:$.QuantityBreak,quantitySelector:!1,title:`Duo`,subtitle:`You save 20%`,label:`SAVE $32`,quantity:2,discountType:`percentage`,discountValue:`20`,badgeStyle:`most-popular`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null,subscriptionMode:`customer-choice`},{id:`trio`,dealBarType:$.QuantityBreak,quantitySelector:!1,title:`Trio`,subtitle:`You save 25%`,label:`SAVE $60`,quantity:3,discountType:`percentage`,discountValue:`25`,badgeStyle:`simple`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null,subscriptionMode:`customer-choice`}],badgesEnabled:!0,badges:[{id:`bdg1`,attachedTo:{type:`dealBar`,dealBarId:`duo`},text:`MOST POPULAR`,colors:null,badgeType:`most-popular`,size:90}],swatchOptions:[],swatchSize:18,swatchShape:`circle`,imageSize:48,imageCornerRadius:6,defaultVariantsV2:[],collectionBreaksEnabled:!1,collectionBreaks:null,chooseProductModal:null,timerEnabled:!1,timer:null,subscriptionsEnabled:!1,subscriptions:null,stickyAtcEnabled:!1,stickyAtc:null,progressiveGiftsEnabled:!1,progressiveGifts:null,checkboxUpsellsEnabled:!1,checkboxUpsells:null,customStylesEnabled:!1,shopCustomStyles:``,customStyles:``,lowStockAlertEnabled:!1,lowStockAlert:null},product:{id:1,handle:`example-product`,url:null,availableForSale:!0,title:`Example product`,image:null,collectionIds:[],options:[],selectedVariantId:1,variants:[{id:1,availableForSale:!0,price:8e3,compareAtPrice:null,options:[`Default Title`],imageId:null,image:null,unitPriceMeasurement:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50}],metafields:{text:null,text2:null,text3:null,text4:null},requiresSellingPlan:!1,sellingPlans:[],isNativeBundle:!1},otherProducts:[],mediaImages:[],collectionBreaksProducts:[],translations:{}},Se=class extends HTMLElement{constructor(...e){super(...e),this.innerElement=null,this.handleItemsChanged=null,this.initializeId=0}static get observedAttributes(){return[`selected-variant-id`,`product-id`,`country`,`language`]}async connectedCallback(){await this.initialize()}async initialize(){let e=++this.initializeId;if(this.cleanup(),this.hasAttribute(`demo`)){if(await Y(window),e!==this.initializeId)return;this.renderInnerElement(xe);return}let t=this.getAttribute(`shop-domain`),n=this.getAttribute(`storefront-token`),r=this.getAttribute(`product-id`);if(!t||!n||!r)return;let[i]=await Promise.all([W({shopifyDomain:t,storefrontAccessToken:n},{productId:r,dealBlockId:this.getAttribute(`deal-block-id`)??void 0,abTestVariantId:this.getAttribute(`ab-test-variant-id`)??void 0,country:this.getAttribute(`country`)?.toUpperCase()??void 0,language:this.getAttribute(`language`)?.toUpperCase()??void 0}),Y(window)]);i&&e===this.initializeId&&this.renderInnerElement(i)}renderInnerElement(e){let{config:t,dealBlock:n,product:r,otherProducts:i,mediaImages:a,collectionBreaksProducts:o,translations:s}=e;this.innerElement=document.createElement(`kaching-bundles-block`),this.innerElement.setAttribute(`deal-block-id`,n.id),this.innerElement.setAttribute(`config`,JSON.stringify(t)),this.innerElement.setAttribute(`deal-block`,JSON.stringify(n)),this.innerElement.setAttribute(`media-images`,JSON.stringify(a??[])),this.innerElement.setAttribute(`product`,JSON.stringify(r)),this.innerElement.setAttribute(`other-products`,JSON.stringify(i??[])),this.innerElement.setAttribute(`collection-breaks-products`,JSON.stringify(o??[])),this.innerElement.setAttribute(`translations`,JSON.stringify(s??{}));let c=this.getAttribute(`selected-variant-id`);this.innerElement.setAttribute(`current-variant-id`,String(c?c.split(`/`).pop():r.variants[0].id)),this.hasAttribute(`compact`)&&this.innerElement.setAttribute(`compact`,``);let l=this.innerElement,u=()=>{if(this.innerElement!==l)return;let e=l.items();e&&this.dispatchEvent(new CustomEvent(`items-changed`,{detail:{items:e},bubbles:!0}))};this.handleItemsChanged=e=>{e.stopPropagation(),u()};let d=this.handleItemsChanged;l.addEventListener(`kaching-bundles-block-loaded`,()=>{this.innerElement===l&&(l.addEventListener(`items-changed`,d),this.dispatchEvent(new CustomEvent(`loaded`,{bubbles:!0})))},{once:!0}),this.appendChild(this.innerElement)}cleanup(){this.handleItemsChanged&&this.innerElement&&(this.innerElement.removeEventListener(`items-changed`,this.handleItemsChanged),this.handleItemsChanged=null),this.innerElement&&=(this.innerElement.remove(),null)}attributeChangedCallback(e,t,n){t!==n&&this.isConnected&&(e===`product-id`||e===`country`||e===`language`?this.initialize():e===`selected-variant-id`&&this.innerElement&&n&&this.innerElement.setAttribute(`current-variant-id`,n.includes(`/`)?String(n.split(`/`).pop()):n))}items(){return this.innerElement?this.innerElement.items():[]}disconnectedCallback(){this.cleanup(),this.initializeId++}};return customElements.define(`kaching-bundle-component`,Se),e.fetchKachingBundlesData=W,e})({});
|
package/dist/index.js
CHANGED
|
@@ -498,12 +498,12 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
498
498
|
...k(e),
|
|
499
499
|
...A(e),
|
|
500
500
|
...j(e),
|
|
501
|
-
...ee(e),
|
|
502
501
|
...M(e),
|
|
503
502
|
...N(e),
|
|
504
503
|
...P(e),
|
|
505
504
|
...F(e),
|
|
506
|
-
...I(e)
|
|
505
|
+
...I(e),
|
|
506
|
+
...L(e)
|
|
507
507
|
].filter((e) => e != null && !e.includes("placeholder")), T = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), E = (e) => e.dealBars.flatMap((e) => e.dealBarType === d.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), D = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), O = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), k = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), A = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
|
|
508
508
|
let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
|
|
509
509
|
return [...e, ...n];
|
|
@@ -511,56 +511,56 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
511
511
|
if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
|
|
512
512
|
let t = e.collectionBreaks.mediaImageGID;
|
|
513
513
|
return t ? [t] : [];
|
|
514
|
-
},
|
|
514
|
+
}, M = (e) => e.progressiveGifts ? [
|
|
515
515
|
...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
|
|
516
516
|
e.progressiveGifts.style?.lockedMediaImageGID,
|
|
517
517
|
e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
|
|
518
|
-
].filter((e) => e != null) : [],
|
|
518
|
+
].filter((e) => e != null) : [], N = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), P = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), F = (e) => {
|
|
519
519
|
let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
|
|
520
520
|
return n ? [...t, n] : t;
|
|
521
|
-
},
|
|
521
|
+
}, I = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), L = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], R = (e) => {
|
|
522
522
|
let t = [
|
|
523
|
-
...R(e),
|
|
524
523
|
...z(e),
|
|
525
524
|
...B(e),
|
|
526
525
|
...V(e),
|
|
527
526
|
...H(e),
|
|
528
527
|
...U(e),
|
|
529
528
|
...W(e),
|
|
530
|
-
...G(e)
|
|
529
|
+
...G(e),
|
|
530
|
+
...K(e)
|
|
531
531
|
];
|
|
532
532
|
return Array.from(new Set(t.filter((e) => e != null)));
|
|
533
|
-
},
|
|
533
|
+
}, z = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), B = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), V = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], H = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), U = (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"), W = (e) => e.dealBars.filter((e) => e.dealBarType === d.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...e.selectedProducts?.map((e) => e.id) ?? []]) : []).filter((e) => e != null).filter((e) => e !== "default"), G = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), K = (e) => e.dealBars.filter((e) => e.dealBarType === d.Sku).flatMap(({ productGID: e }) => e ? [e] : []), q = class extends Error {
|
|
534
534
|
constructor({ status: e, operationName: t, graphqlErrors: n }) {
|
|
535
535
|
let r = n.length ? `: ${n.join("; ")}` : "";
|
|
536
536
|
super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
|
|
537
537
|
}
|
|
538
|
-
},
|
|
538
|
+
}, J = async (e, t) => {
|
|
539
539
|
let n = await e.text();
|
|
540
540
|
if (!n) throw Error("Empty graphql response");
|
|
541
541
|
let r;
|
|
542
542
|
try {
|
|
543
543
|
r = JSON.parse(n);
|
|
544
544
|
} catch (n) {
|
|
545
|
-
throw e.ok ? n : new
|
|
545
|
+
throw e.ok ? n : new q({
|
|
546
546
|
status: e.status,
|
|
547
547
|
operationName: t,
|
|
548
548
|
graphqlErrors: []
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
|
-
if (!e.ok || r.data === null || r.data === void 0) throw new
|
|
551
|
+
if (!e.ok || r.data === null || r.data === void 0) throw new q({
|
|
552
552
|
status: e.status,
|
|
553
553
|
operationName: t,
|
|
554
554
|
graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
|
|
555
555
|
});
|
|
556
556
|
return r.data;
|
|
557
|
-
},
|
|
557
|
+
}, Y = class {
|
|
558
558
|
constructor(e, t) {
|
|
559
559
|
this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
|
|
560
560
|
}
|
|
561
561
|
async query(e, t) {
|
|
562
562
|
let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
|
|
563
|
-
return i && (r += `?operation_name=${i}`),
|
|
563
|
+
return i && (r += `?operation_name=${i}`), J(await fetch(r, {
|
|
564
564
|
method: "POST",
|
|
565
565
|
headers: {
|
|
566
566
|
"Content-Type": "application/json",
|
|
@@ -572,7 +572,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
572
572
|
})
|
|
573
573
|
}), i);
|
|
574
574
|
}
|
|
575
|
-
},
|
|
575
|
+
}, X = (e, t) => {
|
|
576
576
|
let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
|
|
577
577
|
for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
|
|
578
578
|
let i = e.filter((e) => e.blockVisibility === "selected-collections");
|
|
@@ -582,7 +582,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
582
582
|
let o = e.filter((e) => e.blockVisibility === "all-products");
|
|
583
583
|
for (let e of o) n.push(e);
|
|
584
584
|
return n;
|
|
585
|
-
},
|
|
585
|
+
}, Z = async (e, t, { country: n, language: r }) => {
|
|
586
586
|
let i = t.collectionBreaks;
|
|
587
587
|
if (!t.collectionBreaksEnabled || !i) return;
|
|
588
588
|
let a;
|
|
@@ -606,9 +606,9 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
606
606
|
language: r,
|
|
607
607
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
608
608
|
useExternalMetafieldNamespace: !0
|
|
609
|
-
});
|
|
610
|
-
return o = o.filter((e) => e.availableForSale), o;
|
|
611
|
-
},
|
|
609
|
+
}), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
|
|
610
|
+
return o = o.filter((e) => e.availableForSale && (!s || X([t], e).length > 0)), o;
|
|
611
|
+
}, Q = ({ language: e, dealBlockId: t }) => {
|
|
612
612
|
let n = {
|
|
613
613
|
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
614
614
|
"system.invalid_variant": "Sorry, this is not currently available.",
|
|
@@ -635,13 +635,13 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
635
635
|
"system.numbers_only": "Only numbers are allowed.",
|
|
636
636
|
"system.personalisation_required_alert": "Please add personalisation for every item to continue.",
|
|
637
637
|
"system.gifts_required_alert": "Please choose your free gifts"
|
|
638
|
-
}, r = e ?
|
|
638
|
+
}, r = e ? ee(e) : void 0;
|
|
639
639
|
return {
|
|
640
640
|
...n,
|
|
641
641
|
...r?.system,
|
|
642
642
|
...r?.dealBlocks[t]
|
|
643
643
|
};
|
|
644
|
-
},
|
|
644
|
+
}, ee = (e) => {
|
|
645
645
|
if (typeof document > "u") return;
|
|
646
646
|
let t = document.querySelector("script#kaching-bundles-translations");
|
|
647
647
|
if (!t?.textContent) return;
|
|
@@ -663,7 +663,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
663
663
|
useExternalMetafieldNamespace: !0
|
|
664
664
|
});
|
|
665
665
|
s.shopifyDomain = l.shopifyDomain;
|
|
666
|
-
let u = l.storefrontAccessToken ? new
|
|
666
|
+
let u = l.storefrontAccessToken ? new Y(l.shopifyDomain, l.storefrontAccessToken) : s, [d, f] = await Promise.all([m(u, {
|
|
667
667
|
country: i,
|
|
668
668
|
language: a,
|
|
669
669
|
productIds: o,
|
|
@@ -673,9 +673,9 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
673
673
|
useMetaobjects: l.featureFlags.storefront_metaobjects
|
|
674
674
|
})]), p = d[0];
|
|
675
675
|
if (!p) return null;
|
|
676
|
-
let h =
|
|
676
|
+
let h = X(f, p), g = n ? h.filter((e) => e.id === n || e.nanoId === n) : h, _ = (r ? g.find((e) => e.abTestVariantId === r) : void 0) ?? g[0] ?? h[0];
|
|
677
677
|
if (!_) return null;
|
|
678
|
-
let v = w(_), y =
|
|
678
|
+
let v = w(_), y = R(_), [b, S, T, E] = await Promise.all([
|
|
679
679
|
m(u, {
|
|
680
680
|
country: i,
|
|
681
681
|
language: a,
|
|
@@ -683,11 +683,11 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
683
683
|
useExternalMetafieldNamespace: !0
|
|
684
684
|
}),
|
|
685
685
|
C(u, v, 300),
|
|
686
|
-
|
|
686
|
+
Z(u, _, {
|
|
687
687
|
country: i,
|
|
688
688
|
language: a
|
|
689
689
|
}),
|
|
690
|
-
|
|
690
|
+
Q({
|
|
691
691
|
language: a,
|
|
692
692
|
dealBlockId: _.id
|
|
693
693
|
})
|
|
@@ -498,12 +498,12 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
498
498
|
...k(e),
|
|
499
499
|
...A(e),
|
|
500
500
|
...j(e),
|
|
501
|
+
...M(e),
|
|
501
502
|
...ee(e),
|
|
502
503
|
...te(e),
|
|
503
504
|
...ne(e),
|
|
504
505
|
...re(e),
|
|
505
|
-
...ie(e)
|
|
506
|
-
...ae(e)
|
|
506
|
+
...ie(e)
|
|
507
507
|
].filter((e) => e != null && !e.includes("placeholder")), T = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), E = (e) => e.dealBars.flatMap((e) => e.dealBarType === d.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), D = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), O = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), k = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), A = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
|
|
508
508
|
let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
|
|
509
509
|
return [...e, ...n];
|
|
@@ -511,26 +511,26 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
511
511
|
if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
|
|
512
512
|
let t = e.collectionBreaks.mediaImageGID;
|
|
513
513
|
return t ? [t] : [];
|
|
514
|
-
},
|
|
514
|
+
}, M = (e) => e.progressiveGifts ? [
|
|
515
515
|
...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
|
|
516
516
|
e.progressiveGifts.style?.lockedMediaImageGID,
|
|
517
517
|
e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
|
|
518
|
-
].filter((e) => e != null) : [],
|
|
518
|
+
].filter((e) => e != null) : [], ee = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), te = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), ne = (e) => {
|
|
519
519
|
let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
|
|
520
520
|
return n ? [...t, n] : t;
|
|
521
|
-
},
|
|
521
|
+
}, re = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), ie = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], ae = (e) => {
|
|
522
522
|
let t = [
|
|
523
|
+
...oe(e),
|
|
523
524
|
...se(e),
|
|
524
525
|
...ce(e),
|
|
525
526
|
...le(e),
|
|
526
527
|
...ue(e),
|
|
527
|
-
...M(e),
|
|
528
528
|
...N(e),
|
|
529
529
|
...P(e),
|
|
530
530
|
...F(e)
|
|
531
531
|
];
|
|
532
532
|
return Array.from(new Set(t.filter((e) => e != null)));
|
|
533
|
-
},
|
|
533
|
+
}, oe = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), se = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), ce = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], le = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), ue = (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"), N = (e) => e.dealBars.filter((e) => e.dealBarType === d.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...e.selectedProducts?.map((e) => e.id) ?? []]) : []).filter((e) => e != null).filter((e) => e !== "default"), P = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), F = (e) => e.dealBars.filter((e) => e.dealBarType === d.Sku).flatMap(({ productGID: e }) => e ? [e] : []), I = class extends Error {
|
|
534
534
|
constructor({ status: e, operationName: t, graphqlErrors: n }) {
|
|
535
535
|
let r = n.length ? `: ${n.join("; ")}` : "";
|
|
536
536
|
super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
|
|
@@ -606,8 +606,8 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
606
606
|
language: r,
|
|
607
607
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
608
608
|
useExternalMetafieldNamespace: !0
|
|
609
|
-
});
|
|
610
|
-
return o = o.filter((e) => e.availableForSale), o;
|
|
609
|
+
}), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
|
|
610
|
+
return o = o.filter((e) => e.availableForSale && (!s || z([t], e).length > 0)), o;
|
|
611
611
|
}, V = ({ language: e, dealBlockId: t }) => {
|
|
612
612
|
let n = {
|
|
613
613
|
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
@@ -675,7 +675,7 @@ var d = /* @__PURE__ */ function(e) {
|
|
|
675
675
|
if (!p) return null;
|
|
676
676
|
let h = z(f, p), g = n ? h.filter((e) => e.id === n || e.nanoId === n) : h, _ = (r ? g.find((e) => e.abTestVariantId === r) : void 0) ?? g[0] ?? h[0];
|
|
677
677
|
if (!_) return null;
|
|
678
|
-
let v = w(_), y =
|
|
678
|
+
let v = w(_), y = ae(_), [b, S, T, E] = await Promise.all([
|
|
679
679
|
m(u, {
|
|
680
680
|
country: i,
|
|
681
681
|
language: a,
|
package/dist/react/index.cjs
CHANGED
|
@@ -234,5 +234,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
`,{variables:{mediaImageIds:t,size:n}})))).flatMap(e=>e.nodes).flatMap(e=>e?.image?[{gid:e.id,url:e.image.url}]:[])},E=e=>[...D(e),...O(e),...k(e),...A(e),...ee(e),...te(e),...ne(e),...re(e),...ie(e),...ae(e),...oe(e),...se(e)
|
|
237
|
+
`,{variables:{mediaImageIds:t,size:n}})))).flatMap(e=>e.nodes).flatMap(e=>e?.image?[{gid:e.id,url:e.image.url}]:[])},E=e=>[...D(e),...O(e),...k(e),...A(e),...j(e),...ee(e),...te(e),...ne(e),...re(e),...ie(e),...ae(e),...oe(e),...se(e)].filter(e=>e!=null&&!e.includes(`placeholder`)),D=e=>e.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),O=e=>e.dealBars.flatMap(e=>e.dealBarType===p.Bundle?e.bundleProducts.map(e=>e.mediaImageGID):[]).filter(e=>e!=null),k=e=>e.dealBars.map(({freeGifts:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),A=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(e=>e.mediaImageGID)).filter(e=>e!=null),j=e=>e.dealBars.map(({upsells:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),ee=e=>e.swatchOptions?e.swatchOptions.reduce((e,t)=>{let n=t.images.map(e=>e.mediaImageGID).filter(e=>e!=null);return[...e,...n]},[]):[],te=e=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];let t=e.collectionBreaks.mediaImageGID;return t?[t]:[]},ne=e=>e.progressiveGifts?[...e.progressiveGifts.gifts?.map(e=>e.mediaImageGID)||[],e.progressiveGifts.style?.lockedMediaImageGID,e.progressiveGifts.dealBarStyle?.lockedMediaImageGID].filter(e=>e!=null):[],re=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),ie=e=>e.dealBars.map(e=>e.productPersonalisation?.mediaImageGID).filter(e=>e!=null),ae=e=>{let t=e.dealBars.map(e=>e.highlights?.customIconGID).filter(e=>e!=null),n=e.subscriptions?.highlights?.customIconGID;return n?[...t,n]:t},oe=e=>(e.badges||[]).flatMap(e=>e.badgeType===`custom`&&e.imageGID?[e.imageGID]:[]),se=e=>!e.savingsSummaryEnabled||!e.savingsSummary?[]:e.savingsSummary.customIconGID?[e.savingsSummary.customIconGID]:[],ce=e=>{let t=[...le(e),...ue(e),...M(e),...N(e),...P(e),...F(e),...I(e),...L(e)];return Array.from(new Set(t.filter(e=>e!=null)))},le=e=>e.dealBars.flatMap(({freeGifts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),ue=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(e=>e.products?e.products.map(e=>e.id):[]):[]).filter(e=>e!=null),M=e=>e.progressiveGiftsEnabled&&e.progressiveGifts?.gifts.map(e=>e.productGID).filter(e=>e!=null)||[],N=e=>e.dealBars.flatMap(({upsells:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),P=e=>e.dealBars.filter(e=>e.dealBarType===p.Bundle).flatMap(({bundleProducts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),F=e=>e.dealBars.filter(e=>e.dealBarType===p.MixAndMatch).flatMap(({bundleProducts:e})=>e?e.flatMap(e=>[e.productGID,...e.selectedProducts?.map(e=>e.id)??[]]):[]).filter(e=>e!=null).filter(e=>e!=="default"),I=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),L=e=>e.dealBars.filter(e=>e.dealBarType===p.Sku).flatMap(({productGID:e})=>e?[e]:[]),R=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}},z=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 R({status:e.status,operationName:t,graphqlErrors:[]})}if(!e.ok||r.data===null||r.data===void 0)throw new R({status:e.status,operationName:t,graphqlErrors:(r.errors??[]).map(({message:e})=>e).filter(Boolean)});return r.data},B=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}`),z(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)}},V=(e,t)=>{let n=[],r=e.filter(e=>e.blockVisibility===`selected-products`);for(let e of r)e.selectedProductIds.map(Number).includes(t.id)&&n.push(e);let i=e.filter(e=>e.blockVisibility===`selected-collections`);for(let e of i)t.collectionIds.some(t=>e.selectedCollectionIds.map(Number).includes(t))&&n.push(e);let a=e.filter(e=>e.blockVisibility===`excluded-products`);for(let e of a)!e.excludedProductIds.map(Number).includes(t.id)&&!(e.excludedCollectionIds||[]).some(e=>t.collectionIds.includes(e))&&n.push(e);let o=e.filter(e=>e.blockVisibility===`all-products`);for(let e of o)n.push(e);return n},H=async(e,t,{country:n,language:r})=>{let i=t.collectionBreaks;if(!t.collectionBreaksEnabled||!i)return;let a;a=i.visibility===`deal-products`?await m(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 m(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 g(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||V([t],e).length>0)),o},U=({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=W(e);return n.find(e=>W(e.locale)===r)?.translations},W=e=>e.toLowerCase().replace(/_/g,`-`),fe=`2026-07`,pe=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 me(e);i||=s.i18n?.country,a||=s.i18n?.language;let c=await C(s,{language:a,country:i,useExternalMetafieldNamespace:!0});s.shopifyDomain=c.shopifyDomain;let l=c.storefrontAccessToken?new B(c.shopifyDomain,c.storefrontAccessToken):s,[d,f]=await Promise.all([g(l,{country:i,language:a,productIds:o,useExternalMetafieldNamespace:!0}),u(l,{useExternalMetafieldNamespace:!0,useMetaobjects:c.featureFlags.storefront_metaobjects})]),p=d[0];if(!p)return null;let m=V(f,p),h=n?m.filter(e=>e.id===n||e.nanoId===n):m,_=(r?h.find(e=>e.abTestVariantId===r):void 0)??h[0]??m[0];if(!_)return null;let v=E(_),y=ce(_),[b,x,S,w]=await Promise.all([g(l,{country:i,language:a,productIds:y,useExternalMetafieldNamespace:!0}),T(l,v,300),H(l,_,{country:i,language:a}),U({language:a,dealBlockId:_.id})]);return{product:p,dealBlock:_,config:c,otherProducts:b,mediaImages:x,collectionBreaksProducts:S??[],translations:w}}catch(e){return console.error(e),null}},me=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(`
|
|
238
238
|
`));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/${fe}/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}},he=pe,G=`kaching-bundles-block`,K=1e4,q=`/kaching-bundles-block.js`,ge=`https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js`,_e=`https://bundles-integrations.kachingappz.app/kaching-bundles-block.js`,J=new WeakSet,ve=async e=>{let t=e.document;if(!e.customElements.get(G)){if(J.has(t))return X(e,G);J.add(t);try{await xe(e)}catch(e){throw J.delete(t),e}}},ye=()=>typeof window<`u`&&window.__KACHING_DEV__!==void 0,be=()=>ye()?ge:_e,xe=async e=>{let t=e.document,n=be();if(t.querySelector(`script[src="${n}"]`))return X(e,G);let r=Se(t);if(r&&await we(t,r))return X(e,G);let i=t.createElement(`script`);return i.src=n,await Y(t,i),X(e,G)},Se=e=>{let t=e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);return Array.from(t,e=>e.href).find(Ce)},Ce=e=>{try{return new URL(e).pathname.endsWith(q)}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 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`,Te=`#?[${Q}]{3}[${Q}]?`,Ee=`#?[${Q}]{6}([${Q}]{2})?`,De=RegExp(`[^#${Q}]`,`gi`),Oe=RegExp(`^${Te}$|^${Ee}$`,`i`);function ke(e,t={}){if(typeof e!=`string`||De.test(e)||!Oe.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 Ae=({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}),$=()=>({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:{}}),je=({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={...ke(e),alpha:1}),n},Me=({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 ve(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?Pe(n,r):i?Fe(i):null;return Ne(()=>{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},Ne=typeof window>`u`?e.useEffect:e.useLayoutEffect,Pe=({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)}}),Fe=({cornerRadius:e,color:t,price:n})=>{let r=Ae({price:n}),i=$(),a=je({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=Me,exports.fetchKachingBundlesData=he;
|
package/dist/react/index.js
CHANGED
|
@@ -505,7 +505,7 @@ var g = /* @__PURE__ */ function(e) {
|
|
|
505
505
|
...ce(e),
|
|
506
506
|
...le(e),
|
|
507
507
|
...ue(e),
|
|
508
|
-
...
|
|
508
|
+
...de(e)
|
|
509
509
|
].filter((e) => e != null && !e.includes("placeholder")), A = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ee = (e) => e.dealBars.flatMap((e) => e.dealBarType === g.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), te = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ne = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), re = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ie = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
|
|
510
510
|
let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
|
|
511
511
|
return [...e, ...n];
|
|
@@ -520,49 +520,49 @@ var g = /* @__PURE__ */ function(e) {
|
|
|
520
520
|
].filter((e) => e != null) : [], se = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ce = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), le = (e) => {
|
|
521
521
|
let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
|
|
522
522
|
return n ? [...t, n] : t;
|
|
523
|
-
}, ue = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []),
|
|
523
|
+
}, ue = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), de = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], j = (e) => {
|
|
524
524
|
let t = [
|
|
525
|
+
...M(e),
|
|
525
526
|
...N(e),
|
|
526
527
|
...P(e),
|
|
527
528
|
...F(e),
|
|
528
529
|
...I(e),
|
|
529
530
|
...L(e),
|
|
530
531
|
...R(e),
|
|
531
|
-
...z(e)
|
|
532
|
-
...B(e)
|
|
532
|
+
...z(e)
|
|
533
533
|
];
|
|
534
534
|
return Array.from(new Set(t.filter((e) => e != null)));
|
|
535
|
-
},
|
|
535
|
+
}, M = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), N = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), P = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], F = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), I = (e) => e.dealBars.filter((e) => e.dealBarType === g.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), L = (e) => e.dealBars.filter((e) => e.dealBarType === g.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...e.selectedProducts?.map((e) => e.id) ?? []]) : []).filter((e) => e != null).filter((e) => e !== "default"), R = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), z = (e) => e.dealBars.filter((e) => e.dealBarType === g.Sku).flatMap(({ productGID: e }) => e ? [e] : []), B = class extends Error {
|
|
536
536
|
constructor({ status: e, operationName: t, graphqlErrors: n }) {
|
|
537
537
|
let r = n.length ? `: ${n.join("; ")}` : "";
|
|
538
538
|
super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
|
|
539
539
|
}
|
|
540
|
-
},
|
|
540
|
+
}, V = async (e, t) => {
|
|
541
541
|
let n = await e.text();
|
|
542
542
|
if (!n) throw Error("Empty graphql response");
|
|
543
543
|
let r;
|
|
544
544
|
try {
|
|
545
545
|
r = JSON.parse(n);
|
|
546
546
|
} catch (n) {
|
|
547
|
-
throw e.ok ? n : new
|
|
547
|
+
throw e.ok ? n : new B({
|
|
548
548
|
status: e.status,
|
|
549
549
|
operationName: t,
|
|
550
550
|
graphqlErrors: []
|
|
551
551
|
});
|
|
552
552
|
}
|
|
553
|
-
if (!e.ok || r.data === null || r.data === void 0) throw new
|
|
553
|
+
if (!e.ok || r.data === null || r.data === void 0) throw new B({
|
|
554
554
|
status: e.status,
|
|
555
555
|
operationName: t,
|
|
556
556
|
graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
|
|
557
557
|
});
|
|
558
558
|
return r.data;
|
|
559
|
-
},
|
|
559
|
+
}, H = class {
|
|
560
560
|
constructor(e, t) {
|
|
561
561
|
this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
|
|
562
562
|
}
|
|
563
563
|
async query(e, t) {
|
|
564
564
|
let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
|
|
565
|
-
return i && (r += `?operation_name=${i}`),
|
|
565
|
+
return i && (r += `?operation_name=${i}`), V(await fetch(r, {
|
|
566
566
|
method: "POST",
|
|
567
567
|
headers: {
|
|
568
568
|
"Content-Type": "application/json",
|
|
@@ -574,7 +574,7 @@ var g = /* @__PURE__ */ function(e) {
|
|
|
574
574
|
})
|
|
575
575
|
}), i);
|
|
576
576
|
}
|
|
577
|
-
},
|
|
577
|
+
}, U = (e, t) => {
|
|
578
578
|
let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
|
|
579
579
|
for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
|
|
580
580
|
let i = e.filter((e) => e.blockVisibility === "selected-collections");
|
|
@@ -608,8 +608,8 @@ var g = /* @__PURE__ */ function(e) {
|
|
|
608
608
|
language: r,
|
|
609
609
|
productIds: a.map((e) => Number(e.split("/").pop())),
|
|
610
610
|
useExternalMetafieldNamespace: !0
|
|
611
|
-
});
|
|
612
|
-
return o = o.filter((e) => e.availableForSale), o;
|
|
611
|
+
}), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
|
|
612
|
+
return o = o.filter((e) => e.availableForSale && (!s || U([t], e).length > 0)), o;
|
|
613
613
|
}, pe = ({ language: e, dealBlockId: t }) => {
|
|
614
614
|
let n = {
|
|
615
615
|
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
@@ -665,7 +665,7 @@ var g = /* @__PURE__ */ function(e) {
|
|
|
665
665
|
useExternalMetafieldNamespace: !0
|
|
666
666
|
});
|
|
667
667
|
s.shopifyDomain = c.shopifyDomain;
|
|
668
|
-
let l = c.storefrontAccessToken ? new
|
|
668
|
+
let l = c.storefrontAccessToken ? new H(c.shopifyDomain, c.storefrontAccessToken) : s, [u, d] = await Promise.all([y(l, {
|
|
669
669
|
country: i,
|
|
670
670
|
language: a,
|
|
671
671
|
productIds: o,
|
|
@@ -675,9 +675,9 @@ var g = /* @__PURE__ */ function(e) {
|
|
|
675
675
|
useMetaobjects: c.featureFlags.storefront_metaobjects
|
|
676
676
|
})]), f = u[0];
|
|
677
677
|
if (!f) return null;
|
|
678
|
-
let m =
|
|
678
|
+
let m = U(d, f), h = n ? m.filter((e) => e.id === n || e.nanoId === n) : m, g = (r ? h.find((e) => e.abTestVariantId === r) : void 0) ?? h[0] ?? m[0];
|
|
679
679
|
if (!g) return null;
|
|
680
|
-
let _ = k(g), v =
|
|
680
|
+
let _ = k(g), v = j(g), [b, x, S, C] = await Promise.all([
|
|
681
681
|
y(l, {
|
|
682
682
|
country: i,
|
|
683
683
|
language: a,
|