@jay-framework/wix-stores-v1 0.22.2 → 0.24.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/package.json +14 -14
- package/dist/actions/get-collections.jay-action +0 -12
- package/dist/actions/get-product-by-slug.jay-action +0 -10
- package/dist/actions/search-products.jay-action +0 -32
- package/dist/contracts/category-list.jay-contract +0 -56
- package/dist/contracts/category-list.jay-contract.d.ts +0 -41
- package/dist/contracts/category-page.jay-contract +0 -204
- package/dist/contracts/category-page.jay-contract.d.ts +0 -131
- package/dist/contracts/media-gallery.jay-contract +0 -22
- package/dist/contracts/media-gallery.jay-contract.d.ts +0 -53
- package/dist/contracts/media.jay-contract +0 -4
- package/dist/contracts/media.jay-contract.d.ts +0 -24
- package/dist/contracts/product-card.jay-contract +0 -179
- package/dist/contracts/product-card.jay-contract.d.ts +0 -119
- package/dist/contracts/product-options.jay-contract +0 -66
- package/dist/contracts/product-options.jay-contract.d.ts +0 -57
- package/dist/contracts/product-page.jay-contract +0 -153
- package/dist/contracts/product-page.jay-contract.d.ts +0 -224
- package/dist/contracts/product-search.jay-contract +0 -240
- package/dist/contracts/product-search.jay-contract.d.ts +0 -165
- package/dist/index.client.js +0 -860
- package/dist/index.d.ts +0 -920
- package/dist/index.js +0 -976
package/dist/index.js
DELETED
|
@@ -1,976 +0,0 @@
|
|
|
1
|
-
import { WIX_CART_CONTEXT, WIX_CART_SERVICE, cartIndicator, cartPage, provideWixCartContext, provideWixCartService } from "@jay-framework/wix-cart";
|
|
2
|
-
import { createJayService, makeJayQuery, ActionError, makeJayStackComponent, RenderPipeline, makeJayInit } from "@jay-framework/fullstack-component";
|
|
3
|
-
import { registerService, getService } from "@jay-framework/stack-server-runtime";
|
|
4
|
-
import { createJayContext } from "@jay-framework/runtime";
|
|
5
|
-
import "@jay-framework/component";
|
|
6
|
-
import { wixFetch, WIX_CLIENT_SERVICE } from "@jay-framework/wix-server-client";
|
|
7
|
-
const WIX_STORES_V1_SERVICE_MARKER = createJayService("Wix Store V1 Service");
|
|
8
|
-
function provideWixStoresV1Service(wixClient) {
|
|
9
|
-
const service = { wixClient };
|
|
10
|
-
registerService(WIX_STORES_V1_SERVICE_MARKER, service);
|
|
11
|
-
return service;
|
|
12
|
-
}
|
|
13
|
-
function normalizeProduct(product) {
|
|
14
|
-
const p = { ...product };
|
|
15
|
-
const raw = product;
|
|
16
|
-
if (raw.id && !p._id) {
|
|
17
|
-
p._id = raw.id;
|
|
18
|
-
}
|
|
19
|
-
return p;
|
|
20
|
-
}
|
|
21
|
-
async function queryProducts(client, request) {
|
|
22
|
-
const query = {};
|
|
23
|
-
if (request?.filter) query.filter = JSON.stringify(request.filter);
|
|
24
|
-
if (request?.sort) {
|
|
25
|
-
const v1Sort = request.sort.map((s) => ({
|
|
26
|
-
[s.fieldName]: (s.order || "ASC").toLowerCase()
|
|
27
|
-
}));
|
|
28
|
-
query.sort = JSON.stringify(v1Sort);
|
|
29
|
-
}
|
|
30
|
-
if (request?.paging) query.paging = request.paging;
|
|
31
|
-
const result = await wixFetch(client, "/stores/v1/products/query", {
|
|
32
|
-
method: "POST",
|
|
33
|
-
body: {
|
|
34
|
-
query,
|
|
35
|
-
includeVariants: request?.includeVariants ?? true,
|
|
36
|
-
includeMerchantSpecificData: request?.includeMerchantSpecificData ?? true
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
if (result.products) {
|
|
40
|
-
result.products = result.products.map(
|
|
41
|
-
(p) => normalizeProduct(p)
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
function normalizeCollection(col) {
|
|
47
|
-
const c = { ...col };
|
|
48
|
-
if (col.id && !c._id) {
|
|
49
|
-
c._id = col.id;
|
|
50
|
-
}
|
|
51
|
-
return c;
|
|
52
|
-
}
|
|
53
|
-
async function queryCollections(client, request) {
|
|
54
|
-
const query = {};
|
|
55
|
-
const result = await wixFetch(
|
|
56
|
-
client,
|
|
57
|
-
"/stores/v1/collections/query",
|
|
58
|
-
{
|
|
59
|
-
method: "POST",
|
|
60
|
-
body: {
|
|
61
|
-
query,
|
|
62
|
-
includeNumberOfProducts: true,
|
|
63
|
-
includeDescription: true
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
if (result.collections) {
|
|
68
|
-
result.collections = result.collections.map(
|
|
69
|
-
(c) => normalizeCollection(c)
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
var MediaType$2 = /* @__PURE__ */ ((MediaType2) => {
|
|
75
|
-
MediaType2[MediaType2["IMAGE"] = 0] = "IMAGE";
|
|
76
|
-
MediaType2[MediaType2["VIDEO"] = 1] = "VIDEO";
|
|
77
|
-
return MediaType2;
|
|
78
|
-
})(MediaType$2 || {});
|
|
79
|
-
var AvailabilityStatus = /* @__PURE__ */ ((AvailabilityStatus2) => {
|
|
80
|
-
AvailabilityStatus2[AvailabilityStatus2["IN_STOCK"] = 0] = "IN_STOCK";
|
|
81
|
-
AvailabilityStatus2[AvailabilityStatus2["OUT_OF_STOCK"] = 1] = "OUT_OF_STOCK";
|
|
82
|
-
AvailabilityStatus2[AvailabilityStatus2["PARTIALLY_OUT_OF_STOCK"] = 2] = "PARTIALLY_OUT_OF_STOCK";
|
|
83
|
-
return AvailabilityStatus2;
|
|
84
|
-
})(AvailabilityStatus || {});
|
|
85
|
-
var PreorderStatus = /* @__PURE__ */ ((PreorderStatus2) => {
|
|
86
|
-
PreorderStatus2[PreorderStatus2["ENABLED"] = 0] = "ENABLED";
|
|
87
|
-
PreorderStatus2[PreorderStatus2["DISABLED"] = 1] = "DISABLED";
|
|
88
|
-
PreorderStatus2[PreorderStatus2["PARTIALLY_ENABLED"] = 2] = "PARTIALLY_ENABLED";
|
|
89
|
-
return PreorderStatus2;
|
|
90
|
-
})(PreorderStatus || {});
|
|
91
|
-
var ProductType$1 = /* @__PURE__ */ ((ProductType2) => {
|
|
92
|
-
ProductType2[ProductType2["PHYSICAL"] = 0] = "PHYSICAL";
|
|
93
|
-
ProductType2[ProductType2["DIGITAL"] = 1] = "DIGITAL";
|
|
94
|
-
return ProductType2;
|
|
95
|
-
})(ProductType$1 || {});
|
|
96
|
-
var QuickAddType = /* @__PURE__ */ ((QuickAddType2) => {
|
|
97
|
-
QuickAddType2[QuickAddType2["SIMPLE"] = 0] = "SIMPLE";
|
|
98
|
-
QuickAddType2[QuickAddType2["SINGLE_OPTION"] = 1] = "SINGLE_OPTION";
|
|
99
|
-
QuickAddType2[QuickAddType2["NEEDS_CONFIGURATION"] = 2] = "NEEDS_CONFIGURATION";
|
|
100
|
-
return QuickAddType2;
|
|
101
|
-
})(QuickAddType || {});
|
|
102
|
-
var OptionRenderType$1 = /* @__PURE__ */ ((OptionRenderType2) => {
|
|
103
|
-
OptionRenderType2[OptionRenderType2["TEXT_CHOICES"] = 0] = "TEXT_CHOICES";
|
|
104
|
-
OptionRenderType2[OptionRenderType2["COLOR_SWATCH_CHOICES"] = 1] = "COLOR_SWATCH_CHOICES";
|
|
105
|
-
return OptionRenderType2;
|
|
106
|
-
})(OptionRenderType$1 || {});
|
|
107
|
-
var ChoiceType$1 = /* @__PURE__ */ ((ChoiceType2) => {
|
|
108
|
-
ChoiceType2[ChoiceType2["CHOICE_TEXT"] = 0] = "CHOICE_TEXT";
|
|
109
|
-
ChoiceType2[ChoiceType2["ONE_COLOR"] = 1] = "ONE_COLOR";
|
|
110
|
-
return ChoiceType2;
|
|
111
|
-
})(ChoiceType$1 || {});
|
|
112
|
-
function stripWixMediaResize(url) {
|
|
113
|
-
return url.replace(/\/v1\/(?:fit|fill|crop)\/[^/]+\/file\.\w+$/, "");
|
|
114
|
-
}
|
|
115
|
-
function mapAvailabilityStatus(status) {
|
|
116
|
-
switch (status) {
|
|
117
|
-
case "OUT_OF_STOCK":
|
|
118
|
-
return AvailabilityStatus.OUT_OF_STOCK;
|
|
119
|
-
case "PARTIALLY_OUT_OF_STOCK":
|
|
120
|
-
return AvailabilityStatus.PARTIALLY_OUT_OF_STOCK;
|
|
121
|
-
default:
|
|
122
|
-
return AvailabilityStatus.IN_STOCK;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function mapPreorderStatus() {
|
|
126
|
-
return PreorderStatus.DISABLED;
|
|
127
|
-
}
|
|
128
|
-
function mapMediaType(mediaType) {
|
|
129
|
-
return mediaType === "video" ? MediaType$2.VIDEO : MediaType$2.IMAGE;
|
|
130
|
-
}
|
|
131
|
-
function mapProductType$1(productType) {
|
|
132
|
-
return productType === "digital" ? ProductType$1.DIGITAL : ProductType$1.PHYSICAL;
|
|
133
|
-
}
|
|
134
|
-
function hasProductDiscount(product) {
|
|
135
|
-
const price = product.price?.price || 0;
|
|
136
|
-
const discountedPrice = product.price?.discountedPrice || price;
|
|
137
|
-
return discountedPrice < price;
|
|
138
|
-
}
|
|
139
|
-
function getQuickAddType(product) {
|
|
140
|
-
const optionCount = product.productOptions?.length ?? 0;
|
|
141
|
-
if (optionCount > 1) {
|
|
142
|
-
return QuickAddType.NEEDS_CONFIGURATION;
|
|
143
|
-
}
|
|
144
|
-
if (optionCount === 1) {
|
|
145
|
-
return QuickAddType.SINGLE_OPTION;
|
|
146
|
-
}
|
|
147
|
-
return QuickAddType.SIMPLE;
|
|
148
|
-
}
|
|
149
|
-
function mapOptionRenderType(optionType) {
|
|
150
|
-
return optionType === "color" ? OptionRenderType$1.COLOR_SWATCH_CHOICES : OptionRenderType$1.TEXT_CHOICES;
|
|
151
|
-
}
|
|
152
|
-
function mapQuickOption(option, variants) {
|
|
153
|
-
if (!option) return null;
|
|
154
|
-
const choices = option.choices || [];
|
|
155
|
-
return {
|
|
156
|
-
_id: option.name,
|
|
157
|
-
name: option.name || "",
|
|
158
|
-
optionRenderType: mapOptionRenderType(option.optionType),
|
|
159
|
-
choices: choices.map((choice) => {
|
|
160
|
-
const variant = variants?.find((v) => Object.values(v.choices).includes(choice.value));
|
|
161
|
-
return {
|
|
162
|
-
choiceId: choice.description,
|
|
163
|
-
name: choice.value || "",
|
|
164
|
-
choiceType: option.optionType === "color" ? ChoiceType$1.ONE_COLOR : ChoiceType$1.CHOICE_TEXT,
|
|
165
|
-
colorCode: "",
|
|
166
|
-
// V1 doesn't store color code in choices
|
|
167
|
-
inStock: variant?.stock?.inStock ?? choice.inStock ?? true,
|
|
168
|
-
variantId: variant?._id || "",
|
|
169
|
-
isSelected: false
|
|
170
|
-
};
|
|
171
|
-
})
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
const DEFAULT_PRODUCT_PAGE_PATH = "/products";
|
|
175
|
-
function mapProductToCard(product, productPagePath = DEFAULT_PRODUCT_PAGE_PATH) {
|
|
176
|
-
const mainMedia = product.media?.mainMedia;
|
|
177
|
-
const slug = product.slug || "";
|
|
178
|
-
product.price?.discountedPrice ?? product.price?.price ?? 0;
|
|
179
|
-
product.price?.price ?? 0;
|
|
180
|
-
const formattedActualPrice = product.price?.formatted?.discountedPrice || "";
|
|
181
|
-
const formattedCompareAtPrice = product.price?.formatted?.price || "";
|
|
182
|
-
const hasDiscount = hasProductDiscount(product);
|
|
183
|
-
return {
|
|
184
|
-
_id: product._id || "",
|
|
185
|
-
name: product.name || "",
|
|
186
|
-
slug,
|
|
187
|
-
productUrl: slug ? `${productPagePath}/${slug}` : "",
|
|
188
|
-
mainMedia: {
|
|
189
|
-
url: stripWixMediaResize(mainMedia?.image?.url || ""),
|
|
190
|
-
altText: mainMedia?.title || product.name || "",
|
|
191
|
-
mediaType: mapMediaType(mainMedia?.mediaType)
|
|
192
|
-
},
|
|
193
|
-
thumbnail: {
|
|
194
|
-
url: stripWixMediaResize(mainMedia?.thumbnail?.url || ""),
|
|
195
|
-
altText: mainMedia?.title || product.name || "",
|
|
196
|
-
width: mainMedia?.thumbnail?.width || 300,
|
|
197
|
-
height: mainMedia?.thumbnail?.height || 300
|
|
198
|
-
},
|
|
199
|
-
// Simplified price fields
|
|
200
|
-
price: formattedActualPrice,
|
|
201
|
-
strikethroughPrice: hasDiscount ? formattedCompareAtPrice : "",
|
|
202
|
-
hasDiscount,
|
|
203
|
-
inventory: {
|
|
204
|
-
// V1 uses stock.inventoryStatus
|
|
205
|
-
availabilityStatus: mapAvailabilityStatus(product.stock?.inventoryStatus),
|
|
206
|
-
preorderStatus: mapPreorderStatus()
|
|
207
|
-
},
|
|
208
|
-
ribbon: {
|
|
209
|
-
_id: product.ribbon || "",
|
|
210
|
-
name: product.ribbon || ""
|
|
211
|
-
},
|
|
212
|
-
hasRibbon: !!product.ribbon,
|
|
213
|
-
brand: {
|
|
214
|
-
_id: product.brand || "",
|
|
215
|
-
name: product.brand || ""
|
|
216
|
-
},
|
|
217
|
-
productType: mapProductType$1(product.productType),
|
|
218
|
-
isAddingToCart: false,
|
|
219
|
-
// Quick add behavior
|
|
220
|
-
quickAddType: getQuickAddType(product),
|
|
221
|
-
quickOption: getQuickAddType(product) === QuickAddType.SINGLE_OPTION ? mapQuickOption(product.productOptions?.[0], product.variants) : null
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function mapCollectionToViewState(collection) {
|
|
225
|
-
return {
|
|
226
|
-
_id: collection._id,
|
|
227
|
-
name: collection.name || "",
|
|
228
|
-
slug: collection.slug || "",
|
|
229
|
-
description: collection.description || "",
|
|
230
|
-
imageUrl: stripWixMediaResize(collection.media?.mainMedia?.image?.url || ""),
|
|
231
|
-
productCount: collection.numberOfProducts || 0
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
const WIX_STORES_V1_CONTEXT = createJayContext("wix:stores-v1");
|
|
235
|
-
function getNiceBoundaries(minPrice, maxPrice) {
|
|
236
|
-
const multipliers = [1, 2, 5];
|
|
237
|
-
const boundaries = [];
|
|
238
|
-
let magnitude = 1;
|
|
239
|
-
while (magnitude <= maxPrice * 10) {
|
|
240
|
-
for (const mult of multipliers) {
|
|
241
|
-
const value = magnitude * mult;
|
|
242
|
-
if (value > minPrice && value < maxPrice) {
|
|
243
|
-
boundaries.push(value);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
magnitude *= 10;
|
|
247
|
-
}
|
|
248
|
-
return boundaries.sort((a, b) => a - b);
|
|
249
|
-
}
|
|
250
|
-
function generatePriceBuckets(minPrice, maxPrice, currencySymbol = "$") {
|
|
251
|
-
if (maxPrice <= minPrice || maxPrice === 0) {
|
|
252
|
-
return [
|
|
253
|
-
{ rangeId: "all", label: "Show all", minValue: null, maxValue: null, isSelected: true }
|
|
254
|
-
];
|
|
255
|
-
}
|
|
256
|
-
let niceBoundaries = getNiceBoundaries(minPrice, maxPrice);
|
|
257
|
-
while (niceBoundaries.length > 5) {
|
|
258
|
-
niceBoundaries = niceBoundaries.filter((_, i) => i % 2 === 0);
|
|
259
|
-
}
|
|
260
|
-
const allBoundaries = [minPrice, ...niceBoundaries, maxPrice];
|
|
261
|
-
const buckets = [
|
|
262
|
-
{ rangeId: "all", label: "Show all", minValue: null, maxValue: null, isSelected: true }
|
|
263
|
-
];
|
|
264
|
-
for (let i = 0; i < allBoundaries.length - 1; i++) {
|
|
265
|
-
const from = Math.round(allBoundaries[i]);
|
|
266
|
-
const to = Math.round(allBoundaries[i + 1]);
|
|
267
|
-
if (from < to) {
|
|
268
|
-
buckets.push({
|
|
269
|
-
rangeId: `${from}-${to}`,
|
|
270
|
-
label: `${currencySymbol}${from} - ${currencySymbol}${to}`,
|
|
271
|
-
minValue: from,
|
|
272
|
-
maxValue: to,
|
|
273
|
-
isSelected: false
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return buckets;
|
|
278
|
-
}
|
|
279
|
-
function buildBaseFilter(query, filters) {
|
|
280
|
-
const conditions = [];
|
|
281
|
-
if (query && query.trim().length > 0) {
|
|
282
|
-
conditions.push({ name: { $startsWith: query.trim() } });
|
|
283
|
-
}
|
|
284
|
-
if (filters.collectionIds && filters.collectionIds.length > 0) {
|
|
285
|
-
conditions.push({ "collections.id": { $hasSome: filters.collectionIds } });
|
|
286
|
-
}
|
|
287
|
-
if (conditions.length === 0) return {};
|
|
288
|
-
if (conditions.length === 1) return conditions[0];
|
|
289
|
-
return { $and: conditions };
|
|
290
|
-
}
|
|
291
|
-
function buildPriceFilter(baseFilter, minPrice, maxPrice) {
|
|
292
|
-
const priceFilter = {};
|
|
293
|
-
if (minPrice !== void 0 && minPrice > 0) {
|
|
294
|
-
priceFilter.price = { $gte: minPrice };
|
|
295
|
-
}
|
|
296
|
-
if (maxPrice !== void 0 && maxPrice > 0) {
|
|
297
|
-
const existing = priceFilter.price;
|
|
298
|
-
priceFilter.price = typeof existing === "object" && existing !== null ? { ...existing, $lte: maxPrice } : { $lte: maxPrice };
|
|
299
|
-
}
|
|
300
|
-
if (Object.keys(priceFilter).length === 0) return baseFilter;
|
|
301
|
-
if (Object.keys(baseFilter).length === 0) return priceFilter;
|
|
302
|
-
return { $and: [baseFilter, priceFilter] };
|
|
303
|
-
}
|
|
304
|
-
const searchProducts = makeJayQuery("wixStoresV1.searchProducts").withServices(WIX_STORES_V1_SERVICE_MARKER).withHandler(
|
|
305
|
-
async (input, wixStores) => {
|
|
306
|
-
const { query, filters = {}, sortBy = "relevance", page = 1, pageSize = 12 } = input;
|
|
307
|
-
try {
|
|
308
|
-
const baseFilter = buildBaseFilter(query, filters);
|
|
309
|
-
const fullFilter = buildPriceFilter(baseFilter, filters.minPrice, filters.maxPrice);
|
|
310
|
-
const sort = [];
|
|
311
|
-
switch (sortBy) {
|
|
312
|
-
case "price_asc":
|
|
313
|
-
sort.push({ fieldName: "price", order: "ASC" });
|
|
314
|
-
break;
|
|
315
|
-
case "price_desc":
|
|
316
|
-
sort.push({ fieldName: "price", order: "DESC" });
|
|
317
|
-
break;
|
|
318
|
-
case "name_asc":
|
|
319
|
-
sort.push({ fieldName: "name", order: "ASC" });
|
|
320
|
-
break;
|
|
321
|
-
case "name_desc":
|
|
322
|
-
sort.push({ fieldName: "name", order: "DESC" });
|
|
323
|
-
break;
|
|
324
|
-
case "newest":
|
|
325
|
-
sort.push({ fieldName: "lastUpdated", order: "DESC" });
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
const [result, minPriceResult, maxPriceResult] = await Promise.all([
|
|
329
|
-
queryProducts(wixStores.wixClient, {
|
|
330
|
-
filter: fullFilter,
|
|
331
|
-
sort: sort.length > 0 ? sort : void 0,
|
|
332
|
-
paging: { limit: pageSize, offset: (page - 1) * pageSize }
|
|
333
|
-
}),
|
|
334
|
-
queryProducts(wixStores.wixClient, {
|
|
335
|
-
filter: baseFilter,
|
|
336
|
-
sort: [{ fieldName: "price", order: "ASC" }],
|
|
337
|
-
paging: { limit: 1 }
|
|
338
|
-
}),
|
|
339
|
-
queryProducts(wixStores.wixClient, {
|
|
340
|
-
filter: baseFilter,
|
|
341
|
-
sort: [{ fieldName: "price", order: "DESC" }],
|
|
342
|
-
paging: { limit: 1 }
|
|
343
|
-
})
|
|
344
|
-
]);
|
|
345
|
-
const products = result.products || [];
|
|
346
|
-
const minBound = minPriceResult.products?.[0]?.price?.price ?? 0;
|
|
347
|
-
const maxBound = maxPriceResult.products?.[0]?.price?.price ?? 0;
|
|
348
|
-
const currency = products[0]?.price?.currency || minPriceResult.products?.[0]?.price?.currency;
|
|
349
|
-
const currencySymbol = currency === "ILS" ? "₪" : currency === "USD" ? "$" : currency === "EUR" ? "€" : currency === "GBP" ? "£" : "$";
|
|
350
|
-
const ranges = generatePriceBuckets(minBound, maxBound, currencySymbol);
|
|
351
|
-
const totalCount = result.totalResults ?? products.length;
|
|
352
|
-
const totalPages = Math.ceil(totalCount / pageSize);
|
|
353
|
-
const mappedProducts = products.map((p) => mapProductToCard(p));
|
|
354
|
-
return {
|
|
355
|
-
products: mappedProducts,
|
|
356
|
-
totalCount,
|
|
357
|
-
currentPage: page,
|
|
358
|
-
totalPages,
|
|
359
|
-
hasMore: page < totalPages,
|
|
360
|
-
priceAggregation: { minBound, maxBound, ranges }
|
|
361
|
-
};
|
|
362
|
-
} catch (error) {
|
|
363
|
-
console.error("[wixStoresV1.searchProducts] Search failed:", error);
|
|
364
|
-
throw new ActionError("SEARCH_FAILED", "Failed to search products");
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
);
|
|
368
|
-
const getProductBySlug = makeJayQuery("wixStoresV1.getProductBySlug").withServices(WIX_STORES_V1_SERVICE_MARKER).withCaching({ maxAge: 300, staleWhileRevalidate: 600 }).withHandler(
|
|
369
|
-
async (input, wixStores) => {
|
|
370
|
-
const { slug } = input;
|
|
371
|
-
if (!slug) {
|
|
372
|
-
throw new ActionError("INVALID_INPUT", "Product slug is required");
|
|
373
|
-
}
|
|
374
|
-
try {
|
|
375
|
-
let result = await queryProducts(wixStores.wixClient, {
|
|
376
|
-
filter: { slug },
|
|
377
|
-
paging: { limit: 1 }
|
|
378
|
-
});
|
|
379
|
-
if (!result.products?.length) {
|
|
380
|
-
result = await queryProducts(wixStores.wixClient, {
|
|
381
|
-
filter: { id: slug },
|
|
382
|
-
paging: { limit: 1 }
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
const product = result.products?.[0];
|
|
386
|
-
if (!product) return null;
|
|
387
|
-
return mapProductToCard(product);
|
|
388
|
-
} catch (error) {
|
|
389
|
-
console.error("[wixStoresV1.getProductBySlug] Failed to get product:", error);
|
|
390
|
-
return null;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
);
|
|
394
|
-
const getCollections = makeJayQuery("wixStoresV1.getCollections").withServices(WIX_STORES_V1_SERVICE_MARKER).withCaching({ maxAge: 3600 }).withHandler(
|
|
395
|
-
async (_input, wixStores) => {
|
|
396
|
-
try {
|
|
397
|
-
const result = await queryCollections(wixStores.wixClient);
|
|
398
|
-
return (result.collections || []).map((col) => mapCollectionToViewState(col));
|
|
399
|
-
} catch (error) {
|
|
400
|
-
console.error("[wixStoresV1.getCollections] Failed to load collections:", error);
|
|
401
|
-
throw new ActionError("LOAD_FAILED", "Failed to load collections");
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
);
|
|
405
|
-
var ProductType = /* @__PURE__ */ ((ProductType2) => {
|
|
406
|
-
ProductType2[ProductType2["PHYSICAL"] = 0] = "PHYSICAL";
|
|
407
|
-
ProductType2[ProductType2["DIGITAL"] = 1] = "DIGITAL";
|
|
408
|
-
return ProductType2;
|
|
409
|
-
})(ProductType || {});
|
|
410
|
-
var StockStatus = /* @__PURE__ */ ((StockStatus2) => {
|
|
411
|
-
StockStatus2[StockStatus2["OUT_OF_STOCK"] = 0] = "OUT_OF_STOCK";
|
|
412
|
-
StockStatus2[StockStatus2["IN_STOCK"] = 1] = "IN_STOCK";
|
|
413
|
-
return StockStatus2;
|
|
414
|
-
})(StockStatus || {});
|
|
415
|
-
var OptionRenderType = /* @__PURE__ */ ((OptionRenderType2) => {
|
|
416
|
-
OptionRenderType2[OptionRenderType2["TEXT_CHOICES"] = 0] = "TEXT_CHOICES";
|
|
417
|
-
OptionRenderType2[OptionRenderType2["COLOR_SWATCH_CHOICES"] = 1] = "COLOR_SWATCH_CHOICES";
|
|
418
|
-
return OptionRenderType2;
|
|
419
|
-
})(OptionRenderType || {});
|
|
420
|
-
var ChoiceType = /* @__PURE__ */ ((ChoiceType2) => {
|
|
421
|
-
ChoiceType2[ChoiceType2["CHOICE_TEXT"] = 0] = "CHOICE_TEXT";
|
|
422
|
-
ChoiceType2[ChoiceType2["ONE_COLOR"] = 1] = "ONE_COLOR";
|
|
423
|
-
return ChoiceType2;
|
|
424
|
-
})(ChoiceType || {});
|
|
425
|
-
var ChoiceType = /* @__PURE__ */ ((ChoiceType2) => {
|
|
426
|
-
ChoiceType2[ChoiceType2["CHOICE_TEXT"] = 0] = "CHOICE_TEXT";
|
|
427
|
-
ChoiceType2[ChoiceType2["ONE_COLOR"] = 1] = "ONE_COLOR";
|
|
428
|
-
return ChoiceType2;
|
|
429
|
-
})(ChoiceType || {});
|
|
430
|
-
var Selected = /* @__PURE__ */ ((Selected2) => {
|
|
431
|
-
Selected2[Selected2["selected"] = 0] = "selected";
|
|
432
|
-
Selected2[Selected2["notSelected"] = 1] = "notSelected";
|
|
433
|
-
return Selected2;
|
|
434
|
-
})(Selected || {});
|
|
435
|
-
var MediaType$1 = /* @__PURE__ */ ((MediaType2) => {
|
|
436
|
-
MediaType2[MediaType2["IMAGE"] = 0] = "IMAGE";
|
|
437
|
-
MediaType2[MediaType2["VIDEO"] = 1] = "VIDEO";
|
|
438
|
-
return MediaType2;
|
|
439
|
-
})(MediaType$1 || {});
|
|
440
|
-
function mapProductType(productType) {
|
|
441
|
-
return productType === "digital" ? ProductType.DIGITAL : ProductType.PHYSICAL;
|
|
442
|
-
}
|
|
443
|
-
function mapInfoSections(sections) {
|
|
444
|
-
return (sections || []).map((section, index) => ({
|
|
445
|
-
_id: String(index),
|
|
446
|
-
title: section.title || "",
|
|
447
|
-
plainDescription: section.description || "",
|
|
448
|
-
uniqueName: section.title || ""
|
|
449
|
-
}));
|
|
450
|
-
}
|
|
451
|
-
function mapMedia(product) {
|
|
452
|
-
const mainMedia = product.media?.mainMedia;
|
|
453
|
-
const mediaItems = product.media?.items || [];
|
|
454
|
-
const mainUrl = stripWixMediaResize(mainMedia?.image?.url || "");
|
|
455
|
-
const mainMediaType = mainMedia?.mediaType === "video" ? MediaType$1.VIDEO : MediaType$1.IMAGE;
|
|
456
|
-
return {
|
|
457
|
-
selectedMedia: {
|
|
458
|
-
url: mainUrl,
|
|
459
|
-
mediaType: mainMediaType
|
|
460
|
-
},
|
|
461
|
-
availableMedia: mediaItems.map((item, index) => ({
|
|
462
|
-
mediaId: item._id || String(index),
|
|
463
|
-
media: {
|
|
464
|
-
url: stripWixMediaResize(item.image?.url || ""),
|
|
465
|
-
mediaType: item.mediaType === "video" ? MediaType$1.VIDEO : MediaType$1.IMAGE
|
|
466
|
-
},
|
|
467
|
-
selected: item._id === mainMedia?._id ? Selected.selected : Selected.notSelected
|
|
468
|
-
}))
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
function mapOptionsToSlowVS(product) {
|
|
472
|
-
return (product.productOptions || []).map((option) => ({
|
|
473
|
-
_id: option.name || "",
|
|
474
|
-
name: option.name || "",
|
|
475
|
-
optionRenderType: option.optionType === "color" ? OptionRenderType.COLOR_SWATCH_CHOICES : OptionRenderType.TEXT_CHOICES,
|
|
476
|
-
choices: (option.choices || []).map((choice) => ({
|
|
477
|
-
choiceId: choice.value || "",
|
|
478
|
-
name: choice.value || "",
|
|
479
|
-
choiceType: option.optionType === "color" ? ChoiceType.ONE_COLOR : ChoiceType.CHOICE_TEXT,
|
|
480
|
-
inStock: choice.inStock ?? true,
|
|
481
|
-
colorCode: ""
|
|
482
|
-
}))
|
|
483
|
-
}));
|
|
484
|
-
}
|
|
485
|
-
function mapOptionsToFastVS(product) {
|
|
486
|
-
return (product.productOptions || []).map((option) => ({
|
|
487
|
-
_id: option.name || "",
|
|
488
|
-
textChoiceSelection: void 0,
|
|
489
|
-
choices: (option.choices || []).map((choice) => ({
|
|
490
|
-
choiceId: choice.value || "",
|
|
491
|
-
isSelected: false
|
|
492
|
-
}))
|
|
493
|
-
}));
|
|
494
|
-
}
|
|
495
|
-
function mapVariants(product) {
|
|
496
|
-
return (product.variants || []).map((variant) => ({
|
|
497
|
-
_id: variant._id || "",
|
|
498
|
-
sku: variant.variant?.sku || "",
|
|
499
|
-
price: variant.variant?.priceData?.formatted?.discountedPrice || variant.variant?.priceData?.formatted?.price || "",
|
|
500
|
-
strikethroughPrice: variant.variant?.priceData?.discountedPrice < variant.variant?.priceData?.price ? variant.variant?.priceData?.formatted?.price || "" : "",
|
|
501
|
-
choices: variant.choices || {},
|
|
502
|
-
inventoryStatus: variant.stock?.inStock ? StockStatus.IN_STOCK : StockStatus.OUT_OF_STOCK
|
|
503
|
-
}));
|
|
504
|
-
}
|
|
505
|
-
function mapSeoHeadTags(product, seoData) {
|
|
506
|
-
const headTags = (seoData?.tags || []).map((tag) => ({
|
|
507
|
-
tag: tag.type || "meta",
|
|
508
|
-
attrs: Object.fromEntries(Object.entries(tag.props || {}).map(([key, value]) => [key, value])),
|
|
509
|
-
children: tag.children || void 0
|
|
510
|
-
}));
|
|
511
|
-
if (!headTags.some((t) => t.tag === "title") && product.name) {
|
|
512
|
-
headTags.push({ tag: "title", children: product.name });
|
|
513
|
-
}
|
|
514
|
-
if (!headTags.some((t) => t.tag === "meta" && t.attrs?.name === "description") && product.description) {
|
|
515
|
-
headTags.push({
|
|
516
|
-
tag: "meta",
|
|
517
|
-
attrs: { name: "description", content: product.description }
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
const keywords = seoData?.settings?.keywords;
|
|
521
|
-
if (keywords?.length) {
|
|
522
|
-
const terms = keywords.map((k) => k.term).filter(Boolean);
|
|
523
|
-
if (terms.length) {
|
|
524
|
-
headTags.push({
|
|
525
|
-
tag: "meta",
|
|
526
|
-
attrs: { name: "keywords", content: terms.join(", ") }
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
return headTags;
|
|
531
|
-
}
|
|
532
|
-
async function* loadProductParams([wixStores]) {
|
|
533
|
-
const PAGE_SIZE2 = 100;
|
|
534
|
-
try {
|
|
535
|
-
let offset = 0;
|
|
536
|
-
let hasMore = true;
|
|
537
|
-
while (hasMore) {
|
|
538
|
-
const result = await queryProducts(wixStores.wixClient, {
|
|
539
|
-
paging: { limit: PAGE_SIZE2, offset }
|
|
540
|
-
});
|
|
541
|
-
const products = result.products || [];
|
|
542
|
-
yield products.map((product) => ({ slug: product.slug || "" }));
|
|
543
|
-
offset += products.length;
|
|
544
|
-
hasMore = products.length === PAGE_SIZE2;
|
|
545
|
-
}
|
|
546
|
-
} catch (error) {
|
|
547
|
-
console.error("[ProductPage V1] Failed to load product slugs:", error);
|
|
548
|
-
yield [];
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
async function renderSlowlyChanging$3(props, wixStores) {
|
|
552
|
-
const Pipeline = RenderPipeline.for();
|
|
553
|
-
return Pipeline.try(async () => {
|
|
554
|
-
const bySlug = await queryProducts(wixStores.wixClient, {
|
|
555
|
-
filter: { slug: props.slug },
|
|
556
|
-
paging: { limit: 1 }
|
|
557
|
-
});
|
|
558
|
-
if (bySlug.products?.length)
|
|
559
|
-
return bySlug;
|
|
560
|
-
return queryProducts(wixStores.wixClient, {
|
|
561
|
-
filter: { id: props.slug },
|
|
562
|
-
paging: { limit: 1 }
|
|
563
|
-
});
|
|
564
|
-
}).recover((error) => {
|
|
565
|
-
console.error("[ProductPage V1] Error loading product:", error);
|
|
566
|
-
return Pipeline.clientError(404, "Product not found");
|
|
567
|
-
}).toPhaseOutput((result) => {
|
|
568
|
-
const product = result.products?.[0];
|
|
569
|
-
if (!product) {
|
|
570
|
-
throw new Error("Product not found");
|
|
571
|
-
}
|
|
572
|
-
const variants = mapVariants(product);
|
|
573
|
-
const stockStatus = product.stock?.inStock ? StockStatus.IN_STOCK : StockStatus.OUT_OF_STOCK;
|
|
574
|
-
return {
|
|
575
|
-
viewState: {
|
|
576
|
-
_id: product._id || "",
|
|
577
|
-
productName: product.name || "",
|
|
578
|
-
description: product.description || "",
|
|
579
|
-
brand: product.brand || "",
|
|
580
|
-
ribbon: product.ribbon || "",
|
|
581
|
-
productType: mapProductType(product.productType),
|
|
582
|
-
options: mapOptionsToSlowVS(product),
|
|
583
|
-
infoSections: mapInfoSections(product.additionalInfoSections),
|
|
584
|
-
modifiers: [],
|
|
585
|
-
// V1 doesn't have modifiers in same format
|
|
586
|
-
seoData: { tags: [], settings: { preventAutoRedirect: false, keywords: [] } }
|
|
587
|
-
},
|
|
588
|
-
headTags: mapSeoHeadTags(product, product.seoData),
|
|
589
|
-
carryForward: {
|
|
590
|
-
productId: product._id || "",
|
|
591
|
-
mediaGallery: mapMedia(product),
|
|
592
|
-
options: mapOptionsToFastVS(product),
|
|
593
|
-
pricePerUnit: "",
|
|
594
|
-
stockStatus,
|
|
595
|
-
variants
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
async function renderFastChanging$2(props, slowCarryForward, wixStores) {
|
|
601
|
-
const Pipeline = RenderPipeline.for();
|
|
602
|
-
const isInStock = slowCarryForward.stockStatus === StockStatus.IN_STOCK;
|
|
603
|
-
const firstVariant = slowCarryForward.variants[0];
|
|
604
|
-
return Pipeline.ok({
|
|
605
|
-
actionsEnabled: isInStock,
|
|
606
|
-
options: slowCarryForward.options,
|
|
607
|
-
modifiers: [],
|
|
608
|
-
mediaGallery: slowCarryForward.mediaGallery,
|
|
609
|
-
sku: firstVariant?.sku || "",
|
|
610
|
-
price: firstVariant?.price || "",
|
|
611
|
-
pricePerUnit: slowCarryForward.pricePerUnit,
|
|
612
|
-
stockStatus: slowCarryForward.stockStatus,
|
|
613
|
-
strikethroughPrice: firstVariant?.strikethroughPrice || "",
|
|
614
|
-
quantity: { quantity: 1 }
|
|
615
|
-
}).toPhaseOutput((viewState) => ({
|
|
616
|
-
viewState,
|
|
617
|
-
carryForward: {
|
|
618
|
-
productId: slowCarryForward.productId,
|
|
619
|
-
variants: slowCarryForward.variants
|
|
620
|
-
}
|
|
621
|
-
}));
|
|
622
|
-
}
|
|
623
|
-
const productPage = makeJayStackComponent().withProps().withServices(WIX_STORES_V1_SERVICE_MARKER).withLoadParams(loadProductParams).withSlowlyRender(renderSlowlyChanging$3).withFastRender(renderFastChanging$2);
|
|
624
|
-
var CurrentSort = /* @__PURE__ */ ((CurrentSort2) => {
|
|
625
|
-
CurrentSort2[CurrentSort2["relevance"] = 0] = "relevance";
|
|
626
|
-
CurrentSort2[CurrentSort2["priceAsc"] = 1] = "priceAsc";
|
|
627
|
-
CurrentSort2[CurrentSort2["priceDesc"] = 2] = "priceDesc";
|
|
628
|
-
CurrentSort2[CurrentSort2["newest"] = 3] = "newest";
|
|
629
|
-
CurrentSort2[CurrentSort2["nameAsc"] = 4] = "nameAsc";
|
|
630
|
-
CurrentSort2[CurrentSort2["nameDesc"] = 5] = "nameDesc";
|
|
631
|
-
return CurrentSort2;
|
|
632
|
-
})(CurrentSort || {});
|
|
633
|
-
const PAGE_SIZE$1 = 12;
|
|
634
|
-
async function renderSlowlyChanging$2(props, wixStores) {
|
|
635
|
-
const Pipeline = RenderPipeline.for();
|
|
636
|
-
return Pipeline.try(async () => {
|
|
637
|
-
const collectionsResult = await queryCollections(wixStores.wixClient);
|
|
638
|
-
return collectionsResult.collections || [];
|
|
639
|
-
}).recover((error) => {
|
|
640
|
-
console.error("[ProductSearch V1] Failed to load collections:", error);
|
|
641
|
-
return Pipeline.ok([]);
|
|
642
|
-
}).toPhaseOutput((collections) => {
|
|
643
|
-
const collectionInfos = collections.map((col) => ({
|
|
644
|
-
categoryId: col._id || "",
|
|
645
|
-
categoryName: col.name || "",
|
|
646
|
-
categorySlug: col.slug || ""
|
|
647
|
-
}));
|
|
648
|
-
return {
|
|
649
|
-
viewState: {
|
|
650
|
-
searchFields: "name,description,sku",
|
|
651
|
-
fuzzySearch: false,
|
|
652
|
-
// V1 doesn't support fuzzy search
|
|
653
|
-
emptyStateMessage: "Enter a search term to find products",
|
|
654
|
-
filters: {
|
|
655
|
-
categoryFilter: {
|
|
656
|
-
categories: collectionInfos
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
},
|
|
660
|
-
carryForward: {
|
|
661
|
-
searchFields: "name,description,sku",
|
|
662
|
-
fuzzySearch: false,
|
|
663
|
-
collections: collectionInfos
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
async function renderFastChanging$1(props, slowCarryForward, _wixStores) {
|
|
669
|
-
const Pipeline = RenderPipeline.for();
|
|
670
|
-
return Pipeline.try(async () => {
|
|
671
|
-
const result = await searchProducts({
|
|
672
|
-
query: "",
|
|
673
|
-
pageSize: PAGE_SIZE$1,
|
|
674
|
-
page: 1
|
|
675
|
-
});
|
|
676
|
-
return result;
|
|
677
|
-
}).recover((error) => {
|
|
678
|
-
console.error("[ProductSearch V1] Failed to load products:", error);
|
|
679
|
-
return Pipeline.ok({
|
|
680
|
-
products: [],
|
|
681
|
-
totalCount: 0,
|
|
682
|
-
currentPage: 1,
|
|
683
|
-
totalPages: 0,
|
|
684
|
-
hasMore: false,
|
|
685
|
-
priceAggregation: {
|
|
686
|
-
minBound: 0,
|
|
687
|
-
maxBound: 1e4,
|
|
688
|
-
ranges: [
|
|
689
|
-
{
|
|
690
|
-
rangeId: "all",
|
|
691
|
-
label: "Show all",
|
|
692
|
-
minValue: null,
|
|
693
|
-
maxValue: null,
|
|
694
|
-
productCount: 0,
|
|
695
|
-
isSelected: true
|
|
696
|
-
}
|
|
697
|
-
]
|
|
698
|
-
}
|
|
699
|
-
});
|
|
700
|
-
}).toPhaseOutput((result) => {
|
|
701
|
-
return {
|
|
702
|
-
viewState: {
|
|
703
|
-
searchExpression: "",
|
|
704
|
-
isSearching: false,
|
|
705
|
-
hasSearched: false,
|
|
706
|
-
searchResults: result.products,
|
|
707
|
-
resultCount: result.products.length,
|
|
708
|
-
hasResults: result.products.length > 0,
|
|
709
|
-
hasSuggestions: false,
|
|
710
|
-
suggestions: [],
|
|
711
|
-
filters: {
|
|
712
|
-
priceRange: {
|
|
713
|
-
minPrice: 0,
|
|
714
|
-
maxPrice: 0,
|
|
715
|
-
minBound: result.priceAggregation?.minBound ?? 0,
|
|
716
|
-
maxBound: result.priceAggregation?.maxBound ?? 1e4,
|
|
717
|
-
ranges: result.priceAggregation?.ranges ?? [
|
|
718
|
-
{
|
|
719
|
-
rangeId: "all",
|
|
720
|
-
label: "Show all",
|
|
721
|
-
minValue: null,
|
|
722
|
-
maxValue: null,
|
|
723
|
-
isSelected: true
|
|
724
|
-
}
|
|
725
|
-
]
|
|
726
|
-
},
|
|
727
|
-
categoryFilter: {
|
|
728
|
-
categories: slowCarryForward.collections.map((col) => ({
|
|
729
|
-
categoryId: col.categoryId,
|
|
730
|
-
isSelected: false
|
|
731
|
-
}))
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
sortBy: {
|
|
735
|
-
currentSort: CurrentSort.relevance
|
|
736
|
-
},
|
|
737
|
-
hasMore: result.hasMore,
|
|
738
|
-
loadedCount: result.products.length,
|
|
739
|
-
totalCount: result.totalCount
|
|
740
|
-
},
|
|
741
|
-
carryForward: {
|
|
742
|
-
searchFields: slowCarryForward.searchFields,
|
|
743
|
-
fuzzySearch: slowCarryForward.fuzzySearch,
|
|
744
|
-
collections: slowCarryForward.collections
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
const productSearch = makeJayStackComponent().withProps().withServices(WIX_STORES_V1_SERVICE_MARKER).withSlowlyRender(renderSlowlyChanging$2).withFastRender(renderFastChanging$1);
|
|
750
|
-
async function renderSlowlyChanging$1(props, wixStores) {
|
|
751
|
-
const Pipeline = RenderPipeline.for();
|
|
752
|
-
return Pipeline.try(async () => {
|
|
753
|
-
const result = await queryCollections(wixStores.wixClient);
|
|
754
|
-
return result.collections || [];
|
|
755
|
-
}).recover((error) => {
|
|
756
|
-
console.error("[CollectionList V1] Failed to load collections:", error);
|
|
757
|
-
return Pipeline.ok([]);
|
|
758
|
-
}).toPhaseOutput((collections) => {
|
|
759
|
-
const collectionItems = collections.map((col) => {
|
|
760
|
-
const imageUrl = stripWixMediaResize(col.media?.mainMedia?.image?.url || "");
|
|
761
|
-
return {
|
|
762
|
-
_id: col._id || "",
|
|
763
|
-
name: col.name || "",
|
|
764
|
-
slug: col.slug || "",
|
|
765
|
-
description: col.description || "",
|
|
766
|
-
productCount: col.numberOfProducts || 0,
|
|
767
|
-
imageUrl,
|
|
768
|
-
hasImage: !!imageUrl
|
|
769
|
-
};
|
|
770
|
-
});
|
|
771
|
-
return {
|
|
772
|
-
viewState: {
|
|
773
|
-
// Reuse 'categories' field from contract for compatibility
|
|
774
|
-
categories: collectionItems,
|
|
775
|
-
hasCategories: collectionItems.length > 0
|
|
776
|
-
},
|
|
777
|
-
carryForward: {}
|
|
778
|
-
};
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
const collectionList = makeJayStackComponent().withProps().withServices(WIX_STORES_V1_SERVICE_MARKER).withSlowlyRender(renderSlowlyChanging$1);
|
|
782
|
-
const categoryList = collectionList;
|
|
783
|
-
var MediaType = /* @__PURE__ */ ((MediaType2) => {
|
|
784
|
-
MediaType2[MediaType2["IMAGE"] = 0] = "IMAGE";
|
|
785
|
-
MediaType2[MediaType2["VIDEO"] = 1] = "VIDEO";
|
|
786
|
-
MediaType2[MediaType2["AUDIO"] = 2] = "AUDIO";
|
|
787
|
-
MediaType2[MediaType2["DOCUMENT"] = 3] = "DOCUMENT";
|
|
788
|
-
MediaType2[MediaType2["ZIP"] = 4] = "ZIP";
|
|
789
|
-
return MediaType2;
|
|
790
|
-
})(MediaType || {});
|
|
791
|
-
var MediaType = /* @__PURE__ */ ((MediaType2) => {
|
|
792
|
-
MediaType2[MediaType2["IMAGE"] = 0] = "IMAGE";
|
|
793
|
-
MediaType2[MediaType2["VIDEO"] = 1] = "VIDEO";
|
|
794
|
-
MediaType2[MediaType2["AUDIO"] = 2] = "AUDIO";
|
|
795
|
-
MediaType2[MediaType2["DOCUMENT"] = 3] = "DOCUMENT";
|
|
796
|
-
MediaType2[MediaType2["ZIP"] = 4] = "ZIP";
|
|
797
|
-
return MediaType2;
|
|
798
|
-
})(MediaType || {});
|
|
799
|
-
const PAGE_SIZE = 20;
|
|
800
|
-
async function* loadCollectionParams([wixStores]) {
|
|
801
|
-
try {
|
|
802
|
-
const result = await queryCollections(wixStores.wixClient);
|
|
803
|
-
yield (result.collections || []).filter((col) => col.slug).map((col) => ({ slug: col.slug }));
|
|
804
|
-
} catch (error) {
|
|
805
|
-
console.error("[CollectionPage V1] Failed to load collection slugs:", error);
|
|
806
|
-
yield [];
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
async function loadCollectionProducts(collectionId, wixStores, offset = 0) {
|
|
810
|
-
const result = await queryProducts(wixStores.wixClient, {
|
|
811
|
-
filter: { "collections.id": { $hasSome: [collectionId] } },
|
|
812
|
-
paging: { limit: PAGE_SIZE, offset }
|
|
813
|
-
});
|
|
814
|
-
const products = (result.products || []).map((product) => mapProductToCard(product, "/products"));
|
|
815
|
-
return {
|
|
816
|
-
products,
|
|
817
|
-
total: result.totalResults || products.length
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
function mapCollectionMedia(collection) {
|
|
821
|
-
const mainMedia = collection.media?.mainMedia;
|
|
822
|
-
return {
|
|
823
|
-
mainMedia: mainMedia?.image?.url ? {
|
|
824
|
-
_id: "",
|
|
825
|
-
url: stripWixMediaResize(mainMedia.image.url),
|
|
826
|
-
altText: collection.name || "",
|
|
827
|
-
mediaType: MediaType.IMAGE
|
|
828
|
-
} : void 0,
|
|
829
|
-
items: []
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
async function renderSlowlyChanging(props, wixStores) {
|
|
833
|
-
const Pipeline = RenderPipeline.for();
|
|
834
|
-
return Pipeline.try(async () => {
|
|
835
|
-
const result = await queryCollections(wixStores.wixClient);
|
|
836
|
-
const collection = (result.collections || []).find((col) => col.slug === props.slug);
|
|
837
|
-
if (!collection) {
|
|
838
|
-
throw new Error("Collection not found");
|
|
839
|
-
}
|
|
840
|
-
const productData = await loadCollectionProducts(collection._id, wixStores, 0);
|
|
841
|
-
return { collection, productData };
|
|
842
|
-
}).recover((error) => {
|
|
843
|
-
console.error("[CollectionPage V1] Failed to load collection:", error);
|
|
844
|
-
return Pipeline.clientError(404, "Collection not found");
|
|
845
|
-
}).toPhaseOutput((data) => {
|
|
846
|
-
const { collection, productData } = data;
|
|
847
|
-
const breadcrumbs = [
|
|
848
|
-
{
|
|
849
|
-
categoryId: collection._id || "",
|
|
850
|
-
categoryName: collection.name || "",
|
|
851
|
-
categorySlug: collection.slug || ""
|
|
852
|
-
}
|
|
853
|
-
];
|
|
854
|
-
const media = mapCollectionMedia(collection);
|
|
855
|
-
return {
|
|
856
|
-
viewState: {
|
|
857
|
-
_id: collection._id || "",
|
|
858
|
-
name: collection.name || "",
|
|
859
|
-
description: collection.description || "",
|
|
860
|
-
slug: collection.slug || "",
|
|
861
|
-
visible: true,
|
|
862
|
-
numberOfProducts: collection.numberOfProducts || productData.total,
|
|
863
|
-
hasImage: !!media.mainMedia?.url,
|
|
864
|
-
media,
|
|
865
|
-
breadcrumbs,
|
|
866
|
-
products: productData.products
|
|
867
|
-
},
|
|
868
|
-
carryForward: {
|
|
869
|
-
collectionId: collection._id || "",
|
|
870
|
-
collectionSlug: collection.slug || "",
|
|
871
|
-
totalProducts: productData.total,
|
|
872
|
-
products: productData.products,
|
|
873
|
-
currentOffset: productData.products.length
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
async function renderFastChanging(props, slowCarryForward, _wixStores) {
|
|
879
|
-
const Pipeline = RenderPipeline.for();
|
|
880
|
-
const hasMore = slowCarryForward.currentOffset < slowCarryForward.totalProducts;
|
|
881
|
-
return Pipeline.ok(slowCarryForward).toPhaseOutput((data) => {
|
|
882
|
-
return {
|
|
883
|
-
viewState: {
|
|
884
|
-
// Products array with fast+interactive properties for SSR items
|
|
885
|
-
products: data.products.map((p) => ({
|
|
886
|
-
_id: p._id,
|
|
887
|
-
price: p.price,
|
|
888
|
-
strikethroughPrice: p.strikethroughPrice,
|
|
889
|
-
isAddingToCart: false,
|
|
890
|
-
quickOption: p.quickOption ? {
|
|
891
|
-
choices: p.quickOption.choices.map((c) => ({
|
|
892
|
-
choiceId: c.choiceId,
|
|
893
|
-
inStock: c.inStock,
|
|
894
|
-
isSelected: c.isSelected
|
|
895
|
-
}))
|
|
896
|
-
} : { choices: [] }
|
|
897
|
-
})),
|
|
898
|
-
loadedProducts: [],
|
|
899
|
-
hasMore,
|
|
900
|
-
loadedCount: data.products.length,
|
|
901
|
-
isLoading: false,
|
|
902
|
-
hasProducts: data.products.length > 0
|
|
903
|
-
},
|
|
904
|
-
carryForward: {
|
|
905
|
-
collectionId: data.collectionId,
|
|
906
|
-
totalProducts: data.totalProducts,
|
|
907
|
-
currentOffset: data.currentOffset
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
const collectionPage = makeJayStackComponent().withProps().withServices(WIX_STORES_V1_SERVICE_MARKER).withLoadParams(loadCollectionParams).withSlowlyRender(renderSlowlyChanging).withFastRender(renderFastChanging);
|
|
913
|
-
const categoryPage = collectionPage;
|
|
914
|
-
const init = makeJayInit().withServer(async () => {
|
|
915
|
-
console.log("[wix-stores-v1] Initializing Wix Stores V1 service...");
|
|
916
|
-
const wixClient = getService(WIX_CLIENT_SERVICE);
|
|
917
|
-
provideWixStoresV1Service(wixClient);
|
|
918
|
-
console.log("[wix-stores-v1] Server initialization complete");
|
|
919
|
-
return {
|
|
920
|
-
enableClientCart: true,
|
|
921
|
-
enableClientSearch: true
|
|
922
|
-
};
|
|
923
|
-
});
|
|
924
|
-
async function setupWixStoresV1(ctx) {
|
|
925
|
-
if (ctx.initError) {
|
|
926
|
-
return {
|
|
927
|
-
status: "error",
|
|
928
|
-
message: `Service init failed (is wix-server-client configured?). ${ctx.initError.message}`
|
|
929
|
-
};
|
|
930
|
-
}
|
|
931
|
-
let service;
|
|
932
|
-
try {
|
|
933
|
-
service = getService(WIX_STORES_V1_SERVICE_MARKER);
|
|
934
|
-
} catch {
|
|
935
|
-
return {
|
|
936
|
-
status: "error",
|
|
937
|
-
message: "WixStoresV1Service not available. Run setup for wix-server-client first."
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
try {
|
|
941
|
-
await queryProducts(service.wixClient, { paging: { limit: 1 } });
|
|
942
|
-
} catch (e) {
|
|
943
|
-
const msg = e.message || "";
|
|
944
|
-
const hint = msg.includes("404") || msg.includes("not found") ? "Wix Stores may not be installed on this site" : msg.includes("403") || msg.includes("permission") ? "API key may lack Wix Stores permissions" : "This package requires the Stores Catalog V1 API — if using Catalog V3, use @jay-framework/wix-stores instead";
|
|
945
|
-
return {
|
|
946
|
-
status: "error",
|
|
947
|
-
message: `Wix Stores V1 API check failed: ${hint}. (${msg})`
|
|
948
|
-
};
|
|
949
|
-
}
|
|
950
|
-
return {
|
|
951
|
-
status: "configured",
|
|
952
|
-
message: "Wix Stores V1 connected"
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
export {
|
|
956
|
-
WIX_CART_CONTEXT,
|
|
957
|
-
WIX_CART_SERVICE,
|
|
958
|
-
WIX_STORES_V1_CONTEXT,
|
|
959
|
-
WIX_STORES_V1_SERVICE_MARKER,
|
|
960
|
-
cartIndicator,
|
|
961
|
-
cartPage,
|
|
962
|
-
categoryList,
|
|
963
|
-
categoryPage,
|
|
964
|
-
collectionList,
|
|
965
|
-
collectionPage,
|
|
966
|
-
getCollections,
|
|
967
|
-
getProductBySlug,
|
|
968
|
-
init,
|
|
969
|
-
productPage,
|
|
970
|
-
productSearch,
|
|
971
|
-
provideWixCartContext,
|
|
972
|
-
provideWixCartService,
|
|
973
|
-
provideWixStoresV1Service,
|
|
974
|
-
searchProducts,
|
|
975
|
-
setupWixStoresV1
|
|
976
|
-
};
|