@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
package/dist/services/index.js
CHANGED
|
@@ -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,
|
|
@@ -1,29 +1,100 @@
|
|
|
1
1
|
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
2
|
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
3
|
+
/**
|
|
4
|
+
* API interface for the Product service, providing reactive product data management.
|
|
5
|
+
* This service handles loading and managing a single product's data, loading state, and errors.
|
|
6
|
+
*
|
|
7
|
+
* @interface ProductServiceAPI
|
|
8
|
+
*/
|
|
3
9
|
export interface ProductServiceAPI {
|
|
10
|
+
/** Reactive signal containing the current product data */
|
|
4
11
|
product: Signal<productsV3.V3Product>;
|
|
12
|
+
/** Reactive signal indicating if a product is currently being loaded */
|
|
5
13
|
isLoading: Signal<boolean>;
|
|
14
|
+
/** Reactive signal containing any error message, or null if no error */
|
|
6
15
|
error: Signal<string | null>;
|
|
16
|
+
/** Function to load a product by its slug */
|
|
7
17
|
loadProduct: (slug: string) => Promise<void>;
|
|
8
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Service definition for the Product service.
|
|
21
|
+
* This defines the contract that the ProductService must implement.
|
|
22
|
+
*
|
|
23
|
+
* @constant
|
|
24
|
+
*/
|
|
9
25
|
export declare const ProductServiceDefinition: string & {
|
|
10
26
|
__api: ProductServiceAPI;
|
|
11
27
|
__config: {};
|
|
12
28
|
isServiceDefinition?: boolean;
|
|
13
29
|
} & ProductServiceAPI;
|
|
30
|
+
/**
|
|
31
|
+
* Configuration interface required to initialize the ProductService.
|
|
32
|
+
* Contains the initial product data that will be loaded into the service.
|
|
33
|
+
*
|
|
34
|
+
* @interface ProductServiceConfig
|
|
35
|
+
*/
|
|
14
36
|
export interface ProductServiceConfig {
|
|
37
|
+
/** The initial product data to configure the service with */
|
|
15
38
|
product: productsV3.V3Product;
|
|
16
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Implementation of the Product service that manages reactive product data.
|
|
42
|
+
* This service provides signals for product data, loading state, and error handling,
|
|
43
|
+
* along with methods to dynamically load products.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* import { ProductService, ProductServiceDefinition } from '@wix/stores/services';
|
|
48
|
+
* import { useService } from '@wix/services-manager-react';
|
|
49
|
+
*
|
|
50
|
+
* function ProductComponent({ productConfig }) {
|
|
51
|
+
* return (
|
|
52
|
+
* <ServiceProvider services={createServicesMap([
|
|
53
|
+
* [ProductServiceDefinition, ProductService.withConfig(productConfig)]
|
|
54
|
+
* ])}>
|
|
55
|
+
* <ProductDisplay />
|
|
56
|
+
* </ServiceProvider>
|
|
57
|
+
* );
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* function ProductDisplay() {
|
|
61
|
+
* const productService = useService(ProductServiceDefinition);
|
|
62
|
+
* const product = productService.product.get();
|
|
63
|
+
* const isLoading = productService.isLoading.get();
|
|
64
|
+
* const error = productService.error.get();
|
|
65
|
+
*
|
|
66
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
67
|
+
* if (error) return <div>Error: {error}</div>;
|
|
68
|
+
*
|
|
69
|
+
* return <h1>{product.name}</h1>;
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
17
73
|
export declare const ProductService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
18
74
|
__api: ProductServiceAPI;
|
|
19
75
|
__config: {};
|
|
20
76
|
isServiceDefinition?: boolean;
|
|
21
77
|
} & ProductServiceAPI, ProductServiceConfig>;
|
|
78
|
+
/**
|
|
79
|
+
* Success result interface for product service configuration loading.
|
|
80
|
+
* Returned when a product is successfully found and loaded.
|
|
81
|
+
*
|
|
82
|
+
* @interface SuccessProductServiceConfigResult
|
|
83
|
+
*/
|
|
22
84
|
export interface SuccessProductServiceConfigResult {
|
|
85
|
+
/** Type "success" means that the product was found and the config is valid */
|
|
23
86
|
type: "success";
|
|
87
|
+
/** The product config containing the loaded product data */
|
|
24
88
|
config: ProductServiceConfig;
|
|
25
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Not found result interface for product service configuration loading.
|
|
92
|
+
* Returned when a product with the given slug cannot be found.
|
|
93
|
+
*
|
|
94
|
+
* @interface NotFoundProductServiceConfigResult
|
|
95
|
+
*/
|
|
26
96
|
export interface NotFoundProductServiceConfigResult {
|
|
97
|
+
/** Type "notFound" means that the product was not found */
|
|
27
98
|
type: "notFound";
|
|
28
99
|
}
|
|
29
100
|
/**
|
|
@@ -1,7 +1,46 @@
|
|
|
1
1
|
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
2
|
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
3
|
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
4
|
+
/**
|
|
5
|
+
* Service definition for the Product service.
|
|
6
|
+
* This defines the contract that the ProductService must implement.
|
|
7
|
+
*
|
|
8
|
+
* @constant
|
|
9
|
+
*/
|
|
4
10
|
export const ProductServiceDefinition = defineService("product");
|
|
11
|
+
/**
|
|
12
|
+
* Implementation of the Product service that manages reactive product data.
|
|
13
|
+
* This service provides signals for product data, loading state, and error handling,
|
|
14
|
+
* along with methods to dynamically load products.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { ProductService, ProductServiceDefinition } from '@wix/stores/services';
|
|
19
|
+
* import { useService } from '@wix/services-manager-react';
|
|
20
|
+
*
|
|
21
|
+
* function ProductComponent({ productConfig }) {
|
|
22
|
+
* return (
|
|
23
|
+
* <ServiceProvider services={createServicesMap([
|
|
24
|
+
* [ProductServiceDefinition, ProductService.withConfig(productConfig)]
|
|
25
|
+
* ])}>
|
|
26
|
+
* <ProductDisplay />
|
|
27
|
+
* </ServiceProvider>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* function ProductDisplay() {
|
|
32
|
+
* const productService = useService(ProductServiceDefinition);
|
|
33
|
+
* const product = productService.product.get();
|
|
34
|
+
* const isLoading = productService.isLoading.get();
|
|
35
|
+
* const error = productService.error.get();
|
|
36
|
+
*
|
|
37
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
38
|
+
* if (error) return <div>Error: {error}</div>;
|
|
39
|
+
*
|
|
40
|
+
* return <h1>{product.name}</h1>;
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
5
44
|
export const ProductService = implementService.withConfig()(ProductServiceDefinition, ({ getService, config }) => {
|
|
6
45
|
const signalsService = getService(SignalsServiceDefinition);
|
|
7
46
|
const product = signalsService.signal(config.product);
|
|
@@ -26,6 +65,14 @@ export const ProductService = implementService.withConfig()(ProductServiceDefini
|
|
|
26
65
|
loadProduct,
|
|
27
66
|
};
|
|
28
67
|
});
|
|
68
|
+
/**
|
|
69
|
+
* Internal helper function to load a product by its slug from the Wix Products API.
|
|
70
|
+
* Fetches comprehensive product data including description, categories, media, etc.
|
|
71
|
+
*
|
|
72
|
+
* @private
|
|
73
|
+
* @param {string} slug - The product slug to load
|
|
74
|
+
* @returns {Promise} Product response from the API
|
|
75
|
+
*/
|
|
29
76
|
const loadProductBySlug = async (slug) => {
|
|
30
77
|
const productResponse = await productsV3.getProductBySlug(slug, {
|
|
31
78
|
fields: [
|