@wix/headless-stores 0.0.12 → 0.0.14
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/cjs/dist/astro/actions/custom-checkout.d.ts +4 -2
- package/cjs/dist/astro/actions/custom-checkout.js +4 -8
- package/cjs/dist/astro/actions/index.d.ts +1 -1
- package/cjs/dist/astro/actions/index.js +1 -17
- package/cjs/dist/enums/index.d.ts +2 -2
- package/cjs/dist/enums/index.js +2 -18
- package/cjs/dist/enums/social-platform-enums.js +4 -7
- package/cjs/dist/enums/sort-enums.js +3 -6
- package/cjs/dist/react/BuyNow.js +6 -11
- package/cjs/dist/react/Category.d.ts +2 -2
- package/cjs/dist/react/Category.js +6 -10
- package/cjs/dist/react/Collection.d.ts +1 -1
- package/cjs/dist/react/Collection.js +31 -39
- package/cjs/dist/react/FilteredCollection.d.ts +6 -20
- package/cjs/dist/react/FilteredCollection.js +29 -57
- package/cjs/dist/react/PayNow.js +4 -9
- package/cjs/dist/react/Product.d.ts +3 -3
- package/cjs/dist/react/Product.js +6 -11
- package/cjs/dist/react/ProductActions.js +12 -17
- package/cjs/dist/react/ProductModifiers.d.ts +3 -1
- package/cjs/dist/react/ProductModifiers.js +23 -29
- package/cjs/dist/react/ProductVariantSelector.d.ts +1 -1
- package/cjs/dist/react/ProductVariantSelector.js +18 -28
- package/cjs/dist/react/RelatedProducts.d.ts +2 -2
- package/cjs/dist/react/RelatedProducts.js +35 -33
- package/cjs/dist/react/SelectedVariant.js +8 -14
- package/cjs/dist/react/SocialSharing.d.ts +2 -3
- package/cjs/dist/react/SocialSharing.js +35 -33
- package/cjs/dist/react/Sort.d.ts +4 -3
- package/cjs/dist/react/Sort.js +6 -10
- package/cjs/dist/react/index.d.ts +13 -13
- package/cjs/dist/react/index.js +13 -52
- package/cjs/dist/server-actions/custom-checkout-action.js +8 -11
- package/cjs/dist/server-actions/index.d.ts +1 -1
- package/cjs/dist/server-actions/index.js +1 -17
- package/cjs/dist/services/buy-now-service.d.ts +44 -3
- package/cjs/dist/services/buy-now-service.js +20 -22
- package/cjs/dist/services/catalog-options-service.d.ts +3 -3
- package/cjs/dist/services/catalog-options-service.js +45 -46
- package/cjs/dist/services/catalog-price-range-service.d.ts +3 -3
- package/cjs/dist/services/catalog-price-range-service.js +21 -25
- package/cjs/dist/services/category-service.d.ts +7 -7
- package/cjs/dist/services/category-service.js +20 -22
- package/cjs/dist/services/collection-service.d.ts +8 -8
- package/cjs/dist/services/collection-service.js +102 -133
- package/cjs/dist/services/filter-service.d.ts +4 -4
- package/cjs/dist/services/filter-service.js +47 -61
- package/cjs/dist/services/index.d.ts +13 -2
- package/cjs/dist/services/index.js +13 -9
- package/cjs/dist/services/pay-now-service.d.ts +4 -3
- package/cjs/dist/services/pay-now-service.js +11 -16
- package/cjs/dist/services/product-modifiers-service.d.ts +6 -6
- package/cjs/dist/services/product-modifiers-service.js +17 -21
- package/cjs/dist/services/product-service.d.ts +8 -8
- package/cjs/dist/services/product-service.js +22 -26
- package/cjs/dist/services/related-products-service.d.ts +5 -5
- package/cjs/dist/services/related-products-service.js +9 -13
- package/cjs/dist/services/selected-variant-service.d.ts +11 -8
- package/cjs/dist/services/selected-variant-service.js +73 -90
- package/cjs/dist/services/social-sharing-service.d.ts +2 -9
- package/cjs/dist/services/social-sharing-service.js +48 -60
- package/cjs/dist/services/sort-service.d.ts +3 -3
- package/cjs/dist/services/sort-service.js +14 -19
- package/cjs/dist/utils/index.js +6 -9
- package/cjs/dist/utils/url-params.js +5 -9
- package/dist/astro/actions/custom-checkout.d.ts +1 -1
- package/dist/astro/actions/custom-checkout.js +1 -1
- package/dist/astro/actions/index.d.ts +1 -1
- package/dist/astro/actions/index.js +1 -1
- package/dist/enums/index.d.ts +2 -2
- package/dist/enums/index.js +2 -2
- package/dist/react/BuyNow.js +4 -6
- package/dist/react/Category.d.ts +2 -2
- package/dist/react/Category.js +2 -2
- package/dist/react/Collection.d.ts +1 -1
- package/dist/react/Collection.js +20 -20
- package/dist/react/FilteredCollection.d.ts +6 -20
- package/dist/react/FilteredCollection.js +17 -35
- package/dist/react/PayNow.js +2 -4
- package/dist/react/Product.d.ts +3 -3
- package/dist/react/Product.js +2 -2
- package/dist/react/ProductActions.js +9 -10
- package/dist/react/ProductModifiers.d.ts +3 -1
- package/dist/react/ProductModifiers.js +14 -12
- package/dist/react/ProductVariantSelector.d.ts +1 -1
- package/dist/react/ProductVariantSelector.js +6 -8
- package/dist/react/RelatedProducts.d.ts +2 -2
- package/dist/react/RelatedProducts.js +25 -15
- package/dist/react/SelectedVariant.js +2 -2
- package/dist/react/SocialSharing.d.ts +2 -3
- package/dist/react/SocialSharing.js +24 -13
- package/dist/react/Sort.d.ts +4 -3
- package/dist/react/Sort.js +3 -4
- package/dist/react/index.d.ts +13 -13
- package/dist/react/index.js +13 -13
- package/dist/server-actions/index.d.ts +1 -1
- package/dist/server-actions/index.js +1 -1
- package/dist/services/buy-now-service.d.ts +44 -3
- package/dist/services/buy-now-service.js +7 -4
- package/dist/services/catalog-options-service.d.ts +3 -3
- package/dist/services/catalog-options-service.js +33 -30
- package/dist/services/catalog-price-range-service.d.ts +3 -3
- package/dist/services/catalog-price-range-service.js +18 -18
- package/dist/services/category-service.d.ts +7 -7
- package/dist/services/category-service.js +17 -15
- package/dist/services/collection-service.d.ts +8 -8
- package/dist/services/collection-service.js +80 -74
- package/dist/services/filter-service.d.ts +4 -4
- package/dist/services/filter-service.js +37 -48
- package/dist/services/index.d.ts +13 -2
- package/dist/services/index.js +13 -2
- package/dist/services/pay-now-service.d.ts +4 -3
- package/dist/services/pay-now-service.js +1 -1
- package/dist/services/product-modifiers-service.d.ts +6 -6
- package/dist/services/product-modifiers-service.js +13 -13
- package/dist/services/product-service.d.ts +8 -8
- package/dist/services/product-service.js +19 -19
- package/dist/services/related-products-service.d.ts +5 -5
- package/dist/services/related-products-service.js +6 -6
- package/dist/services/selected-variant-service.d.ts +11 -8
- package/dist/services/selected-variant-service.js +71 -85
- package/dist/services/social-sharing-service.d.ts +2 -9
- package/dist/services/social-sharing-service.js +29 -37
- package/dist/services/sort-service.d.ts +3 -3
- package/dist/services/sort-service.js +8 -10
- package/dist/utils/url-params.js +4 -4
- package/package.json +5 -5
- package/cjs/dist/services/product-media-gallery-service.d.ts +0 -25
- package/cjs/dist/services/product-media-gallery-service.js +0 -105
- package/dist/services/product-media-gallery-service.d.ts +0 -25
- package/dist/services/product-media-gallery-service.js +0 -101
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const signals_1 = require("@wix/services-definitions/core-services/signals");
|
|
7
|
-
const auto_sdk_stores_products_v_3_1 = require("@wix/auto_sdk_stores_products-v-3");
|
|
8
|
-
const auto_sdk_stores_customizations_v_3_1 = require("@wix/auto_sdk_stores_customizations-v-3");
|
|
1
|
+
import { defineService, implementService, } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
4
|
+
import * as customizationsV3 from "@wix/auto_sdk_stores_customizations-v-3";
|
|
5
|
+
const { SortDirection, SortType: SDKSortType } = productsV3;
|
|
9
6
|
// Helper functions
|
|
10
7
|
const extractAggregationValues = (aggregationResponse, name) => {
|
|
11
8
|
const aggregation = aggregationResponse.aggregations?.[name] ||
|
|
@@ -13,7 +10,7 @@ const extractAggregationValues = (aggregationResponse, name) => {
|
|
|
13
10
|
return aggregation?.values?.results?.map((item) => item.value) || [];
|
|
14
11
|
};
|
|
15
12
|
const matchesAggregationName = (name, aggregationNames) => {
|
|
16
|
-
return aggregationNames.some(aggName => aggName.toLowerCase() === name.toLowerCase());
|
|
13
|
+
return aggregationNames.some((aggName) => aggName.toLowerCase() === name.toLowerCase());
|
|
17
14
|
};
|
|
18
15
|
const sortChoicesIntelligently = (choices) => {
|
|
19
16
|
return [...choices].sort((a, b) => {
|
|
@@ -35,14 +32,14 @@ const buildCategoryFilter = (categoryId) => {
|
|
|
35
32
|
}
|
|
36
33
|
return {
|
|
37
34
|
visible: true,
|
|
38
|
-
|
|
35
|
+
"allCategoriesInfo.categories": {
|
|
39
36
|
$matchItems: [{ _id: { $in: [categoryId] } }],
|
|
40
37
|
},
|
|
41
38
|
};
|
|
42
39
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const signalsService = getService(
|
|
40
|
+
export const CatalogOptionsServiceDefinition = defineService("catalogOptions");
|
|
41
|
+
export const CatalogOptionsService = implementService.withConfig()(CatalogOptionsServiceDefinition, ({ getService }) => {
|
|
42
|
+
const signalsService = getService(SignalsServiceDefinition);
|
|
46
43
|
const catalogOptions = signalsService.signal(null);
|
|
47
44
|
const isLoading = signalsService.signal(false);
|
|
48
45
|
const error = signalsService.signal(null);
|
|
@@ -54,33 +51,33 @@ exports.CatalogOptionsService = services_definitions_1.implementService.withConf
|
|
|
54
51
|
const aggregationRequest = {
|
|
55
52
|
aggregations: [
|
|
56
53
|
{
|
|
57
|
-
name:
|
|
58
|
-
fieldPath:
|
|
59
|
-
type:
|
|
54
|
+
name: "optionNames",
|
|
55
|
+
fieldPath: "options.name",
|
|
56
|
+
type: SDKSortType.VALUE,
|
|
60
57
|
value: {
|
|
61
58
|
limit: 20,
|
|
62
|
-
sortType:
|
|
63
|
-
sortDirection:
|
|
59
|
+
sortType: SDKSortType.VALUE,
|
|
60
|
+
sortDirection: SortDirection.ASC,
|
|
64
61
|
},
|
|
65
62
|
},
|
|
66
63
|
{
|
|
67
|
-
name:
|
|
68
|
-
fieldPath:
|
|
69
|
-
type:
|
|
64
|
+
name: "choiceNames",
|
|
65
|
+
fieldPath: "options.choicesSettings.choices.name",
|
|
66
|
+
type: SDKSortType.VALUE,
|
|
70
67
|
value: {
|
|
71
68
|
limit: 50,
|
|
72
|
-
sortType:
|
|
73
|
-
sortDirection:
|
|
69
|
+
sortType: SDKSortType.VALUE,
|
|
70
|
+
sortDirection: SortDirection.ASC,
|
|
74
71
|
},
|
|
75
72
|
},
|
|
76
73
|
{
|
|
77
|
-
name:
|
|
78
|
-
fieldPath:
|
|
79
|
-
type:
|
|
74
|
+
name: "inventoryStatus",
|
|
75
|
+
fieldPath: "inventory.availabilityStatus",
|
|
76
|
+
type: SDKSortType.VALUE,
|
|
80
77
|
value: {
|
|
81
78
|
limit: 10,
|
|
82
|
-
sortType:
|
|
83
|
-
sortDirection:
|
|
79
|
+
sortType: SDKSortType.VALUE,
|
|
80
|
+
sortDirection: SortDirection.ASC,
|
|
84
81
|
},
|
|
85
82
|
},
|
|
86
83
|
],
|
|
@@ -88,26 +85,28 @@ exports.CatalogOptionsService = services_definitions_1.implementService.withConf
|
|
|
88
85
|
includeProducts: false,
|
|
89
86
|
cursorPaging: { limit: 0 },
|
|
90
87
|
};
|
|
91
|
-
const aggregationResponse = await
|
|
92
|
-
const optionNames = extractAggregationValues(aggregationResponse,
|
|
93
|
-
const choiceNames = extractAggregationValues(aggregationResponse,
|
|
94
|
-
const inventoryStatuses = extractAggregationValues(aggregationResponse,
|
|
88
|
+
const aggregationResponse = await productsV3.searchProducts(aggregationRequest);
|
|
89
|
+
const optionNames = extractAggregationValues(aggregationResponse, "optionNames");
|
|
90
|
+
const choiceNames = extractAggregationValues(aggregationResponse, "choiceNames");
|
|
91
|
+
const inventoryStatuses = extractAggregationValues(aggregationResponse, "inventoryStatus");
|
|
95
92
|
// Step 2: Get option structure from customizations API
|
|
96
|
-
const customizationsResponse = await
|
|
93
|
+
const customizationsResponse = await customizationsV3
|
|
94
|
+
.queryCustomizations()
|
|
95
|
+
.find();
|
|
97
96
|
const customizations = customizationsResponse.items || [];
|
|
98
97
|
// Step 3: Build options by matching customizations with aggregation data
|
|
99
98
|
const options = customizations
|
|
100
|
-
.filter(customization => customization.name &&
|
|
99
|
+
.filter((customization) => customization.name &&
|
|
101
100
|
customization._id &&
|
|
102
101
|
customization.customizationType ===
|
|
103
|
-
|
|
102
|
+
customizationsV3.CustomizationType.PRODUCT_OPTION &&
|
|
104
103
|
matchesAggregationName(customization.name, optionNames))
|
|
105
|
-
.map(customization => {
|
|
104
|
+
.map((customization) => {
|
|
106
105
|
const choices = (customization.choicesSettings?.choices || [])
|
|
107
|
-
.filter(choice => choice._id &&
|
|
106
|
+
.filter((choice) => choice._id &&
|
|
108
107
|
choice.name &&
|
|
109
108
|
matchesAggregationName(choice.name, choiceNames))
|
|
110
|
-
.map(choice => ({
|
|
109
|
+
.map((choice) => ({
|
|
111
110
|
id: choice._id,
|
|
112
111
|
name: choice.name,
|
|
113
112
|
colorCode: choice.colorCode,
|
|
@@ -119,25 +118,25 @@ exports.CatalogOptionsService = services_definitions_1.implementService.withConf
|
|
|
119
118
|
optionRenderType: customization.customizationRenderType,
|
|
120
119
|
};
|
|
121
120
|
})
|
|
122
|
-
.filter(option => option.choices.length > 0);
|
|
121
|
+
.filter((option) => option.choices.length > 0);
|
|
123
122
|
// Step 4: Add inventory filter if there are multiple inventory statuses
|
|
124
123
|
if (inventoryStatuses.length > 1) {
|
|
125
|
-
const inventoryChoices = inventoryStatuses.map(status => ({
|
|
124
|
+
const inventoryChoices = inventoryStatuses.map((status) => ({
|
|
126
125
|
id: status.toUpperCase(), // Use uppercase to match actual availabilityStatus values
|
|
127
126
|
name: status.toUpperCase(), // Use raw status value - UI components will handle display conversion
|
|
128
127
|
}));
|
|
129
128
|
options.push({
|
|
130
|
-
id:
|
|
131
|
-
name:
|
|
129
|
+
id: "inventory-filter",
|
|
130
|
+
name: "Availability",
|
|
132
131
|
choices: inventoryChoices,
|
|
133
|
-
optionRenderType:
|
|
132
|
+
optionRenderType: productsV3.ModifierRenderType.TEXT_CHOICES,
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
135
|
catalogOptions.set(options);
|
|
137
136
|
}
|
|
138
137
|
catch (err) {
|
|
139
|
-
console.error(
|
|
140
|
-
error.set(err instanceof Error ? err.message :
|
|
138
|
+
console.error("Failed to load catalog options:", err);
|
|
139
|
+
error.set(err instanceof Error ? err.message : "Failed to load catalog options");
|
|
141
140
|
catalogOptions.set([]);
|
|
142
141
|
}
|
|
143
142
|
finally {
|
|
@@ -151,6 +150,6 @@ exports.CatalogOptionsService = services_definitions_1.implementService.withConf
|
|
|
151
150
|
loadCatalogOptions,
|
|
152
151
|
};
|
|
153
152
|
});
|
|
154
|
-
async function loadCatalogOptionsServiceConfig() {
|
|
153
|
+
export async function loadCatalogOptionsServiceConfig() {
|
|
155
154
|
return {};
|
|
156
155
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ServiceFactoryConfig } from
|
|
2
|
-
import type
|
|
1
|
+
import { type ServiceFactoryConfig } from "@wix/services-definitions";
|
|
2
|
+
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
3
3
|
export interface CatalogPriceRange {
|
|
4
4
|
minPrice: number;
|
|
5
5
|
maxPrice: number;
|
|
@@ -19,5 +19,5 @@ export declare const CatalogPriceRangeService: import("@wix/services-definitions
|
|
|
19
19
|
__api: CatalogPriceRangeServiceAPI;
|
|
20
20
|
__config: {};
|
|
21
21
|
isServiceDefinition?: boolean;
|
|
22
|
-
} & CatalogPriceRangeServiceAPI, {}
|
|
22
|
+
} & CatalogPriceRangeServiceAPI, {}>;
|
|
23
23
|
export declare function loadCatalogPriceRangeServiceConfig(): Promise<ServiceFactoryConfig<typeof CatalogPriceRangeService>>;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.loadCatalogPriceRangeServiceConfig = loadCatalogPriceRangeServiceConfig;
|
|
5
|
-
const services_definitions_1 = require("@wix/services-definitions");
|
|
6
|
-
const signals_1 = require("@wix/services-definitions/core-services/signals");
|
|
7
|
-
const auto_sdk_stores_products_v_3_1 = require("@wix/auto_sdk_stores_products-v-3");
|
|
1
|
+
import { defineService, implementService, } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
8
4
|
// Helper function to extract scalar aggregation values
|
|
9
5
|
const extractScalarAggregationValue = (aggregationResponse, name) => {
|
|
10
6
|
const aggregation = aggregationResponse.aggregations?.[name] ||
|
|
@@ -18,14 +14,14 @@ const buildCategoryFilter = (categoryId) => {
|
|
|
18
14
|
}
|
|
19
15
|
return {
|
|
20
16
|
visible: true,
|
|
21
|
-
|
|
17
|
+
"allCategoriesInfo.categories": {
|
|
22
18
|
$matchItems: [{ _id: { $in: [categoryId] } }],
|
|
23
19
|
},
|
|
24
20
|
};
|
|
25
21
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const signalsService = getService(
|
|
22
|
+
export const CatalogPriceRangeServiceDefinition = defineService("catalogPriceRange");
|
|
23
|
+
export const CatalogPriceRangeService = implementService.withConfig()(CatalogPriceRangeServiceDefinition, ({ getService }) => {
|
|
24
|
+
const signalsService = getService(SignalsServiceDefinition);
|
|
29
25
|
// Signal declarations
|
|
30
26
|
const catalogPriceRange = signalsService.signal(null);
|
|
31
27
|
const isLoading = signalsService.signal(false);
|
|
@@ -42,25 +38,25 @@ exports.CatalogPriceRangeService = services_definitions_1.implementService.withC
|
|
|
42
38
|
const aggregationRequest = {
|
|
43
39
|
aggregations: [
|
|
44
40
|
{
|
|
45
|
-
name:
|
|
46
|
-
fieldPath:
|
|
47
|
-
type:
|
|
48
|
-
scalar: { type:
|
|
41
|
+
name: "minPrice",
|
|
42
|
+
fieldPath: "actualPriceRange.minValue.amount",
|
|
43
|
+
type: "SCALAR",
|
|
44
|
+
scalar: { type: "MIN" },
|
|
49
45
|
},
|
|
50
46
|
{
|
|
51
|
-
name:
|
|
52
|
-
fieldPath:
|
|
53
|
-
type:
|
|
54
|
-
scalar: { type:
|
|
47
|
+
name: "maxPrice",
|
|
48
|
+
fieldPath: "actualPriceRange.maxValue.amount",
|
|
49
|
+
type: "SCALAR",
|
|
50
|
+
scalar: { type: "MAX" },
|
|
55
51
|
},
|
|
56
52
|
],
|
|
57
53
|
filter: buildCategoryFilter(categoryId),
|
|
58
54
|
includeProducts: false,
|
|
59
55
|
cursorPaging: { limit: 0 },
|
|
60
56
|
};
|
|
61
|
-
const aggregationResponse = await
|
|
62
|
-
const minPrice = extractScalarAggregationValue(aggregationResponse,
|
|
63
|
-
const maxPrice = extractScalarAggregationValue(aggregationResponse,
|
|
57
|
+
const aggregationResponse = await productsV3.searchProducts(aggregationRequest);
|
|
58
|
+
const minPrice = extractScalarAggregationValue(aggregationResponse, "minPrice");
|
|
59
|
+
const maxPrice = extractScalarAggregationValue(aggregationResponse, "maxPrice");
|
|
64
60
|
// Only set price range if we found valid prices
|
|
65
61
|
if (minPrice !== null &&
|
|
66
62
|
maxPrice !== null &&
|
|
@@ -76,8 +72,8 @@ exports.CatalogPriceRangeService = services_definitions_1.implementService.withC
|
|
|
76
72
|
}
|
|
77
73
|
}
|
|
78
74
|
catch (err) {
|
|
79
|
-
console.error(
|
|
80
|
-
error.set(err instanceof Error ? err.message :
|
|
75
|
+
console.error("Failed to load catalog price range:", err);
|
|
76
|
+
error.set(err instanceof Error ? err.message : "Failed to load price range");
|
|
81
77
|
// Don't set fallback values - let the component handle the error state
|
|
82
78
|
catalogPriceRange.set(null);
|
|
83
79
|
}
|
|
@@ -92,6 +88,6 @@ exports.CatalogPriceRangeService = services_definitions_1.implementService.withC
|
|
|
92
88
|
loadCatalogPriceRange,
|
|
93
89
|
};
|
|
94
90
|
});
|
|
95
|
-
async function loadCatalogPriceRangeServiceConfig() {
|
|
91
|
+
export async function loadCatalogPriceRangeServiceConfig() {
|
|
96
92
|
return {};
|
|
97
93
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
1
|
+
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
|
+
import * as categories from "@wix/auto_sdk_categories_categories";
|
|
3
3
|
export interface CategoryServiceAPI {
|
|
4
4
|
selectedCategory: Signal<string | null>;
|
|
5
|
-
categories: Signal<Category[]>;
|
|
5
|
+
categories: Signal<categories.Category[]>;
|
|
6
6
|
setSelectedCategory: (categoryId: string | null) => void;
|
|
7
7
|
loadCategories: () => Promise<void>;
|
|
8
8
|
}
|
|
@@ -12,15 +12,15 @@ export declare const CategoryServiceDefinition: string & {
|
|
|
12
12
|
isServiceDefinition?: boolean;
|
|
13
13
|
} & CategoryServiceAPI;
|
|
14
14
|
export interface CategoryServiceConfig {
|
|
15
|
-
categories: Category[];
|
|
15
|
+
categories: categories.Category[];
|
|
16
16
|
initialCategoryId?: string | null;
|
|
17
|
-
onCategoryChange?: (categoryId: string | null, category: Category | null) => void;
|
|
17
|
+
onCategoryChange?: (categoryId: string | null, category: categories.Category | null) => void;
|
|
18
18
|
}
|
|
19
19
|
export declare const CategoryService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
20
20
|
__api: CategoryServiceAPI;
|
|
21
21
|
__config: {};
|
|
22
22
|
isServiceDefinition?: boolean;
|
|
23
|
-
} & CategoryServiceAPI, CategoryServiceConfig
|
|
23
|
+
} & CategoryServiceAPI, CategoryServiceConfig>;
|
|
24
24
|
export declare function loadCategoriesConfig(): Promise<{
|
|
25
|
-
categories: Category[];
|
|
25
|
+
categories: categories.Category[];
|
|
26
26
|
}>;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
exports.CategoryService = services_definitions_1.implementService.withConfig()(exports.CategoryServiceDefinition, ({ getService, config }) => {
|
|
10
|
-
const signalsService = getService(signals_1.SignalsServiceDefinition);
|
|
11
|
-
const selectedCategory = signalsService.signal((config.initialCategoryId || null));
|
|
12
|
-
const categories = signalsService.signal(config.categories);
|
|
1
|
+
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import * as categories from "@wix/auto_sdk_categories_categories";
|
|
4
|
+
export const CategoryServiceDefinition = defineService("category-service");
|
|
5
|
+
export const CategoryService = implementService.withConfig()(CategoryServiceDefinition, ({ getService, config }) => {
|
|
6
|
+
const signalsService = getService(SignalsServiceDefinition);
|
|
7
|
+
const selectedCategory = signalsService.signal((config?.initialCategoryId || null));
|
|
8
|
+
const categories = signalsService.signal(config?.categories);
|
|
13
9
|
const loadCategories = async () => {
|
|
14
10
|
const { categories: loadedCategories } = await loadCategoriesConfig();
|
|
15
11
|
categories.set(loadedCategories);
|
|
@@ -20,16 +16,17 @@ exports.CategoryService = services_definitions_1.implementService.withConfig()(e
|
|
|
20
16
|
selectedCategory.set(categoryId);
|
|
21
17
|
};
|
|
22
18
|
// Subscribe to category changes and handle navigation as a side effect
|
|
23
|
-
|
|
19
|
+
signalsService.effect(() => {
|
|
20
|
+
const categoryId = selectedCategory.get();
|
|
24
21
|
// Skip navigation on initial load (when service is first created)
|
|
25
22
|
if (isInitialLoad) {
|
|
26
23
|
isInitialLoad = false;
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
26
|
// If a navigation handler is provided, use it
|
|
30
|
-
if (config
|
|
27
|
+
if (config?.onCategoryChange) {
|
|
31
28
|
const category = categoryId
|
|
32
|
-
? config
|
|
29
|
+
? config?.categories.find((cat) => cat._id === categoryId) || null
|
|
33
30
|
: null;
|
|
34
31
|
config.onCategoryChange(categoryId, category);
|
|
35
32
|
}
|
|
@@ -41,20 +38,21 @@ exports.CategoryService = services_definitions_1.implementService.withConfig()(e
|
|
|
41
38
|
loadCategories,
|
|
42
39
|
};
|
|
43
40
|
});
|
|
44
|
-
async function loadCategoriesConfig() {
|
|
41
|
+
export async function loadCategoriesConfig() {
|
|
45
42
|
try {
|
|
46
|
-
const categoriesResponse = await
|
|
43
|
+
const categoriesResponse = await categories
|
|
44
|
+
.queryCategories({
|
|
47
45
|
treeReference: {
|
|
48
|
-
appNamespace:
|
|
46
|
+
appNamespace: "@wix/stores",
|
|
49
47
|
treeKey: null,
|
|
50
48
|
},
|
|
51
49
|
})
|
|
52
|
-
.eq(
|
|
50
|
+
.eq("visible", true)
|
|
53
51
|
.find();
|
|
54
52
|
const fetchedCategories = categoriesResponse.items || [];
|
|
55
53
|
// Sort categories to put "all-products" first, keep the rest in original order
|
|
56
|
-
const allProductsCategory = fetchedCategories.find(cat => cat.slug ===
|
|
57
|
-
const otherCategories = fetchedCategories.filter(cat => cat.slug !==
|
|
54
|
+
const allProductsCategory = fetchedCategories.find((cat) => cat.slug === "all-products");
|
|
55
|
+
const otherCategories = fetchedCategories.filter((cat) => cat.slug !== "all-products");
|
|
58
56
|
const allCategories = allProductsCategory
|
|
59
57
|
? [allProductsCategory, ...otherCategories]
|
|
60
58
|
: fetchedCategories;
|
|
@@ -63,7 +61,7 @@ async function loadCategoriesConfig() {
|
|
|
63
61
|
};
|
|
64
62
|
}
|
|
65
63
|
catch (error) {
|
|
66
|
-
console.warn(
|
|
64
|
+
console.warn("Failed to load categories:", error);
|
|
67
65
|
return {
|
|
68
66
|
categories: [],
|
|
69
67
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type ServiceFactoryConfig } from
|
|
2
|
-
import type
|
|
3
|
-
import
|
|
4
|
-
import { type Filter } from
|
|
5
|
-
import { type SortBy } from
|
|
1
|
+
import { type ServiceFactoryConfig } from "@wix/services-definitions";
|
|
2
|
+
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
4
|
+
import { type Filter } from "./filter-service.js";
|
|
5
|
+
import { type SortBy } from "./sort-service.js";
|
|
6
6
|
export interface CollectionServiceAPI {
|
|
7
|
-
products: Signal<V3Product[]>;
|
|
7
|
+
products: Signal<productsV3.V3Product[]>;
|
|
8
8
|
isLoading: Signal<boolean>;
|
|
9
9
|
error: Signal<string | null>;
|
|
10
10
|
totalProducts: Signal<number>;
|
|
@@ -23,12 +23,12 @@ export declare const CollectionService: import("@wix/services-definitions").Serv
|
|
|
23
23
|
__config: {};
|
|
24
24
|
isServiceDefinition?: boolean;
|
|
25
25
|
} & CollectionServiceAPI, {
|
|
26
|
-
initialProducts?: V3Product[];
|
|
26
|
+
initialProducts?: productsV3.V3Product[];
|
|
27
27
|
pageSize?: number;
|
|
28
28
|
initialCursor?: string;
|
|
29
29
|
initialHasMore?: boolean;
|
|
30
30
|
categories?: any[];
|
|
31
|
-
}
|
|
31
|
+
}>;
|
|
32
32
|
export declare function loadCollectionServiceConfig(categoryId?: string, searchParams?: URLSearchParams, preloadedCategories?: any[]): Promise<ServiceFactoryConfig<typeof CollectionService> & {
|
|
33
33
|
initialCursor?: string;
|
|
34
34
|
initialHasMore?: boolean;
|