@wix/headless-stores 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/astro/actions/package.json +4 -0
- package/cjs/dist/astro/actions/custom-checkout.d.ts +50 -0
- package/cjs/dist/astro/actions/custom-checkout.js +53 -0
- package/cjs/dist/astro/actions/index.d.ts +1 -0
- package/cjs/dist/astro/actions/index.js +1 -0
- package/cjs/dist/data-component-tags.d.ts +8 -0
- package/cjs/dist/data-component-tags.js +9 -0
- package/cjs/dist/enums/index.d.ts +2 -0
- package/cjs/dist/enums/index.js +2 -0
- package/cjs/dist/enums/social-platform-enums.d.ts +25 -0
- package/cjs/dist/enums/social-platform-enums.js +27 -0
- package/cjs/dist/enums/sort-enums.d.ts +17 -0
- package/cjs/dist/enums/sort-enums.js +18 -0
- package/cjs/dist/react/Category.d.ts +242 -0
- package/cjs/dist/react/Category.js +235 -0
- package/cjs/dist/react/CategoryList.d.ts +107 -0
- package/cjs/dist/react/CategoryList.js +91 -0
- package/cjs/dist/react/Choice.d.ts +211 -0
- package/cjs/dist/react/Choice.js +213 -0
- package/cjs/dist/react/Option.d.ts +242 -0
- package/cjs/dist/react/Option.js +346 -0
- package/cjs/dist/react/Product.d.ts +1065 -0
- package/cjs/dist/react/Product.js +1157 -0
- package/cjs/dist/react/ProductList.d.ts +400 -0
- package/cjs/dist/react/ProductList.js +368 -0
- package/cjs/dist/react/core/CategoryList.d.ts +194 -0
- package/cjs/dist/react/core/CategoryList.js +180 -0
- package/cjs/dist/react/core/Product.d.ts +225 -0
- package/cjs/dist/react/core/Product.js +190 -0
- package/cjs/dist/react/core/ProductList.d.ts +235 -0
- package/cjs/dist/react/core/ProductList.js +217 -0
- package/cjs/dist/react/core/ProductListFilters.d.ts +138 -0
- package/cjs/dist/react/core/ProductListFilters.js +242 -0
- package/cjs/dist/react/core/ProductListPagination.d.ts +49 -0
- package/cjs/dist/react/core/ProductListPagination.js +41 -0
- package/cjs/dist/react/core/ProductListSort.d.ts +19 -0
- package/cjs/dist/react/core/ProductListSort.js +52 -0
- package/cjs/dist/react/core/ProductModifiers.d.ts +416 -0
- package/cjs/dist/react/core/ProductModifiers.js +413 -0
- package/cjs/dist/react/core/ProductVariantSelector.d.ts +313 -0
- package/cjs/dist/react/core/ProductVariantSelector.js +291 -0
- package/cjs/dist/react/core/SelectedVariant.d.ts +230 -0
- package/cjs/dist/react/core/SelectedVariant.js +269 -0
- package/cjs/dist/react/index.d.ts +6 -0
- package/cjs/dist/react/index.js +6 -0
- package/cjs/dist/react/types.d.ts +8 -0
- package/cjs/dist/react/types.js +9 -0
- package/cjs/dist/server-actions/custom-checkout-action.d.ts +49 -0
- package/cjs/dist/server-actions/custom-checkout-action.js +64 -0
- package/cjs/dist/server-actions/index.d.ts +1 -0
- package/cjs/dist/server-actions/index.js +1 -0
- package/cjs/dist/services/buy-now-service.d.ts +346 -0
- package/cjs/dist/services/buy-now-service.js +197 -0
- package/cjs/dist/services/categories-list-service.d.ts +164 -0
- package/cjs/dist/services/categories-list-service.js +148 -0
- package/cjs/dist/services/index.d.ts +5 -0
- package/cjs/dist/services/index.js +5 -0
- package/cjs/dist/services/pay-now-service.d.ts +214 -0
- package/cjs/dist/services/pay-now-service.js +156 -0
- package/cjs/dist/services/product-modifiers-service.d.ts +34 -0
- package/cjs/dist/services/product-modifiers-service.js +107 -0
- package/cjs/dist/services/product-service.d.ts +177 -0
- package/cjs/dist/services/product-service.js +190 -0
- package/cjs/dist/services/products-list-search-service.d.ts +1 -0
- package/cjs/dist/services/products-list-search-service.js +1 -0
- package/cjs/dist/services/products-list-service.d.ts +429 -0
- package/cjs/dist/services/products-list-service.js +893 -0
- package/cjs/dist/services/selected-variant-service.d.ts +66 -0
- package/cjs/dist/services/selected-variant-service.js +527 -0
- package/cjs/dist/utils/index.d.ts +1 -0
- package/cjs/dist/utils/index.js +30 -0
- package/cjs/dist/utils/url-params.d.ts +73 -0
- package/cjs/dist/utils/url-params.js +114 -0
- package/cjs/package.json +3 -0
- package/dist/astro/actions/custom-checkout.d.ts +50 -0
- package/dist/astro/actions/custom-checkout.js +53 -0
- package/dist/astro/actions/index.d.ts +1 -0
- package/dist/astro/actions/index.js +1 -0
- package/dist/data-component-tags.d.ts +8 -0
- package/dist/data-component-tags.js +9 -0
- package/dist/enums/index.d.ts +2 -0
- package/dist/enums/index.js +2 -0
- package/dist/enums/social-platform-enums.d.ts +25 -0
- package/dist/enums/social-platform-enums.js +27 -0
- package/dist/enums/sort-enums.d.ts +17 -0
- package/dist/enums/sort-enums.js +18 -0
- package/dist/react/Category.d.ts +242 -0
- package/dist/react/Category.js +235 -0
- package/dist/react/CategoryList.d.ts +107 -0
- package/dist/react/CategoryList.js +91 -0
- package/dist/react/Choice.d.ts +211 -0
- package/dist/react/Choice.js +213 -0
- package/dist/react/Option.d.ts +242 -0
- package/dist/react/Option.js +346 -0
- package/dist/react/Product.d.ts +1065 -0
- package/dist/react/Product.js +1157 -0
- package/dist/react/ProductList.d.ts +400 -0
- package/dist/react/ProductList.js +368 -0
- package/dist/react/core/CategoryList.d.ts +194 -0
- package/dist/react/core/CategoryList.js +180 -0
- package/dist/react/core/Product.d.ts +225 -0
- package/dist/react/core/Product.js +190 -0
- package/dist/react/core/ProductList.d.ts +235 -0
- package/dist/react/core/ProductList.js +217 -0
- package/dist/react/core/ProductListFilters.d.ts +138 -0
- package/dist/react/core/ProductListFilters.js +242 -0
- package/dist/react/core/ProductListPagination.d.ts +49 -0
- package/dist/react/core/ProductListPagination.js +41 -0
- package/dist/react/core/ProductListSort.d.ts +19 -0
- package/dist/react/core/ProductListSort.js +52 -0
- package/dist/react/core/ProductModifiers.d.ts +416 -0
- package/dist/react/core/ProductModifiers.js +413 -0
- package/dist/react/core/ProductVariantSelector.d.ts +313 -0
- package/dist/react/core/ProductVariantSelector.js +291 -0
- package/dist/react/core/SelectedVariant.d.ts +230 -0
- package/dist/react/core/SelectedVariant.js +269 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.js +6 -0
- package/dist/react/types.d.ts +8 -0
- package/dist/react/types.js +9 -0
- package/dist/server-actions/custom-checkout-action.d.ts +49 -0
- package/dist/server-actions/custom-checkout-action.js +64 -0
- package/dist/server-actions/index.d.ts +1 -0
- package/dist/server-actions/index.js +1 -0
- package/dist/services/buy-now-service.d.ts +346 -0
- package/dist/services/buy-now-service.js +197 -0
- package/dist/services/categories-list-service.d.ts +164 -0
- package/dist/services/categories-list-service.js +148 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.js +5 -0
- package/dist/services/pay-now-service.d.ts +214 -0
- package/dist/services/pay-now-service.js +156 -0
- package/dist/services/product-modifiers-service.d.ts +34 -0
- package/dist/services/product-modifiers-service.js +107 -0
- package/dist/services/product-service.d.ts +177 -0
- package/dist/services/product-service.js +190 -0
- package/dist/services/products-list-search-service.d.ts +0 -0
- package/dist/services/products-list-search-service.js +1 -0
- package/dist/services/products-list-service.d.ts +429 -0
- package/dist/services/products-list-service.js +893 -0
- package/dist/services/selected-variant-service.d.ts +66 -0
- package/dist/services/selected-variant-service.js +527 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +30 -0
- package/dist/utils/url-params.d.ts +73 -0
- package/dist/utils/url-params.js +114 -0
- package/package.json +89 -0
- package/react/package.json +4 -0
- package/server-actions/package.json +4 -0
- package/services/package.json +4 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import { type Signal, type ReadOnlySignal } from '@wix/services-definitions/core-services/signals';
|
|
2
|
+
import { customizationsV3, productsV3 } from '@wix/stores';
|
|
3
|
+
import { categories } from '@wix/categories';
|
|
4
|
+
type Category = categories.Category;
|
|
5
|
+
export declare const DEFAULT_QUERY_LIMIT = 100;
|
|
6
|
+
import { SortType } from './../enums/sort-enums.js';
|
|
7
|
+
export { SortType } from './../enums/sort-enums.js';
|
|
8
|
+
/**
|
|
9
|
+
* Enumeration of inventory status types available for filtering.
|
|
10
|
+
* Re-exports the Wix inventory availability status enum values.
|
|
11
|
+
*/
|
|
12
|
+
export declare const InventoryStatusType: typeof productsV3.InventoryAvailabilityStatus;
|
|
13
|
+
/**
|
|
14
|
+
* Type for inventory status values.
|
|
15
|
+
* Re-exports the Wix inventory availability status enum type.
|
|
16
|
+
*/
|
|
17
|
+
export type InventoryStatusType = productsV3.InventoryAvailabilityStatus;
|
|
18
|
+
/**
|
|
19
|
+
* Interface representing a product option (like Size, Color, etc.).
|
|
20
|
+
*/
|
|
21
|
+
export interface ProductOption {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
choices: ProductChoice[];
|
|
25
|
+
optionRenderType?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Interface representing a choice within a product option.
|
|
29
|
+
*/
|
|
30
|
+
export interface ProductChoice {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
colorCode?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Configuration interface for the Products List service.
|
|
37
|
+
* Contains the initial products data, search options, and metadata.
|
|
38
|
+
*
|
|
39
|
+
* @interface ProductsListServiceConfig
|
|
40
|
+
*/
|
|
41
|
+
export type ProductsListServiceConfig = {
|
|
42
|
+
/** Array of product objects to initialize the service with */
|
|
43
|
+
products: productsV3.V3Product[];
|
|
44
|
+
/** Search options used to fetch the products */
|
|
45
|
+
searchOptions: productsV3.V3ProductSearch;
|
|
46
|
+
/** Pagination metadata from the search response */
|
|
47
|
+
pagingMetadata: productsV3.CommonCursorPagingMetadata;
|
|
48
|
+
/** Aggregation data containing filters, facets, and counts */
|
|
49
|
+
aggregations: productsV3.AggregationData;
|
|
50
|
+
/** Customizations used to fetch the products */
|
|
51
|
+
customizations: customizationsV3.Customization[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Loads products list service configuration from the Wix Stores API for SSR initialization.
|
|
55
|
+
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
56
|
+
* a list of products based on search criteria or URL parameters.
|
|
57
|
+
*
|
|
58
|
+
* @param {string | { searchOptions: productsV3.V3ProductSearch; initialSearchState: InitialSearchState }} input - Either a URL to parse or parsed URL result from parseUrlToSearchOptions
|
|
59
|
+
* @returns {Promise<ProductsListServiceConfig>} Promise that resolves to the products list configuration
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```astro
|
|
63
|
+
* ---
|
|
64
|
+
* // Astro page example - pages/products.astro
|
|
65
|
+
* import { loadProductsListServiceConfig, parseUrlToSearchOptions, loadCategoriesListServiceConfig } from '@wix/stores/services';
|
|
66
|
+
* import { ProductList } from '@wix/stores/components';
|
|
67
|
+
*
|
|
68
|
+
* // Option 1: Load from URL (will parse filters, sort, pagination from URL params)
|
|
69
|
+
* const productsConfig = await loadProductsListServiceConfig(Astro.url.href);
|
|
70
|
+
*
|
|
71
|
+
* // Option 2: Custom parsing with defaults
|
|
72
|
+
* const categories = await loadCategoriesListServiceConfig();
|
|
73
|
+
* const parsed = await parseUrlToSearchOptions(
|
|
74
|
+
* Astro.url.href,
|
|
75
|
+
* categories.categories,
|
|
76
|
+
* {
|
|
77
|
+
* cursorPaging: { limit: 12 },
|
|
78
|
+
* filter: {},
|
|
79
|
+
* sort: [{ fieldName: 'name' as const, order: 'ASC' as const }]
|
|
80
|
+
* }
|
|
81
|
+
* );
|
|
82
|
+
* const productsConfig = await loadProductsListServiceConfig(parsed);
|
|
83
|
+
* ---
|
|
84
|
+
*
|
|
85
|
+
* <ProductList.Root productsConfig={productsConfig}>
|
|
86
|
+
* <ProductList.ItemContent>
|
|
87
|
+
* {({ product }) => (
|
|
88
|
+
* <div>
|
|
89
|
+
* <h3>{product.name}</h3>
|
|
90
|
+
* <p>{product.description}</p>
|
|
91
|
+
* </div>
|
|
92
|
+
* )}
|
|
93
|
+
* </ProductList.ItemContent>
|
|
94
|
+
* </ProductList.Root>
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* // Next.js page example - pages/products.tsx
|
|
100
|
+
* import { GetServerSideProps } from 'next';
|
|
101
|
+
* import { loadProductsListServiceConfig, parseUrlToSearchOptions, loadCategoriesListServiceConfig } from '@wix/stores/services';
|
|
102
|
+
* import { ProductsList } from '@wix/stores/components';
|
|
103
|
+
*
|
|
104
|
+
* interface ProductsPageProps {
|
|
105
|
+
* productsConfig: Awaited<ReturnType<typeof loadProductsListServiceConfig>>;
|
|
106
|
+
* }
|
|
107
|
+
*
|
|
108
|
+
* export const getServerSideProps: GetServerSideProps<ProductsPageProps> = async ({ req }) => {
|
|
109
|
+
* // Option 1: Parse from URL
|
|
110
|
+
* const productsConfig = await loadProductsListServiceConfig(`${req.url}`);
|
|
111
|
+
*
|
|
112
|
+
* // Option 2: Custom parsing with filters
|
|
113
|
+
* const categories = await loadCategoriesListServiceConfig();
|
|
114
|
+
* const parsed = await parseUrlToSearchOptions(
|
|
115
|
+
* `${req.url}`,
|
|
116
|
+
* categories.categories,
|
|
117
|
+
* {
|
|
118
|
+
* cursorPaging: { limit: 12 },
|
|
119
|
+
* filter: {
|
|
120
|
+
* 'allCategoriesInfo.categories': { $matchItems: [{ _id: { $in: [category._id] } }] }
|
|
121
|
+
* },
|
|
122
|
+
* sort: [{ fieldName: 'name' as const, order: 'ASC' as const }]
|
|
123
|
+
* }
|
|
124
|
+
* );
|
|
125
|
+
* const productsConfig = await loadProductsListServiceConfig(parsed);
|
|
126
|
+
*
|
|
127
|
+
* return {
|
|
128
|
+
* props: {
|
|
129
|
+
* productsConfig,
|
|
130
|
+
* },
|
|
131
|
+
* };
|
|
132
|
+
* };
|
|
133
|
+
*
|
|
134
|
+
* export default function ProductsPage({ productsConfig }: ProductsPageProps) {
|
|
135
|
+
* return (
|
|
136
|
+
* <ProductList.Root productsConfig={productsConfig}>
|
|
137
|
+
* <ProductList.ItemContent>
|
|
138
|
+
* {({ product }) => (
|
|
139
|
+
* <div>
|
|
140
|
+
* <h3>{product.name}</h3>
|
|
141
|
+
* <p>{product.description}</p>
|
|
142
|
+
* </div>
|
|
143
|
+
* )}
|
|
144
|
+
* </ProductList.ItemContent>
|
|
145
|
+
* </ProductList.Root>
|
|
146
|
+
* );
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```tsx
|
|
152
|
+
* // Advanced: Performance optimization when using both services
|
|
153
|
+
* import { parseUrlToSearchOptions, loadProductsListServiceConfig, loadProductsListSearchServiceConfig, loadCategoriesListServiceConfig } from '@wix/stores/services';
|
|
154
|
+
*
|
|
155
|
+
* const categories = await loadCategoriesListServiceConfig();
|
|
156
|
+
* const parsed = await parseUrlToSearchOptions(url, categories.categories);
|
|
157
|
+
*
|
|
158
|
+
* // Both services use the same parsed result (no duplicate URL parsing)
|
|
159
|
+
* const [productsConfig, searchConfig] = await Promise.all([
|
|
160
|
+
* loadProductsListServiceConfig(parsed),
|
|
161
|
+
* loadProductsListSearchServiceConfig(parsed)
|
|
162
|
+
* ]);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare function loadProductsListServiceConfig(input: string | {
|
|
166
|
+
searchOptions: productsV3.V3ProductSearch;
|
|
167
|
+
}): Promise<ProductsListServiceConfig>;
|
|
168
|
+
/**
|
|
169
|
+
* Service definition for the Products List service.
|
|
170
|
+
* This defines the reactive API contract for managing a list of products with search, pagination, and filtering capabilities.
|
|
171
|
+
*
|
|
172
|
+
* @constant
|
|
173
|
+
*/
|
|
174
|
+
export declare const ProductsListServiceDefinition: string & {
|
|
175
|
+
__api: {
|
|
176
|
+
/** Reactive signal containing the list of products */
|
|
177
|
+
products: Signal<productsV3.V3Product[]>;
|
|
178
|
+
/** Reactive signal containing aggregation data for filters and facets */
|
|
179
|
+
aggregations: Signal<productsV3.AggregationData>;
|
|
180
|
+
/** Reactive signal containing pagination metadata */
|
|
181
|
+
pagingMetadata: Signal<productsV3.CommonCursorPagingMetadata>;
|
|
182
|
+
/** Reactive signal containing current search options */
|
|
183
|
+
searchOptions: Signal<productsV3.V3ProductSearch>;
|
|
184
|
+
/** Reactive signal indicating if products are currently being loaded */
|
|
185
|
+
isLoading: Signal<boolean>;
|
|
186
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
187
|
+
error: Signal<string | null>;
|
|
188
|
+
/** Reactive signal containing the minimum price of the products */
|
|
189
|
+
minPrice: Signal<number>;
|
|
190
|
+
/** Reactive signal containing the maximum price of the products */
|
|
191
|
+
maxPrice: Signal<number>;
|
|
192
|
+
/** Reactive signal containing the available inventory statuses */
|
|
193
|
+
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
194
|
+
/** Reactive signal containing the available product options */
|
|
195
|
+
availableProductOptions: Signal<ProductOption[]>;
|
|
196
|
+
/** Function to update search options and trigger a new search */
|
|
197
|
+
setSearchOptions: (searchOptions: productsV3.V3ProductSearch) => void;
|
|
198
|
+
/** Function to update only the sort part of search options */
|
|
199
|
+
setSort: (sort: productsV3.V3ProductSearch["sort"]) => void;
|
|
200
|
+
/** Function to update only the filter part of search options */
|
|
201
|
+
setFilter: (filter: productsV3.V3ProductSearch["filter"]) => void;
|
|
202
|
+
/** Function to reset the filter part of search options */
|
|
203
|
+
resetFilter: () => void;
|
|
204
|
+
/** Reactive signal indicating if any filters are currently applied */
|
|
205
|
+
isFiltered: () => ReadOnlySignal<boolean>;
|
|
206
|
+
/** Function to load more products */
|
|
207
|
+
loadMore: (count: number) => void;
|
|
208
|
+
/** Reactive signal indicating if there are more products to load */
|
|
209
|
+
hasMoreProducts: ReadOnlySignal<boolean>;
|
|
210
|
+
};
|
|
211
|
+
__config: ProductsListServiceConfig;
|
|
212
|
+
isServiceDefinition?: boolean;
|
|
213
|
+
} & {
|
|
214
|
+
/** Reactive signal containing the list of products */
|
|
215
|
+
products: Signal<productsV3.V3Product[]>;
|
|
216
|
+
/** Reactive signal containing aggregation data for filters and facets */
|
|
217
|
+
aggregations: Signal<productsV3.AggregationData>;
|
|
218
|
+
/** Reactive signal containing pagination metadata */
|
|
219
|
+
pagingMetadata: Signal<productsV3.CommonCursorPagingMetadata>;
|
|
220
|
+
/** Reactive signal containing current search options */
|
|
221
|
+
searchOptions: Signal<productsV3.V3ProductSearch>;
|
|
222
|
+
/** Reactive signal indicating if products are currently being loaded */
|
|
223
|
+
isLoading: Signal<boolean>;
|
|
224
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
225
|
+
error: Signal<string | null>;
|
|
226
|
+
/** Reactive signal containing the minimum price of the products */
|
|
227
|
+
minPrice: Signal<number>;
|
|
228
|
+
/** Reactive signal containing the maximum price of the products */
|
|
229
|
+
maxPrice: Signal<number>;
|
|
230
|
+
/** Reactive signal containing the available inventory statuses */
|
|
231
|
+
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
232
|
+
/** Reactive signal containing the available product options */
|
|
233
|
+
availableProductOptions: Signal<ProductOption[]>;
|
|
234
|
+
/** Function to update search options and trigger a new search */
|
|
235
|
+
setSearchOptions: (searchOptions: productsV3.V3ProductSearch) => void;
|
|
236
|
+
/** Function to update only the sort part of search options */
|
|
237
|
+
setSort: (sort: productsV3.V3ProductSearch["sort"]) => void;
|
|
238
|
+
/** Function to update only the filter part of search options */
|
|
239
|
+
setFilter: (filter: productsV3.V3ProductSearch["filter"]) => void;
|
|
240
|
+
/** Function to reset the filter part of search options */
|
|
241
|
+
resetFilter: () => void;
|
|
242
|
+
/** Reactive signal indicating if any filters are currently applied */
|
|
243
|
+
isFiltered: () => ReadOnlySignal<boolean>;
|
|
244
|
+
/** Function to load more products */
|
|
245
|
+
loadMore: (count: number) => void;
|
|
246
|
+
/** Reactive signal indicating if there are more products to load */
|
|
247
|
+
hasMoreProducts: ReadOnlySignal<boolean>;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Implementation of the Products List service that manages reactive products data.
|
|
251
|
+
* This service provides signals for products data, search options, pagination, aggregations,
|
|
252
|
+
* loading state, and error handling. It automatically re-fetches products when search options change.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```tsx
|
|
256
|
+
* import { ProductListService, ProductsListServiceDefinition } from '@wix/stores/services';
|
|
257
|
+
* import { useService } from '@wix/services-manager-react';
|
|
258
|
+
*
|
|
259
|
+
* function ProductsComponent({ productsConfig }) {
|
|
260
|
+
* return (
|
|
261
|
+
* <ServiceProvider services={createServicesMap([
|
|
262
|
+
* [ProductsListServiceDefinition, ProductListService.withConfig(productsConfig)]
|
|
263
|
+
* ])}>
|
|
264
|
+
* <ProductsDisplay />
|
|
265
|
+
* </ServiceProvider>
|
|
266
|
+
* );
|
|
267
|
+
* }
|
|
268
|
+
*
|
|
269
|
+
* function ProductsDisplay() {
|
|
270
|
+
* const productsService = useService(ProductsListServiceDefinition);
|
|
271
|
+
* const products = productsService.products.get();
|
|
272
|
+
* const isLoading = productsService.isLoading.get();
|
|
273
|
+
* const error = productsService.error.get();
|
|
274
|
+
*
|
|
275
|
+
* // Update search options to filter by category
|
|
276
|
+
* const filterByCategory = (categoryId: string) => {
|
|
277
|
+
* const currentOptions = productsService.searchOptions.get();
|
|
278
|
+
* productsService.setSearchOptions({
|
|
279
|
+
* ...currentOptions,
|
|
280
|
+
* filter: {
|
|
281
|
+
* ...currentOptions.filter,
|
|
282
|
+
* categoryIds: [categoryId]
|
|
283
|
+
* }
|
|
284
|
+
* });
|
|
285
|
+
* };
|
|
286
|
+
*
|
|
287
|
+
* if (isLoading) return <div>Loading products...</div>;
|
|
288
|
+
* if (error) return <div>Error: {error}</div>;
|
|
289
|
+
*
|
|
290
|
+
* return (
|
|
291
|
+
* <div>
|
|
292
|
+
* {products.map(product => (
|
|
293
|
+
* <div key={product._id}>
|
|
294
|
+
* <h3>{product.name}</h3>
|
|
295
|
+
* <p>{product.description}</p>
|
|
296
|
+
* </div>
|
|
297
|
+
* ))}
|
|
298
|
+
* </div>
|
|
299
|
+
* );
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
export declare const ProductListService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
304
|
+
__api: {
|
|
305
|
+
/** Reactive signal containing the list of products */
|
|
306
|
+
products: Signal<productsV3.V3Product[]>;
|
|
307
|
+
/** Reactive signal containing aggregation data for filters and facets */
|
|
308
|
+
aggregations: Signal<productsV3.AggregationData>;
|
|
309
|
+
/** Reactive signal containing pagination metadata */
|
|
310
|
+
pagingMetadata: Signal<productsV3.CommonCursorPagingMetadata>;
|
|
311
|
+
/** Reactive signal containing current search options */
|
|
312
|
+
searchOptions: Signal<productsV3.V3ProductSearch>;
|
|
313
|
+
/** Reactive signal indicating if products are currently being loaded */
|
|
314
|
+
isLoading: Signal<boolean>;
|
|
315
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
316
|
+
error: Signal<string | null>;
|
|
317
|
+
/** Reactive signal containing the minimum price of the products */
|
|
318
|
+
minPrice: Signal<number>;
|
|
319
|
+
/** Reactive signal containing the maximum price of the products */
|
|
320
|
+
maxPrice: Signal<number>;
|
|
321
|
+
/** Reactive signal containing the available inventory statuses */
|
|
322
|
+
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
323
|
+
/** Reactive signal containing the available product options */
|
|
324
|
+
availableProductOptions: Signal<ProductOption[]>;
|
|
325
|
+
/** Function to update search options and trigger a new search */
|
|
326
|
+
setSearchOptions: (searchOptions: productsV3.V3ProductSearch) => void;
|
|
327
|
+
/** Function to update only the sort part of search options */
|
|
328
|
+
setSort: (sort: productsV3.V3ProductSearch["sort"]) => void;
|
|
329
|
+
/** Function to update only the filter part of search options */
|
|
330
|
+
setFilter: (filter: productsV3.V3ProductSearch["filter"]) => void;
|
|
331
|
+
/** Function to reset the filter part of search options */
|
|
332
|
+
resetFilter: () => void;
|
|
333
|
+
/** Reactive signal indicating if any filters are currently applied */
|
|
334
|
+
isFiltered: () => ReadOnlySignal<boolean>;
|
|
335
|
+
/** Function to load more products */
|
|
336
|
+
loadMore: (count: number) => void;
|
|
337
|
+
/** Reactive signal indicating if there are more products to load */
|
|
338
|
+
hasMoreProducts: ReadOnlySignal<boolean>;
|
|
339
|
+
};
|
|
340
|
+
__config: ProductsListServiceConfig;
|
|
341
|
+
isServiceDefinition?: boolean;
|
|
342
|
+
} & {
|
|
343
|
+
/** Reactive signal containing the list of products */
|
|
344
|
+
products: Signal<productsV3.V3Product[]>;
|
|
345
|
+
/** Reactive signal containing aggregation data for filters and facets */
|
|
346
|
+
aggregations: Signal<productsV3.AggregationData>;
|
|
347
|
+
/** Reactive signal containing pagination metadata */
|
|
348
|
+
pagingMetadata: Signal<productsV3.CommonCursorPagingMetadata>;
|
|
349
|
+
/** Reactive signal containing current search options */
|
|
350
|
+
searchOptions: Signal<productsV3.V3ProductSearch>;
|
|
351
|
+
/** Reactive signal indicating if products are currently being loaded */
|
|
352
|
+
isLoading: Signal<boolean>;
|
|
353
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
354
|
+
error: Signal<string | null>;
|
|
355
|
+
/** Reactive signal containing the minimum price of the products */
|
|
356
|
+
minPrice: Signal<number>;
|
|
357
|
+
/** Reactive signal containing the maximum price of the products */
|
|
358
|
+
maxPrice: Signal<number>;
|
|
359
|
+
/** Reactive signal containing the available inventory statuses */
|
|
360
|
+
availableInventoryStatuses: Signal<InventoryStatusType[]>;
|
|
361
|
+
/** Reactive signal containing the available product options */
|
|
362
|
+
availableProductOptions: Signal<ProductOption[]>;
|
|
363
|
+
/** Function to update search options and trigger a new search */
|
|
364
|
+
setSearchOptions: (searchOptions: productsV3.V3ProductSearch) => void;
|
|
365
|
+
/** Function to update only the sort part of search options */
|
|
366
|
+
setSort: (sort: productsV3.V3ProductSearch["sort"]) => void;
|
|
367
|
+
/** Function to update only the filter part of search options */
|
|
368
|
+
setFilter: (filter: productsV3.V3ProductSearch["filter"]) => void;
|
|
369
|
+
/** Function to reset the filter part of search options */
|
|
370
|
+
resetFilter: () => void;
|
|
371
|
+
/** Reactive signal indicating if any filters are currently applied */
|
|
372
|
+
isFiltered: () => ReadOnlySignal<boolean>;
|
|
373
|
+
/** Function to load more products */
|
|
374
|
+
loadMore: (count: number) => void;
|
|
375
|
+
/** Reactive signal indicating if there are more products to load */
|
|
376
|
+
hasMoreProducts: ReadOnlySignal<boolean>;
|
|
377
|
+
}, ProductsListServiceConfig>;
|
|
378
|
+
/**
|
|
379
|
+
* Initial search state that can be loaded from URL parameters.
|
|
380
|
+
*/
|
|
381
|
+
export type InitialSearchState = {
|
|
382
|
+
sort?: SortType;
|
|
383
|
+
limit?: number;
|
|
384
|
+
cursor?: string | null;
|
|
385
|
+
priceRange?: {
|
|
386
|
+
min?: number;
|
|
387
|
+
max?: number;
|
|
388
|
+
};
|
|
389
|
+
inventoryStatuses?: InventoryStatusType[];
|
|
390
|
+
productOptions?: Record<string, string[]>;
|
|
391
|
+
category?: Category;
|
|
392
|
+
visible?: boolean;
|
|
393
|
+
productType?: string;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Parse URL and build complete search options with all filters, sort, and pagination.
|
|
397
|
+
* This function extracts search parameters, filters, sorting, and pagination from a URL
|
|
398
|
+
* and converts them into the format expected by the Wix Stores API.
|
|
399
|
+
*
|
|
400
|
+
* @param {string} url - The URL to parse search parameters from
|
|
401
|
+
* @param {Category[]} categoriesList - List of available categories for category slug resolution
|
|
402
|
+
* @param {productsV3.V3ProductSearch} [defaultSearchOptions] - Default search options to merge with parsed URL parameters
|
|
403
|
+
* @returns {Promise<{searchOptions: productsV3.V3ProductSearch, initialSearchState: InitialSearchState}>}
|
|
404
|
+
* Object containing both API-ready search options and UI-ready initial state
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```tsx
|
|
408
|
+
* // Parse URL with filters, sort, and pagination
|
|
409
|
+
* const categories = await loadCategoriesListServiceConfig();
|
|
410
|
+
* const { searchOptions, initialSearchState } = await parseUrlToSearchOptions(
|
|
411
|
+
* 'https://example.com/products?sort=price:desc&Color=red,blue&minPrice=50',
|
|
412
|
+
* categories.categories
|
|
413
|
+
* );
|
|
414
|
+
*
|
|
415
|
+
* // Use searchOptions for API calls
|
|
416
|
+
* const products = await productsV3.searchProducts(searchOptions);
|
|
417
|
+
*
|
|
418
|
+
* // Use initialSearchState for UI initialization
|
|
419
|
+
* const filterState = initialSearchState.productOptions; // { colorId: ['red-id', 'blue-id'] }
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
export declare function parseUrlToSearchOptions(url: string, categoriesList: Category[], customizations: customizationsV3.Customization[], defaultSearchOptions?: productsV3.V3ProductSearch): Promise<{
|
|
423
|
+
searchOptions: productsV3.V3ProductSearch;
|
|
424
|
+
initialSearchState: InitialSearchState;
|
|
425
|
+
}>;
|
|
426
|
+
/**
|
|
427
|
+
* Convert URL sort format to SortType enum
|
|
428
|
+
*/
|
|
429
|
+
export declare function convertUrlSortToSortType(urlSort: string): SortType | null;
|