@kachingappz/bundles-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles-js.iife.js +203 -0
- package/dist/bundles-js.js +1228 -0
- package/dist/index.d.ts +25 -0
- package/package.json +44 -0
|
@@ -0,0 +1,1228 @@
|
|
|
1
|
+
const G = {
|
|
2
|
+
id: 1,
|
|
3
|
+
handle: "example-product",
|
|
4
|
+
url: null,
|
|
5
|
+
availableForSale: !0,
|
|
6
|
+
title: "Example product",
|
|
7
|
+
image: null,
|
|
8
|
+
collectionIds: [],
|
|
9
|
+
options: [],
|
|
10
|
+
selectedVariantId: 1,
|
|
11
|
+
variants: [
|
|
12
|
+
{
|
|
13
|
+
id: 1,
|
|
14
|
+
availableForSale: !0,
|
|
15
|
+
price: 8e3,
|
|
16
|
+
compareAtPrice: null,
|
|
17
|
+
options: ["Default Title"],
|
|
18
|
+
imageId: null,
|
|
19
|
+
image: null,
|
|
20
|
+
unitPriceMeasurement: null,
|
|
21
|
+
sellingPlans: [],
|
|
22
|
+
inventoryManagement: null,
|
|
23
|
+
inventoryPolicy: null,
|
|
24
|
+
inventoryQuantity: 50
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
metafields: { text: null, text2: null, text3: null, text4: null },
|
|
28
|
+
requiresSellingPlan: !1,
|
|
29
|
+
sellingPlans: [],
|
|
30
|
+
isNativeBundle: !1
|
|
31
|
+
}, T = {
|
|
32
|
+
id: "example",
|
|
33
|
+
nanoId: "example",
|
|
34
|
+
blockName: "Bundle",
|
|
35
|
+
discountName: "",
|
|
36
|
+
blockTitle: "BUNDLE & SAVE",
|
|
37
|
+
blockLayout: "vertical",
|
|
38
|
+
blockVisibility: "all-products",
|
|
39
|
+
marketId: null,
|
|
40
|
+
currency: null,
|
|
41
|
+
excludeB2bCustomers: !1,
|
|
42
|
+
excludePos: !1,
|
|
43
|
+
startTimestamp: 0,
|
|
44
|
+
endTimestamp: null,
|
|
45
|
+
differentVariantsEnabled: !0,
|
|
46
|
+
hideVariantPicker: !0,
|
|
47
|
+
disableVariantOptionSync: !1,
|
|
48
|
+
hideUnavailableOptions: !1,
|
|
49
|
+
showPricesPerItem: !1,
|
|
50
|
+
showBothPrices: !1,
|
|
51
|
+
unitLabel: "",
|
|
52
|
+
useProductCompareAtPrice: !0,
|
|
53
|
+
showPricesWithoutDecimals: !1,
|
|
54
|
+
priceRounding: !1,
|
|
55
|
+
priceRoundingPrecision: ".00",
|
|
56
|
+
updateNativePrice: !1,
|
|
57
|
+
updateNativePriceType: "item",
|
|
58
|
+
skipCart: !1,
|
|
59
|
+
showVariantsForSingleQuantity: !1,
|
|
60
|
+
preselectedDealBarId: "duo",
|
|
61
|
+
cornerRadius: 8,
|
|
62
|
+
spacing: 1,
|
|
63
|
+
selectedProductIds: [],
|
|
64
|
+
selectedCollectionIds: [],
|
|
65
|
+
excludedProductIds: [],
|
|
66
|
+
excludedCollectionIds: [],
|
|
67
|
+
colors: {
|
|
68
|
+
background: { red: 255, green: 255, blue: 255, alpha: 1 },
|
|
69
|
+
selectedBackground: { red: 255, green: 255, blue: 255, alpha: 1 },
|
|
70
|
+
border: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
71
|
+
blockTitle: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
72
|
+
title: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
73
|
+
subtitle: { red: 85, green: 85, blue: 85, alpha: 1 },
|
|
74
|
+
price: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
75
|
+
fullPrice: { red: 85, green: 85, blue: 85, alpha: 1 },
|
|
76
|
+
labelBackground: { red: 238, green: 238, blue: 238, alpha: 1 },
|
|
77
|
+
label: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
78
|
+
badgeBackground: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
79
|
+
badgeText: { red: 255, green: 255, blue: 255, alpha: 1 },
|
|
80
|
+
freeGiftBackground: { red: 0, green: 0, blue: 0, alpha: 0.3 },
|
|
81
|
+
freeGiftText: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
82
|
+
freeGiftSelectedBackground: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
83
|
+
freeGiftSelectedText: { red: 255, green: 255, blue: 255, alpha: 1 },
|
|
84
|
+
upsellBackground: { red: 0, green: 0, blue: 0, alpha: 0.2 },
|
|
85
|
+
upsellText: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
86
|
+
upsellSelectedBackground: { red: 0, green: 0, blue: 0, alpha: 0.2 },
|
|
87
|
+
upsellSelectedText: { red: 0, green: 0, blue: 0, alpha: 1 }
|
|
88
|
+
},
|
|
89
|
+
fonts: {
|
|
90
|
+
blockTitle: { size: "14", style: "bold" },
|
|
91
|
+
title: { size: "20", style: "medium" },
|
|
92
|
+
subtitle: { size: "14", style: "regular" },
|
|
93
|
+
label: { size: "12", style: "regular" },
|
|
94
|
+
freeGift: { size: "13", style: "bold" },
|
|
95
|
+
upsell: { size: "13", style: "bold" },
|
|
96
|
+
unitLabel: { size: "14", style: "regular" }
|
|
97
|
+
},
|
|
98
|
+
dealBars: [
|
|
99
|
+
{
|
|
100
|
+
id: "single",
|
|
101
|
+
dealBarType: "quantity-break",
|
|
102
|
+
quantitySelector: !1,
|
|
103
|
+
title: "Single",
|
|
104
|
+
subtitle: "Standard price",
|
|
105
|
+
label: "",
|
|
106
|
+
quantity: 1,
|
|
107
|
+
discountType: "default",
|
|
108
|
+
discountValue: "",
|
|
109
|
+
badgeStyle: "simple",
|
|
110
|
+
badgeText: "",
|
|
111
|
+
badgeImageGID: null,
|
|
112
|
+
mediaImageGID: null,
|
|
113
|
+
freeGifts: [],
|
|
114
|
+
multipleGiftsSelectors: [],
|
|
115
|
+
upsells: [],
|
|
116
|
+
showAsSoldOutEnabled: !1,
|
|
117
|
+
showAsSoldOut: null,
|
|
118
|
+
productPersonalisation: null,
|
|
119
|
+
highlights: null,
|
|
120
|
+
sellingPlanEnabled: !1,
|
|
121
|
+
sellingPlanGid: null
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: "duo",
|
|
125
|
+
dealBarType: "quantity-break",
|
|
126
|
+
quantitySelector: !1,
|
|
127
|
+
title: "Duo",
|
|
128
|
+
subtitle: "You save 20%",
|
|
129
|
+
label: "SAVE $32",
|
|
130
|
+
quantity: 2,
|
|
131
|
+
discountType: "percentage",
|
|
132
|
+
discountValue: "20",
|
|
133
|
+
badgeStyle: "most-popular",
|
|
134
|
+
badgeText: "",
|
|
135
|
+
badgeImageGID: null,
|
|
136
|
+
mediaImageGID: null,
|
|
137
|
+
freeGifts: [],
|
|
138
|
+
multipleGiftsSelectors: [],
|
|
139
|
+
upsells: [],
|
|
140
|
+
showAsSoldOutEnabled: !1,
|
|
141
|
+
showAsSoldOut: null,
|
|
142
|
+
productPersonalisation: null,
|
|
143
|
+
highlights: null,
|
|
144
|
+
sellingPlanEnabled: !1,
|
|
145
|
+
sellingPlanGid: null
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "trio",
|
|
149
|
+
dealBarType: "quantity-break",
|
|
150
|
+
quantitySelector: !1,
|
|
151
|
+
title: "Trio",
|
|
152
|
+
subtitle: "You save 25%",
|
|
153
|
+
label: "SAVE $60",
|
|
154
|
+
quantity: 3,
|
|
155
|
+
discountType: "percentage",
|
|
156
|
+
discountValue: "25",
|
|
157
|
+
badgeStyle: "simple",
|
|
158
|
+
badgeText: "",
|
|
159
|
+
badgeImageGID: null,
|
|
160
|
+
mediaImageGID: null,
|
|
161
|
+
freeGifts: [],
|
|
162
|
+
multipleGiftsSelectors: [],
|
|
163
|
+
upsells: [],
|
|
164
|
+
showAsSoldOutEnabled: !1,
|
|
165
|
+
showAsSoldOut: null,
|
|
166
|
+
productPersonalisation: null,
|
|
167
|
+
highlights: null,
|
|
168
|
+
sellingPlanEnabled: !1,
|
|
169
|
+
sellingPlanGid: null
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
swatchOptions: [],
|
|
173
|
+
swatchSize: 18,
|
|
174
|
+
swatchShape: "circle",
|
|
175
|
+
imageSize: 48,
|
|
176
|
+
imageCornerRadius: 6,
|
|
177
|
+
defaultVariantsV2: [],
|
|
178
|
+
collectionBreaksEnabled: !1,
|
|
179
|
+
collectionBreaks: null,
|
|
180
|
+
chooseProductModal: null,
|
|
181
|
+
timerEnabled: !1,
|
|
182
|
+
timer: null,
|
|
183
|
+
subscriptionsEnabled: !1,
|
|
184
|
+
subscriptions: null,
|
|
185
|
+
stickyAtcEnabled: !1,
|
|
186
|
+
stickyAtc: null,
|
|
187
|
+
progressiveGiftsEnabled: !1,
|
|
188
|
+
progressiveGifts: null,
|
|
189
|
+
checkboxUpsellsEnabled: !1,
|
|
190
|
+
checkboxUpsells: null,
|
|
191
|
+
customStylesEnabled: !1,
|
|
192
|
+
shopCustomStyles: "",
|
|
193
|
+
customStyles: "",
|
|
194
|
+
lowStockAlertEnabled: !1,
|
|
195
|
+
lowStockAlert: null
|
|
196
|
+
}, B = {
|
|
197
|
+
shopifyDomain: "",
|
|
198
|
+
moneyFormat: "${{amount}}",
|
|
199
|
+
locale: "en",
|
|
200
|
+
country: "US",
|
|
201
|
+
currencyRate: 1,
|
|
202
|
+
marketId: 0,
|
|
203
|
+
productId: null,
|
|
204
|
+
storefrontAccessToken: null,
|
|
205
|
+
accessScopes: [],
|
|
206
|
+
customApiHost: null,
|
|
207
|
+
keepQuantityInput: !1,
|
|
208
|
+
ignoreDeselect: !1,
|
|
209
|
+
ignoreUnitPrice: !1,
|
|
210
|
+
requireCustomerLogin: !1,
|
|
211
|
+
abTestsRunning: !1,
|
|
212
|
+
webPixel: !1,
|
|
213
|
+
b2bCustomer: !1,
|
|
214
|
+
isLoggedIn: !1,
|
|
215
|
+
preview: !0,
|
|
216
|
+
previewAlerts: !1,
|
|
217
|
+
defaultTranslations: {
|
|
218
|
+
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
219
|
+
"system.invalid_variant": "Sorry, this is not currently available.",
|
|
220
|
+
"system.unavailable_option_value": "Unavailable",
|
|
221
|
+
"system.confirm": "Confirm",
|
|
222
|
+
"system.cancel": "Cancel",
|
|
223
|
+
"system.free": "FREE",
|
|
224
|
+
"system.search": "Search",
|
|
225
|
+
"system.sort_by": "Sort by",
|
|
226
|
+
"system.sort_relevance": "Relevance",
|
|
227
|
+
"system.sort_newest_first": "Newest first",
|
|
228
|
+
"system.sort_price_low_to_high": "Price: Low → High",
|
|
229
|
+
"system.sort_price_high_to_low": "Price: High → Low",
|
|
230
|
+
"system.no_results_found": "No results found",
|
|
231
|
+
"system.no_results_description": "We can't find any item matching your search.",
|
|
232
|
+
"system.clear_search": "Clear search",
|
|
233
|
+
"system.no_products_available": "No products available"
|
|
234
|
+
},
|
|
235
|
+
customSelectors: {
|
|
236
|
+
quantity: null,
|
|
237
|
+
addToCartButton: null,
|
|
238
|
+
variantPicker: null,
|
|
239
|
+
price: null,
|
|
240
|
+
priceCompare: null
|
|
241
|
+
},
|
|
242
|
+
featureFlags: {},
|
|
243
|
+
shopCustomStyles: ""
|
|
244
|
+
}, q = {
|
|
245
|
+
config: B,
|
|
246
|
+
dealBlock: T,
|
|
247
|
+
product: G,
|
|
248
|
+
otherProducts: [],
|
|
249
|
+
mediaImages: [],
|
|
250
|
+
collectionBreaksProducts: [],
|
|
251
|
+
translations: {}
|
|
252
|
+
}, P = ({
|
|
253
|
+
country: t,
|
|
254
|
+
language: e
|
|
255
|
+
}) => {
|
|
256
|
+
const s = [];
|
|
257
|
+
return t && s.push(`country: ${t}`), e && s.push(`language: ${e}`), s.length > 0 ? `@inContext(${s.join(", ")})` : "";
|
|
258
|
+
}, M = async (t, {
|
|
259
|
+
useExternalMetafieldNamespace: e,
|
|
260
|
+
useMetaobjects: s
|
|
261
|
+
}) => s ? j(
|
|
262
|
+
t
|
|
263
|
+
) : O(t), O = async (t, e) => {
|
|
264
|
+
var l;
|
|
265
|
+
const s = (l = (await t.query(
|
|
266
|
+
`
|
|
267
|
+
query FetchDealBlocks($metafieldNamespace: String!) {
|
|
268
|
+
shop {
|
|
269
|
+
metafield(namespace: $metafieldNamespace, key: "deal_blocks") {
|
|
270
|
+
value
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
`,
|
|
275
|
+
{
|
|
276
|
+
variables: {
|
|
277
|
+
metafieldNamespace: "app--2935586817--kaching_bundles"
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
)).shop.metafield) == null ? void 0 : l.value;
|
|
281
|
+
return s ? JSON.parse(s) : [];
|
|
282
|
+
}, j = async (t, e) => {
|
|
283
|
+
const s = "app--2935586817--deal_block", l = [];
|
|
284
|
+
let a = null;
|
|
285
|
+
for (; ; ) {
|
|
286
|
+
const r = await t.query(
|
|
287
|
+
`
|
|
288
|
+
query FetchDealBlockMetaobjects($type: String!, $cursor: String) {
|
|
289
|
+
metaobjects(type: $type, first: 250, after: $cursor) {
|
|
290
|
+
nodes {
|
|
291
|
+
fields {
|
|
292
|
+
key
|
|
293
|
+
value
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
pageInfo {
|
|
297
|
+
hasNextPage
|
|
298
|
+
endCursor
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
`,
|
|
303
|
+
{
|
|
304
|
+
variables: {
|
|
305
|
+
type: s,
|
|
306
|
+
cursor: a
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
for (const c of r.metaobjects.nodes) {
|
|
311
|
+
const n = c.fields.find(
|
|
312
|
+
(m) => m.key === "settings"
|
|
313
|
+
);
|
|
314
|
+
n != null && n.value && l.push(JSON.parse(n.value));
|
|
315
|
+
}
|
|
316
|
+
if (!r.metaobjects.pageInfo.hasNextPage)
|
|
317
|
+
break;
|
|
318
|
+
a = r.metaobjects.pageInfo.endCursor;
|
|
319
|
+
}
|
|
320
|
+
return l;
|
|
321
|
+
}, E = "app--2935586817", U = async (t, {
|
|
322
|
+
language: e,
|
|
323
|
+
country: s,
|
|
324
|
+
useExternalMetafieldNamespace: l
|
|
325
|
+
}) => {
|
|
326
|
+
const a = `${E}--kaching_bundles`, r = E, {
|
|
327
|
+
shop: {
|
|
328
|
+
moneyFormat: c,
|
|
329
|
+
currencyRateConstant: n,
|
|
330
|
+
primaryDomain: m,
|
|
331
|
+
settingsMetafield: p
|
|
332
|
+
}
|
|
333
|
+
} = await t.query(
|
|
334
|
+
`
|
|
335
|
+
query config($metafieldNamespace: String!, $settingsNamespace: String!) {
|
|
336
|
+
shop {
|
|
337
|
+
moneyFormat
|
|
338
|
+
primaryDomain {
|
|
339
|
+
host
|
|
340
|
+
}
|
|
341
|
+
currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
|
|
342
|
+
value
|
|
343
|
+
}
|
|
344
|
+
settingsMetafield: metafield(namespace: $settingsNamespace, key: "config") {
|
|
345
|
+
value
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
`,
|
|
350
|
+
{
|
|
351
|
+
variables: {
|
|
352
|
+
metafieldNamespace: a,
|
|
353
|
+
settingsNamespace: r
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
), u = n ? V(n.value) : 1, i = p ? JSON.parse(p.value) : null, d = (i == null ? void 0 : i.feature_flags) ?? {}, o = (i == null ? void 0 : i.custom_selectors) ?? {};
|
|
357
|
+
return {
|
|
358
|
+
shopifyDomain: m.host,
|
|
359
|
+
moneyFormat: c,
|
|
360
|
+
locale: (e == null ? void 0 : e.toLowerCase()) || "en",
|
|
361
|
+
liquidLocale: (e == null ? void 0 : e.toLowerCase()) || "en",
|
|
362
|
+
country: s ?? "US",
|
|
363
|
+
currencyRate: u,
|
|
364
|
+
marketId: 0,
|
|
365
|
+
productId: null,
|
|
366
|
+
storefrontAccessToken: (i == null ? void 0 : i.storefront_access_token) ?? null,
|
|
367
|
+
accessScopes: (i == null ? void 0 : i.access_scopes) ?? [],
|
|
368
|
+
customApiHost: (i == null ? void 0 : i.custom_api_host) ?? null,
|
|
369
|
+
keepQuantityInput: (i == null ? void 0 : i.keep_quantity_input) ?? !1,
|
|
370
|
+
ignoreDeselect: (i == null ? void 0 : i.ignore_deselect) ?? !1,
|
|
371
|
+
ignoreUnitPrice: (i == null ? void 0 : i.ignore_unit_price) ?? !1,
|
|
372
|
+
requireCustomerLogin: (i == null ? void 0 : i.require_customer_login) ?? !1,
|
|
373
|
+
abTestsRunning: (i == null ? void 0 : i.ab_tests_running) ?? !1,
|
|
374
|
+
webPixel: (i == null ? void 0 : i.web_pixel) ?? !1,
|
|
375
|
+
b2bCustomer: !1,
|
|
376
|
+
isLoggedIn: !1,
|
|
377
|
+
preview: !1,
|
|
378
|
+
previewAlerts: !1,
|
|
379
|
+
defaultTranslations: {
|
|
380
|
+
"system.out_of_stock": "Out of stock",
|
|
381
|
+
"system.invalid_variant": "Invalid variant",
|
|
382
|
+
"system.unavailable_option_value": "Unavailable option value",
|
|
383
|
+
"system.confirm": "Confirm",
|
|
384
|
+
"system.cancel": "Cancel",
|
|
385
|
+
"system.free": "FREE",
|
|
386
|
+
"system.search": "Search",
|
|
387
|
+
"system.sort_by": "Sort by",
|
|
388
|
+
"system.sort_relevance": "Relevance",
|
|
389
|
+
"system.sort_newest_first": "Newest first",
|
|
390
|
+
"system.sort_price_low_to_high": "Price: Low → High",
|
|
391
|
+
"system.sort_price_high_to_low": "Price: High → Low",
|
|
392
|
+
"system.no_results_found": "No results found",
|
|
393
|
+
"system.no_results_description": "We can't find any item matching your search.",
|
|
394
|
+
"system.clear_search": "Clear search",
|
|
395
|
+
"system.no_products_available": "No products available"
|
|
396
|
+
},
|
|
397
|
+
customSelectors: {
|
|
398
|
+
quantity: o.quantity ?? null,
|
|
399
|
+
addToCartButton: o.add_to_cart_button ?? null,
|
|
400
|
+
variantPicker: o.variant_picker ?? null,
|
|
401
|
+
price: o.price ?? null,
|
|
402
|
+
priceCompare: o.price_compare ?? null
|
|
403
|
+
},
|
|
404
|
+
shopCustomStyles: (i == null ? void 0 : i.shop_custom_styles) ?? "",
|
|
405
|
+
featureFlags: d
|
|
406
|
+
};
|
|
407
|
+
}, V = (t) => JSON.parse(t).amount / 1e6, L = async (t, e, s = 200) => (e = e.filter(Boolean).filter((l) => !l.startsWith("placeholder")), e.length === 0 ? [] : (await t.query(
|
|
408
|
+
`
|
|
409
|
+
query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
|
|
410
|
+
nodes(ids: $mediaImageIds) {
|
|
411
|
+
... on MediaImage {
|
|
412
|
+
id
|
|
413
|
+
image {
|
|
414
|
+
url(transform: { maxWidth: $size, maxHeight: $size })
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
`,
|
|
420
|
+
{
|
|
421
|
+
variables: {
|
|
422
|
+
mediaImageIds: e,
|
|
423
|
+
size: s
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
)).nodes.filter(Boolean).map((l) => ({
|
|
427
|
+
gid: l.id,
|
|
428
|
+
url: l.image.url
|
|
429
|
+
}))), w = async (t, {
|
|
430
|
+
country: e,
|
|
431
|
+
language: s,
|
|
432
|
+
blockVisibility: l,
|
|
433
|
+
excludedProductGIDs: a,
|
|
434
|
+
selectedProductGIDs: r,
|
|
435
|
+
selectedCollectionGIDs: c,
|
|
436
|
+
limit: n = 250
|
|
437
|
+
}) => {
|
|
438
|
+
switch (l) {
|
|
439
|
+
case "selected-products":
|
|
440
|
+
return r.slice(0, n);
|
|
441
|
+
case "all-products":
|
|
442
|
+
case "excluded-products": {
|
|
443
|
+
const m = P({ country: e, language: s });
|
|
444
|
+
let p = (await t.query(
|
|
445
|
+
`
|
|
446
|
+
query FetchProductGIDs($limit: Int!) ${m} {
|
|
447
|
+
products(first: $limit) {
|
|
448
|
+
nodes {
|
|
449
|
+
id
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
`,
|
|
454
|
+
{
|
|
455
|
+
variables: {
|
|
456
|
+
limit: n
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
)).products.nodes.map((u) => u.id);
|
|
460
|
+
return l === "excluded-products" && (p = p.filter(
|
|
461
|
+
(u) => !a.includes(u)
|
|
462
|
+
)), p;
|
|
463
|
+
}
|
|
464
|
+
case "selected-collections": {
|
|
465
|
+
const m = P({ country: e, language: s }), p = (await t.query(
|
|
466
|
+
`
|
|
467
|
+
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${m} {
|
|
468
|
+
nodes(ids: $collectionGIDs) {
|
|
469
|
+
... on Collection {
|
|
470
|
+
products(first: $limit) {
|
|
471
|
+
nodes {
|
|
472
|
+
id
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
`,
|
|
479
|
+
{
|
|
480
|
+
variables: {
|
|
481
|
+
collectionGIDs: c,
|
|
482
|
+
limit: n
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
)).nodes.filter((u) => u !== null).flatMap(
|
|
486
|
+
(u) => u.products.nodes.map((i) => i.id)
|
|
487
|
+
);
|
|
488
|
+
return Array.from(new Set(p)).slice(0, n);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}, $ = `
|
|
492
|
+
id
|
|
493
|
+
availableForSale
|
|
494
|
+
price {
|
|
495
|
+
amount
|
|
496
|
+
}
|
|
497
|
+
compareAtPrice {
|
|
498
|
+
amount
|
|
499
|
+
}
|
|
500
|
+
selectedOptions {
|
|
501
|
+
name
|
|
502
|
+
value
|
|
503
|
+
}
|
|
504
|
+
image {
|
|
505
|
+
id
|
|
506
|
+
url(transform: { maxWidth: 200, maxHeight: 200 })
|
|
507
|
+
}
|
|
508
|
+
unitPriceMeasurement {
|
|
509
|
+
quantityUnit
|
|
510
|
+
quantityValue
|
|
511
|
+
referenceUnit
|
|
512
|
+
referenceValue
|
|
513
|
+
}
|
|
514
|
+
requiresComponents
|
|
515
|
+
sellingPlanAllocations(first: 100) @include(if: $includeSellingPlans) {
|
|
516
|
+
nodes {
|
|
517
|
+
sellingPlan {
|
|
518
|
+
id
|
|
519
|
+
}
|
|
520
|
+
priceAdjustments {
|
|
521
|
+
price {
|
|
522
|
+
amount
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
quantityAvailable @include(if: $includeAvailableQuantity)
|
|
528
|
+
`, _ = async (t, {
|
|
529
|
+
country: e,
|
|
530
|
+
language: s,
|
|
531
|
+
productIds: l,
|
|
532
|
+
includeSellingPlans: a = !0,
|
|
533
|
+
includeAvailableQuantity: r = !0,
|
|
534
|
+
useExternalMetafieldNamespace: c = !1
|
|
535
|
+
}) => {
|
|
536
|
+
if (!l.length)
|
|
537
|
+
return [];
|
|
538
|
+
const n = l.map((u) => typeof u == "string" && u.startsWith("gid://") ? u : `gid://shopify/Product/${u}`), m = P({ country: e, language: s });
|
|
539
|
+
let p = (await t.query(
|
|
540
|
+
`
|
|
541
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${m} {
|
|
542
|
+
nodes(ids: $productGIDs) {
|
|
543
|
+
... on Product {
|
|
544
|
+
id
|
|
545
|
+
handle
|
|
546
|
+
onlineStoreUrl
|
|
547
|
+
availableForSale
|
|
548
|
+
createdAt
|
|
549
|
+
title
|
|
550
|
+
featuredImage {
|
|
551
|
+
url
|
|
552
|
+
}
|
|
553
|
+
options {
|
|
554
|
+
name
|
|
555
|
+
optionValues {
|
|
556
|
+
id
|
|
557
|
+
name
|
|
558
|
+
swatch {
|
|
559
|
+
color
|
|
560
|
+
image {
|
|
561
|
+
previewImage {
|
|
562
|
+
url(transform: { maxWidth: 200, maxHeight: 200 })
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
variants(first: 250) {
|
|
569
|
+
nodes {
|
|
570
|
+
${$}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
collections(first: 50) {
|
|
574
|
+
nodes {
|
|
575
|
+
id
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
metafield: metafield(namespace: $metafieldNamespace, key: "text") {
|
|
579
|
+
value
|
|
580
|
+
}
|
|
581
|
+
metafield2: metafield(namespace: $metafieldNamespace, key: "text2") {
|
|
582
|
+
value
|
|
583
|
+
}
|
|
584
|
+
metafield3: metafield(namespace: $metafieldNamespace, key: "text3") {
|
|
585
|
+
value
|
|
586
|
+
}
|
|
587
|
+
metafield4: metafield(namespace: $metafieldNamespace, key: "text4") {
|
|
588
|
+
value
|
|
589
|
+
}
|
|
590
|
+
requiresSellingPlan
|
|
591
|
+
sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
|
|
592
|
+
nodes {
|
|
593
|
+
sellingPlans(first: 100) {
|
|
594
|
+
nodes {
|
|
595
|
+
id
|
|
596
|
+
name
|
|
597
|
+
priceAdjustments {
|
|
598
|
+
adjustmentValue {
|
|
599
|
+
__typename
|
|
600
|
+
... on SellingPlanPercentagePriceAdjustment {
|
|
601
|
+
adjustmentPercentage
|
|
602
|
+
}
|
|
603
|
+
... on SellingPlanFixedAmountPriceAdjustment {
|
|
604
|
+
adjustmentAmount {
|
|
605
|
+
amount
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
... on SellingPlanFixedPriceAdjustment {
|
|
609
|
+
price {
|
|
610
|
+
amount
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
`,
|
|
623
|
+
{
|
|
624
|
+
variables: {
|
|
625
|
+
productGIDs: n,
|
|
626
|
+
includeSellingPlans: a,
|
|
627
|
+
includeAvailableQuantity: r,
|
|
628
|
+
metafieldNamespace: c ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles"
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
)).nodes.filter(
|
|
632
|
+
(u) => u != null
|
|
633
|
+
);
|
|
634
|
+
return p = await Promise.all(
|
|
635
|
+
p.map(
|
|
636
|
+
(u) => F(t, u, {
|
|
637
|
+
includeSellingPlans: a,
|
|
638
|
+
includeAvailableQuantity: r
|
|
639
|
+
})
|
|
640
|
+
)
|
|
641
|
+
), p.map(R);
|
|
642
|
+
}, F = async (t, e, s) => {
|
|
643
|
+
if (e.variants.nodes.length < 250)
|
|
644
|
+
return e;
|
|
645
|
+
const l = /* @__PURE__ */ new Set(), a = [], r = [], c = async (n) => {
|
|
646
|
+
let m = !0, p = null;
|
|
647
|
+
for (; m; ) {
|
|
648
|
+
const u = await t.query(
|
|
649
|
+
`
|
|
650
|
+
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!) {
|
|
651
|
+
product(id: $productGID) {
|
|
652
|
+
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
653
|
+
nodes {
|
|
654
|
+
${$}
|
|
655
|
+
}
|
|
656
|
+
pageInfo {
|
|
657
|
+
endCursor
|
|
658
|
+
hasNextPage
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
`,
|
|
664
|
+
{
|
|
665
|
+
variables: {
|
|
666
|
+
productGID: e.id,
|
|
667
|
+
cursor: p,
|
|
668
|
+
reverse: n,
|
|
669
|
+
...s
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
), { nodes: i, pageInfo: d } = u.product.variants;
|
|
673
|
+
for (const o of i) {
|
|
674
|
+
if (l.has(o.id)) {
|
|
675
|
+
m = !1;
|
|
676
|
+
break;
|
|
677
|
+
}
|
|
678
|
+
l.add(o.id), n ? r.push(o) : a.push(o);
|
|
679
|
+
}
|
|
680
|
+
d.hasNextPage || (m = !1), p = d.endCursor;
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
return await Promise.all([
|
|
684
|
+
c(!1),
|
|
685
|
+
c(!0)
|
|
686
|
+
]), e.variants.nodes = [...a, ...r.reverse()], e;
|
|
687
|
+
}, R = (t) => {
|
|
688
|
+
var c, n, m, p, u, i;
|
|
689
|
+
const e = t.variants.nodes.map(
|
|
690
|
+
({ unitPriceMeasurement: d, ...o }) => {
|
|
691
|
+
var h, f;
|
|
692
|
+
return {
|
|
693
|
+
id: Number(o.id.split("/").pop()),
|
|
694
|
+
availableForSale: o.availableForSale,
|
|
695
|
+
price: Math.round(Number(o.price.amount) * 100),
|
|
696
|
+
compareAtPrice: o.compareAtPrice ? Math.round(Number(o.compareAtPrice.amount) * 100) : null,
|
|
697
|
+
options: o.selectedOptions.map((g) => g.value),
|
|
698
|
+
imageId: o.image ? Number(o.image.id.split("/").pop()) : null,
|
|
699
|
+
image: ((h = o.image) == null ? void 0 : h.url) || null,
|
|
700
|
+
sellingPlans: ((f = o.sellingPlanAllocations) == null ? void 0 : f.nodes.map((g) => ({
|
|
701
|
+
id: Number(g.sellingPlan.id.split("/").pop()),
|
|
702
|
+
price: g.priceAdjustments.length > 0 ? Math.round(Number(g.priceAdjustments[0].price.amount) * 100) : Math.round(Number(o.price.amount) * 100)
|
|
703
|
+
}))) || [],
|
|
704
|
+
inventoryManagement: null,
|
|
705
|
+
// Storefront API does not return inventory management, only available in liquid
|
|
706
|
+
inventoryPolicy: null,
|
|
707
|
+
// Storefront API does not return inventory policy, only available in liquid
|
|
708
|
+
inventoryQuantity: o.quantityAvailable ?? null,
|
|
709
|
+
unitPriceMeasurement: d != null && d.quantityUnit && (d != null && d.referenceUnit) ? {
|
|
710
|
+
quantityValue: d.quantityValue,
|
|
711
|
+
quantityUnit: d.quantityUnit.toLowerCase(),
|
|
712
|
+
referenceValue: d.referenceValue,
|
|
713
|
+
referenceUnit: d.referenceUnit.toLowerCase()
|
|
714
|
+
} : null
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
), s = t.options.map((d, o) => {
|
|
718
|
+
const h = d.optionValues.map((f) => {
|
|
719
|
+
var g, b, y, v;
|
|
720
|
+
return {
|
|
721
|
+
id: Number(f.id.split("/").pop()),
|
|
722
|
+
defaultName: f.name,
|
|
723
|
+
name: f.name,
|
|
724
|
+
swatch: {
|
|
725
|
+
color: ((g = f.swatch) == null ? void 0 : g.color) || null,
|
|
726
|
+
image: ((v = (y = (b = f.swatch) == null ? void 0 : b.image) == null ? void 0 : y.previewImage) == null ? void 0 : v.url) || null
|
|
727
|
+
}
|
|
728
|
+
};
|
|
729
|
+
});
|
|
730
|
+
return {
|
|
731
|
+
defaultName: d.name,
|
|
732
|
+
name: d.name,
|
|
733
|
+
position: o + 1,
|
|
734
|
+
optionValues: z(h, o, e)
|
|
735
|
+
};
|
|
736
|
+
}), l = (d) => {
|
|
737
|
+
const o = d.priceAdjustments[0];
|
|
738
|
+
if (!o)
|
|
739
|
+
return null;
|
|
740
|
+
const h = o.adjustmentValue;
|
|
741
|
+
switch (h.__typename) {
|
|
742
|
+
case "SellingPlanPercentagePriceAdjustment":
|
|
743
|
+
return {
|
|
744
|
+
type: "percentage",
|
|
745
|
+
value: h.adjustmentPercentage
|
|
746
|
+
};
|
|
747
|
+
case "SellingPlanFixedAmountPriceAdjustment":
|
|
748
|
+
return {
|
|
749
|
+
type: "fixed_amount",
|
|
750
|
+
value: Number(h.adjustmentAmount.amount) * 100
|
|
751
|
+
};
|
|
752
|
+
case "SellingPlanFixedPriceAdjustment":
|
|
753
|
+
return {
|
|
754
|
+
type: "price",
|
|
755
|
+
value: Number(h.price.amount) * 100
|
|
756
|
+
};
|
|
757
|
+
default:
|
|
758
|
+
throw new Error(
|
|
759
|
+
`Unknown price adjustment type: ${h.__typename}`
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
}, a = ((c = t.sellingPlanGroups) == null ? void 0 : c.nodes.flatMap(
|
|
763
|
+
(d) => d.sellingPlans.nodes.map((o) => ({
|
|
764
|
+
id: Number(o.id.split("/").pop()),
|
|
765
|
+
name: o.name,
|
|
766
|
+
priceAdjustment: l(o)
|
|
767
|
+
}))
|
|
768
|
+
)) || [], r = t.variants.nodes.some(
|
|
769
|
+
(d) => d.requiresComponents
|
|
770
|
+
);
|
|
771
|
+
return {
|
|
772
|
+
id: Number(t.id.split("/").pop()),
|
|
773
|
+
handle: t.handle,
|
|
774
|
+
url: t.onlineStoreUrl,
|
|
775
|
+
availableForSale: t.availableForSale,
|
|
776
|
+
createdAt: t.createdAt,
|
|
777
|
+
title: t.title,
|
|
778
|
+
image: ((n = t.featuredImage) == null ? void 0 : n.url) || null,
|
|
779
|
+
collectionIds: t.collections.nodes.map(
|
|
780
|
+
(d) => Number(d.id.split("/").pop())
|
|
781
|
+
),
|
|
782
|
+
options: s,
|
|
783
|
+
selectedVariantId: Number(
|
|
784
|
+
t.variants.nodes[0].id.split("/").pop()
|
|
785
|
+
),
|
|
786
|
+
variants: e,
|
|
787
|
+
requiresSellingPlan: t.requiresSellingPlan,
|
|
788
|
+
sellingPlans: a,
|
|
789
|
+
isNativeBundle: r,
|
|
790
|
+
metafields: {
|
|
791
|
+
text: ((m = t.metafield) == null ? void 0 : m.value) || null,
|
|
792
|
+
text2: ((p = t.metafield2) == null ? void 0 : p.value) || null,
|
|
793
|
+
text3: ((u = t.metafield3) == null ? void 0 : u.value) || null,
|
|
794
|
+
text4: ((i = t.metafield4) == null ? void 0 : i.value) || null
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
}, z = (t, e, s) => t.filter((l) => s.filter(
|
|
798
|
+
(a) => a.options[e] === l.name
|
|
799
|
+
).length > 0), H = (t, e) => {
|
|
800
|
+
const s = [], l = t.filter(
|
|
801
|
+
(n) => n.blockVisibility === "selected-products"
|
|
802
|
+
);
|
|
803
|
+
for (const n of l)
|
|
804
|
+
n.selectedProductIds.map(Number).includes(e.id) && s.push(n);
|
|
805
|
+
const a = t.filter(
|
|
806
|
+
(n) => n.blockVisibility === "selected-collections"
|
|
807
|
+
);
|
|
808
|
+
for (const n of a)
|
|
809
|
+
e.collectionIds.some(
|
|
810
|
+
(m) => n.selectedCollectionIds.map(Number).includes(m)
|
|
811
|
+
) && s.push(n);
|
|
812
|
+
const r = t.filter(
|
|
813
|
+
(n) => n.blockVisibility === "excluded-products"
|
|
814
|
+
);
|
|
815
|
+
for (const n of r)
|
|
816
|
+
!n.excludedProductIds.map(Number).includes(e.id) && !(n.excludedCollectionIds || []).some(
|
|
817
|
+
(m) => e.collectionIds.includes(m)
|
|
818
|
+
) && s.push(n);
|
|
819
|
+
const c = t.filter(
|
|
820
|
+
(n) => n.blockVisibility === "all-products"
|
|
821
|
+
);
|
|
822
|
+
for (const n of c)
|
|
823
|
+
s.push(n);
|
|
824
|
+
return s;
|
|
825
|
+
}, J = (t) => [
|
|
826
|
+
...Q(t),
|
|
827
|
+
...W(t),
|
|
828
|
+
...X(t),
|
|
829
|
+
...K(t),
|
|
830
|
+
...Y(t),
|
|
831
|
+
...Z(t),
|
|
832
|
+
...ee(t),
|
|
833
|
+
...te(t),
|
|
834
|
+
...se(t),
|
|
835
|
+
...le(t)
|
|
836
|
+
].filter((e) => e != null && !e.includes("placeholder")), Q = (t) => t.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), W = (t) => t.dealBars.map(
|
|
837
|
+
({ freeGifts: e }) => (e || []).map((s) => s.mediaImageGID)
|
|
838
|
+
).reduce((e, s) => e.concat(s), []).filter((e) => e != null), X = (t) => t.dealBars.flatMap(
|
|
839
|
+
({ multipleGiftsSelectors: e }) => (e || []).map((s) => s.mediaImageGID)
|
|
840
|
+
).filter((e) => e != null), K = (t) => t.dealBars.map(({ upsells: e }) => (e || []).map((s) => s.mediaImageGID)).reduce((e, s) => e.concat(s), []).filter((e) => e != null), Y = (t) => t.swatchOptions ? t.swatchOptions.reduce((e, s) => {
|
|
841
|
+
const l = s.images.map((a) => a.mediaImageGID).filter((a) => a != null);
|
|
842
|
+
return [...e, ...l];
|
|
843
|
+
}, []) : [], Z = (t) => {
|
|
844
|
+
if (!t.collectionBreaksEnabled || !t.collectionBreaks)
|
|
845
|
+
return [];
|
|
846
|
+
const e = t.collectionBreaks.mediaImageGID;
|
|
847
|
+
return e ? [e] : [];
|
|
848
|
+
}, ee = (t) => {
|
|
849
|
+
var e, s, l;
|
|
850
|
+
return t.progressiveGifts ? [
|
|
851
|
+
...((e = t.progressiveGifts.gifts) == null ? void 0 : e.map((a) => a.mediaImageGID)) || [],
|
|
852
|
+
(s = t.progressiveGifts.style) == null ? void 0 : s.lockedMediaImageGID,
|
|
853
|
+
(l = t.progressiveGifts.dealBarStyle) == null ? void 0 : l.lockedMediaImageGID
|
|
854
|
+
].filter((a) => a != null) : [];
|
|
855
|
+
}, te = (t) => !t.checkboxUpsellsEnabled || !t.checkboxUpsells ? [] : t.checkboxUpsells.upsells.map((e) => e.mediaImageGID).filter((e) => e != null), se = (t) => t.dealBars.map((e) => {
|
|
856
|
+
var s;
|
|
857
|
+
return (s = e.productPersonalisation) == null ? void 0 : s.mediaImageGID;
|
|
858
|
+
}).filter((e) => e != null), le = (t) => t.dealBars.map((e) => {
|
|
859
|
+
var s;
|
|
860
|
+
return (s = e.highlights) == null ? void 0 : s.customIconGID;
|
|
861
|
+
}).filter((e) => e != null), ne = (t) => {
|
|
862
|
+
const e = [
|
|
863
|
+
...ae(t),
|
|
864
|
+
...ie(t),
|
|
865
|
+
...re(t),
|
|
866
|
+
...oe(t),
|
|
867
|
+
...ce(t),
|
|
868
|
+
...ue(t),
|
|
869
|
+
...de(t)
|
|
870
|
+
];
|
|
871
|
+
return Array.from(new Set(e.filter((s) => s != null)));
|
|
872
|
+
}, ae = (t) => t.dealBars.flatMap(
|
|
873
|
+
({ freeGifts: e }) => e ? e.map((s) => s.productGID) : []
|
|
874
|
+
).filter((e) => e != null), ie = (t) => t.dealBars.flatMap(
|
|
875
|
+
({ multipleGiftsSelectors: e }) => e ? e.flatMap(
|
|
876
|
+
(s) => s.products ? s.products.map((l) => l.id) : []
|
|
877
|
+
) : []
|
|
878
|
+
).filter((e) => e != null), re = (t) => {
|
|
879
|
+
var e;
|
|
880
|
+
return t.progressiveGiftsEnabled ? ((e = t.progressiveGifts) == null ? void 0 : e.gifts.map((s) => s.productGID).filter((s) => s != null)) || [] : [];
|
|
881
|
+
}, oe = (t) => t.dealBars.flatMap(({ upsells: e }) => e ? e.map((s) => s.productGID) : []).filter((e) => e != null), ce = (t) => t.dealBars.filter((e) => e.dealBarType === "bundle").flatMap(
|
|
882
|
+
({ bundleProducts: e }) => e ? e.map((s) => s.productGID) : []
|
|
883
|
+
).filter((e) => e != null).filter((e) => e !== "default"), ue = (t) => !t.checkboxUpsellsEnabled || !t.checkboxUpsells ? [] : t.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), de = (t) => t.dealBars.filter((e) => e.dealBarType === "sku").flatMap(({ productGID: e }) => e ? [e] : []);
|
|
884
|
+
class me {
|
|
885
|
+
constructor(e, s) {
|
|
886
|
+
this.storefrontApiVersion = "2025-10", this.storefrontAccessToken = s, this.shopifyDomain = e;
|
|
887
|
+
}
|
|
888
|
+
async query(e, s) {
|
|
889
|
+
var n;
|
|
890
|
+
const l = (s == null ? void 0 : s.variables) ?? {};
|
|
891
|
+
let a = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;
|
|
892
|
+
const r = (n = e.match(/query\s+(\w+)/)) == null ? void 0 : n[1];
|
|
893
|
+
r && (a += `?operation_name=${r}`);
|
|
894
|
+
const c = await (await fetch(a, {
|
|
895
|
+
method: "POST",
|
|
896
|
+
headers: {
|
|
897
|
+
"Content-Type": "application/json",
|
|
898
|
+
"X-Shopify-Storefront-Access-Token": this.storefrontAccessToken
|
|
899
|
+
},
|
|
900
|
+
body: JSON.stringify({
|
|
901
|
+
query: e,
|
|
902
|
+
variables: l
|
|
903
|
+
})
|
|
904
|
+
})).text();
|
|
905
|
+
if (!c)
|
|
906
|
+
throw new Error("Empty graphql response");
|
|
907
|
+
return JSON.parse(c).data;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
const pe = async (t, e, { country: s, language: l }) => {
|
|
911
|
+
const a = e.collectionBreaks;
|
|
912
|
+
if (!e.collectionBreaksEnabled || !a) return;
|
|
913
|
+
let r;
|
|
914
|
+
a.visibility === "deal-products" ? r = await w(t, {
|
|
915
|
+
country: s,
|
|
916
|
+
language: l,
|
|
917
|
+
blockVisibility: e.blockVisibility,
|
|
918
|
+
excludedProductGIDs: (e.excludedProductIds || []).map(
|
|
919
|
+
(n) => `gid://shopify/Product/${n}`
|
|
920
|
+
),
|
|
921
|
+
selectedProductGIDs: (e.selectedProductIds || []).map(
|
|
922
|
+
(n) => `gid://shopify/Product/${n}`
|
|
923
|
+
),
|
|
924
|
+
selectedCollectionGIDs: (e.selectedCollectionIds || []).map(
|
|
925
|
+
(n) => `gid://shopify/Collection/${n}`
|
|
926
|
+
)
|
|
927
|
+
}) : r = await w(t, {
|
|
928
|
+
country: s,
|
|
929
|
+
language: l,
|
|
930
|
+
blockVisibility: a.visibility,
|
|
931
|
+
excludedProductGIDs: (a.excludedProducts || []).map(
|
|
932
|
+
({ id: n }) => n
|
|
933
|
+
),
|
|
934
|
+
selectedProductGIDs: (a.selectedProducts || []).map(
|
|
935
|
+
({ id: n }) => n
|
|
936
|
+
),
|
|
937
|
+
selectedCollectionGIDs: (a.selectedCollections || []).map(
|
|
938
|
+
({ id: n }) => n
|
|
939
|
+
)
|
|
940
|
+
}), r = r.slice(0, 250);
|
|
941
|
+
let c = await _(t, {
|
|
942
|
+
country: s,
|
|
943
|
+
language: l,
|
|
944
|
+
productIds: r.map((n) => Number(n.split("/").pop())),
|
|
945
|
+
useExternalMetafieldNamespace: !0
|
|
946
|
+
});
|
|
947
|
+
return c = c.filter(
|
|
948
|
+
(n) => n.availableForSale
|
|
949
|
+
), c;
|
|
950
|
+
}, fe = () => ({
|
|
951
|
+
"system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
|
|
952
|
+
"system.invalid_variant": "Sorry, this is not currently available.",
|
|
953
|
+
"system.unavailable_option_value": "Unavailable",
|
|
954
|
+
"system.confirm": "Confirm",
|
|
955
|
+
"system.cancel": "Cancel",
|
|
956
|
+
"system.free": "FREE",
|
|
957
|
+
"system.search": "Search",
|
|
958
|
+
"system.sort_by": "Sort by",
|
|
959
|
+
"system.sort_relevance": "Relevance",
|
|
960
|
+
"system.sort_newest_first": "Newest first",
|
|
961
|
+
"system.sort_price_low_to_high": "Price: Low → High",
|
|
962
|
+
"system.sort_price_high_to_low": "Price: High → Low",
|
|
963
|
+
"system.no_results_found": "No results found",
|
|
964
|
+
"system.no_results_description": "We can't find any item matching your search.",
|
|
965
|
+
"system.clear_search": "Clear search",
|
|
966
|
+
"system.no_products_available": "No products available"
|
|
967
|
+
}), he = "2025-10", ge = async (t, {
|
|
968
|
+
productId: e,
|
|
969
|
+
dealBlockId: s,
|
|
970
|
+
country: l = void 0,
|
|
971
|
+
language: a = void 0
|
|
972
|
+
}) => {
|
|
973
|
+
var r, c;
|
|
974
|
+
try {
|
|
975
|
+
const n = [Number(e.split("/").pop())], m = new be(t);
|
|
976
|
+
l = l || ((r = m.i18n) == null ? void 0 : r.country), a = a || ((c = m.i18n) == null ? void 0 : c.language);
|
|
977
|
+
const p = await U(m, {
|
|
978
|
+
language: a,
|
|
979
|
+
country: l,
|
|
980
|
+
useExternalMetafieldNamespace: !0
|
|
981
|
+
}), u = p.storefrontAccessToken ? new me(
|
|
982
|
+
p.shopifyDomain,
|
|
983
|
+
p.storefrontAccessToken
|
|
984
|
+
) : m, [i, d] = await Promise.all([
|
|
985
|
+
_(u, {
|
|
986
|
+
country: l,
|
|
987
|
+
language: a,
|
|
988
|
+
productIds: n,
|
|
989
|
+
useExternalMetafieldNamespace: !0
|
|
990
|
+
}),
|
|
991
|
+
M(u, {
|
|
992
|
+
useExternalMetafieldNamespace: !0,
|
|
993
|
+
useMetaobjects: p.featureFlags.storefront_metaobjects
|
|
994
|
+
})
|
|
995
|
+
]), o = i[0];
|
|
996
|
+
if (!o)
|
|
997
|
+
return null;
|
|
998
|
+
const h = H(d, o);
|
|
999
|
+
let f;
|
|
1000
|
+
if (s ? (f = h.find(
|
|
1001
|
+
(k) => k.id === s || k.nanoId === s
|
|
1002
|
+
), f || (f = h[0])) : f = h[0], !f)
|
|
1003
|
+
return null;
|
|
1004
|
+
const g = J(f), b = ne(f), [y, v, x, C] = await Promise.all([
|
|
1005
|
+
_(u, {
|
|
1006
|
+
country: l,
|
|
1007
|
+
language: a,
|
|
1008
|
+
productIds: b,
|
|
1009
|
+
useExternalMetafieldNamespace: !0
|
|
1010
|
+
}),
|
|
1011
|
+
L(u, g, 300),
|
|
1012
|
+
pe(u, f, {
|
|
1013
|
+
country: l,
|
|
1014
|
+
language: a
|
|
1015
|
+
}),
|
|
1016
|
+
fe()
|
|
1017
|
+
]);
|
|
1018
|
+
return {
|
|
1019
|
+
product: o,
|
|
1020
|
+
dealBlock: f,
|
|
1021
|
+
config: p,
|
|
1022
|
+
otherProducts: y,
|
|
1023
|
+
mediaImages: v,
|
|
1024
|
+
collectionBreaksProducts: x ?? [],
|
|
1025
|
+
translations: C
|
|
1026
|
+
};
|
|
1027
|
+
} catch (n) {
|
|
1028
|
+
return console.error(n), null;
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
class be {
|
|
1032
|
+
constructor(e) {
|
|
1033
|
+
this.storefront = e;
|
|
1034
|
+
}
|
|
1035
|
+
async query(e, s) {
|
|
1036
|
+
if ("query" in this.storefront && "i18n" in this.storefront)
|
|
1037
|
+
return await this.storefront.query(e, s);
|
|
1038
|
+
if ("request" in this.storefront)
|
|
1039
|
+
return (await this.storefront.request(e, s)).data;
|
|
1040
|
+
if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
|
|
1041
|
+
const l = await fetch(
|
|
1042
|
+
`https://${this.storefront.shopifyDomain}/api/${he}/graphql.json`,
|
|
1043
|
+
{
|
|
1044
|
+
body: JSON.stringify({
|
|
1045
|
+
query: e,
|
|
1046
|
+
variables: s == null ? void 0 : s.variables
|
|
1047
|
+
}),
|
|
1048
|
+
headers: {
|
|
1049
|
+
"Content-Type": "application/json",
|
|
1050
|
+
"X-Shopify-Storefront-Access-Token": this.storefront.storefrontAccessToken
|
|
1051
|
+
},
|
|
1052
|
+
method: "POST"
|
|
1053
|
+
}
|
|
1054
|
+
);
|
|
1055
|
+
if (!l.ok)
|
|
1056
|
+
throw new Error(l.statusText);
|
|
1057
|
+
return (await l.json()).data;
|
|
1058
|
+
} else {
|
|
1059
|
+
const l = await fetch(this.storefront.getStorefrontApiUrl(), {
|
|
1060
|
+
body: JSON.stringify({
|
|
1061
|
+
query: e,
|
|
1062
|
+
variables: s == null ? void 0 : s.variables
|
|
1063
|
+
}),
|
|
1064
|
+
headers: this.storefront.getPublicTokenHeaders(),
|
|
1065
|
+
method: "POST"
|
|
1066
|
+
});
|
|
1067
|
+
if (!l.ok)
|
|
1068
|
+
throw new Error(l.statusText);
|
|
1069
|
+
return (await l.json()).data;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
get i18n() {
|
|
1073
|
+
if ("i18n" in this.storefront)
|
|
1074
|
+
return this.storefront.i18n;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
const S = "kaching-bundles-block", A = 1e4, ye = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", ve = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", I = /* @__PURE__ */ new WeakSet(), D = async (t) => {
|
|
1078
|
+
const e = t.document;
|
|
1079
|
+
if (!t.customElements.get(S)) {
|
|
1080
|
+
if (I.has(e))
|
|
1081
|
+
return N(t, S);
|
|
1082
|
+
I.add(e);
|
|
1083
|
+
try {
|
|
1084
|
+
await _e(t);
|
|
1085
|
+
} catch (s) {
|
|
1086
|
+
throw I.delete(e), s;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}, Ie = () => typeof window < "u" && typeof window.__KACHING_DEV__ < "u", Pe = () => Ie() ? ye : ve, _e = (t) => {
|
|
1090
|
+
const e = t.document;
|
|
1091
|
+
return new Promise((s, l) => {
|
|
1092
|
+
const a = Pe();
|
|
1093
|
+
if (e.querySelector(
|
|
1094
|
+
`script[src="${a}"]`
|
|
1095
|
+
)) {
|
|
1096
|
+
s();
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
const c = e.createElement("script");
|
|
1100
|
+
c.src = a, c.onload = () => N(t, S).then(s).catch(l), c.onerror = () => l(new Error("Failed to load script")), e.head.appendChild(c);
|
|
1101
|
+
});
|
|
1102
|
+
}, N = (t, e) => new Promise((s, l) => {
|
|
1103
|
+
if (t.customElements.get(e)) {
|
|
1104
|
+
s();
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
Promise.race([
|
|
1108
|
+
t.customElements.whenDefined(e),
|
|
1109
|
+
new Promise(
|
|
1110
|
+
(a, r) => setTimeout(
|
|
1111
|
+
() => r(
|
|
1112
|
+
new Error(
|
|
1113
|
+
`Custom element "${e}" failed to register within ${A}ms`
|
|
1114
|
+
)
|
|
1115
|
+
),
|
|
1116
|
+
A
|
|
1117
|
+
)
|
|
1118
|
+
)
|
|
1119
|
+
]).then(() => s()).catch(l);
|
|
1120
|
+
});
|
|
1121
|
+
class Se extends HTMLElement {
|
|
1122
|
+
constructor() {
|
|
1123
|
+
super(...arguments), this.innerElement = null, this.handleItemsChanged = null, this.currentProductId = null;
|
|
1124
|
+
}
|
|
1125
|
+
static get observedAttributes() {
|
|
1126
|
+
return ["selected-variant-id", "product-id"];
|
|
1127
|
+
}
|
|
1128
|
+
async connectedCallback() {
|
|
1129
|
+
await this.initialize();
|
|
1130
|
+
}
|
|
1131
|
+
async initialize() {
|
|
1132
|
+
var r, c;
|
|
1133
|
+
if (this.hasAttribute("demo")) {
|
|
1134
|
+
this.cleanup(), await D(window), this.renderInnerElement(q);
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
const e = this.getAttribute("shop-domain"), s = this.getAttribute("storefront-token"), l = this.getAttribute("product-id");
|
|
1138
|
+
if (!e || !s || !l || l === this.currentProductId) return;
|
|
1139
|
+
this.currentProductId = l, this.cleanup();
|
|
1140
|
+
const [a] = await Promise.all([
|
|
1141
|
+
ge(
|
|
1142
|
+
{
|
|
1143
|
+
shopifyDomain: e,
|
|
1144
|
+
storefrontAccessToken: s
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
productId: l,
|
|
1148
|
+
dealBlockId: this.getAttribute("deal-block-id") ?? void 0,
|
|
1149
|
+
country: ((r = this.getAttribute("country")) == null ? void 0 : r.toUpperCase()) ?? void 0,
|
|
1150
|
+
language: ((c = this.getAttribute("language")) == null ? void 0 : c.toUpperCase()) ?? void 0
|
|
1151
|
+
}
|
|
1152
|
+
),
|
|
1153
|
+
D(window)
|
|
1154
|
+
]);
|
|
1155
|
+
!a || l !== this.currentProductId || this.renderInnerElement(a);
|
|
1156
|
+
}
|
|
1157
|
+
renderInnerElement(e) {
|
|
1158
|
+
const {
|
|
1159
|
+
config: s,
|
|
1160
|
+
dealBlock: l,
|
|
1161
|
+
product: a,
|
|
1162
|
+
otherProducts: r,
|
|
1163
|
+
mediaImages: c,
|
|
1164
|
+
collectionBreaksProducts: n,
|
|
1165
|
+
translations: m
|
|
1166
|
+
} = e;
|
|
1167
|
+
this.innerElement = document.createElement(
|
|
1168
|
+
"kaching-bundles-block"
|
|
1169
|
+
), this.innerElement.setAttribute("deal-block-id", l.id), this.innerElement.setAttribute("config", JSON.stringify(s)), this.innerElement.setAttribute("deal-block", JSON.stringify(l)), this.innerElement.setAttribute(
|
|
1170
|
+
"media-images",
|
|
1171
|
+
JSON.stringify(c ?? [])
|
|
1172
|
+
), this.innerElement.setAttribute("product", JSON.stringify(a)), this.innerElement.setAttribute(
|
|
1173
|
+
"other-products",
|
|
1174
|
+
JSON.stringify(r ?? [])
|
|
1175
|
+
), this.innerElement.setAttribute(
|
|
1176
|
+
"collection-breaks-products",
|
|
1177
|
+
JSON.stringify(n ?? [])
|
|
1178
|
+
), this.innerElement.setAttribute(
|
|
1179
|
+
"translations",
|
|
1180
|
+
JSON.stringify(m ?? {})
|
|
1181
|
+
);
|
|
1182
|
+
const p = this.getAttribute("selected-variant-id");
|
|
1183
|
+
this.innerElement.setAttribute(
|
|
1184
|
+
"current-variant-id",
|
|
1185
|
+
String(p ? p.split("/").pop() : a.variants[0].id)
|
|
1186
|
+
), this.appendChild(this.innerElement);
|
|
1187
|
+
const u = () => {
|
|
1188
|
+
const i = this.innerElement.items();
|
|
1189
|
+
i && this.dispatchEvent(
|
|
1190
|
+
new CustomEvent("items-changed", {
|
|
1191
|
+
detail: { items: i },
|
|
1192
|
+
bubbles: !0
|
|
1193
|
+
})
|
|
1194
|
+
);
|
|
1195
|
+
};
|
|
1196
|
+
this.handleItemsChanged = (i) => {
|
|
1197
|
+
i.stopPropagation(), u();
|
|
1198
|
+
}, this.innerElement.addEventListener(
|
|
1199
|
+
"kaching-bundles-block-loaded",
|
|
1200
|
+
() => {
|
|
1201
|
+
this.innerElement.addEventListener(
|
|
1202
|
+
"items-changed",
|
|
1203
|
+
this.handleItemsChanged
|
|
1204
|
+
), u(), this.dispatchEvent(new CustomEvent("loaded", { bubbles: !0 }));
|
|
1205
|
+
},
|
|
1206
|
+
{ once: !0 }
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
cleanup() {
|
|
1210
|
+
this.handleItemsChanged && this.innerElement && (this.innerElement.removeEventListener(
|
|
1211
|
+
"items-changed",
|
|
1212
|
+
this.handleItemsChanged
|
|
1213
|
+
), this.handleItemsChanged = null), this.innerElement && (this.innerElement.remove(), this.innerElement = null);
|
|
1214
|
+
}
|
|
1215
|
+
attributeChangedCallback(e, s, l) {
|
|
1216
|
+
s !== l && (e === "product-id" ? this.initialize() : e === "selected-variant-id" && this.innerElement && l && this.innerElement.setAttribute(
|
|
1217
|
+
"current-variant-id",
|
|
1218
|
+
l.includes("/") ? String(l.split("/").pop()) : l
|
|
1219
|
+
));
|
|
1220
|
+
}
|
|
1221
|
+
items() {
|
|
1222
|
+
return this.innerElement ? this.innerElement.items() : [];
|
|
1223
|
+
}
|
|
1224
|
+
disconnectedCallback() {
|
|
1225
|
+
this.cleanup(), this.currentProductId = null;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
customElements.define("kaching-bundle-component", Se);
|