@wix/headless-stores 0.0.36 → 0.0.37
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/react/Category.d.ts +65 -59
- package/cjs/dist/react/Category.js +50 -83
- package/cjs/dist/react/CategoryList.d.ts +184 -0
- package/cjs/dist/react/CategoryList.js +174 -0
- package/cjs/dist/react/Product.d.ts +3 -3
- package/cjs/dist/react/Product.js +6 -6
- package/cjs/dist/react/ProductActions.d.ts +1 -1
- package/cjs/dist/react/ProductActions.js +2 -2
- package/{dist/react/ProductsList.d.ts → cjs/dist/react/ProductList.d.ts} +71 -38
- package/cjs/dist/react/{ProductsList.js → ProductList.js} +30 -26
- package/cjs/dist/react/ProductListFilters.d.ts +244 -0
- package/cjs/dist/react/ProductListFilters.js +216 -0
- package/cjs/dist/react/ProductListPagination.d.ts +246 -0
- package/cjs/dist/react/ProductListPagination.js +207 -0
- package/cjs/dist/react/ProductListSort.d.ts +87 -0
- package/cjs/dist/react/ProductListSort.js +85 -0
- package/cjs/dist/react/ProductModifiers.d.ts +5 -5
- package/cjs/dist/react/ProductModifiers.js +10 -10
- package/cjs/dist/react/ProductVariantSelector.d.ts +5 -5
- package/cjs/dist/react/ProductVariantSelector.js +13 -10
- package/cjs/dist/react/SelectedVariant.d.ts +3 -3
- package/cjs/dist/react/SelectedVariant.js +6 -6
- package/cjs/dist/react/index.d.ts +7 -9
- package/cjs/dist/react/index.js +7 -9
- package/cjs/dist/services/buy-now-service.d.ts +208 -0
- package/cjs/dist/services/buy-now-service.js +132 -1
- package/cjs/dist/services/categories-list-service.d.ts +163 -0
- package/cjs/dist/services/categories-list-service.js +148 -0
- package/cjs/dist/services/category-service.d.ts +115 -70
- package/cjs/dist/services/category-service.js +101 -110
- package/cjs/dist/services/index.d.ts +6 -7
- package/cjs/dist/services/index.js +5 -16
- package/cjs/dist/services/pay-now-service.d.ts +146 -0
- package/cjs/dist/services/pay-now-service.js +112 -1
- package/cjs/dist/services/product-service.d.ts +71 -0
- package/cjs/dist/services/product-service.js +47 -0
- package/cjs/dist/services/products-list-filters-service.d.ts +292 -0
- package/cjs/dist/services/products-list-filters-service.js +446 -0
- package/cjs/dist/services/products-list-pagination-service.d.ts +186 -0
- package/cjs/dist/services/products-list-pagination-service.js +179 -0
- package/cjs/dist/services/products-list-service.d.ts +138 -52
- package/cjs/dist/services/products-list-service.js +98 -51
- package/cjs/dist/services/products-list-sort-service.d.ts +117 -0
- package/cjs/dist/services/products-list-sort-service.js +144 -0
- package/cjs/dist/utils/url-params.d.ts +68 -0
- package/cjs/dist/utils/url-params.js +72 -4
- package/dist/react/Category.d.ts +65 -59
- package/dist/react/Category.js +50 -83
- package/dist/react/CategoryList.d.ts +184 -0
- package/dist/react/CategoryList.js +174 -0
- package/dist/react/Product.d.ts +3 -3
- package/dist/react/Product.js +6 -6
- package/dist/react/ProductActions.d.ts +1 -1
- package/dist/react/ProductActions.js +2 -2
- package/{cjs/dist/react/ProductsList.d.ts → dist/react/ProductList.d.ts} +71 -38
- package/dist/react/{ProductsList.js → ProductList.js} +30 -26
- package/dist/react/ProductListFilters.d.ts +244 -0
- package/dist/react/ProductListFilters.js +216 -0
- package/dist/react/ProductListPagination.d.ts +246 -0
- package/dist/react/ProductListPagination.js +207 -0
- package/dist/react/ProductListSort.d.ts +87 -0
- package/dist/react/ProductListSort.js +85 -0
- package/dist/react/ProductModifiers.d.ts +5 -5
- package/dist/react/ProductModifiers.js +10 -10
- package/dist/react/ProductVariantSelector.d.ts +5 -5
- package/dist/react/ProductVariantSelector.js +13 -10
- package/dist/react/SelectedVariant.d.ts +3 -3
- package/dist/react/SelectedVariant.js +6 -6
- package/dist/react/index.d.ts +7 -9
- package/dist/react/index.js +7 -9
- package/dist/services/buy-now-service.d.ts +208 -0
- package/dist/services/buy-now-service.js +132 -1
- package/dist/services/categories-list-service.d.ts +163 -0
- package/dist/services/categories-list-service.js +148 -0
- package/dist/services/category-service.d.ts +115 -70
- package/dist/services/category-service.js +101 -110
- package/dist/services/index.d.ts +6 -7
- package/dist/services/index.js +5 -16
- package/dist/services/pay-now-service.d.ts +146 -0
- package/dist/services/pay-now-service.js +112 -1
- package/dist/services/product-service.d.ts +71 -0
- package/dist/services/product-service.js +47 -0
- package/dist/services/products-list-filters-service.d.ts +292 -0
- package/dist/services/products-list-filters-service.js +446 -0
- package/dist/services/products-list-pagination-service.d.ts +186 -0
- package/dist/services/products-list-pagination-service.js +179 -0
- package/dist/services/products-list-service.d.ts +138 -52
- package/dist/services/products-list-service.js +98 -51
- package/dist/services/products-list-sort-service.d.ts +117 -0
- package/dist/services/products-list-sort-service.js +144 -0
- package/dist/utils/url-params.d.ts +68 -0
- package/dist/utils/url-params.js +72 -4
- package/package.json +3 -3
- package/cjs/dist/react/Collection.d.ts +0 -294
- package/cjs/dist/react/Collection.js +0 -345
- package/cjs/dist/react/FilteredCollection.d.ts +0 -299
- package/cjs/dist/react/FilteredCollection.js +0 -352
- package/cjs/dist/react/RelatedProducts.d.ts +0 -169
- package/cjs/dist/react/RelatedProducts.js +0 -180
- package/cjs/dist/react/Sort.d.ts +0 -37
- package/cjs/dist/react/Sort.js +0 -36
- package/cjs/dist/services/catalog-service.d.ts +0 -36
- package/cjs/dist/services/catalog-service.js +0 -193
- package/cjs/dist/services/collection-service.d.ts +0 -124
- package/cjs/dist/services/collection-service.js +0 -628
- package/cjs/dist/services/filter-service.d.ts +0 -35
- package/cjs/dist/services/filter-service.js +0 -119
- package/cjs/dist/services/related-products-service.d.ts +0 -100
- package/cjs/dist/services/related-products-service.js +0 -127
- package/cjs/dist/services/sort-service.d.ts +0 -20
- package/cjs/dist/services/sort-service.js +0 -27
- package/dist/react/Collection.d.ts +0 -294
- package/dist/react/Collection.js +0 -345
- package/dist/react/FilteredCollection.d.ts +0 -299
- package/dist/react/FilteredCollection.js +0 -352
- package/dist/react/RelatedProducts.d.ts +0 -169
- package/dist/react/RelatedProducts.js +0 -180
- package/dist/react/Sort.d.ts +0 -37
- package/dist/react/Sort.js +0 -36
- package/dist/services/catalog-service.d.ts +0 -36
- package/dist/services/catalog-service.js +0 -193
- package/dist/services/collection-service.d.ts +0 -124
- package/dist/services/collection-service.js +0 -628
- package/dist/services/filter-service.d.ts +0 -35
- package/dist/services/filter-service.js +0 -119
- package/dist/services/related-products-service.d.ts +0 -100
- package/dist/services/related-products-service.js +0 -127
- package/dist/services/sort-service.d.ts +0 -20
- package/dist/services/sort-service.js +0 -27
|
@@ -1,156 +1,147 @@
|
|
|
1
1
|
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
+
import { categories } from "@wix/categories";
|
|
2
3
|
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Service definition for the Category service.
|
|
6
|
+
* This defines the reactive API contract for managing a single product category.
|
|
7
|
+
*
|
|
8
|
+
* @constant
|
|
9
|
+
*/
|
|
10
|
+
export const CategoryServiceDefinition = defineService("category");
|
|
11
|
+
/**
|
|
12
|
+
* Implementation of the Category service that manages reactive category data.
|
|
13
|
+
* This service provides a signal for category data and maintains it in a reactive state.
|
|
14
|
+
* The service is initialized with pre-loaded category data.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { CategoryService, CategoryServiceDefinition } from '@wix/stores/services';
|
|
19
|
+
* import { useService } from '@wix/services-manager-react';
|
|
20
|
+
*
|
|
21
|
+
* function CategoryComponent({ categoryConfig }) {
|
|
22
|
+
* return (
|
|
23
|
+
* <ServiceProvider services={createServicesMap([
|
|
24
|
+
* [CategoryServiceDefinition, CategoryService.withConfig(categoryConfig)]
|
|
25
|
+
* ])}>
|
|
26
|
+
* <CategoryDisplay />
|
|
27
|
+
* </ServiceProvider>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* function CategoryDisplay() {
|
|
32
|
+
* const categoryService = useService(CategoryServiceDefinition);
|
|
33
|
+
* const category = categoryService.category.get();
|
|
34
|
+
*
|
|
35
|
+
* return (
|
|
36
|
+
* <div>
|
|
37
|
+
* <h1>{category.name}</h1>
|
|
38
|
+
* <p>{category.description}</p>
|
|
39
|
+
* </div>
|
|
40
|
+
* );
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
5
44
|
export const CategoryService = implementService.withConfig()(CategoryServiceDefinition, ({ getService, config }) => {
|
|
6
45
|
const signalsService = getService(SignalsServiceDefinition);
|
|
7
|
-
const
|
|
8
|
-
const categories = signalsService.signal(config?.categories);
|
|
9
|
-
const loadCategories = async () => {
|
|
10
|
-
const { categories: loadedCategories } = await loadCategoriesConfig();
|
|
11
|
-
categories.set(loadedCategories);
|
|
12
|
-
};
|
|
13
|
-
// Track if this is the initial load to prevent navigation on service creation
|
|
14
|
-
let isInitialLoad = true;
|
|
15
|
-
const setSelectedCategory = (categoryId) => {
|
|
16
|
-
selectedCategory.set(categoryId);
|
|
17
|
-
};
|
|
18
|
-
// Subscribe to category changes and handle navigation as a side effect
|
|
19
|
-
signalsService.effect(() => {
|
|
20
|
-
const categoryId = selectedCategory.get();
|
|
21
|
-
// Skip navigation on initial load (when service is first created)
|
|
22
|
-
if (isInitialLoad) {
|
|
23
|
-
isInitialLoad = false;
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
// If a navigation handler is provided, use it
|
|
27
|
-
if (config?.onCategoryChange) {
|
|
28
|
-
const category = categoryId
|
|
29
|
-
? config?.categories.find((cat) => cat._id === categoryId) || null
|
|
30
|
-
: null;
|
|
31
|
-
config.onCategoryChange(categoryId, category);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
46
|
+
const categorySignal = signalsService.signal(config.category);
|
|
34
47
|
return {
|
|
35
|
-
|
|
36
|
-
categories,
|
|
37
|
-
setSelectedCategory,
|
|
38
|
-
loadCategories,
|
|
48
|
+
category: categorySignal,
|
|
39
49
|
};
|
|
40
50
|
});
|
|
41
51
|
/**
|
|
42
|
-
* Loads
|
|
52
|
+
* Loads category service configuration from the Wix Categories API for SSR initialization.
|
|
43
53
|
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
44
|
-
*
|
|
45
|
-
* Fetches all visible categories and sorts them with "all-products" category first.
|
|
54
|
+
* a specific category by slug that will be used to configure the CategoryService.
|
|
46
55
|
*
|
|
47
|
-
* @
|
|
56
|
+
* @param {string} slug - The category slug to load
|
|
57
|
+
* @returns {Promise} Promise that resolves to either success with config or not-found result
|
|
48
58
|
*
|
|
49
59
|
* @example
|
|
50
60
|
* ```astro
|
|
51
61
|
* ---
|
|
52
|
-
* // Astro page example - pages/
|
|
53
|
-
* import {
|
|
62
|
+
* // Astro page example - pages/category/[slug].astro
|
|
63
|
+
* import { loadCategoryServiceConfig } from '@wix/stores/services';
|
|
54
64
|
* import { Category } from '@wix/stores/components';
|
|
55
65
|
*
|
|
56
|
-
* //
|
|
57
|
-
* const
|
|
66
|
+
* // Get category slug from URL params
|
|
67
|
+
* const { slug } = Astro.params;
|
|
68
|
+
*
|
|
69
|
+
* // Load category data during SSR
|
|
70
|
+
* const categoryResult = await loadCategoryServiceConfig(slug);
|
|
71
|
+
*
|
|
72
|
+
* // Handle not found case
|
|
73
|
+
* if (categoryResult.type === 'not-found') {
|
|
74
|
+
* return Astro.redirect('/404');
|
|
75
|
+
* }
|
|
58
76
|
* ---
|
|
59
77
|
*
|
|
60
|
-
* <Category.Root categoryConfig={
|
|
61
|
-
* <Category.
|
|
62
|
-
* {({
|
|
63
|
-
*
|
|
64
|
-
* <h2>Shop by Category</h2>
|
|
65
|
-
* {categories.map(category => (
|
|
66
|
-
* <button
|
|
67
|
-
* key={category.id}
|
|
68
|
-
* onClick={() => setSelectedCategory(category.id)}
|
|
69
|
-
* className={selectedCategory === category.id ? 'active' : ''}
|
|
70
|
-
* >
|
|
71
|
-
* {category.name}
|
|
72
|
-
* </button>
|
|
73
|
-
* ))}
|
|
74
|
-
* </nav>
|
|
75
|
-
* )}
|
|
76
|
-
* </Category.List>
|
|
78
|
+
* <Category.Root categoryConfig={categoryResult.config}>
|
|
79
|
+
* <Category.Name>
|
|
80
|
+
* {({ name }) => <h1>{name}</h1>}
|
|
81
|
+
* </Category.Name>
|
|
77
82
|
* </Category.Root>
|
|
78
83
|
* ```
|
|
79
84
|
*
|
|
80
85
|
* @example
|
|
81
86
|
* ```tsx
|
|
82
|
-
* // Next.js page example - pages/
|
|
87
|
+
* // Next.js page example - pages/category/[slug].tsx
|
|
83
88
|
* import { GetServerSideProps } from 'next';
|
|
84
|
-
* import {
|
|
89
|
+
* import { loadCategoryServiceConfig } from '@wix/stores/services';
|
|
85
90
|
* import { Category } from '@wix/stores/components';
|
|
86
91
|
*
|
|
87
92
|
* interface CategoryPageProps {
|
|
88
|
-
* categoryConfig: Awaited<ReturnType<typeof
|
|
93
|
+
* categoryConfig: Awaited<ReturnType<typeof loadCategoryServiceConfig>>['config'];
|
|
89
94
|
* }
|
|
90
95
|
*
|
|
91
|
-
* export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async () => {
|
|
92
|
-
*
|
|
93
|
-
*
|
|
96
|
+
* export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async ({ params }) => {
|
|
97
|
+
* const slug = params?.slug as string;
|
|
98
|
+
*
|
|
99
|
+
* // Load category data during SSR
|
|
100
|
+
* const categoryResult = await loadCategoryServiceConfig(slug);
|
|
101
|
+
*
|
|
102
|
+
* // Handle not found case
|
|
103
|
+
* if (categoryResult.type === 'not-found') {
|
|
104
|
+
* return {
|
|
105
|
+
* notFound: true,
|
|
106
|
+
* };
|
|
107
|
+
* }
|
|
94
108
|
*
|
|
95
109
|
* return {
|
|
96
110
|
* props: {
|
|
97
|
-
* categoryConfig,
|
|
111
|
+
* categoryConfig: categoryResult.config,
|
|
98
112
|
* },
|
|
99
113
|
* };
|
|
100
114
|
* };
|
|
101
115
|
*
|
|
102
116
|
* export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
|
|
103
117
|
* return (
|
|
104
|
-
* <
|
|
105
|
-
* <
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* <nav className="category-nav">
|
|
110
|
-
* {categories.map(category => (
|
|
111
|
-
* <button
|
|
112
|
-
* key={category.id}
|
|
113
|
-
* onClick={() => setSelectedCategory(category.id)}
|
|
114
|
-
* className={`category-btn ${selectedCategory === category.id ? 'active' : ''}`}
|
|
115
|
-
* >
|
|
116
|
-
* {category.name}
|
|
117
|
-
* </button>
|
|
118
|
-
* ))}
|
|
119
|
-
* </nav>
|
|
120
|
-
* )}
|
|
121
|
-
* </Category.List>
|
|
122
|
-
* </Category.Root>
|
|
123
|
-
* </div>
|
|
118
|
+
* <Category.Root categoryConfig={categoryConfig}>
|
|
119
|
+
* <Category.Name>
|
|
120
|
+
* {({ name }) => <h1>{name}</h1>}
|
|
121
|
+
* </Category.Name>
|
|
122
|
+
* </Category.Root>
|
|
124
123
|
* );
|
|
125
124
|
* }
|
|
126
125
|
* ```
|
|
127
126
|
*/
|
|
128
|
-
export async function
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.find();
|
|
139
|
-
const fetchedCategories = categoriesResponse.items || [];
|
|
140
|
-
// Sort categories to put "all-products" first, keep the rest in original order
|
|
141
|
-
const allProductsCategory = fetchedCategories.find((cat) => cat.slug === "all-products");
|
|
142
|
-
const otherCategories = fetchedCategories.filter((cat) => cat.slug !== "all-products");
|
|
143
|
-
const allCategories = allProductsCategory
|
|
144
|
-
? [allProductsCategory, ...otherCategories]
|
|
145
|
-
: fetchedCategories;
|
|
146
|
-
return {
|
|
147
|
-
categories: allCategories,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
console.warn("Failed to load categories:", error);
|
|
127
|
+
export async function loadCategoryServiceConfig(slug) {
|
|
128
|
+
const category = await categories
|
|
129
|
+
.queryCategories({
|
|
130
|
+
treeReference: {
|
|
131
|
+
appNamespace: "@wix/stores",
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
.eq("slug", slug)
|
|
135
|
+
.find();
|
|
136
|
+
if (category.items.length === 0) {
|
|
152
137
|
return {
|
|
153
|
-
|
|
138
|
+
type: "not-found",
|
|
154
139
|
};
|
|
155
140
|
}
|
|
141
|
+
return {
|
|
142
|
+
type: "success",
|
|
143
|
+
config: {
|
|
144
|
+
category: category.items[0],
|
|
145
|
+
},
|
|
146
|
+
};
|
|
156
147
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { CollectionService, CollectionServiceDefinition, loadCollectionServiceConfig, } from "./collection-service.js";
|
|
4
|
-
export { FilterService, FilterServiceDefinition, Filter, AvailableOptions, } from "./filter-service.js";
|
|
1
|
+
export { CategoryService, CategoryServiceDefinition, loadCategoryServiceConfig, CategoryServiceConfig, } from "./category-service.js";
|
|
2
|
+
export { CategoriesListService, CategoriesListServiceDefinition, loadCategoriesListServiceConfig, CategoriesListServiceConfig, } from "./categories-list-service.js";
|
|
5
3
|
export { ProductModifiersService, ProductModifiersServiceDefinition, } from "./product-modifiers-service.js";
|
|
6
4
|
export { ProductService, ProductServiceDefinition, loadProductServiceConfig, } from "./product-service.js";
|
|
7
|
-
export { RelatedProductsService, RelatedProductsServiceDefinition, loadRelatedProductsServiceConfig, } from "./related-products-service.js";
|
|
8
5
|
export { SelectedVariantService, SelectedVariantServiceDefinition, } from "./selected-variant-service.js";
|
|
9
|
-
export { ProductListService, ProductsListServiceDefinition, loadProductsListServiceConfig, } from "./products-list-service.js";
|
|
10
|
-
export {
|
|
6
|
+
export { ProductListService, ProductsListServiceDefinition, loadProductsListServiceConfig, ProductsListServiceConfig, } from "./products-list-service.js";
|
|
7
|
+
export { SortType, ProductsListSortService, ProductsListSortServiceDefinition, } from "./products-list-sort-service.js";
|
|
8
|
+
export { InventoryStatusType, ProductsListFiltersService, ProductsListFiltersServiceDefinition, loadProductsListFiltersServiceConfig, ProductsListFiltersServiceConfig, } from "./products-list-filters-service.js";
|
|
9
|
+
export { ProductsListPaginationService, ProductsListPaginationServiceDefinition, } from "./products-list-pagination-service.js";
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// loadBuyNowServiceInitialData,
|
|
4
|
-
// } from "./buy-now-service.js";
|
|
5
|
-
// export {
|
|
6
|
-
// payNowServiceBinding,
|
|
7
|
-
// loadPayNowServiceInitialData,
|
|
8
|
-
// } from "./pay-now-service.js";
|
|
9
|
-
export { CatalogService, CatalogServiceDefinition,
|
|
10
|
-
// loadCatalogServiceConfig,
|
|
11
|
-
} from "./catalog-service.js";
|
|
12
|
-
export { CategoryService, CategoryServiceDefinition, loadCategoriesConfig, } from "./category-service.js";
|
|
13
|
-
export { CollectionService, CollectionServiceDefinition, loadCollectionServiceConfig, } from "./collection-service.js";
|
|
14
|
-
export { FilterService, FilterServiceDefinition, } from "./filter-service.js";
|
|
1
|
+
export { CategoryService, CategoryServiceDefinition, loadCategoryServiceConfig, } from "./category-service.js";
|
|
2
|
+
export { CategoriesListService, CategoriesListServiceDefinition, loadCategoriesListServiceConfig, } from "./categories-list-service.js";
|
|
15
3
|
export { ProductModifiersService, ProductModifiersServiceDefinition, } from "./product-modifiers-service.js";
|
|
16
4
|
export { ProductService, ProductServiceDefinition, loadProductServiceConfig, } from "./product-service.js";
|
|
17
|
-
export { RelatedProductsService, RelatedProductsServiceDefinition, loadRelatedProductsServiceConfig, } from "./related-products-service.js";
|
|
18
5
|
export { SelectedVariantService, SelectedVariantServiceDefinition, } from "./selected-variant-service.js";
|
|
19
6
|
export { ProductListService, ProductsListServiceDefinition, loadProductsListServiceConfig, } from "./products-list-service.js";
|
|
20
|
-
export {
|
|
7
|
+
export { SortType, ProductsListSortService, ProductsListSortServiceDefinition, } from "./products-list-sort-service.js";
|
|
8
|
+
export { InventoryStatusType, ProductsListFiltersService, ProductsListFiltersServiceDefinition, loadProductsListFiltersServiceConfig, } from "./products-list-filters-service.js";
|
|
9
|
+
export { ProductsListPaginationService, ProductsListPaginationServiceDefinition, } from "./products-list-pagination-service.js";
|
|
@@ -1,68 +1,214 @@
|
|
|
1
1
|
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
|
+
/**
|
|
3
|
+
* Service definition for the Pay Now service.
|
|
4
|
+
* This defines the reactive API contract for managing custom payment checkout functionality.
|
|
5
|
+
*
|
|
6
|
+
* @constant
|
|
7
|
+
*/
|
|
2
8
|
export declare const PayNowServiceDefinition: string & {
|
|
3
9
|
__api: {
|
|
10
|
+
/** Function to redirect to checkout using custom checkout action */
|
|
4
11
|
redirectToCheckout: () => Promise<void>;
|
|
12
|
+
/** Reactive signal indicating if a checkout redirect is in progress */
|
|
5
13
|
loadingSignal: Signal<boolean>;
|
|
14
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
6
15
|
errorSignal: Signal<string | null>;
|
|
7
16
|
};
|
|
8
17
|
__config: {};
|
|
9
18
|
isServiceDefinition?: boolean;
|
|
10
19
|
} & {
|
|
20
|
+
/** Function to redirect to checkout using custom checkout action */
|
|
11
21
|
redirectToCheckout: () => Promise<void>;
|
|
22
|
+
/** Reactive signal indicating if a checkout redirect is in progress */
|
|
12
23
|
loadingSignal: Signal<boolean>;
|
|
24
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
13
25
|
errorSignal: Signal<string | null>;
|
|
14
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Configuration interface for the Pay Now service.
|
|
29
|
+
* Contains an optional custom checkout action function.
|
|
30
|
+
*
|
|
31
|
+
* @interface PayNowServiceConfig
|
|
32
|
+
*/
|
|
15
33
|
export interface PayNowServiceConfig {
|
|
34
|
+
/** Optional custom checkout action that returns a checkout URL or error */
|
|
16
35
|
customCheckoutAction?: () => Promise<{
|
|
36
|
+
/** The checkout URL to redirect to */
|
|
17
37
|
data: string | undefined;
|
|
38
|
+
/** Any error that occurred during checkout creation */
|
|
18
39
|
error: unknown;
|
|
19
40
|
}>;
|
|
20
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Implementation of the Pay Now service that manages custom payment checkout functionality.
|
|
44
|
+
* This service provides signals for loading state and error handling, along with a method
|
|
45
|
+
* to redirect to checkout using a custom checkout action.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* import { PayNowServiceImplementation, PayNowServiceDefinition } from '@wix/stores/services';
|
|
50
|
+
* import { useService } from '@wix/services-manager-react';
|
|
51
|
+
*
|
|
52
|
+
* function PayNowComponent({ payNowConfig }) {
|
|
53
|
+
* return (
|
|
54
|
+
* <ServiceProvider services={createServicesMap([
|
|
55
|
+
* [PayNowServiceDefinition, PayNowServiceImplementation.withConfig(payNowConfig)]
|
|
56
|
+
* ])}>
|
|
57
|
+
* <PayNowButton />
|
|
58
|
+
* </ServiceProvider>
|
|
59
|
+
* );
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* function PayNowButton() {
|
|
63
|
+
* const payNowService = useService(PayNowServiceDefinition);
|
|
64
|
+
* const isLoading = payNowService.loadingSignal.get();
|
|
65
|
+
* const error = payNowService.errorSignal.get();
|
|
66
|
+
*
|
|
67
|
+
* const handlePayNow = async () => {
|
|
68
|
+
* await payNowService.redirectToCheckout();
|
|
69
|
+
* };
|
|
70
|
+
*
|
|
71
|
+
* return (
|
|
72
|
+
* <div>
|
|
73
|
+
* {error && <div className="error">{error}</div>}
|
|
74
|
+
* <button
|
|
75
|
+
* onClick={handlePayNow}
|
|
76
|
+
* disabled={isLoading}
|
|
77
|
+
* className="pay-now-btn"
|
|
78
|
+
* >
|
|
79
|
+
* {isLoading ? 'Processing...' : 'Pay Now'}
|
|
80
|
+
* </button>
|
|
81
|
+
* </div>
|
|
82
|
+
* );
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
21
86
|
export declare const PayNowServiceImplementation: import("@wix/services-definitions").ServiceFactory<string & {
|
|
22
87
|
__api: {
|
|
88
|
+
/** Function to redirect to checkout using custom checkout action */
|
|
23
89
|
redirectToCheckout: () => Promise<void>;
|
|
90
|
+
/** Reactive signal indicating if a checkout redirect is in progress */
|
|
24
91
|
loadingSignal: Signal<boolean>;
|
|
92
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
25
93
|
errorSignal: Signal<string | null>;
|
|
26
94
|
};
|
|
27
95
|
__config: {};
|
|
28
96
|
isServiceDefinition?: boolean;
|
|
29
97
|
} & {
|
|
98
|
+
/** Function to redirect to checkout using custom checkout action */
|
|
30
99
|
redirectToCheckout: () => Promise<void>;
|
|
100
|
+
/** Reactive signal indicating if a checkout redirect is in progress */
|
|
31
101
|
loadingSignal: Signal<boolean>;
|
|
102
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
32
103
|
errorSignal: Signal<string | null>;
|
|
33
104
|
}, PayNowServiceConfig>;
|
|
105
|
+
/**
|
|
106
|
+
* Loads pay now service initial data for SSR initialization.
|
|
107
|
+
* This function returns an empty configuration as the Pay Now service
|
|
108
|
+
* is typically configured with custom checkout actions at runtime.
|
|
109
|
+
*
|
|
110
|
+
* @returns {Promise} Promise that resolves to an empty pay now service configuration
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```astro
|
|
114
|
+
* ---
|
|
115
|
+
* // Astro page example
|
|
116
|
+
* import { loadPayNowServiceInitialData } from '@wix/stores/services';
|
|
117
|
+
* import { PayNow } from '@wix/stores/components';
|
|
118
|
+
*
|
|
119
|
+
* // Load initial data (empty for PayNow)
|
|
120
|
+
* const payNowData = await loadPayNowServiceInitialData();
|
|
121
|
+
* ---
|
|
122
|
+
*
|
|
123
|
+
* <PayNow.PayNow payNowConfig={payNowData.PayNow}>
|
|
124
|
+
* {({ redirectToCheckout, isLoading, error }) => (
|
|
125
|
+
* <button onClick={redirectToCheckout} disabled={isLoading}>
|
|
126
|
+
* {isLoading ? 'Processing...' : 'Pay Now'}
|
|
127
|
+
* </button>
|
|
128
|
+
* )}
|
|
129
|
+
* </PayNow.PayNow>
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
34
132
|
export declare const loadPayNowServiceInitialData: () => Promise<{
|
|
35
133
|
[PayNowServiceDefinition]: {};
|
|
36
134
|
}>;
|
|
135
|
+
/**
|
|
136
|
+
* Helper function to create a pay now service binding with configuration.
|
|
137
|
+
* This function simplifies the process of binding the pay now service with its configuration
|
|
138
|
+
* and allows for additional configuration overrides, particularly for custom checkout actions.
|
|
139
|
+
*
|
|
140
|
+
* @template T - Type of the services configurations object
|
|
141
|
+
* @param {T} servicesConfigs - Object containing service configurations
|
|
142
|
+
* @param {Partial<PayNowServiceConfig>} [additionalConfig={}] - Additional configuration to override defaults
|
|
143
|
+
* @returns Tuple containing service definition, implementation, and merged configuration
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```tsx
|
|
147
|
+
* import { payNowServiceBinding, loadPayNowServiceInitialData } from '@wix/stores/services';
|
|
148
|
+
* import { actions } from 'astro:actions';
|
|
149
|
+
*
|
|
150
|
+
* // Load initial data
|
|
151
|
+
* const initialData = await loadPayNowServiceInitialData();
|
|
152
|
+
*
|
|
153
|
+
* // Create service binding with custom checkout action
|
|
154
|
+
* const payNowBinding = payNowServiceBinding(initialData, {
|
|
155
|
+
* customCheckoutAction: async () => {
|
|
156
|
+
* try {
|
|
157
|
+
* const result = await actions.customCheckout();
|
|
158
|
+
* return { data: result, error: null };
|
|
159
|
+
* } catch (error) {
|
|
160
|
+
* return { data: undefined, error };
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* // Use in service provider
|
|
166
|
+
* const services = createServicesMap([payNowBinding]);
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
37
169
|
export declare const payNowServiceBinding: <T extends {
|
|
38
170
|
[key: string]: Awaited<ReturnType<typeof loadPayNowServiceInitialData>>[typeof PayNowServiceDefinition];
|
|
39
171
|
}>(servicesConfigs: T, additionalConfig?: Partial<PayNowServiceConfig>) => readonly [string & {
|
|
40
172
|
__api: {
|
|
173
|
+
/** Function to redirect to checkout using custom checkout action */
|
|
41
174
|
redirectToCheckout: () => Promise<void>;
|
|
175
|
+
/** Reactive signal indicating if a checkout redirect is in progress */
|
|
42
176
|
loadingSignal: Signal<boolean>;
|
|
177
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
43
178
|
errorSignal: Signal<string | null>;
|
|
44
179
|
};
|
|
45
180
|
__config: {};
|
|
46
181
|
isServiceDefinition?: boolean;
|
|
47
182
|
} & {
|
|
183
|
+
/** Function to redirect to checkout using custom checkout action */
|
|
48
184
|
redirectToCheckout: () => Promise<void>;
|
|
185
|
+
/** Reactive signal indicating if a checkout redirect is in progress */
|
|
49
186
|
loadingSignal: Signal<boolean>;
|
|
187
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
50
188
|
errorSignal: Signal<string | null>;
|
|
51
189
|
}, import("@wix/services-definitions").ServiceFactory<string & {
|
|
52
190
|
__api: {
|
|
191
|
+
/** Function to redirect to checkout using custom checkout action */
|
|
53
192
|
redirectToCheckout: () => Promise<void>;
|
|
193
|
+
/** Reactive signal indicating if a checkout redirect is in progress */
|
|
54
194
|
loadingSignal: Signal<boolean>;
|
|
195
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
55
196
|
errorSignal: Signal<string | null>;
|
|
56
197
|
};
|
|
57
198
|
__config: {};
|
|
58
199
|
isServiceDefinition?: boolean;
|
|
59
200
|
} & {
|
|
201
|
+
/** Function to redirect to checkout using custom checkout action */
|
|
60
202
|
redirectToCheckout: () => Promise<void>;
|
|
203
|
+
/** Reactive signal indicating if a checkout redirect is in progress */
|
|
61
204
|
loadingSignal: Signal<boolean>;
|
|
205
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
62
206
|
errorSignal: Signal<string | null>;
|
|
63
207
|
}, PayNowServiceConfig>, {
|
|
64
208
|
customCheckoutAction?: () => Promise<{
|
|
209
|
+
/** The checkout URL to redirect to */
|
|
65
210
|
data: string | undefined;
|
|
211
|
+
/** Any error that occurred during checkout creation */
|
|
66
212
|
error: unknown;
|
|
67
213
|
}>;
|
|
68
214
|
}];
|
|
@@ -1,6 +1,56 @@
|
|
|
1
|
-
import { defineService, implementService
|
|
1
|
+
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
2
|
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
/**
|
|
4
|
+
* Service definition for the Pay Now service.
|
|
5
|
+
* This defines the reactive API contract for managing custom payment checkout functionality.
|
|
6
|
+
*
|
|
7
|
+
* @constant
|
|
8
|
+
*/
|
|
3
9
|
export const PayNowServiceDefinition = defineService("PayNow");
|
|
10
|
+
/**
|
|
11
|
+
* Implementation of the Pay Now service that manages custom payment checkout functionality.
|
|
12
|
+
* This service provides signals for loading state and error handling, along with a method
|
|
13
|
+
* to redirect to checkout using a custom checkout action.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { PayNowServiceImplementation, PayNowServiceDefinition } from '@wix/stores/services';
|
|
18
|
+
* import { useService } from '@wix/services-manager-react';
|
|
19
|
+
*
|
|
20
|
+
* function PayNowComponent({ payNowConfig }) {
|
|
21
|
+
* return (
|
|
22
|
+
* <ServiceProvider services={createServicesMap([
|
|
23
|
+
* [PayNowServiceDefinition, PayNowServiceImplementation.withConfig(payNowConfig)]
|
|
24
|
+
* ])}>
|
|
25
|
+
* <PayNowButton />
|
|
26
|
+
* </ServiceProvider>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* function PayNowButton() {
|
|
31
|
+
* const payNowService = useService(PayNowServiceDefinition);
|
|
32
|
+
* const isLoading = payNowService.loadingSignal.get();
|
|
33
|
+
* const error = payNowService.errorSignal.get();
|
|
34
|
+
*
|
|
35
|
+
* const handlePayNow = async () => {
|
|
36
|
+
* await payNowService.redirectToCheckout();
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* return (
|
|
40
|
+
* <div>
|
|
41
|
+
* {error && <div className="error">{error}</div>}
|
|
42
|
+
* <button
|
|
43
|
+
* onClick={handlePayNow}
|
|
44
|
+
* disabled={isLoading}
|
|
45
|
+
* className="pay-now-btn"
|
|
46
|
+
* >
|
|
47
|
+
* {isLoading ? 'Processing...' : 'Pay Now'}
|
|
48
|
+
* </button>
|
|
49
|
+
* </div>
|
|
50
|
+
* );
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
4
54
|
export const PayNowServiceImplementation = implementService.withConfig()(PayNowServiceDefinition, ({ getService, config }) => {
|
|
5
55
|
const signalsService = getService(SignalsServiceDefinition);
|
|
6
56
|
const loadingSignal = signalsService.signal(false);
|
|
@@ -28,11 +78,72 @@ export const PayNowServiceImplementation = implementService.withConfig()(PayNowS
|
|
|
28
78
|
errorSignal,
|
|
29
79
|
};
|
|
30
80
|
});
|
|
81
|
+
/**
|
|
82
|
+
* Loads pay now service initial data for SSR initialization.
|
|
83
|
+
* This function returns an empty configuration as the Pay Now service
|
|
84
|
+
* is typically configured with custom checkout actions at runtime.
|
|
85
|
+
*
|
|
86
|
+
* @returns {Promise} Promise that resolves to an empty pay now service configuration
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```astro
|
|
90
|
+
* ---
|
|
91
|
+
* // Astro page example
|
|
92
|
+
* import { loadPayNowServiceInitialData } from '@wix/stores/services';
|
|
93
|
+
* import { PayNow } from '@wix/stores/components';
|
|
94
|
+
*
|
|
95
|
+
* // Load initial data (empty for PayNow)
|
|
96
|
+
* const payNowData = await loadPayNowServiceInitialData();
|
|
97
|
+
* ---
|
|
98
|
+
*
|
|
99
|
+
* <PayNow.PayNow payNowConfig={payNowData.PayNow}>
|
|
100
|
+
* {({ redirectToCheckout, isLoading, error }) => (
|
|
101
|
+
* <button onClick={redirectToCheckout} disabled={isLoading}>
|
|
102
|
+
* {isLoading ? 'Processing...' : 'Pay Now'}
|
|
103
|
+
* </button>
|
|
104
|
+
* )}
|
|
105
|
+
* </PayNow.PayNow>
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
31
108
|
export const loadPayNowServiceInitialData = async () => {
|
|
32
109
|
return {
|
|
33
110
|
[PayNowServiceDefinition]: {},
|
|
34
111
|
};
|
|
35
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* Helper function to create a pay now service binding with configuration.
|
|
115
|
+
* This function simplifies the process of binding the pay now service with its configuration
|
|
116
|
+
* and allows for additional configuration overrides, particularly for custom checkout actions.
|
|
117
|
+
*
|
|
118
|
+
* @template T - Type of the services configurations object
|
|
119
|
+
* @param {T} servicesConfigs - Object containing service configurations
|
|
120
|
+
* @param {Partial<PayNowServiceConfig>} [additionalConfig={}] - Additional configuration to override defaults
|
|
121
|
+
* @returns Tuple containing service definition, implementation, and merged configuration
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
* import { payNowServiceBinding, loadPayNowServiceInitialData } from '@wix/stores/services';
|
|
126
|
+
* import { actions } from 'astro:actions';
|
|
127
|
+
*
|
|
128
|
+
* // Load initial data
|
|
129
|
+
* const initialData = await loadPayNowServiceInitialData();
|
|
130
|
+
*
|
|
131
|
+
* // Create service binding with custom checkout action
|
|
132
|
+
* const payNowBinding = payNowServiceBinding(initialData, {
|
|
133
|
+
* customCheckoutAction: async () => {
|
|
134
|
+
* try {
|
|
135
|
+
* const result = await actions.customCheckout();
|
|
136
|
+
* return { data: result, error: null };
|
|
137
|
+
* } catch (error) {
|
|
138
|
+
* return { data: undefined, error };
|
|
139
|
+
* }
|
|
140
|
+
* }
|
|
141
|
+
* });
|
|
142
|
+
*
|
|
143
|
+
* // Use in service provider
|
|
144
|
+
* const services = createServicesMap([payNowBinding]);
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
36
147
|
export const payNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
|
|
37
148
|
return [
|
|
38
149
|
PayNowServiceDefinition,
|