@wix/headless-stores 0.0.109 → 0.0.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/dist/astro/actions/custom-checkout.d.ts +1 -3
- package/cjs/dist/astro/actions/custom-checkout.js +8 -4
- package/cjs/dist/astro/actions/index.js +17 -1
- package/cjs/dist/data-component-tags.js +5 -2
- package/cjs/dist/enums/index.js +18 -2
- package/cjs/dist/enums/social-platform-enums.js +7 -4
- package/cjs/dist/enums/sort-enums.js +6 -3
- package/cjs/dist/react/Category.js +64 -25
- package/cjs/dist/react/CategoryList.js +55 -14
- package/cjs/dist/react/Choice.js +32 -25
- package/cjs/dist/react/Option.js +68 -29
- package/cjs/dist/react/Product.js +194 -155
- package/cjs/dist/react/ProductList.js +84 -45
- package/cjs/dist/react/core/CategoryList.js +26 -16
- package/cjs/dist/react/core/Product.js +30 -20
- package/cjs/dist/react/core/ProductList.js +29 -21
- package/cjs/dist/react/core/ProductListFilters.js +30 -22
- package/cjs/dist/react/core/ProductListPagination.js +7 -4
- package/cjs/dist/react/core/ProductListSort.js +11 -6
- package/cjs/dist/react/core/ProductModifiers.js +25 -17
- package/cjs/dist/react/core/ProductVariantSelector.js +27 -19
- package/cjs/dist/react/core/SelectedVariant.js +28 -21
- package/cjs/dist/react/index.js +42 -6
- package/cjs/dist/react/types.js +5 -2
- package/cjs/dist/server-actions/custom-checkout-action.js +11 -8
- package/cjs/dist/server-actions/index.js +17 -1
- package/cjs/dist/services/buy-now-service.js +20 -15
- package/cjs/dist/services/categories-list-service.js +12 -8
- package/cjs/dist/services/index.js +25 -5
- package/cjs/dist/services/pay-now-service.js +16 -11
- package/cjs/dist/services/product-modifiers-service.js +16 -12
- package/cjs/dist/services/product-service.js +16 -12
- package/cjs/dist/services/products-list-search-service.d.ts +0 -1
- package/cjs/dist/services/products-list-search-service.js +1 -1
- package/cjs/dist/services/products-list-service.js +66 -59
- package/cjs/dist/services/selected-variant-service.js +21 -18
- package/cjs/dist/utils/index.js +9 -6
- package/cjs/dist/utils/url-params.js +5 -1
- package/dist/astro/actions/custom-checkout.d.ts +1 -3
- package/package.json +6 -6
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertUrlSortToSortType = exports.parseUrlToSearchOptions = exports.SortType = exports.InventoryStatusType = exports.loadProductsListServiceConfig = exports.ProductsListServiceDefinition = exports.ProductListService = exports.SelectedVariantServiceDefinition = exports.SelectedVariantService = exports.loadProductServiceConfig = exports.ProductServiceDefinition = exports.ProductService = exports.ProductModifiersServiceDefinition = exports.ProductModifiersService = exports.loadCategoriesListServiceConfig = exports.CategoriesListServiceDefinition = exports.CategoriesListService = void 0;
|
|
4
|
+
var categories_list_service_js_1 = require("./categories-list-service.js");
|
|
5
|
+
Object.defineProperty(exports, "CategoriesListService", { enumerable: true, get: function () { return categories_list_service_js_1.CategoriesListService; } });
|
|
6
|
+
Object.defineProperty(exports, "CategoriesListServiceDefinition", { enumerable: true, get: function () { return categories_list_service_js_1.CategoriesListServiceDefinition; } });
|
|
7
|
+
Object.defineProperty(exports, "loadCategoriesListServiceConfig", { enumerable: true, get: function () { return categories_list_service_js_1.loadCategoriesListServiceConfig; } });
|
|
8
|
+
var product_modifiers_service_js_1 = require("./product-modifiers-service.js");
|
|
9
|
+
Object.defineProperty(exports, "ProductModifiersService", { enumerable: true, get: function () { return product_modifiers_service_js_1.ProductModifiersService; } });
|
|
10
|
+
Object.defineProperty(exports, "ProductModifiersServiceDefinition", { enumerable: true, get: function () { return product_modifiers_service_js_1.ProductModifiersServiceDefinition; } });
|
|
11
|
+
var product_service_js_1 = require("./product-service.js");
|
|
12
|
+
Object.defineProperty(exports, "ProductService", { enumerable: true, get: function () { return product_service_js_1.ProductService; } });
|
|
13
|
+
Object.defineProperty(exports, "ProductServiceDefinition", { enumerable: true, get: function () { return product_service_js_1.ProductServiceDefinition; } });
|
|
14
|
+
Object.defineProperty(exports, "loadProductServiceConfig", { enumerable: true, get: function () { return product_service_js_1.loadProductServiceConfig; } });
|
|
15
|
+
var selected_variant_service_js_1 = require("./selected-variant-service.js");
|
|
16
|
+
Object.defineProperty(exports, "SelectedVariantService", { enumerable: true, get: function () { return selected_variant_service_js_1.SelectedVariantService; } });
|
|
17
|
+
Object.defineProperty(exports, "SelectedVariantServiceDefinition", { enumerable: true, get: function () { return selected_variant_service_js_1.SelectedVariantServiceDefinition; } });
|
|
18
|
+
var products_list_service_js_1 = require("./products-list-service.js");
|
|
19
|
+
Object.defineProperty(exports, "ProductListService", { enumerable: true, get: function () { return products_list_service_js_1.ProductListService; } });
|
|
20
|
+
Object.defineProperty(exports, "ProductsListServiceDefinition", { enumerable: true, get: function () { return products_list_service_js_1.ProductsListServiceDefinition; } });
|
|
21
|
+
Object.defineProperty(exports, "loadProductsListServiceConfig", { enumerable: true, get: function () { return products_list_service_js_1.loadProductsListServiceConfig; } });
|
|
22
|
+
Object.defineProperty(exports, "InventoryStatusType", { enumerable: true, get: function () { return products_list_service_js_1.InventoryStatusType; } });
|
|
23
|
+
Object.defineProperty(exports, "SortType", { enumerable: true, get: function () { return products_list_service_js_1.SortType; } });
|
|
24
|
+
Object.defineProperty(exports, "parseUrlToSearchOptions", { enumerable: true, get: function () { return products_list_service_js_1.parseUrlToSearchOptions; } });
|
|
25
|
+
Object.defineProperty(exports, "convertUrlSortToSortType", { enumerable: true, get: function () { return products_list_service_js_1.convertUrlSortToSortType; } });
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.payNowServiceBinding = exports.loadPayNowServiceInitialData = exports.PayNowServiceImplementation = exports.PayNowServiceDefinition = void 0;
|
|
4
|
+
const services_definitions_1 = require("@wix/services-definitions");
|
|
5
|
+
const signals_1 = require("@wix/services-definitions/core-services/signals");
|
|
3
6
|
/**
|
|
4
7
|
* Service definition for the Pay Now service.
|
|
5
8
|
* This defines the reactive API contract for managing custom payment checkout functionality.
|
|
6
9
|
*
|
|
7
10
|
* @constant
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
exports.PayNowServiceDefinition = (0, services_definitions_1.defineService)('PayNow');
|
|
10
13
|
/**
|
|
11
14
|
* Implementation of the Pay Now service that manages custom payment checkout functionality.
|
|
12
15
|
* This service provides signals for loading state and error handling, along with a method
|
|
@@ -51,8 +54,8 @@ export const PayNowServiceDefinition = defineService('PayNow');
|
|
|
51
54
|
* }
|
|
52
55
|
* ```
|
|
53
56
|
*/
|
|
54
|
-
|
|
55
|
-
const signalsService = getService(SignalsServiceDefinition);
|
|
57
|
+
exports.PayNowServiceImplementation = services_definitions_1.implementService.withConfig()(exports.PayNowServiceDefinition, ({ getService, config }) => {
|
|
58
|
+
const signalsService = getService(signals_1.SignalsServiceDefinition);
|
|
56
59
|
const loadingSignal = signalsService.signal(false);
|
|
57
60
|
const errorSignal = signalsService.signal(null);
|
|
58
61
|
return {
|
|
@@ -105,11 +108,12 @@ export const PayNowServiceImplementation = implementService.withConfig()(PayNowS
|
|
|
105
108
|
* </PayNow.PayNow>
|
|
106
109
|
* ```
|
|
107
110
|
*/
|
|
108
|
-
|
|
111
|
+
const loadPayNowServiceInitialData = async () => {
|
|
109
112
|
return {
|
|
110
|
-
[PayNowServiceDefinition]: {},
|
|
113
|
+
[exports.PayNowServiceDefinition]: {},
|
|
111
114
|
};
|
|
112
115
|
};
|
|
116
|
+
exports.loadPayNowServiceInitialData = loadPayNowServiceInitialData;
|
|
113
117
|
/**
|
|
114
118
|
* Helper function to create a pay now service binding with configuration.
|
|
115
119
|
* This function simplifies the process of binding the pay now service with its configuration
|
|
@@ -144,13 +148,14 @@ export const loadPayNowServiceInitialData = async () => {
|
|
|
144
148
|
* const services = createServicesMap([payNowBinding]);
|
|
145
149
|
* ```
|
|
146
150
|
*/
|
|
147
|
-
|
|
151
|
+
const payNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
|
|
148
152
|
return [
|
|
149
|
-
PayNowServiceDefinition,
|
|
150
|
-
PayNowServiceImplementation,
|
|
153
|
+
exports.PayNowServiceDefinition,
|
|
154
|
+
exports.PayNowServiceImplementation,
|
|
151
155
|
{
|
|
152
|
-
...servicesConfigs[PayNowServiceDefinition],
|
|
156
|
+
...servicesConfigs[exports.PayNowServiceDefinition],
|
|
153
157
|
...additionalConfig,
|
|
154
158
|
},
|
|
155
159
|
];
|
|
156
160
|
};
|
|
161
|
+
exports.payNowServiceBinding = payNowServiceBinding;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductModifiersService = exports.ProductModifiersServiceDefinition = void 0;
|
|
4
|
+
exports.createProductModifiersServiceConfig = createProductModifiersServiceConfig;
|
|
5
|
+
const services_definitions_1 = require("@wix/services-definitions");
|
|
6
|
+
const signals_1 = require("@wix/services-definitions/core-services/signals");
|
|
7
|
+
const stores_1 = require("@wix/stores");
|
|
8
|
+
const product_service_js_1 = require("./product-service.js");
|
|
9
|
+
exports.ProductModifiersServiceDefinition = (0, services_definitions_1.defineService)('productModifiers');
|
|
10
|
+
exports.ProductModifiersService = services_definitions_1.implementService.withConfig()(exports.ProductModifiersServiceDefinition, ({ getService }) => {
|
|
11
|
+
const signalsService = getService(signals_1.SignalsServiceDefinition);
|
|
12
|
+
const productService = getService(product_service_js_1.ProductServiceDefinition);
|
|
9
13
|
const selectedModifiers = signalsService.signal({});
|
|
10
14
|
const isLoading = signalsService.signal(false);
|
|
11
15
|
const error = signalsService.signal(null);
|
|
@@ -73,11 +77,11 @@ export const ProductModifiersService = implementService.withConfig()(ProductModi
|
|
|
73
77
|
const renderType = modifier.modifierRenderType;
|
|
74
78
|
if (!renderType)
|
|
75
79
|
return false;
|
|
76
|
-
if (renderType === productsV3.ModifierRenderType.SWATCH_CHOICES ||
|
|
77
|
-
renderType === productsV3.ModifierRenderType.TEXT_CHOICES) {
|
|
80
|
+
if (renderType === stores_1.productsV3.ModifierRenderType.SWATCH_CHOICES ||
|
|
81
|
+
renderType === stores_1.productsV3.ModifierRenderType.TEXT_CHOICES) {
|
|
78
82
|
return !!selectedValue.choiceValue;
|
|
79
83
|
}
|
|
80
|
-
else if (renderType === productsV3.ModifierRenderType.FREE_TEXT) {
|
|
84
|
+
else if (renderType === stores_1.productsV3.ModifierRenderType.FREE_TEXT) {
|
|
81
85
|
return (!!selectedValue.freeTextValue &&
|
|
82
86
|
selectedValue.freeTextValue.trim() !== '');
|
|
83
87
|
}
|
|
@@ -100,7 +104,7 @@ export const ProductModifiersService = implementService.withConfig()(ProductModi
|
|
|
100
104
|
areAllRequiredModifiersFilled,
|
|
101
105
|
};
|
|
102
106
|
});
|
|
103
|
-
|
|
107
|
+
function createProductModifiersServiceConfig(product) {
|
|
104
108
|
return {
|
|
105
109
|
product,
|
|
106
110
|
};
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductService = exports.ProductServiceDefinition = void 0;
|
|
4
|
+
exports.loadProductServiceConfig = loadProductServiceConfig;
|
|
5
|
+
const stores_1 = require("@wix/stores");
|
|
6
|
+
const services_definitions_1 = require("@wix/services-definitions");
|
|
7
|
+
const signals_1 = require("@wix/services-definitions/core-services/signals");
|
|
8
|
+
const site_1 = require("@wix/site");
|
|
5
9
|
/**
|
|
6
10
|
* Service definition for the Product service.
|
|
7
11
|
* This defines the contract that the ProductService must implement.
|
|
8
12
|
*
|
|
9
13
|
* @constant
|
|
10
14
|
*/
|
|
11
|
-
|
|
15
|
+
exports.ProductServiceDefinition = (0, services_definitions_1.defineService)('product');
|
|
12
16
|
/**
|
|
13
17
|
* Implementation of the Product service that manages reactive product data.
|
|
14
18
|
* This service provides signals for product data, loading state, and error handling,
|
|
@@ -42,8 +46,8 @@ export const ProductServiceDefinition = defineService('product');
|
|
|
42
46
|
* }
|
|
43
47
|
* ```
|
|
44
48
|
*/
|
|
45
|
-
|
|
46
|
-
const signalsService = getService(SignalsServiceDefinition);
|
|
49
|
+
exports.ProductService = services_definitions_1.implementService.withConfig()(exports.ProductServiceDefinition, ({ getService, config }) => {
|
|
50
|
+
const signalsService = getService(signals_1.SignalsServiceDefinition);
|
|
47
51
|
const product = signalsService.signal(config.product);
|
|
48
52
|
const isLoading = signalsService.signal(!!config.productSlug);
|
|
49
53
|
const error = signalsService.signal(null);
|
|
@@ -100,7 +104,7 @@ export const ProductService = implementService.withConfig()(ProductServiceDefini
|
|
|
100
104
|
?.amount ?? '0'),
|
|
101
105
|
sku: currentProduct.variantsInfo?.variants?.[0]?.sku ?? undefined,
|
|
102
106
|
};
|
|
103
|
-
analytics.trackEvent('ViewContent', eventData);
|
|
107
|
+
site_1.analytics.trackEvent('ViewContent', eventData);
|
|
104
108
|
};
|
|
105
109
|
/**
|
|
106
110
|
* Reports an AddToCart analytics event for cart tracking.
|
|
@@ -153,7 +157,7 @@ export const ProductService = implementService.withConfig()(ProductServiceDefini
|
|
|
153
157
|
origin: options?.origin,
|
|
154
158
|
position: options?.position,
|
|
155
159
|
};
|
|
156
|
-
analytics.trackEvent('AddToCart', eventData);
|
|
160
|
+
site_1.analytics.trackEvent('AddToCart', eventData);
|
|
157
161
|
};
|
|
158
162
|
/**
|
|
159
163
|
* Reports a ClickProduct analytics event for product click tracking.
|
|
@@ -206,7 +210,7 @@ export const ProductService = implementService.withConfig()(ProductServiceDefini
|
|
|
206
210
|
position: options?.position,
|
|
207
211
|
origin: options?.origin,
|
|
208
212
|
};
|
|
209
|
-
analytics.trackEvent('ClickProduct', eventData);
|
|
213
|
+
site_1.analytics.trackEvent('ClickProduct', eventData);
|
|
210
214
|
};
|
|
211
215
|
return {
|
|
212
216
|
product,
|
|
@@ -227,7 +231,7 @@ export const ProductService = implementService.withConfig()(ProductServiceDefini
|
|
|
227
231
|
* @returns {Promise} Product response from the API
|
|
228
232
|
*/
|
|
229
233
|
const loadProductBySlug = async (slug) => {
|
|
230
|
-
const productResponse = await productsV3.getProductBySlug(slug, {
|
|
234
|
+
const productResponse = await stores_1.productsV3.getProductBySlug(slug, {
|
|
231
235
|
fields: [
|
|
232
236
|
'CURRENCY',
|
|
233
237
|
'DESCRIPTION',
|
|
@@ -320,7 +324,7 @@ const loadProductBySlug = async (slug) => {
|
|
|
320
324
|
* }
|
|
321
325
|
* ```
|
|
322
326
|
*/
|
|
323
|
-
|
|
327
|
+
async function loadProductServiceConfig(productSlug) {
|
|
324
328
|
try {
|
|
325
329
|
// Use getProductBySlug directly - single API call with comprehensive fields
|
|
326
330
|
const productResponse = await loadProductBySlug(productSlug);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductListService = exports.ProductsListServiceDefinition = exports.InventoryStatusType = exports.SortType = exports.DEFAULT_QUERY_LIMIT = void 0;
|
|
4
|
+
exports.loadProductsListServiceConfig = loadProductsListServiceConfig;
|
|
5
|
+
exports.parseUrlToSearchOptions = parseUrlToSearchOptions;
|
|
6
|
+
exports.convertUrlSortToSortType = convertUrlSortToSortType;
|
|
7
|
+
const services_definitions_1 = require("@wix/services-definitions");
|
|
8
|
+
const signals_1 = require("@wix/services-definitions/core-services/signals");
|
|
9
|
+
const stores_1 = require("@wix/stores");
|
|
10
|
+
const categories_list_service_js_1 = require("./categories-list-service.js");
|
|
11
|
+
exports.DEFAULT_QUERY_LIMIT = 100;
|
|
12
|
+
const sort_enums_js_1 = require("./../enums/sort-enums.js");
|
|
13
|
+
var sort_enums_js_2 = require("./../enums/sort-enums.js");
|
|
14
|
+
Object.defineProperty(exports, "SortType", { enumerable: true, get: function () { return sort_enums_js_2.SortType; } });
|
|
8
15
|
/**
|
|
9
16
|
* Enumeration of inventory status types available for filtering.
|
|
10
17
|
* Re-exports the Wix inventory availability status enum values.
|
|
11
18
|
*/
|
|
12
|
-
|
|
19
|
+
exports.InventoryStatusType = stores_1.productsV3.InventoryAvailabilityStatus;
|
|
13
20
|
/**
|
|
14
21
|
* Loads products list service configuration from the Wix Stores API for SSR initialization.
|
|
15
22
|
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
@@ -122,14 +129,14 @@ export const InventoryStatusType = productsV3.InventoryAvailabilityStatus;
|
|
|
122
129
|
* ]);
|
|
123
130
|
* ```
|
|
124
131
|
*/
|
|
125
|
-
|
|
132
|
+
async function loadProductsListServiceConfig(input) {
|
|
126
133
|
let searchOptions;
|
|
127
|
-
const { items: customizations = [] } = await customizationsV3
|
|
134
|
+
const { items: customizations = [] } = await stores_1.customizationsV3
|
|
128
135
|
.queryCustomizations()
|
|
129
136
|
.find();
|
|
130
137
|
if (typeof input === 'string') {
|
|
131
138
|
// URL input - parse it
|
|
132
|
-
const categoriesListConfig = await loadCategoriesListServiceConfig();
|
|
139
|
+
const categoriesListConfig = await (0, categories_list_service_js_1.loadCategoriesListServiceConfig)();
|
|
133
140
|
const { searchOptions: parsedOptions } = await parseUrlToSearchOptions(input, categoriesListConfig.categories, customizations);
|
|
134
141
|
searchOptions = parsedOptions;
|
|
135
142
|
}
|
|
@@ -160,8 +167,8 @@ export async function loadProductsListServiceConfig(input) {
|
|
|
160
167
|
* @returns Promise that resolves to the search result with complete variant data
|
|
161
168
|
*/
|
|
162
169
|
const fetchProducts = async (searchOptions) => {
|
|
163
|
-
const result = await productsV3.searchProducts(searchOptions, {
|
|
164
|
-
fields: [productsV3.RequestedFields.CURRENCY],
|
|
170
|
+
const result = await stores_1.productsV3.searchProducts(searchOptions, {
|
|
171
|
+
fields: [stores_1.productsV3.RequestedFields.CURRENCY],
|
|
165
172
|
});
|
|
166
173
|
// Fetch missing variants for all products in one batch request
|
|
167
174
|
if (result.products) {
|
|
@@ -193,12 +200,12 @@ const fetchMissingVariants = async (products) => {
|
|
|
193
200
|
return products;
|
|
194
201
|
}
|
|
195
202
|
const items = [];
|
|
196
|
-
const res = await readOnlyVariantsV3
|
|
203
|
+
const res = await stores_1.readOnlyVariantsV3
|
|
197
204
|
.queryVariants({
|
|
198
|
-
fields: [readOnlyVariantsV3.RequestedFields.CURRENCY],
|
|
205
|
+
fields: [stores_1.readOnlyVariantsV3.RequestedFields.CURRENCY],
|
|
199
206
|
})
|
|
200
207
|
.in('productData.productId', productIds)
|
|
201
|
-
.limit(DEFAULT_QUERY_LIMIT)
|
|
208
|
+
.limit(exports.DEFAULT_QUERY_LIMIT)
|
|
202
209
|
.find();
|
|
203
210
|
items.push(...res.items);
|
|
204
211
|
let nextRes = res;
|
|
@@ -245,7 +252,7 @@ const fetchMissingVariants = async (products) => {
|
|
|
245
252
|
*
|
|
246
253
|
* @constant
|
|
247
254
|
*/
|
|
248
|
-
|
|
255
|
+
exports.ProductsListServiceDefinition = (0, services_definitions_1.defineService)('products-list');
|
|
249
256
|
/**
|
|
250
257
|
* Implementation of the Products List service that manages reactive products data.
|
|
251
258
|
* This service provides signals for products data, search options, pagination, aggregations,
|
|
@@ -300,9 +307,9 @@ export const ProductsListServiceDefinition = defineService('products-list');
|
|
|
300
307
|
* }
|
|
301
308
|
* ```
|
|
302
309
|
*/
|
|
303
|
-
|
|
310
|
+
exports.ProductListService = services_definitions_1.implementService.withConfig()(exports.ProductsListServiceDefinition, ({ getService, config }) => {
|
|
304
311
|
let firstRun = true;
|
|
305
|
-
const signalsService = getService(SignalsServiceDefinition);
|
|
312
|
+
const signalsService = getService(signals_1.SignalsServiceDefinition);
|
|
306
313
|
const productsSignal = signalsService.signal(config.products);
|
|
307
314
|
const searchOptionsSignal = signalsService.signal(config.searchOptions);
|
|
308
315
|
const pagingMetadataSignal = signalsService.signal(config.pagingMetadata);
|
|
@@ -310,9 +317,9 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
|
|
|
310
317
|
const maxPriceSignal = signalsService.signal(getMaxPrice(config.aggregations.results));
|
|
311
318
|
const availableProductOptionsSignal = signalsService.signal(getAvailableProductOptions(config.aggregations.results, config.customizations));
|
|
312
319
|
const availableInventoryStatusesSignal = signalsService.signal([
|
|
313
|
-
InventoryStatusType.IN_STOCK,
|
|
314
|
-
InventoryStatusType.OUT_OF_STOCK,
|
|
315
|
-
InventoryStatusType.PARTIALLY_OUT_OF_STOCK,
|
|
320
|
+
exports.InventoryStatusType.IN_STOCK,
|
|
321
|
+
exports.InventoryStatusType.OUT_OF_STOCK,
|
|
322
|
+
exports.InventoryStatusType.PARTIALLY_OUT_OF_STOCK,
|
|
316
323
|
]);
|
|
317
324
|
const aggregationsSignal = signalsService.signal(config.aggregations);
|
|
318
325
|
// Extract currency from the first product, fallback to USD
|
|
@@ -349,7 +356,7 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
|
|
|
349
356
|
const affectiveSearchOptions = {
|
|
350
357
|
cursorPaging: {
|
|
351
358
|
cursor: pagingMetadataSignal.get().cursors?.next,
|
|
352
|
-
limit: DEFAULT_QUERY_LIMIT || count,
|
|
359
|
+
limit: exports.DEFAULT_QUERY_LIMIT || count,
|
|
353
360
|
},
|
|
354
361
|
};
|
|
355
362
|
try {
|
|
@@ -471,7 +478,7 @@ function getAvailableProductOptions(aggregationData = [], customizations = []) {
|
|
|
471
478
|
.filter((customization) => customization.name &&
|
|
472
479
|
customization._id &&
|
|
473
480
|
customization.customizationType ===
|
|
474
|
-
customizationsV3.CustomizationType.PRODUCT_OPTION &&
|
|
481
|
+
stores_1.customizationsV3.CustomizationType.PRODUCT_OPTION &&
|
|
475
482
|
(optionNames.length === 0 ||
|
|
476
483
|
matchesAggregationName(customization.name, optionNames)))
|
|
477
484
|
.map((customization) => {
|
|
@@ -522,13 +529,13 @@ function getAvailableProductOptions(aggregationData = [], customizations = []) {
|
|
|
522
529
|
* const filterState = initialSearchState.productOptions; // { colorId: ['red-id', 'blue-id'] }
|
|
523
530
|
* ```
|
|
524
531
|
*/
|
|
525
|
-
|
|
532
|
+
async function parseUrlToSearchOptions(url, categoriesList, customizations, defaultSearchOptions) {
|
|
526
533
|
const urlObj = new URL(url);
|
|
527
534
|
const searchParams = urlObj.searchParams;
|
|
528
535
|
// Build search options
|
|
529
536
|
const searchOptions = {
|
|
530
537
|
cursorPaging: {
|
|
531
|
-
limit: DEFAULT_QUERY_LIMIT,
|
|
538
|
+
limit: exports.DEFAULT_QUERY_LIMIT,
|
|
532
539
|
},
|
|
533
540
|
...defaultSearchOptions,
|
|
534
541
|
};
|
|
@@ -561,37 +568,37 @@ export async function parseUrlToSearchOptions(url, categoriesList, customization
|
|
|
561
568
|
initialSearchState.sort = sortType;
|
|
562
569
|
// Apply sort to search options
|
|
563
570
|
switch (sortType) {
|
|
564
|
-
case SortType.NAME_ASC:
|
|
571
|
+
case sort_enums_js_1.SortType.NAME_ASC:
|
|
565
572
|
searchOptions.sort = [
|
|
566
|
-
{ fieldName: 'name', order: productsV3.SortDirection.ASC },
|
|
573
|
+
{ fieldName: 'name', order: stores_1.productsV3.SortDirection.ASC },
|
|
567
574
|
];
|
|
568
575
|
break;
|
|
569
|
-
case SortType.NAME_DESC:
|
|
576
|
+
case sort_enums_js_1.SortType.NAME_DESC:
|
|
570
577
|
searchOptions.sort = [
|
|
571
|
-
{ fieldName: 'name', order: productsV3.SortDirection.DESC },
|
|
578
|
+
{ fieldName: 'name', order: stores_1.productsV3.SortDirection.DESC },
|
|
572
579
|
];
|
|
573
580
|
break;
|
|
574
|
-
case SortType.PRICE_ASC:
|
|
581
|
+
case sort_enums_js_1.SortType.PRICE_ASC:
|
|
575
582
|
searchOptions.sort = [
|
|
576
583
|
{
|
|
577
584
|
fieldName: 'actualPriceRange.minValue.amount',
|
|
578
|
-
order: productsV3.SortDirection.ASC,
|
|
585
|
+
order: stores_1.productsV3.SortDirection.ASC,
|
|
579
586
|
},
|
|
580
587
|
];
|
|
581
588
|
break;
|
|
582
|
-
case SortType.PRICE_DESC:
|
|
589
|
+
case sort_enums_js_1.SortType.PRICE_DESC:
|
|
583
590
|
searchOptions.sort = [
|
|
584
591
|
{
|
|
585
592
|
fieldName: 'actualPriceRange.minValue.amount',
|
|
586
|
-
order: productsV3.SortDirection.DESC,
|
|
593
|
+
order: stores_1.productsV3.SortDirection.DESC,
|
|
587
594
|
},
|
|
588
595
|
];
|
|
589
596
|
break;
|
|
590
|
-
case SortType.RECOMMENDED:
|
|
597
|
+
case sort_enums_js_1.SortType.RECOMMENDED:
|
|
591
598
|
searchOptions.sort = [
|
|
592
599
|
{
|
|
593
600
|
fieldName: 'name',
|
|
594
|
-
order: productsV3.SortDirection.DESC,
|
|
601
|
+
order: stores_1.productsV3.SortDirection.DESC,
|
|
595
602
|
},
|
|
596
603
|
];
|
|
597
604
|
break;
|
|
@@ -679,7 +686,7 @@ export async function parseUrlToSearchOptions(url, categoriesList, customization
|
|
|
679
686
|
// Find the option by name in customizations
|
|
680
687
|
const option = customizations.find((c) => c.name === optionName &&
|
|
681
688
|
c.customizationType ===
|
|
682
|
-
customizationsV3.CustomizationType.PRODUCT_OPTION);
|
|
689
|
+
stores_1.customizationsV3.CustomizationType.PRODUCT_OPTION);
|
|
683
690
|
if (option && option._id) {
|
|
684
691
|
const choiceValues = optionValues.split(',').filter(Boolean);
|
|
685
692
|
const choiceIds = [];
|
|
@@ -723,31 +730,31 @@ export async function parseUrlToSearchOptions(url, categoriesList, customization
|
|
|
723
730
|
{
|
|
724
731
|
name: 'optionNames',
|
|
725
732
|
fieldPath: 'options.name',
|
|
726
|
-
type: productsV3.SortType.VALUE,
|
|
733
|
+
type: stores_1.productsV3.SortType.VALUE,
|
|
727
734
|
value: {
|
|
728
735
|
limit: 20,
|
|
729
|
-
sortType: productsV3.SortType.VALUE,
|
|
730
|
-
sortDirection: productsV3.SortDirection.ASC,
|
|
736
|
+
sortType: stores_1.productsV3.SortType.VALUE,
|
|
737
|
+
sortDirection: stores_1.productsV3.SortDirection.ASC,
|
|
731
738
|
},
|
|
732
739
|
},
|
|
733
740
|
{
|
|
734
741
|
name: 'choiceNames',
|
|
735
742
|
fieldPath: 'options.choicesSettings.choices.name',
|
|
736
|
-
type: productsV3.SortType.VALUE,
|
|
743
|
+
type: stores_1.productsV3.SortType.VALUE,
|
|
737
744
|
value: {
|
|
738
745
|
limit: 50,
|
|
739
|
-
sortType: productsV3.SortType.VALUE,
|
|
740
|
-
sortDirection: productsV3.SortDirection.ASC,
|
|
746
|
+
sortType: stores_1.productsV3.SortType.VALUE,
|
|
747
|
+
sortDirection: stores_1.productsV3.SortDirection.ASC,
|
|
741
748
|
},
|
|
742
749
|
},
|
|
743
750
|
{
|
|
744
751
|
name: 'inventoryStatus',
|
|
745
752
|
fieldPath: 'inventory.availabilityStatus',
|
|
746
|
-
type: productsV3.SortType.VALUE,
|
|
753
|
+
type: stores_1.productsV3.SortType.VALUE,
|
|
747
754
|
value: {
|
|
748
755
|
limit: 10,
|
|
749
|
-
sortType: productsV3.SortType.VALUE,
|
|
750
|
-
sortDirection: productsV3.SortDirection.ASC,
|
|
756
|
+
sortType: stores_1.productsV3.SortType.VALUE,
|
|
757
|
+
sortDirection: stores_1.productsV3.SortDirection.ASC,
|
|
751
758
|
},
|
|
752
759
|
},
|
|
753
760
|
];
|
|
@@ -758,17 +765,17 @@ export async function parseUrlToSearchOptions(url, categoriesList, customization
|
|
|
758
765
|
*/
|
|
759
766
|
function convertSortTypeToUrl(sortType) {
|
|
760
767
|
switch (sortType) {
|
|
761
|
-
case SortType.NAME_ASC:
|
|
768
|
+
case sort_enums_js_1.SortType.NAME_ASC:
|
|
762
769
|
return 'name';
|
|
763
|
-
case SortType.NAME_DESC:
|
|
770
|
+
case sort_enums_js_1.SortType.NAME_DESC:
|
|
764
771
|
return 'name:desc';
|
|
765
|
-
case SortType.PRICE_ASC:
|
|
772
|
+
case sort_enums_js_1.SortType.PRICE_ASC:
|
|
766
773
|
return 'price';
|
|
767
|
-
case SortType.PRICE_DESC:
|
|
774
|
+
case sort_enums_js_1.SortType.PRICE_DESC:
|
|
768
775
|
return 'price:desc';
|
|
769
|
-
case SortType.NEWEST:
|
|
776
|
+
case sort_enums_js_1.SortType.NEWEST:
|
|
770
777
|
return 'newest';
|
|
771
|
-
case SortType.RECOMMENDED:
|
|
778
|
+
case sort_enums_js_1.SortType.RECOMMENDED:
|
|
772
779
|
return 'recommended';
|
|
773
780
|
default:
|
|
774
781
|
return 'name';
|
|
@@ -777,20 +784,20 @@ function convertSortTypeToUrl(sortType) {
|
|
|
777
784
|
/**
|
|
778
785
|
* Convert URL sort format to SortType enum
|
|
779
786
|
*/
|
|
780
|
-
|
|
787
|
+
function convertUrlSortToSortType(urlSort) {
|
|
781
788
|
const sortParts = urlSort.split(':');
|
|
782
789
|
const field = sortParts[0]?.toLowerCase();
|
|
783
790
|
const order = sortParts[1]?.toLowerCase() === 'desc' ? 'desc' : 'asc';
|
|
784
791
|
switch (field) {
|
|
785
792
|
case 'name':
|
|
786
|
-
return order === 'desc' ? SortType.NAME_DESC : SortType.NAME_ASC;
|
|
793
|
+
return order === 'desc' ? sort_enums_js_1.SortType.NAME_DESC : sort_enums_js_1.SortType.NAME_ASC;
|
|
787
794
|
case 'price':
|
|
788
|
-
return order === 'desc' ? SortType.PRICE_DESC : SortType.PRICE_ASC;
|
|
795
|
+
return order === 'desc' ? sort_enums_js_1.SortType.PRICE_DESC : sort_enums_js_1.SortType.PRICE_ASC;
|
|
789
796
|
case 'newest':
|
|
790
797
|
case 'created':
|
|
791
|
-
return SortType.NEWEST;
|
|
798
|
+
return sort_enums_js_1.SortType.NEWEST;
|
|
792
799
|
case 'recommended':
|
|
793
|
-
return SortType.RECOMMENDED;
|
|
800
|
+
return sort_enums_js_1.SortType.RECOMMENDED;
|
|
794
801
|
default:
|
|
795
802
|
return null;
|
|
796
803
|
}
|
|
@@ -840,14 +847,14 @@ function updateUrlWithSearchState(searchState) {
|
|
|
840
847
|
// Remove existing product option parameters (they have dynamic names)
|
|
841
848
|
for (const customization of customizations) {
|
|
842
849
|
if (customization.customizationType ===
|
|
843
|
-
customizationsV3.CustomizationType.PRODUCT_OPTION &&
|
|
850
|
+
stores_1.customizationsV3.CustomizationType.PRODUCT_OPTION &&
|
|
844
851
|
customization.name) {
|
|
845
852
|
params.delete(customization.name);
|
|
846
853
|
}
|
|
847
854
|
}
|
|
848
855
|
// Add sort parameter (only if not default)
|
|
849
856
|
const urlSort = convertSortTypeToUrl(sort);
|
|
850
|
-
if (sort !== SortType.NAME_ASC) {
|
|
857
|
+
if (sort !== sort_enums_js_1.SortType.NAME_ASC) {
|
|
851
858
|
params.set('sort', urlSort);
|
|
852
859
|
}
|
|
853
860
|
// Add price range parameters only if they differ from catalog bounds
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelectedVariantService = exports.SelectedVariantServiceDefinition = void 0;
|
|
4
|
+
const services_definitions_1 = require("@wix/services-definitions");
|
|
5
|
+
const signals_1 = require("@wix/services-definitions/core-services/signals");
|
|
6
|
+
const stores_1 = require("@wix/stores");
|
|
7
|
+
const services_1 = require("@wix/headless-ecom/services");
|
|
8
|
+
const services_2 = require("@wix/headless-media/services");
|
|
9
|
+
const product_service_js_1 = require("./product-service.js");
|
|
10
|
+
exports.SelectedVariantServiceDefinition = (0, services_definitions_1.defineService)('selectedVariant');
|
|
11
|
+
exports.SelectedVariantService = services_definitions_1.implementService.withConfig()(exports.SelectedVariantServiceDefinition, ({ getService, config: { fetchInventoryData = true } }) => {
|
|
12
|
+
const mediaService = getService(services_2.MediaGalleryServiceDefinition);
|
|
13
|
+
const signalsService = getService(signals_1.SignalsServiceDefinition);
|
|
14
|
+
const cartService = getService(services_1.CurrentCartServiceDefinition);
|
|
15
|
+
const productService = getService(product_service_js_1.ProductServiceDefinition);
|
|
13
16
|
const selectedChoices = signalsService.signal({});
|
|
14
17
|
const preOrderMessage = signalsService.signal(null);
|
|
15
18
|
const initialProduct = productService.product.get();
|
|
@@ -74,7 +77,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
74
77
|
}
|
|
75
78
|
try {
|
|
76
79
|
// Use the correct Wix inventoryItemsV3.queryInventoryItems() API
|
|
77
|
-
const queryResult = await inventoryItemsV3
|
|
80
|
+
const queryResult = await stores_1.inventoryItemsV3
|
|
78
81
|
.queryInventoryItems()
|
|
79
82
|
.eq('variantId', variantId)
|
|
80
83
|
.find();
|
|
@@ -175,9 +178,9 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
175
178
|
},
|
|
176
179
|
inventoryStatus: {
|
|
177
180
|
inStock: currentProduct.inventory?.availabilityStatus ===
|
|
178
|
-
productsV3.InventoryAvailabilityStatus.IN_STOCK ||
|
|
181
|
+
stores_1.productsV3.InventoryAvailabilityStatus.IN_STOCK ||
|
|
179
182
|
currentProduct.inventory?.availabilityStatus ===
|
|
180
|
-
productsV3.InventoryAvailabilityStatus
|
|
183
|
+
stores_1.productsV3.InventoryAvailabilityStatus
|
|
181
184
|
.PARTIALLY_OUT_OF_STOCK,
|
|
182
185
|
preorderEnabled: currentProduct.inventory?.preorderStatus === 'ENABLED',
|
|
183
186
|
},
|
|
@@ -309,15 +312,15 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
309
312
|
if (!productModifier)
|
|
310
313
|
return;
|
|
311
314
|
const renderType = productModifier.modifierRenderType;
|
|
312
|
-
if (renderType === productsV3.ModifierRenderType.TEXT_CHOICES ||
|
|
313
|
-
renderType === productsV3.ModifierRenderType.SWATCH_CHOICES) {
|
|
315
|
+
if (renderType === stores_1.productsV3.ModifierRenderType.TEXT_CHOICES ||
|
|
316
|
+
renderType === stores_1.productsV3.ModifierRenderType.SWATCH_CHOICES) {
|
|
314
317
|
// For choice modifiers, use the modifier key and choice value
|
|
315
318
|
const modifierKey = productModifier.key || modifierName;
|
|
316
319
|
if (modifierValue.choiceValue) {
|
|
317
320
|
options[modifierKey] = modifierValue.choiceValue;
|
|
318
321
|
}
|
|
319
322
|
}
|
|
320
|
-
else if (renderType === productsV3.ModifierRenderType.FREE_TEXT) {
|
|
323
|
+
else if (renderType === stores_1.productsV3.ModifierRenderType.FREE_TEXT) {
|
|
321
324
|
// For free text modifiers, use the freeTextSettings key
|
|
322
325
|
const freeTextKey = productModifier.freeTextSettings?.key || modifierName;
|
|
323
326
|
if (modifierValue.freeTextValue) {
|
package/cjs/dist/utils/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCheckoutUrlForProduct = getCheckoutUrlForProduct;
|
|
4
|
+
const ecom_1 = require("@wix/ecom");
|
|
5
|
+
const redirects_1 = require("@wix/redirects");
|
|
3
6
|
const CATLOG_APP_ID_V3 = '215238eb-22a5-4c36-9e7b-e7c08025e04e';
|
|
4
|
-
|
|
5
|
-
const checkoutResult = await checkout.createCheckout({
|
|
7
|
+
async function getCheckoutUrlForProduct(productId, variantId) {
|
|
8
|
+
const checkoutResult = await ecom_1.checkout.createCheckout({
|
|
6
9
|
lineItems: [
|
|
7
10
|
{
|
|
8
11
|
catalogReference: {
|
|
@@ -15,12 +18,12 @@ export async function getCheckoutUrlForProduct(productId, variantId) {
|
|
|
15
18
|
quantity: 1,
|
|
16
19
|
},
|
|
17
20
|
],
|
|
18
|
-
channelType: checkout.ChannelType.WEB,
|
|
21
|
+
channelType: ecom_1.checkout.ChannelType.WEB,
|
|
19
22
|
});
|
|
20
23
|
if (!checkoutResult._id) {
|
|
21
24
|
throw new Error('Failed to create checkout');
|
|
22
25
|
}
|
|
23
|
-
const { redirectSession } = await redirects.createRedirectSession({
|
|
26
|
+
const { redirectSession } = await redirects_1.redirects.createRedirectSession({
|
|
24
27
|
ecomCheckout: { checkoutId: checkoutResult._id },
|
|
25
28
|
callbacks: {
|
|
26
29
|
postFlowUrl: window.location.href,
|