@kachingappz/bundles-js 0.3.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -3
- package/dist/bundles-js.iife.js +129 -114
- package/dist/index.d.ts +1033 -3
- package/dist/index.js +980 -0
- package/dist/kaching-bundle-component/index.d.ts +1055 -0
- package/dist/kaching-bundle-component/index.js +1406 -0
- package/dist/react/index.cjs +228 -0
- package/dist/react/index.d.ts +1082 -0
- package/dist/react/index.js +1476 -0
- package/package.json +69 -11
- package/dist/bundles-js.js +0 -1202
package/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# @kachingappz/bundles-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Integrate [Kaching Bundles](https://apps.shopify.com/bundle-deals) into any Shopify storefront.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- `@kachingappz/bundles-js`: `fetchKachingBundlesData` and the types. No side effects, safe to import on the server.
|
|
6
|
+
- `@kachingappz/bundles-js/kaching-bundle-component`: importing it defines the `<kaching-bundle-component>` web component. Works with any framework or no framework at all.
|
|
7
|
+
- `@kachingappz/bundles-js/react`: the `KachingBundle` React component, see [React](#react).
|
|
8
|
+
|
|
9
|
+
Upgrading from 0.x: replace `import "@kachingappz/bundles-js"` with `import "@kachingappz/bundles-js/kaching-bundle-component"`.
|
|
6
10
|
|
|
7
11
|
## Installation
|
|
8
12
|
|
|
@@ -20,10 +24,16 @@ npm install @kachingappz/bundles-js
|
|
|
20
24
|
></kaching-bundle-component>
|
|
21
25
|
|
|
22
26
|
<script type="module">
|
|
23
|
-
import "@kachingappz/bundles-js"
|
|
27
|
+
import "@kachingappz/bundles-js/kaching-bundle-component"
|
|
24
28
|
</script>
|
|
25
29
|
```
|
|
26
30
|
|
|
31
|
+
Without a bundler, load the script from a CDN instead:
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<script src="https://cdn.jsdelivr.net/npm/@kachingappz/bundles-js@1"></script>
|
|
35
|
+
```
|
|
36
|
+
|
|
27
37
|
## Attributes
|
|
28
38
|
|
|
29
39
|
| Attribute | Required | Description |
|
|
@@ -91,3 +101,60 @@ document
|
|
|
91
101
|
.querySelector("kaching-bundle-component")
|
|
92
102
|
.setAttribute("product-id", "8001234567890")
|
|
93
103
|
```
|
|
104
|
+
|
|
105
|
+
## React
|
|
106
|
+
|
|
107
|
+
`react` and `react-dom` (18 or 19) are optional peer dependencies, needed only for this entry. It is safe to import during server rendering (Hydrogen, Next.js).
|
|
108
|
+
|
|
109
|
+
```jsx
|
|
110
|
+
import {
|
|
111
|
+
KachingBundle,
|
|
112
|
+
fetchKachingBundlesData,
|
|
113
|
+
} from "@kachingappz/bundles-js/react"
|
|
114
|
+
|
|
115
|
+
const [kachingBundlesData, setKachingBundlesData] = useState(null)
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const loadData = async () => {
|
|
119
|
+
const data = await fetchKachingBundlesData(
|
|
120
|
+
{
|
|
121
|
+
shopifyDomain: "your-store.myshopify.com",
|
|
122
|
+
storefrontAccessToken: "your-storefront-access-token",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
productId: "gid://shopify/Product/123456789",
|
|
126
|
+
dealBlockId: "abc123", // optional - specify which deal block to display
|
|
127
|
+
country: "US", // optional
|
|
128
|
+
language: "EN", // optional
|
|
129
|
+
},
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
setKachingBundlesData(data)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
loadData()
|
|
136
|
+
}, [])
|
|
137
|
+
|
|
138
|
+
{
|
|
139
|
+
kachingBundlesData && (
|
|
140
|
+
<KachingBundle
|
|
141
|
+
data={kachingBundlesData}
|
|
142
|
+
selectedVariantId={selectedVariant.id}
|
|
143
|
+
onLinesChange={(lines) => {
|
|
144
|
+
// lines structure:
|
|
145
|
+
// [
|
|
146
|
+
// {
|
|
147
|
+
// merchandiseId: "gid://shopify/ProductVariant/123456789",
|
|
148
|
+
// quantity: 2,
|
|
149
|
+
// attributes: [{ key: "__kaching_bundles", value: "{ id: 'abc' }" }],
|
|
150
|
+
// sellingPlanId: "gid://shopify/SellingPlan/987654321" // optional
|
|
151
|
+
// }
|
|
152
|
+
// ]
|
|
153
|
+
setLines(lines)
|
|
154
|
+
}}
|
|
155
|
+
/>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`fetchKachingBundlesData` also accepts a Hydrogen `context.storefront`, a `@shopify/hydrogen-react` storefront client or a `@shopify/storefront-api-client` client in place of the credentials. Pass `preview={{ price, color, cornerRadius }}` instead of `data` to render placeholder data, and `targetWindow` to render inside an iframe. The [`@kachingappz/bundles-react` README](https://www.npmjs.com/package/@kachingappz/bundles-react) has Hydrogen and iframe examples.
|
package/dist/bundles-js.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){"use strict";const
|
|
1
|
+
var BundlesJs=(function(A){"use strict";const V=(t,e)=>{const s=[],n=t.filter(l=>l.blockVisibility==="selected-products");for(const l of n)l.selectedProductIds.map(Number).includes(e.id)&&s.push(l);const i=t.filter(l=>l.blockVisibility==="selected-collections");for(const l of i)e.collectionIds.some(m=>l.selectedCollectionIds.map(Number).includes(m))&&s.push(l);const r=t.filter(l=>l.blockVisibility==="excluded-products");for(const l of r)!l.excludedProductIds.map(Number).includes(e.id)&&!(l.excludedCollectionIds||[]).some(m=>e.collectionIds.includes(m))&&s.push(l);const o=t.filter(l=>l.blockVisibility==="all-products");for(const l of o)s.push(l);return s},F=(t,{language:e,country:s})=>{var y,h;const n=R(e,s),i=new Intl.NumberFormat(n,{style:"currency",currency:t,currencyDisplay:"narrowSymbol"}).formatToParts(123456789e-2),r=(y=i.find(f=>f.type==="decimal"))==null?void 0:y.value,o=z((h=i.find(f=>f.type==="group"))==null?void 0:h.value),l=i.some(f=>f.type==="fraction"),m=Q(o,r,l),d=i.findIndex(G),u=i.findLastIndex(G);return[...i.slice(0,d).map(N),m,...i.slice(u+1).map(N)].join("")},N=t=>x(t.value),x=t=>t.replace(/\s/g," "),G=t=>t.type==="integer"||t.type==="group"||t.type==="decimal"||t.type==="fraction",R=(t,e)=>t&&e?`${t}-${e.toUpperCase()}`:t||(e?e.toUpperCase():"en"),z=t=>t===void 0?void 0:x(t).replace(/’/g,"'"),Q=(t,e,s)=>e===","&&t==="."?s?"{{amount_with_comma_separator}}":"{{amount_no_decimals_with_comma_separator}}":e===","&&t===" "?s?"{{amount_with_space_separator}}":"{{amount_no_decimals_with_space_separator}}":e==="."&&t===" "?"{{amount_with_period_and_space_separator}}":e==="."&&t==="'"?"{{amount_with_apostrophe_separator}}":s?"{{amount}}":"{{amount_no_decimals}}",k=({country:t,language:e})=>{const s=[];return t&&s.push(`country: ${t}`),e&&s.push(`language: ${e}`),s.length>0?`@inContext(${s.join(", ")})`:""},J=async(t,{useExternalMetafieldNamespace:e,useMetaobjects:s})=>s?X(t):H(t),H=async(t,e)=>{var n;const s=(n=(await t.query(`
|
|
2
2
|
query FetchDealBlocks($metafieldNamespace: String!) {
|
|
3
3
|
shop {
|
|
4
4
|
metafield(namespace: $metafieldNamespace, key: "deal_blocks") {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
`,{variables:{metafieldNamespace:"app--2935586817--kaching_bundles"}})).shop.metafield)==null?void 0:
|
|
9
|
+
`,{variables:{metafieldNamespace:"app--2935586817--kaching_bundles"}})).shop.metafield)==null?void 0:n.value;return s?JSON.parse(s):[]},X=async(t,e)=>{const s="app--2935586817--deal_block",n=[];let i=null;for(;;){const r=await t.query(`
|
|
10
10
|
query FetchDealBlockMetaobjects($type: String!, $cursor: String) {
|
|
11
11
|
metaobjects(type: $type, first: 250, after: $cursor) {
|
|
12
12
|
nodes {
|
|
@@ -21,51 +21,19 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
`,{variables:{type:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
moneyFormat
|
|
35
|
-
paymentSettings {
|
|
36
|
-
currencyCode
|
|
37
|
-
}
|
|
38
|
-
primaryDomain {
|
|
39
|
-
host
|
|
40
|
-
}
|
|
41
|
-
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
42
|
-
value
|
|
43
|
-
}
|
|
44
|
-
settingsMetafield: metafield(namespace: $settingsNamespace, key: "config") {
|
|
45
|
-
value
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
`,{variables:{metafieldNamespace:n,settingsNamespace:o}}),r=s===p?m:L(s),g=d?M(d.value):1,i=u?JSON.parse(u.value):null,h=(i==null?void 0:i.feature_flags)??{},y=(i==null?void 0:i.custom_selectors)??{};return{shopifyDomain:f.host,moneyFormat:r,locale:(e==null?void 0:e.toLowerCase())||"en",liquidLocale:(e==null?void 0:e.toLowerCase())||"en",country:l??"US",currencyRate:g,marketId:0,productId:null,storefrontAccessToken:(i==null?void 0:i.storefront_access_token)??null,accessScopes:(i==null?void 0:i.access_scopes)??[],customApiHost:(i==null?void 0:i.custom_api_host)??null,keepQuantityInput:(i==null?void 0:i.keep_quantity_input)??!1,ignoreDeselect:(i==null?void 0:i.ignore_deselect)??!1,ignoreUnitPrice:(i==null?void 0:i.ignore_unit_price)??!1,requireCustomerLogin:(i==null?void 0:i.require_customer_login)??!1,abTestsRunning:(i==null?void 0:i.ab_tests_running)??!1,webPixel:(i==null?void 0:i.web_pixel)??!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,defaultTranslations:{"system.out_of_stock":"Out of stock","system.invalid_variant":"Invalid variant","system.unavailable_option_value":"Unavailable option value","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"},customSelectors:{quantity:y.quantity??null,addToCartButton:y.add_to_cart_button??null,variantPicker:y.variant_picker??null,price:y.price??null,priceCompare:y.price_compare??null},shopCustomStyles:(i==null?void 0:i.shop_custom_styles)??"",featureFlags:h}},M=t=>JSON.parse(t).amount/1e6,L=t=>new Intl.NumberFormat("en",{style:"currency",currency:t,currencyDisplay:"narrowSymbol"}).format(1).replace(/1(\.0+)?/,"{{amount}}"),O=async(t,e,l=200)=>(e=e.filter(Boolean).filter(a=>!a.startsWith("placeholder")),e.length===0?[]:(await t.query(`
|
|
50
|
-
query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
|
|
51
|
-
nodes(ids: $mediaImageIds) {
|
|
52
|
-
... on MediaImage {
|
|
53
|
-
id
|
|
54
|
-
image {
|
|
55
|
-
url(transform: { maxWidth: $size, maxHeight: $size })
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
`,{variables:{mediaImageIds:e,size:l}})).nodes.filter(Boolean).map(a=>({gid:a.id,url:a.image.url}))),A=async(t,{country:e,language:l,blockVisibility:a,excludedProductGIDs:n,selectedProductGIDs:o,selectedCollectionGIDs:c,limit:s=250})=>{switch(a){case"selected-products":return o.slice(0,s);case"all-products":case"excluded-products":{const m=b({country:e,language:l});let p=(await t.query(`
|
|
61
|
-
query FetchProductGIDs($limit: Int!) ${m} {
|
|
62
|
-
products(first: $limit) {
|
|
63
|
-
nodes {
|
|
64
|
-
id
|
|
24
|
+
`,{variables:{type:s,cursor:i}});for(const o of r.metaobjects.nodes){const l=o.fields.find(m=>m.key==="settings");l!=null&&l.value&&n.push(JSON.parse(l.value))}if(!r.metaobjects.pageInfo.hasNextPage)break;i=r.metaobjects.pageInfo.endCursor}return n},B=async(t,{country:e,language:s,blockVisibility:n,excludedProductGIDs:i,selectedProductGIDs:r,selectedCollectionGIDs:o,limit:l=1e3})=>{switch(n){case"selected-products":return r.slice(0,l);case"all-products":case"excluded-products":{const m=k({country:e,language:s});let d=[],u=null;for(;d.length<l;){const y=Math.min(l-d.length,250),h=await t.query(`
|
|
25
|
+
query FetchProductGIDs($limit: Int!, $cursor: String) ${m} {
|
|
26
|
+
products(first: $limit, after: $cursor) {
|
|
27
|
+
nodes {
|
|
28
|
+
id
|
|
29
|
+
}
|
|
30
|
+
pageInfo {
|
|
31
|
+
hasNextPage
|
|
32
|
+
endCursor
|
|
33
|
+
}
|
|
65
34
|
}
|
|
66
35
|
}
|
|
67
|
-
}
|
|
68
|
-
`,{variables:{limit:s}})).products.nodes.map(d=>d.id);return a==="excluded-products"&&(p=p.filter(d=>!n.includes(d))),p}case"selected-collections":{const m=b({country:e,language:l}),p=(await t.query(`
|
|
36
|
+
`,{variables:{limit:y,cursor:u}});if(d.push(...h.products.nodes.map(f=>f.id)),!h.products.pageInfo.hasNextPage)break;u=h.products.pageInfo.endCursor}if(n==="excluded-products"){const y=new Set(i);d=d.filter(h=>!y.has(h))}return d}case"selected-collections":{const m=k({country:e,language:s}),d=(await t.query(`
|
|
69
37
|
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${m} {
|
|
70
38
|
nodes(ids: $collectionGIDs) {
|
|
71
39
|
... on Collection {
|
|
@@ -77,7 +45,7 @@
|
|
|
77
45
|
}
|
|
78
46
|
}
|
|
79
47
|
}
|
|
80
|
-
`,{variables:{collectionGIDs:
|
|
48
|
+
`,{variables:{collectionGIDs:o,limit:Math.min(l,250)}})).nodes.filter(u=>u!==null).flatMap(u=>u.products.nodes.map(y=>y.id));return Array.from(new Set(d)).slice(0,l)}}},T=`
|
|
81
49
|
id
|
|
82
50
|
availableForSale
|
|
83
51
|
price {
|
|
@@ -110,82 +78,92 @@
|
|
|
110
78
|
price {
|
|
111
79
|
amount
|
|
112
80
|
}
|
|
81
|
+
compareAtPrice {
|
|
82
|
+
amount
|
|
83
|
+
}
|
|
84
|
+
perDeliveryPrice {
|
|
85
|
+
amount
|
|
86
|
+
}
|
|
113
87
|
}
|
|
114
88
|
}
|
|
115
89
|
}
|
|
116
90
|
quantityAvailable @include(if: $includeAvailableQuantity)
|
|
117
|
-
`,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
91
|
+
`,D=async(t,{country:e,language:s,productIds:n,includeSellingPlans:i=!0,includeAvailableQuantity:r=!0,useExternalMetafieldNamespace:o=!1,batchSize:l=250,onBatchError:m})=>{if(!n.length)return[];const d=n.map(c=>typeof c=="string"&&c.startsWith("gid://")?c:`gid://shopify/Product/${c}`),u=k({country:e,language:s}),y=`
|
|
92
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${u} {
|
|
93
|
+
shop {
|
|
94
|
+
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
95
|
+
value
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
nodes(ids: $productGIDs) {
|
|
99
|
+
... on Product {
|
|
100
|
+
id
|
|
101
|
+
handle
|
|
102
|
+
onlineStoreUrl
|
|
103
|
+
availableForSale
|
|
104
|
+
createdAt
|
|
105
|
+
title
|
|
106
|
+
featuredImage {
|
|
107
|
+
url
|
|
108
|
+
}
|
|
109
|
+
options {
|
|
110
|
+
name
|
|
111
|
+
optionValues {
|
|
112
|
+
id
|
|
131
113
|
name
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
image {
|
|
138
|
-
previewImage {
|
|
139
|
-
url(transform: { maxWidth: 200, maxHeight: 200 })
|
|
140
|
-
}
|
|
114
|
+
swatch {
|
|
115
|
+
color
|
|
116
|
+
image {
|
|
117
|
+
previewImage {
|
|
118
|
+
url(transform: { maxWidth: 200, maxHeight: 200 })
|
|
141
119
|
}
|
|
142
120
|
}
|
|
143
121
|
}
|
|
144
122
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
collections(first: 50) {
|
|
151
|
-
nodes {
|
|
152
|
-
id
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
metafield: metafield(namespace: $metafieldNamespace, key: "text") {
|
|
156
|
-
value
|
|
157
|
-
}
|
|
158
|
-
metafield2: metafield(namespace: $metafieldNamespace, key: "text2") {
|
|
159
|
-
value
|
|
160
|
-
}
|
|
161
|
-
metafield3: metafield(namespace: $metafieldNamespace, key: "text3") {
|
|
162
|
-
value
|
|
123
|
+
}
|
|
124
|
+
variants(first: 250) {
|
|
125
|
+
nodes {
|
|
126
|
+
${T}
|
|
163
127
|
}
|
|
164
|
-
|
|
165
|
-
|
|
128
|
+
}
|
|
129
|
+
collections(first: 50) {
|
|
130
|
+
nodes {
|
|
131
|
+
id
|
|
166
132
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
133
|
+
}
|
|
134
|
+
metafield: metafield(namespace: $metafieldNamespace, key: "text") {
|
|
135
|
+
value
|
|
136
|
+
}
|
|
137
|
+
metafield2: metafield(namespace: $metafieldNamespace, key: "text2") {
|
|
138
|
+
value
|
|
139
|
+
}
|
|
140
|
+
metafield3: metafield(namespace: $metafieldNamespace, key: "text3") {
|
|
141
|
+
value
|
|
142
|
+
}
|
|
143
|
+
metafield4: metafield(namespace: $metafieldNamespace, key: "text4") {
|
|
144
|
+
value
|
|
145
|
+
}
|
|
146
|
+
requiresSellingPlan
|
|
147
|
+
sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
|
|
148
|
+
nodes {
|
|
149
|
+
sellingPlans(first: 100) {
|
|
150
|
+
nodes {
|
|
151
|
+
id
|
|
152
|
+
name
|
|
153
|
+
priceAdjustments {
|
|
154
|
+
adjustmentValue {
|
|
155
|
+
__typename
|
|
156
|
+
... on SellingPlanPercentagePriceAdjustment {
|
|
157
|
+
adjustmentPercentage
|
|
158
|
+
}
|
|
159
|
+
... on SellingPlanFixedAmountPriceAdjustment {
|
|
160
|
+
adjustmentAmount {
|
|
161
|
+
amount
|
|
184
162
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
163
|
+
}
|
|
164
|
+
... on SellingPlanFixedPriceAdjustment {
|
|
165
|
+
price {
|
|
166
|
+
amount
|
|
189
167
|
}
|
|
190
168
|
}
|
|
191
169
|
}
|
|
@@ -196,12 +174,13 @@
|
|
|
196
174
|
}
|
|
197
175
|
}
|
|
198
176
|
}
|
|
199
|
-
|
|
200
|
-
|
|
177
|
+
}
|
|
178
|
+
`,h=o?"app--2935586817--kaching_bundles":"$app:kaching_bundles",f=[],v=Math.min(l,250);for(let c=0;c<d.length;c+=v)f.push(d.slice(c,c+v));let a=1;const p=async c=>{const b=await t.query(y,{variables:{productGIDs:c,includeSellingPlans:i,includeAvailableQuantity:r,metafieldNamespace:h}});return b.shop.currencyRateConstant&&(a=JSON.parse(b.shop.currencyRateConstant.value).amount/1e6),b};let g;if(m){const c=await Promise.allSettled(f.map(p));for(const b of c)b.status==="rejected"&&m(b.reason instanceof Error?b.reason:new Error(String(b.reason)));g=c.filter(b=>b.status==="fulfilled").flatMap(b=>b.value.nodes)}else g=(await Promise.all(f.map(p))).flatMap(c=>c.nodes);const _=g.filter(c=>c!=null);if(m){const c=await Promise.allSettled(_.map(async I=>{const P=await M(t,I,{includeSellingPlans:i,includeAvailableQuantity:r},u);return q(P,t.shopifyDomain,a)})),b=[];for(const I of c)I.status==="fulfilled"?b.push(I.value):m(I.reason instanceof Error?I.reason:new Error(String(I.reason)));return b}return(await Promise.all(_.map(c=>M(t,c,{includeSellingPlans:i,includeAvailableQuantity:r},u)))).map(c=>q(c,t.shopifyDomain,a))},M=async(t,e,s,n="")=>{if(e.variants.nodes.length<250)return e;const i=new Set,r=[],o=[],l=async m=>{let d=!0,u=null;for(;d;){const y=await t.query(`
|
|
179
|
+
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!) ${n} {
|
|
201
180
|
product(id: $productGID) {
|
|
202
181
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
203
182
|
nodes {
|
|
204
|
-
${
|
|
183
|
+
${T}
|
|
205
184
|
}
|
|
206
185
|
pageInfo {
|
|
207
186
|
endCursor
|
|
@@ -210,4 +189,40 @@
|
|
|
210
189
|
}
|
|
211
190
|
}
|
|
212
191
|
}
|
|
213
|
-
`,{variables:{productGID:e.id,cursor:p,reverse:s,...l}}),{nodes:f,pageInfo:u}=d.product.variants;for(const r of f){if(a.has(r.id)){m=!1;break}a.add(r.id),s?o.push(r):n.push(r)}u.hasNextPage||(m=!1),p=u.endCursor}};return await Promise.all([c(!1),c(!0)]),e.variants.nodes=[...n,...o.reverse()],e},F=t=>{var c,s,m,p,d,f;const e=t.variants.nodes.map(({unitPriceMeasurement:u,...r})=>{var g,i;return{id:Number(r.id.split("/").pop()),availableForSale:r.availableForSale,price:Math.round(Number(r.price.amount)*100),compareAtPrice:r.compareAtPrice?Math.round(Number(r.compareAtPrice.amount)*100):null,options:r.selectedOptions.map(h=>h.value),imageId:r.image?Number(r.image.id.split("/").pop()):null,image:((g=r.image)==null?void 0:g.url)||null,sellingPlans:((i=r.sellingPlanAllocations)==null?void 0:i.nodes.map(h=>({id:Number(h.sellingPlan.id.split("/").pop()),price:h.priceAdjustments.length>0?Math.round(Number(h.priceAdjustments[0].price.amount)*100):Math.round(Number(r.price.amount)*100)})))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:r.quantityAvailable??null,unitPriceMeasurement:u!=null&&u.quantityUnit&&(u!=null&&u.referenceUnit)?{quantityValue:u.quantityValue,quantityUnit:u.quantityUnit.toLowerCase(),referenceValue:u.referenceValue,referenceUnit:u.referenceUnit.toLowerCase()}:null}}),l=t.options.map((u,r)=>{const g=u.optionValues.map(i=>{var h,y,v,P;return{id:Number(i.id.split("/").pop()),defaultName:i.name,name:i.name,swatch:{color:((h=i.swatch)==null?void 0:h.color)||null,image:((P=(v=(y=i.swatch)==null?void 0:y.image)==null?void 0:v.previewImage)==null?void 0:P.url)||null}}});return{defaultName:u.name,name:u.name,position:r+1,optionValues:V(g,r,e)}}),a=u=>{const r=u.priceAdjustments[0];if(!r)return null;const g=r.adjustmentValue;switch(g.__typename){case"SellingPlanPercentagePriceAdjustment":return{type:"percentage",value:g.adjustmentPercentage};case"SellingPlanFixedAmountPriceAdjustment":return{type:"fixed_amount",value:Number(g.adjustmentAmount.amount)*100};case"SellingPlanFixedPriceAdjustment":return{type:"price",value:Number(g.price.amount)*100};default:throw new Error(`Unknown price adjustment type: ${g.__typename}`)}},n=((c=t.sellingPlanGroups)==null?void 0:c.nodes.flatMap(u=>u.sellingPlans.nodes.map(r=>({id:Number(r.id.split("/").pop()),name:r.name,priceAdjustment:a(r)}))))||[],o=t.variants.nodes.some(u=>u.requiresComponents);return{id:Number(t.id.split("/").pop()),handle:t.handle,url:t.onlineStoreUrl,availableForSale:t.availableForSale,createdAt:t.createdAt,title:t.title,image:((s=t.featuredImage)==null?void 0:s.url)||null,collectionIds:t.collections.nodes.map(u=>Number(u.id.split("/").pop())),options:l,selectedVariantId:Number(t.variants.nodes[0].id.split("/").pop()),variants:e,requiresSellingPlan:t.requiresSellingPlan,sellingPlans:n,isNativeBundle:o,metafields:{text:((m=t.metafield)==null?void 0:m.value)||null,text2:((p=t.metafield2)==null?void 0:p.value)||null,text3:((d=t.metafield3)==null?void 0:d.value)||null,text4:((f=t.metafield4)==null?void 0:f.value)||null}}},V=(t,e,l)=>t.filter(a=>l.filter(n=>n.options[e]===a.name).length>0),j=(t,e)=>{const l=[],a=t.filter(s=>s.blockVisibility==="selected-products");for(const s of a)s.selectedProductIds.map(Number).includes(e.id)&&l.push(s);const n=t.filter(s=>s.blockVisibility==="selected-collections");for(const s of n)e.collectionIds.some(m=>s.selectedCollectionIds.map(Number).includes(m))&&l.push(s);const o=t.filter(s=>s.blockVisibility==="excluded-products");for(const s of o)!s.excludedProductIds.map(Number).includes(e.id)&&!(s.excludedCollectionIds||[]).some(m=>e.collectionIds.includes(m))&&l.push(s);const c=t.filter(s=>s.blockVisibility==="all-products");for(const s of c)l.push(s);return l},z=t=>[...R(t),...H(t),...J(t),...Q(t),...X(t),...K(t),...W(t),...Y(t),...Z(t),...ee(t)].filter(e=>e!=null&&!e.includes("placeholder")),R=t=>t.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),H=t=>t.dealBars.map(({freeGifts:e})=>(e||[]).map(l=>l.mediaImageGID)).reduce((e,l)=>e.concat(l),[]).filter(e=>e!=null),J=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(l=>l.mediaImageGID)).filter(e=>e!=null),Q=t=>t.dealBars.map(({upsells:e})=>(e||[]).map(l=>l.mediaImageGID)).reduce((e,l)=>e.concat(l),[]).filter(e=>e!=null),X=t=>t.swatchOptions?t.swatchOptions.reduce((e,l)=>{const a=l.images.map(n=>n.mediaImageGID).filter(n=>n!=null);return[...e,...a]},[]):[],K=t=>{if(!t.collectionBreaksEnabled||!t.collectionBreaks)return[];const e=t.collectionBreaks.mediaImageGID;return e?[e]:[]},W=t=>{var e,l,a;return t.progressiveGifts?[...((e=t.progressiveGifts.gifts)==null?void 0:e.map(n=>n.mediaImageGID))||[],(l=t.progressiveGifts.style)==null?void 0:l.lockedMediaImageGID,(a=t.progressiveGifts.dealBarStyle)==null?void 0:a.lockedMediaImageGID].filter(n=>n!=null):[]},Y=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.mediaImageGID).filter(e=>e!=null),Z=t=>t.dealBars.map(e=>{var l;return(l=e.productPersonalisation)==null?void 0:l.mediaImageGID}).filter(e=>e!=null),ee=t=>t.dealBars.map(e=>{var l;return(l=e.highlights)==null?void 0:l.customIconGID}).filter(e=>e!=null),te=t=>{const e=[...le(t),...se(t),...ae(t),...ne(t),...ie(t),...re(t),...oe(t)];return Array.from(new Set(e.filter(l=>l!=null)))},le=t=>t.dealBars.flatMap(({freeGifts:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null),se=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(l=>l.products?l.products.map(a=>a.id):[]):[]).filter(e=>e!=null),ae=t=>{var e;return t.progressiveGiftsEnabled?((e=t.progressiveGifts)==null?void 0:e.gifts.map(l=>l.productGID).filter(l=>l!=null))||[]:[]},ne=t=>t.dealBars.flatMap(({upsells:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null),ie=t=>t.dealBars.filter(e=>e.dealBarType==="bundle").flatMap(({bundleProducts:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),re=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),oe=t=>t.dealBars.filter(e=>e.dealBarType==="sku").flatMap(({productGID:e})=>e?[e]:[]);class C{constructor(e,l){this.storefrontApiVersion="2025-10",this.storefrontAccessToken=l,this.shopifyDomain=e}async query(e,l){var s;const a=(l==null?void 0:l.variables)??{};let n=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const o=(s=e.match(/query\s+(\w+)/))==null?void 0:s[1];o&&(n+=`?operation_name=${o}`);const c=await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:a})})).text();if(!c)throw new Error("Empty graphql response");return JSON.parse(c).data}}const ce=async(t,e,{country:l,language:a})=>{const n=e.collectionBreaks;if(!e.collectionBreaksEnabled||!n)return;let o;n.visibility==="deal-products"?o=await A(t,{country:l,language:a,blockVisibility:e.blockVisibility,excludedProductGIDs:(e.excludedProductIds||[]).map(s=>`gid://shopify/Product/${s}`),selectedProductGIDs:(e.selectedProductIds||[]).map(s=>`gid://shopify/Product/${s}`),selectedCollectionGIDs:(e.selectedCollectionIds||[]).map(s=>`gid://shopify/Collection/${s}`)}):o=await A(t,{country:l,language:a,blockVisibility:n.visibility,excludedProductGIDs:(n.excludedProducts||[]).map(({id:s})=>s),selectedProductGIDs:(n.selectedProducts||[]).map(({id:s})=>s),selectedCollectionGIDs:(n.selectedCollections||[]).map(({id:s})=>s)}),o=o.slice(0,250);let c=await _(t,{country:l,language:a,productIds:o.map(s=>Number(s.split("/").pop())),useExternalMetafieldNamespace:!0});return c=c.filter(s=>s.availableForSale),c},ue=()=>({"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"}),de=async(t,{productId:e,dealBlockId:l,country:a,language:n})=>{try{const o=[Number(e.split("/").pop())],c=new C(t.shopifyDomain,t.storefrontAccessToken),s=await q(c,{language:n,country:a,useExternalMetafieldNamespace:!0}),m=s.storefrontAccessToken?new C(s.shopifyDomain,s.storefrontAccessToken):c,[p,d]=await Promise.all([_(m,{country:a,language:n,productIds:o,useExternalMetafieldNamespace:!0}),x(m,{useExternalMetafieldNamespace:!0,useMetaobjects:s.featureFlags.storefront_metaobjects})]),f=p[0];if(!f)return null;const u=j(d,f);let r;if(l?(r=u.find(G=>G.id===l||G.nanoId===l),r||(r=u[0])):r=u[0],!r)return null;const g=z(r),i=te(r),[h,y,v,P]=await Promise.all([_(m,{country:a,language:n,productIds:i,useExternalMetafieldNamespace:!0}),O(m,g,300),ce(m,r,{country:a,language:n}),ue()]);return{product:f,dealBlock:r,config:s,otherProducts:h,mediaImages:y,collectionBreaksProducts:v??[],translations:P}}catch(o){return console.error(o),null}},I="kaching-bundles-block",D=1e4,me="https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js",pe="https://bundles-integrations.kachingappz.app/kaching-bundles-block.js",k=new WeakSet,$=async t=>{const e=t.document;if(!t.customElements.get(I)){if(k.has(e))return S(t,I);k.add(e);try{await he(t)}catch(l){throw k.delete(e),l}}},fe=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",ge=()=>fe()?me:pe,he=t=>{const e=t.document;return new Promise((l,a)=>{const n=ge();if(e.querySelector(`script[src="${n}"]`)){S(t,I).then(l).catch(a);return}const c=e.createElement("script");c.src=n,c.onload=()=>S(t,I).then(l).catch(a),c.onerror=()=>a(new Error("Failed to load script")),e.head.appendChild(c)})},S=(t,e)=>new Promise((l,a)=>{if(t.customElements.get(e)){l();return}Promise.race([t.customElements.whenDefined(e),new Promise((n,o)=>setTimeout(()=>o(new Error(`Custom element "${e}" failed to register within ${D}ms`)),D))]).then(()=>l()).catch(a)});class ye extends HTMLElement{constructor(){super(...arguments),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(){var c,s;const e=++this.initializeId;if(this.cleanup(),this.hasAttribute("demo")){if(await $(window),e!==this.initializeId)return;this.renderInnerElement(N);return}const l=this.getAttribute("shop-domain"),a=this.getAttribute("storefront-token"),n=this.getAttribute("product-id");if(!l||!a||!n)return;const[o]=await Promise.all([de({shopifyDomain:l,storefrontAccessToken:a},{productId:n,dealBlockId:this.getAttribute("deal-block-id")??void 0,country:((c=this.getAttribute("country"))==null?void 0:c.toUpperCase())??void 0,language:((s=this.getAttribute("language"))==null?void 0:s.toUpperCase())??void 0}),$(window)]);!o||e!==this.initializeId||this.renderInnerElement(o)}renderInnerElement(e){const{config:l,dealBlock:a,product:n,otherProducts:o,mediaImages:c,collectionBreaksProducts:s,translations:m}=e;this.innerElement=document.createElement("kaching-bundles-block"),this.innerElement.setAttribute("deal-block-id",a.id),this.innerElement.setAttribute("config",JSON.stringify(l)),this.innerElement.setAttribute("deal-block",JSON.stringify(a)),this.innerElement.setAttribute("media-images",JSON.stringify(c??[])),this.innerElement.setAttribute("product",JSON.stringify(n)),this.innerElement.setAttribute("other-products",JSON.stringify(o??[])),this.innerElement.setAttribute("collection-breaks-products",JSON.stringify(s??[])),this.innerElement.setAttribute("translations",JSON.stringify(m??{}));const p=this.getAttribute("selected-variant-id");this.innerElement.setAttribute("current-variant-id",String(p?p.split("/").pop():n.variants[0].id)),this.hasAttribute("compact")&&this.innerElement.setAttribute("compact","");const d=this.innerElement,f=()=>{if(this.innerElement!==d)return;const r=d.items();r&&this.dispatchEvent(new CustomEvent("items-changed",{detail:{items:r},bubbles:!0}))};this.handleItemsChanged=r=>{r.stopPropagation(),f()};const u=this.handleItemsChanged;d.addEventListener("kaching-bundles-block-loaded",()=>{this.innerElement===d&&(d.addEventListener("items-changed",u),this.dispatchEvent(new CustomEvent("loaded",{bubbles:!0})))},{once:!0}),this.appendChild(this.innerElement)}cleanup(){this.handleItemsChanged&&this.innerElement&&(this.innerElement.removeEventListener("items-changed",this.handleItemsChanged),this.handleItemsChanged=null),this.innerElement&&(this.innerElement.remove(),this.innerElement=null)}attributeChangedCallback(e,l,a){l!==a&&this.isConnected&&(e==="product-id"||e==="country"||e==="language"?this.initialize():e==="selected-variant-id"&&this.innerElement&&a&&this.innerElement.setAttribute("current-variant-id",a.includes("/")?String(a.split("/").pop()):a))}items(){return this.innerElement?this.innerElement.items():[]}disconnectedCallback(){this.cleanup(),this.initializeId++}}customElements.define("kaching-bundle-component",ye)})();
|
|
192
|
+
`,{variables:{productGID:e.id,cursor:u,reverse:m,...s}}),{nodes:h,pageInfo:f}=y.product.variants;for(const v of h){if(i.has(v.id)){d=!1;break}i.add(v.id),m?o.push(v):r.push(v)}f.hasNextPage||(d=!1),u=f.endCursor}};return await Promise.all([l(!1),l(!0)]),e.variants.nodes=[...r,...o.reverse()],e},q=(t,e,s)=>{var d,u,y,h,f,v;const n=t.variants.nodes.map(({unitPriceMeasurement:a,...p})=>{var g,_;return{id:Number(p.id.split("/").pop()),availableForSale:p.availableForSale,price:Math.round(Number(p.price.amount)*100),compareAtPrice:p.compareAtPrice?Math.round(Number(p.compareAtPrice.amount)*100):null,options:p.selectedOptions.map(c=>c.value),imageId:p.image?Number(p.image.id.split("/").pop()):null,image:((g=p.image)==null?void 0:g.url)||null,sellingPlans:((_=p.sellingPlanAllocations)==null?void 0:_.nodes.map(c=>({id:Number(c.sellingPlan.id.split("/").pop()),price:c.priceAdjustments.length>0?Math.round(Number(c.priceAdjustments[0].price.amount)*100):Math.round(Number(p.price.amount)*100),compareAtPrice:c.priceAdjustments.length>0?Math.round(Number(c.priceAdjustments[0].compareAtPrice.amount)*100):Math.round(Number(p.price.amount)*100),perDeliveryPrice:c.priceAdjustments.length>0?Math.round(Number(c.priceAdjustments[0].perDeliveryPrice.amount)*100):Math.round(Number(p.price.amount)*100)})))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:p.quantityAvailable??null,unitPriceMeasurement:a!=null&&a.quantityUnit&&(a!=null&&a.referenceUnit)?{quantityValue:a.quantityValue,quantityUnit:a.quantityUnit.toLowerCase(),referenceValue:a.referenceValue,referenceUnit:a.referenceUnit.toLowerCase()}:null}}),i=t.options.map((a,p)=>{const g=a.optionValues.map(_=>{var c,b,I,P;return{id:Number(_.id.split("/").pop()),defaultName:_.name,name:_.name,swatch:{color:((c=_.swatch)==null?void 0:c.color)||null,image:((P=(I=(b=_.swatch)==null?void 0:b.image)==null?void 0:I.previewImage)==null?void 0:P.url)||null}}});return{defaultName:a.name,name:a.name,position:p+1,optionValues:K(g,p,n)}}),r=a=>{const p=a.priceAdjustments[0];if(!p)return null;const g=p.adjustmentValue;switch(g.__typename){case"SellingPlanPercentagePriceAdjustment":return{type:"percentage",value:g.adjustmentPercentage};case"SellingPlanFixedAmountPriceAdjustment":return{type:"fixed_amount",value:o(g.adjustmentAmount.amount)};case"SellingPlanFixedPriceAdjustment":return{type:"price",value:o(g.price.amount)};default:throw new Error(`Unknown price adjustment type: ${g.__typename}`)}},o=a=>s===1?Number(a)*100:Math.round(Number(a)*100*s),l=((d=t.sellingPlanGroups)==null?void 0:d.nodes.flatMap(a=>a.sellingPlans.nodes.map(p=>({id:Number(p.id.split("/").pop()),name:p.name,priceAdjustment:r(p)}))))||[],m=t.variants.nodes.some(a=>a.requiresComponents);return{id:Number(t.id.split("/").pop()),handle:t.handle,url:t.onlineStoreUrl||`https://${e}/products/${t.handle}`,availableForSale:t.availableForSale,createdAt:t.createdAt,title:t.title,image:((u=t.featuredImage)==null?void 0:u.url)||null,collectionIds:t.collections.nodes.map(a=>Number(a.id.split("/").pop())),options:i,selectedVariantId:Number(t.variants.nodes[0].id.split("/").pop()),variants:n,requiresSellingPlan:t.requiresSellingPlan,sellingPlans:l,isNativeBundle:m,metafields:{text:((y=t.metafield)==null?void 0:y.value)||null,text2:((h=t.metafield2)==null?void 0:h.value)||null,text3:((f=t.metafield3)==null?void 0:f.value)||null,text4:((v=t.metafield4)==null?void 0:v.value)||null}}},K=(t,e,s)=>t.filter(n=>s.filter(i=>i.options[e]===n.name).length>0),O="app--2935586817",W=async(t,{language:e,country:s,useExternalMetafieldNamespace:n})=>{const i=`${O}--kaching_bundles`,r=O,o=k({country:s}),{localization:{country:{currency:{isoCode:l}}},shop:{moneyFormat:m,paymentSettings:{currencyCode:d},currencyRateConstant:u,primaryDomain:y,settingsMetafield:h}}=await t.query(`
|
|
193
|
+
query config($metafieldNamespace: String!, $settingsNamespace: String!) ${o} {
|
|
194
|
+
localization {
|
|
195
|
+
country {
|
|
196
|
+
currency {
|
|
197
|
+
isoCode
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
shop {
|
|
202
|
+
moneyFormat
|
|
203
|
+
paymentSettings {
|
|
204
|
+
currencyCode
|
|
205
|
+
}
|
|
206
|
+
primaryDomain {
|
|
207
|
+
host
|
|
208
|
+
}
|
|
209
|
+
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
210
|
+
value
|
|
211
|
+
}
|
|
212
|
+
settingsMetafield: metafield(namespace: $settingsNamespace, key: "config") {
|
|
213
|
+
value
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
`,{variables:{metafieldNamespace:i,settingsNamespace:r}}),f=l===d?m:F(l,{language:e,country:s}),v=u?Y(u.value):1,a=h?JSON.parse(h.value):null,p=(a==null?void 0:a.feature_flags)??{},g=(a==null?void 0:a.custom_selectors)??{};return{shopifyDomain:y.host,moneyFormat:f,locale:(e==null?void 0:e.toLowerCase())||"en",liquidLocale:(e==null?void 0:e.toLowerCase())||"en",country:s??"US",currencyRate:v,marketId:0,productId:null,storefrontAccessToken:(a==null?void 0:a.storefront_access_token)??null,includeSellingPlans:(a==null?void 0:a.include_selling_plans)??!1,includeAvailableQuantity:(a==null?void 0:a.include_available_quantity)??!1,customApiHost:(a==null?void 0:a.custom_api_host)??null,keepQuantityInput:(a==null?void 0:a.keep_quantity_input)??!1,ignoreDeselect:(a==null?void 0:a.ignore_deselect)??!1,ignoreUnitPrice:(a==null?void 0:a.ignore_unit_price)??!1,requireCustomerLogin:(a==null?void 0:a.require_customer_login)??!1,abTestsRunning:(a==null?void 0:a.ab_tests_running)??!1,webPixel:(a==null?void 0:a.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:g.quantity??null,addToCartButton:g.add_to_cart_button??null,variantPicker:g.variant_picker??null,price:g.price??null,priceCompare:g.price_compare??null},shopCustomStyles:(a==null?void 0:a.shop_custom_styles)??"",featureFlags:p,brandColors:(a==null?void 0:a.brand_colors)??null}},Y=t=>JSON.parse(t).amount/1e6,Z=async(t,e,s=200)=>(e=e.filter(Boolean).filter(n=>!n.startsWith("placeholder")),e.length===0?[]:(await t.query(`
|
|
218
|
+
query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
|
|
219
|
+
nodes(ids: $mediaImageIds) {
|
|
220
|
+
... on MediaImage {
|
|
221
|
+
id
|
|
222
|
+
image {
|
|
223
|
+
url(transform: { maxWidth: $size, maxHeight: $size })
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
`,{variables:{mediaImageIds:e,size:s}})).nodes.filter(Boolean).map(n=>({gid:n.id,url:n.image.url})));var S=(t=>(t.QuantityBreak="quantity-break",t.Bxgy="bxgy",t.Bundle="bundle",t.MixAndMatch="mix-and-match",t.Sku="sku",t))(S||{});const ee=t=>[...te(t),...se(t),...ae(t),...ne(t),...le(t),...ie(t),...re(t),...oe(t),...ce(t),...ue(t),...de(t),...me(t),...pe(t)].filter(e=>e!=null&&!e.includes("placeholder")),te=t=>t.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),se=t=>t.dealBars.flatMap(e=>e.dealBarType===S.Bundle?e.bundleProducts.map(s=>s.mediaImageGID):[]).filter(e=>e!=null),ae=t=>t.dealBars.map(({freeGifts:e})=>(e||[]).map(s=>s.mediaImageGID)).reduce((e,s)=>e.concat(s),[]).filter(e=>e!=null),ne=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(s=>s.mediaImageGID)).filter(e=>e!=null),le=t=>t.dealBars.map(({upsells:e})=>(e||[]).map(s=>s.mediaImageGID)).reduce((e,s)=>e.concat(s),[]).filter(e=>e!=null),ie=t=>t.swatchOptions?t.swatchOptions.reduce((e,s)=>{const n=s.images.map(i=>i.mediaImageGID).filter(i=>i!=null);return[...e,...n]},[]):[],re=t=>{if(!t.collectionBreaksEnabled||!t.collectionBreaks)return[];const e=t.collectionBreaks.mediaImageGID;return e?[e]:[]},oe=t=>{var e,s,n;return t.progressiveGifts?[...((e=t.progressiveGifts.gifts)==null?void 0:e.map(i=>i.mediaImageGID))||[],(s=t.progressiveGifts.style)==null?void 0:s.lockedMediaImageGID,(n=t.progressiveGifts.dealBarStyle)==null?void 0:n.lockedMediaImageGID].filter(i=>i!=null):[]},ce=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),ue=t=>t.dealBars.map(e=>{var s;return(s=e.productPersonalisation)==null?void 0:s.mediaImageGID}).filter(e=>e!=null),de=t=>{var n,i;const e=t.dealBars.map(r=>{var o;return(o=r.highlights)==null?void 0:o.customIconGID}).filter(r=>r!=null),s=(i=(n=t.subscriptions)==null?void 0:n.highlights)==null?void 0:i.customIconGID;return s?[...e,s]:e},me=t=>(t.badges||[]).flatMap(e=>e.badgeType==="custom"&&e.imageGID?[e.imageGID]:[]),pe=t=>!t.savingsSummaryEnabled||!t.savingsSummary?[]:t.savingsSummary.customIconGID?[t.savingsSummary.customIconGID]:[],fe=t=>{const e=[...he(t),...ge(t),...ye(t),...be(t),...ve(t),..._e(t),...Ie(t),...Pe(t)];return Array.from(new Set(e.filter(s=>s!=null)))},he=t=>t.dealBars.flatMap(({freeGifts:e})=>e?e.map(s=>s.productGID):[]).filter(e=>e!=null),ge=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(s=>s.products?s.products.map(n=>n.id):[]):[]).filter(e=>e!=null),ye=t=>{var e;return t.progressiveGiftsEnabled?((e=t.progressiveGifts)==null?void 0:e.gifts.map(s=>s.productGID).filter(s=>s!=null))||[]:[]},be=t=>t.dealBars.flatMap(({upsells:e})=>e?e.map(s=>s.productGID):[]).filter(e=>e!=null),ve=t=>t.dealBars.filter(e=>e.dealBarType===S.Bundle).flatMap(({bundleProducts:e})=>e?e.map(s=>s.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),_e=t=>t.dealBars.filter(e=>e.dealBarType===S.MixAndMatch).flatMap(({bundleProducts:e})=>e?e.flatMap(s=>{var n;return[s.productGID,...((n=s.selectedProducts)==null?void 0:n.map(i=>i.id))??[]]}):[]).filter(e=>e!=null).filter(e=>e!=="default"),Ie=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),Pe=t=>t.dealBars.filter(e=>e.dealBarType===S.Sku).flatMap(({productGID:e})=>e?[e]:[]);class Se{constructor(e,s){this.storefrontApiVersion="2026-07",this.storefrontAccessToken=s,this.shopifyDomain=e}async query(e,s){var l;const n=(s==null?void 0:s.variables)??{};let i=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const r=(l=e.match(/query\s+(\w+)/))==null?void 0:l[1];r&&(i+=`?operation_name=${r}`);const o=await(await fetch(i,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:n})})).text();if(!o)throw new Error("Empty graphql response");return JSON.parse(o).data}}const ke=async(t,e,{country:s,language:n})=>{const i=e.collectionBreaks;if(!e.collectionBreaksEnabled||!i)return;let r;i.visibility==="deal-products"?r=await B(t,{country:s,language:n,blockVisibility:e.blockVisibility,excludedProductGIDs:(e.excludedProductIds||[]).map(l=>`gid://shopify/Product/${l}`),selectedProductGIDs:(e.selectedProductIds||[]).map(l=>`gid://shopify/Product/${l}`),selectedCollectionGIDs:(e.selectedCollectionIds||[]).map(l=>`gid://shopify/Collection/${l}`)}):r=await B(t,{country:s,language:n,blockVisibility:i.visibility,excludedProductGIDs:(i.excludedProducts||[]).map(({id:l})=>l),selectedProductGIDs:(i.selectedProducts||[]).map(({id:l})=>l),selectedCollectionGIDs:(i.selectedCollections||[]).map(({id:l})=>l)});let o=await D(t,{country:s,language:n,productIds:r.map(l=>Number(l.split("/").pop())),useExternalMetafieldNamespace:!0});return o=o.filter(l=>l.availableForSale),o},we=()=>({"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.quantity":"Quantity","system.subscription_plan":"Subscription plan","system.remove":"Remove","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available","system.original_price":"Original price:","system.price":"Price:","system.letters_only":"Only letters are allowed.","system.numbers_only":"Only numbers are allowed.","system.personalisation_required_alert":"Please add personalisation for every item to continue."}),Ee="2026-07",j=async(t,{productId:e,dealBlockId:s,country:n=void 0,language:i=void 0})=>{var r,o;try{const l=[Number(e.split("/").pop())],m=new Ae(t);n=n||((r=m.i18n)==null?void 0:r.country),i=i||((o=m.i18n)==null?void 0:o.language);const d=await W(m,{language:i,country:n,useExternalMetafieldNamespace:!0});m.shopifyDomain=d.shopifyDomain;const u=d.storefrontAccessToken?new Se(d.shopifyDomain,d.storefrontAccessToken):m,[y,h]=await Promise.all([D(u,{country:n,language:i,productIds:l,useExternalMetafieldNamespace:!0}),J(u,{useExternalMetafieldNamespace:!0,useMetaobjects:d.featureFlags.storefront_metaobjects})]),f=y[0];if(!f)return null;const v=V(h,f);let a;if(s?(a=v.find(P=>P.id===s||P.nanoId===s),a||(a=v[0])):a=v[0],!a)return null;const p=ee(a),g=fe(a),[_,c,b,I]=await Promise.all([D(u,{country:n,language:i,productIds:g,useExternalMetafieldNamespace:!0}),Z(u,p,300),ke(u,a,{country:n,language:i}),we()]);return{product:f,dealBlock:a,config:d,otherProducts:_,mediaImages:c,collectionBreaksProducts:b??[],translations:I}}catch(l){return console.error(l),null}};class Ae{constructor(e){this.storefront=e,this.shopifyDomain=""}async query(e,s){if("query"in this.storefront&&"i18n"in this.storefront)return await this.storefront.query(e,s);if("request"in this.storefront)return(await this.storefront.request(e,s)).data;if("shopifyDomain"in this.storefront&&"storefrontAccessToken"in this.storefront){const n=await fetch(`https://${this.storefront.shopifyDomain}/api/${Ee}/graphql.json`,{body:JSON.stringify({query:e,variables:s==null?void 0:s.variables}),headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:"POST"});if(!n.ok)throw new Error(n.statusText);return(await n.json()).data}else{const n=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:e,variables:s==null?void 0:s.variables}),headers:this.storefront.getPublicTokenHeaders(),method:"POST"});if(!n.ok)throw new Error(n.statusText);return(await n.json()).data}}get i18n(){if("i18n"in this.storefront)return this.storefront.i18n}}const w="kaching-bundles-block",U=1e4,De="https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js",$e="https://bundles-integrations.kachingappz.app/kaching-bundles-block.js",$=new WeakSet,L=async t=>{const e=t.document;if(!t.customElements.get(w)){if($.has(e))return C(t,w);$.add(e);try{await xe(t)}catch(s){throw $.delete(e),s}}},Ce=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",Ne=()=>Ce()?De:$e,xe=t=>{const e=t.document;return new Promise((s,n)=>{const i=Ne();if(e.querySelector(`script[src="${i}"]`)){C(t,w).then(s).catch(n);return}const o=e.createElement("script");o.src=i,o.onload=()=>C(t,w).then(s).catch(n),o.onerror=()=>n(new Error("Failed to load script")),e.head.appendChild(o)})},C=(t,e)=>new Promise((s,n)=>{if(t.customElements.get(e)){s();return}Promise.race([t.customElements.whenDefined(e),new Promise((i,r)=>setTimeout(()=>r(new Error(`Custom element "${e}" failed to register within ${U}ms`)),U))]).then(()=>s()).catch(n)});var E=(t=>(t.QuantityBreak="quantity-break",t.Bxgy="bxgy",t.Bundle="bundle",t.MixAndMatch="mix-and-match",t.Sku="sku",t))(E||{});const Ge={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},Be={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:E.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},{id:"duo",dealBarType:E.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},{id:"trio",dealBarType:E.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}],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},Te={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:Be,product:Ge,otherProducts:[],mediaImages:[],collectionBreaksProducts:[],translations:{}};class Me extends HTMLElement{constructor(){super(...arguments),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(){var o,l;const e=++this.initializeId;if(this.cleanup(),this.hasAttribute("demo")){if(await L(window),e!==this.initializeId)return;this.renderInnerElement(Te);return}const s=this.getAttribute("shop-domain"),n=this.getAttribute("storefront-token"),i=this.getAttribute("product-id");if(!s||!n||!i)return;const[r]=await Promise.all([j({shopifyDomain:s,storefrontAccessToken:n},{productId:i,dealBlockId:this.getAttribute("deal-block-id")??void 0,country:((o=this.getAttribute("country"))==null?void 0:o.toUpperCase())??void 0,language:((l=this.getAttribute("language"))==null?void 0:l.toUpperCase())??void 0}),L(window)]);!r||e!==this.initializeId||this.renderInnerElement(r)}renderInnerElement(e){const{config:s,dealBlock:n,product:i,otherProducts:r,mediaImages:o,collectionBreaksProducts:l,translations:m}=e;this.innerElement=document.createElement("kaching-bundles-block"),this.innerElement.setAttribute("deal-block-id",n.id),this.innerElement.setAttribute("config",JSON.stringify(s)),this.innerElement.setAttribute("deal-block",JSON.stringify(n)),this.innerElement.setAttribute("media-images",JSON.stringify(o??[])),this.innerElement.setAttribute("product",JSON.stringify(i)),this.innerElement.setAttribute("other-products",JSON.stringify(r??[])),this.innerElement.setAttribute("collection-breaks-products",JSON.stringify(l??[])),this.innerElement.setAttribute("translations",JSON.stringify(m??{}));const d=this.getAttribute("selected-variant-id");this.innerElement.setAttribute("current-variant-id",String(d?d.split("/").pop():i.variants[0].id)),this.hasAttribute("compact")&&this.innerElement.setAttribute("compact","");const u=this.innerElement,y=()=>{if(this.innerElement!==u)return;const f=u.items();f&&this.dispatchEvent(new CustomEvent("items-changed",{detail:{items:f},bubbles:!0}))};this.handleItemsChanged=f=>{f.stopPropagation(),y()};const h=this.handleItemsChanged;u.addEventListener("kaching-bundles-block-loaded",()=>{this.innerElement===u&&(u.addEventListener("items-changed",h),this.dispatchEvent(new CustomEvent("loaded",{bubbles:!0})))},{once:!0}),this.appendChild(this.innerElement)}cleanup(){this.handleItemsChanged&&this.innerElement&&(this.innerElement.removeEventListener("items-changed",this.handleItemsChanged),this.handleItemsChanged=null),this.innerElement&&(this.innerElement.remove(),this.innerElement=null)}attributeChangedCallback(e,s,n){s!==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",Me),A.fetchKachingBundlesData=j,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"}),A})({});
|