@wix/headless-stores 0.0.49 → 0.0.50

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.
@@ -206,19 +206,16 @@ export async function parseUrlToSearchOptions(url, categoriesList, defaultSearch
206
206
  };
207
207
  // Initialize search state for service
208
208
  const initialSearchState = {};
209
- // Extract category slug from URL path (e.g., /category/category-slug)
210
- const pathSegments = urlObj.pathname.split("/");
211
- const categoryIndex = pathSegments.findIndex((segment) => segment === "category");
212
- let categorySlug = null;
209
+ // Extract category slug from URL path
210
+ // The category slug is always the last segment of the path
211
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
213
212
  let category = undefined;
214
- if (categoryIndex !== -1 && categoryIndex + 1 < pathSegments.length) {
215
- categorySlug = pathSegments[categoryIndex + 1] || null;
216
- // Find the category by slug from the provided categories list
217
- if (categorySlug) {
218
- category = categoriesList.find((cat) => cat.slug === categorySlug);
219
- if (category) {
220
- initialSearchState.category = category;
221
- }
213
+ if (pathSegments.length > 0) {
214
+ const lastSegment = pathSegments[pathSegments.length - 1];
215
+ // Check if the last segment matches any category in the categories list
216
+ category = categoriesList.find((cat) => cat.slug === lastSegment);
217
+ if (category) {
218
+ initialSearchState.category = category;
222
219
  }
223
220
  }
224
221
  // Handle text search (q parameter)
@@ -459,7 +456,7 @@ export async function parseUrlToSearchOptions(url, categoriesList, defaultSearch
459
456
  */
460
457
  export async function loadProductsListSearchServiceConfig(input) {
461
458
  let initialSearchState;
462
- if (typeof input === 'string') {
459
+ if (typeof input === "string") {
463
460
  // URL input - parse it
464
461
  const categoriesListConfig = await loadCategoriesListServiceConfig();
465
462
  const { initialSearchState: parsedState } = await parseUrlToSearchOptions(input, categoriesListConfig.categories);
@@ -206,19 +206,16 @@ export async function parseUrlToSearchOptions(url, categoriesList, defaultSearch
206
206
  };
207
207
  // Initialize search state for service
208
208
  const initialSearchState = {};
209
- // Extract category slug from URL path (e.g., /category/category-slug)
210
- const pathSegments = urlObj.pathname.split("/");
211
- const categoryIndex = pathSegments.findIndex((segment) => segment === "category");
212
- let categorySlug = null;
209
+ // Extract category slug from URL path
210
+ // The category slug is always the last segment of the path
211
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
213
212
  let category = undefined;
214
- if (categoryIndex !== -1 && categoryIndex + 1 < pathSegments.length) {
215
- categorySlug = pathSegments[categoryIndex + 1] || null;
216
- // Find the category by slug from the provided categories list
217
- if (categorySlug) {
218
- category = categoriesList.find((cat) => cat.slug === categorySlug);
219
- if (category) {
220
- initialSearchState.category = category;
221
- }
213
+ if (pathSegments.length > 0) {
214
+ const lastSegment = pathSegments[pathSegments.length - 1];
215
+ // Check if the last segment matches any category in the categories list
216
+ category = categoriesList.find((cat) => cat.slug === lastSegment);
217
+ if (category) {
218
+ initialSearchState.category = category;
222
219
  }
223
220
  }
224
221
  // Handle text search (q parameter)
@@ -459,7 +456,7 @@ export async function parseUrlToSearchOptions(url, categoriesList, defaultSearch
459
456
  */
460
457
  export async function loadProductsListSearchServiceConfig(input) {
461
458
  let initialSearchState;
462
- if (typeof input === 'string') {
459
+ if (typeof input === "string") {
463
460
  // URL input - parse it
464
461
  const categoriesListConfig = await loadCategoriesListServiceConfig();
465
462
  const { initialSearchState: parsedState } = await parseUrlToSearchOptions(input, categoriesListConfig.categories);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",