@wix/headless-stores 0.0.30 → 0.0.32

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.
Files changed (71) hide show
  1. package/cjs/dist/react/Category.d.ts +30 -0
  2. package/cjs/dist/react/Category.js +30 -0
  3. package/cjs/dist/react/Collection.d.ts +145 -0
  4. package/cjs/dist/react/Collection.js +145 -0
  5. package/cjs/dist/react/FilteredCollection.d.ts +134 -0
  6. package/cjs/dist/react/FilteredCollection.js +134 -0
  7. package/cjs/dist/react/Product.d.ts +43 -18
  8. package/cjs/dist/react/Product.js +43 -18
  9. package/cjs/dist/react/ProductActions.d.ts +30 -0
  10. package/cjs/dist/react/ProductActions.js +30 -0
  11. package/cjs/dist/react/ProductModifiers.d.ts +172 -0
  12. package/cjs/dist/react/ProductModifiers.js +172 -0
  13. package/cjs/dist/react/ProductVariantSelector.d.ts +118 -0
  14. package/cjs/dist/react/ProductVariantSelector.js +118 -0
  15. package/cjs/dist/react/ProductsList.d.ts +101 -0
  16. package/cjs/dist/react/ProductsList.js +101 -0
  17. package/cjs/dist/react/RelatedProducts.d.ts +55 -0
  18. package/cjs/dist/react/RelatedProducts.js +55 -0
  19. package/cjs/dist/react/SelectedVariant.d.ts +59 -0
  20. package/cjs/dist/react/SelectedVariant.js +59 -0
  21. package/cjs/dist/react/SocialSharing.d.ts +82 -0
  22. package/cjs/dist/react/SocialSharing.js +82 -0
  23. package/cjs/dist/react/Sort.d.ts +22 -0
  24. package/cjs/dist/react/Sort.js +22 -0
  25. package/cjs/dist/services/category-service.d.ts +87 -0
  26. package/cjs/dist/services/category-service.js +87 -0
  27. package/cjs/dist/services/collection-service.d.ts +89 -0
  28. package/cjs/dist/services/collection-service.js +89 -0
  29. package/cjs/dist/services/product-service.d.ts +81 -4
  30. package/cjs/dist/services/product-service.js +76 -0
  31. package/cjs/dist/services/products-list-service.d.ts +93 -0
  32. package/cjs/dist/services/products-list-service.js +93 -0
  33. package/cjs/dist/services/related-products-service.d.ts +75 -0
  34. package/cjs/dist/services/related-products-service.js +75 -0
  35. package/cjs/dist/services/selected-variant-service.js +6 -7
  36. package/dist/react/Category.d.ts +30 -0
  37. package/dist/react/Category.js +30 -0
  38. package/dist/react/Collection.d.ts +145 -0
  39. package/dist/react/Collection.js +145 -0
  40. package/dist/react/FilteredCollection.d.ts +134 -0
  41. package/dist/react/FilteredCollection.js +134 -0
  42. package/dist/react/Product.d.ts +43 -18
  43. package/dist/react/Product.js +43 -18
  44. package/dist/react/ProductActions.d.ts +30 -0
  45. package/dist/react/ProductActions.js +30 -0
  46. package/dist/react/ProductModifiers.d.ts +172 -0
  47. package/dist/react/ProductModifiers.js +172 -0
  48. package/dist/react/ProductVariantSelector.d.ts +118 -0
  49. package/dist/react/ProductVariantSelector.js +118 -0
  50. package/dist/react/ProductsList.d.ts +101 -0
  51. package/dist/react/ProductsList.js +101 -0
  52. package/dist/react/RelatedProducts.d.ts +55 -0
  53. package/dist/react/RelatedProducts.js +55 -0
  54. package/dist/react/SelectedVariant.d.ts +59 -0
  55. package/dist/react/SelectedVariant.js +59 -0
  56. package/dist/react/SocialSharing.d.ts +82 -0
  57. package/dist/react/SocialSharing.js +82 -0
  58. package/dist/react/Sort.d.ts +22 -0
  59. package/dist/react/Sort.js +22 -0
  60. package/dist/services/category-service.d.ts +87 -0
  61. package/dist/services/category-service.js +87 -0
  62. package/dist/services/collection-service.d.ts +89 -0
  63. package/dist/services/collection-service.js +89 -0
  64. package/dist/services/product-service.d.ts +81 -4
  65. package/dist/services/product-service.js +76 -0
  66. package/dist/services/products-list-service.d.ts +93 -0
  67. package/dist/services/products-list-service.js +93 -0
  68. package/dist/services/related-products-service.d.ts +75 -0
  69. package/dist/services/related-products-service.js +75 -0
  70. package/dist/services/selected-variant-service.js +6 -7
  71. package/package.json +1 -1
@@ -21,6 +21,93 @@ export declare const CategoryService: import("@wix/services-definitions").Servic
21
21
  __config: {};
22
22
  isServiceDefinition?: boolean;
23
23
  } & CategoryServiceAPI, CategoryServiceConfig>;
24
+ /**
25
+ * Loads categories configuration from the Wix Categories API for SSR initialization.
26
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
27
+ * initial categories data that will be passed to the Category.Root component.
28
+ * Fetches all visible categories and sorts them with "all-products" category first.
29
+ *
30
+ * @returns Promise that resolves to an object containing categories array
31
+ *
32
+ * @example
33
+ * ```astro
34
+ * ---
35
+ * // Astro page example - pages/categories.astro
36
+ * import { loadCategoriesConfig } from '@wix/stores/services';
37
+ * import { Category } from '@wix/stores/components';
38
+ *
39
+ * // Load categories data during SSR
40
+ * const categoryConfig = await loadCategoriesConfig();
41
+ * ---
42
+ *
43
+ * <Category.Root categoryConfig={categoryConfig}>
44
+ * <Category.List>
45
+ * {({ categories, selectedCategory, setSelectedCategory }) => (
46
+ * <nav className="category-nav">
47
+ * <h2>Shop by Category</h2>
48
+ * {categories.map(category => (
49
+ * <button
50
+ * key={category.id}
51
+ * onClick={() => setSelectedCategory(category.id)}
52
+ * className={selectedCategory === category.id ? 'active' : ''}
53
+ * >
54
+ * {category.name}
55
+ * </button>
56
+ * ))}
57
+ * </nav>
58
+ * )}
59
+ * </Category.List>
60
+ * </Category.Root>
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * // Next.js page example - pages/categories.tsx
66
+ * import { GetServerSideProps } from 'next';
67
+ * import { loadCategoriesConfig } from '@wix/stores/services';
68
+ * import { Category } from '@wix/stores/components';
69
+ *
70
+ * interface CategoryPageProps {
71
+ * categoryConfig: Awaited<ReturnType<typeof loadCategoriesConfig>>;
72
+ * }
73
+ *
74
+ * export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async () => {
75
+ * // Load categories data during SSR
76
+ * const categoryConfig = await loadCategoriesConfig();
77
+ *
78
+ * return {
79
+ * props: {
80
+ * categoryConfig,
81
+ * },
82
+ * };
83
+ * };
84
+ *
85
+ * export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
86
+ * return (
87
+ * <div>
88
+ * <h1>Product Categories</h1>
89
+ * <Category.Root categoryConfig={categoryConfig}>
90
+ * <Category.List>
91
+ * {({ categories, selectedCategory, setSelectedCategory }) => (
92
+ * <nav className="category-nav">
93
+ * {categories.map(category => (
94
+ * <button
95
+ * key={category.id}
96
+ * onClick={() => setSelectedCategory(category.id)}
97
+ * className={`category-btn ${selectedCategory === category.id ? 'active' : ''}`}
98
+ * >
99
+ * {category.name}
100
+ * </button>
101
+ * ))}
102
+ * </nav>
103
+ * )}
104
+ * </Category.List>
105
+ * </Category.Root>
106
+ * </div>
107
+ * );
108
+ * }
109
+ * ```
110
+ */
24
111
  export declare function loadCategoriesConfig(): Promise<{
25
112
  categories: categories.Category[];
26
113
  }>;
@@ -38,6 +38,93 @@ export const CategoryService = implementService.withConfig()(CategoryServiceDefi
38
38
  loadCategories,
39
39
  };
40
40
  });
41
+ /**
42
+ * Loads categories configuration from the Wix Categories API for SSR initialization.
43
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
44
+ * initial categories data that will be passed to the Category.Root component.
45
+ * Fetches all visible categories and sorts them with "all-products" category first.
46
+ *
47
+ * @returns Promise that resolves to an object containing categories array
48
+ *
49
+ * @example
50
+ * ```astro
51
+ * ---
52
+ * // Astro page example - pages/categories.astro
53
+ * import { loadCategoriesConfig } from '@wix/stores/services';
54
+ * import { Category } from '@wix/stores/components';
55
+ *
56
+ * // Load categories data during SSR
57
+ * const categoryConfig = await loadCategoriesConfig();
58
+ * ---
59
+ *
60
+ * <Category.Root categoryConfig={categoryConfig}>
61
+ * <Category.List>
62
+ * {({ categories, selectedCategory, setSelectedCategory }) => (
63
+ * <nav className="category-nav">
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>
77
+ * </Category.Root>
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```tsx
82
+ * // Next.js page example - pages/categories.tsx
83
+ * import { GetServerSideProps } from 'next';
84
+ * import { loadCategoriesConfig } from '@wix/stores/services';
85
+ * import { Category } from '@wix/stores/components';
86
+ *
87
+ * interface CategoryPageProps {
88
+ * categoryConfig: Awaited<ReturnType<typeof loadCategoriesConfig>>;
89
+ * }
90
+ *
91
+ * export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async () => {
92
+ * // Load categories data during SSR
93
+ * const categoryConfig = await loadCategoriesConfig();
94
+ *
95
+ * return {
96
+ * props: {
97
+ * categoryConfig,
98
+ * },
99
+ * };
100
+ * };
101
+ *
102
+ * export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
103
+ * return (
104
+ * <div>
105
+ * <h1>Product Categories</h1>
106
+ * <Category.Root categoryConfig={categoryConfig}>
107
+ * <Category.List>
108
+ * {({ categories, selectedCategory, setSelectedCategory }) => (
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>
124
+ * );
125
+ * }
126
+ * ```
127
+ */
41
128
  export async function loadCategoriesConfig() {
42
129
  try {
43
130
  const categoriesResponse = await categories
@@ -29,6 +29,95 @@ export declare const CollectionService: import("@wix/services-definitions").Serv
29
29
  __config: {};
30
30
  isServiceDefinition?: boolean;
31
31
  } & CollectionServiceAPI, CollectionServiceConfig>;
32
+ /**
33
+ * Loads collection service configuration from the Wix Products API for SSR initialization.
34
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
35
+ * initial products data, categories, filters, and sorting that will be used to configure the CollectionService.
36
+ * Fetches products for a specific category, parses URL parameters for filters and sorting, and returns initial state.
37
+ *
38
+ * @param categoryId Optional category ID to filter products by
39
+ * @param searchParams Optional URLSearchParams for initial filters and sorting
40
+ * @param preloadedCategories Optional pre-loaded categories to avoid redundant API calls
41
+ * @returns Promise that resolves to CollectionServiceConfig with initial data
42
+ *
43
+ * @example
44
+ * ```astro
45
+ * ---
46
+ * // Astro page example - pages/products/[categorySlug].astro
47
+ * import { loadCollectionServiceConfig } from '@wix/stores/services';
48
+ * import { Collection } from '@wix/stores/components';
49
+ *
50
+ * // Get category from URL params
51
+ * const { categorySlug } = Astro.params;
52
+ * const categoryId = categorySlug === 'all' ? undefined : categorySlug;
53
+ *
54
+ * // Load collection data during SSR
55
+ * const collectionConfig = await loadCollectionServiceConfig(
56
+ * categoryId,
57
+ * Astro.url.searchParams
58
+ * );
59
+ * ---
60
+ *
61
+ * <Collection.Root collectionConfig={collectionConfig}>
62
+ * <Collection.Grid>
63
+ * {({ products, isLoading }) => (
64
+ * <div>
65
+ * {isLoading ? 'Loading...' : `${products.length} products`}
66
+ * </div>
67
+ * )}
68
+ * </Collection.Grid>
69
+ * </Collection.Root>
70
+ * ```
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * // Next.js page example - pages/products/[categorySlug].tsx
75
+ * import { GetServerSideProps } from 'next';
76
+ * import { loadCollectionServiceConfig } from '@wix/stores/services';
77
+ * import { Collection } from '@wix/stores/components';
78
+ *
79
+ * interface ProductsPageProps {
80
+ * collectionConfig: Awaited<ReturnType<typeof loadCollectionServiceConfig>>;
81
+ * }
82
+ *
83
+ * export const getServerSideProps: GetServerSideProps<ProductsPageProps> = async ({ params, query }) => {
84
+ * const categorySlug = params?.categorySlug as string;
85
+ * const categoryId = categorySlug === 'all' ? undefined : categorySlug;
86
+ *
87
+ * // Convert Next.js query to URLSearchParams
88
+ * const searchParams = new URLSearchParams();
89
+ * Object.entries(query).forEach(([key, value]) => {
90
+ * if (typeof value === 'string') searchParams.set(key, value);
91
+ * });
92
+ *
93
+ * // Load collection data during SSR
94
+ * const collectionConfig = await loadCollectionServiceConfig(
95
+ * categoryId,
96
+ * searchParams
97
+ * );
98
+ *
99
+ * return {
100
+ * props: {
101
+ * collectionConfig,
102
+ * },
103
+ * };
104
+ * };
105
+ *
106
+ * export default function ProductsPage({ collectionConfig }: ProductsPageProps) {
107
+ * return (
108
+ * <Collection.Root collectionConfig={collectionConfig}>
109
+ * <Collection.Grid>
110
+ * {({ products, isLoading }) => (
111
+ * <div>
112
+ * {isLoading ? 'Loading...' : `${products.length} products`}
113
+ * </div>
114
+ * )}
115
+ * </Collection.Grid>
116
+ * </Collection.Root>
117
+ * );
118
+ * }
119
+ * ```
120
+ */
32
121
  export declare function loadCollectionServiceConfig(categoryId?: string, searchParams?: URLSearchParams, preloadedCategories?: any[]): Promise<CollectionServiceConfig & {
33
122
  initialSort?: SortBy;
34
123
  initialFilters?: Filter;
@@ -432,6 +432,95 @@ function parseOptionFilters(urlParams, optionsMap, filters) {
432
432
  }
433
433
  });
434
434
  }
435
+ /**
436
+ * Loads collection service configuration from the Wix Products API for SSR initialization.
437
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
438
+ * initial products data, categories, filters, and sorting that will be used to configure the CollectionService.
439
+ * Fetches products for a specific category, parses URL parameters for filters and sorting, and returns initial state.
440
+ *
441
+ * @param categoryId Optional category ID to filter products by
442
+ * @param searchParams Optional URLSearchParams for initial filters and sorting
443
+ * @param preloadedCategories Optional pre-loaded categories to avoid redundant API calls
444
+ * @returns Promise that resolves to CollectionServiceConfig with initial data
445
+ *
446
+ * @example
447
+ * ```astro
448
+ * ---
449
+ * // Astro page example - pages/products/[categorySlug].astro
450
+ * import { loadCollectionServiceConfig } from '@wix/stores/services';
451
+ * import { Collection } from '@wix/stores/components';
452
+ *
453
+ * // Get category from URL params
454
+ * const { categorySlug } = Astro.params;
455
+ * const categoryId = categorySlug === 'all' ? undefined : categorySlug;
456
+ *
457
+ * // Load collection data during SSR
458
+ * const collectionConfig = await loadCollectionServiceConfig(
459
+ * categoryId,
460
+ * Astro.url.searchParams
461
+ * );
462
+ * ---
463
+ *
464
+ * <Collection.Root collectionConfig={collectionConfig}>
465
+ * <Collection.Grid>
466
+ * {({ products, isLoading }) => (
467
+ * <div>
468
+ * {isLoading ? 'Loading...' : `${products.length} products`}
469
+ * </div>
470
+ * )}
471
+ * </Collection.Grid>
472
+ * </Collection.Root>
473
+ * ```
474
+ *
475
+ * @example
476
+ * ```tsx
477
+ * // Next.js page example - pages/products/[categorySlug].tsx
478
+ * import { GetServerSideProps } from 'next';
479
+ * import { loadCollectionServiceConfig } from '@wix/stores/services';
480
+ * import { Collection } from '@wix/stores/components';
481
+ *
482
+ * interface ProductsPageProps {
483
+ * collectionConfig: Awaited<ReturnType<typeof loadCollectionServiceConfig>>;
484
+ * }
485
+ *
486
+ * export const getServerSideProps: GetServerSideProps<ProductsPageProps> = async ({ params, query }) => {
487
+ * const categorySlug = params?.categorySlug as string;
488
+ * const categoryId = categorySlug === 'all' ? undefined : categorySlug;
489
+ *
490
+ * // Convert Next.js query to URLSearchParams
491
+ * const searchParams = new URLSearchParams();
492
+ * Object.entries(query).forEach(([key, value]) => {
493
+ * if (typeof value === 'string') searchParams.set(key, value);
494
+ * });
495
+ *
496
+ * // Load collection data during SSR
497
+ * const collectionConfig = await loadCollectionServiceConfig(
498
+ * categoryId,
499
+ * searchParams
500
+ * );
501
+ *
502
+ * return {
503
+ * props: {
504
+ * collectionConfig,
505
+ * },
506
+ * };
507
+ * };
508
+ *
509
+ * export default function ProductsPage({ collectionConfig }: ProductsPageProps) {
510
+ * return (
511
+ * <Collection.Root collectionConfig={collectionConfig}>
512
+ * <Collection.Grid>
513
+ * {({ products, isLoading }) => (
514
+ * <div>
515
+ * {isLoading ? 'Loading...' : `${products.length} products`}
516
+ * </div>
517
+ * )}
518
+ * </Collection.Grid>
519
+ * </Collection.Root>
520
+ * );
521
+ * }
522
+ * ```
523
+ */
435
524
  export async function loadCollectionServiceConfig(categoryId, searchParams, preloadedCategories) {
436
525
  try {
437
526
  // Use pre-loaded categories if provided, otherwise load them
@@ -19,10 +19,87 @@ export declare const ProductService: import("@wix/services-definitions").Service
19
19
  __config: {};
20
20
  isServiceDefinition?: boolean;
21
21
  } & ProductServiceAPI, ProductServiceConfig>;
22
- export type ProductServiceConfigResult = {
22
+ export interface SuccessProductServiceConfigResult {
23
23
  type: "success";
24
24
  config: ProductServiceConfig;
25
- } | {
25
+ }
26
+ export interface NotFoundProductServiceConfigResult {
26
27
  type: "notFound";
27
- };
28
- export declare function loadProductServiceConfig(productSlug: string): Promise<ProductServiceConfigResult>;
28
+ }
29
+ /**
30
+ * Loads product service configuration from the Wix Products API for SSR initialization.
31
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
32
+ * a specific product by slug that will be used to configure the ProductService.
33
+ *
34
+ * @param productSlug The product slug to load
35
+ * @returns Promise that resolves to ProductServiceConfigResult (success with config or notFound)
36
+ *
37
+ * @example
38
+ * ```astro
39
+ * ---
40
+ * // Astro page example - pages/product/[slug].astro
41
+ * import { loadProductServiceConfig } from '@wix/stores/services';
42
+ * import { Product } from '@wix/stores/components';
43
+ *
44
+ * // Get product slug from URL params
45
+ * const { slug } = Astro.params;
46
+ *
47
+ * // Load product data during SSR
48
+ * const productResult = await loadProductServiceConfig(slug);
49
+ *
50
+ * // Handle not found case
51
+ * if (productResult.type === 'notFound') {
52
+ * return Astro.redirect('/404');
53
+ * }
54
+ * ---
55
+ *
56
+ * <Product.Root productConfig={productResult.config}>
57
+ * <Product.Name>
58
+ * {({ name }) => <h1>{name}</h1>}
59
+ * </Product.Name>
60
+ * </Product.Root>
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * // Next.js page example - pages/product/[slug].tsx
66
+ * import { GetServerSideProps } from 'next';
67
+ * import { loadProductServiceConfig } from '@wix/stores/services';
68
+ * import { Product } from '@wix/stores/components';
69
+ *
70
+ * interface ProductPageProps {
71
+ * productConfig: Awaited<ReturnType<typeof loadProductServiceConfig>>['config'];
72
+ * }
73
+ *
74
+ * export const getServerSideProps: GetServerSideProps<ProductPageProps> = async ({ params }) => {
75
+ * const slug = params?.slug as string;
76
+ *
77
+ * // Load product data during SSR
78
+ * const productResult = await loadProductServiceConfig(slug);
79
+ *
80
+ * // Handle not found case
81
+ * if (productResult.type === 'notFound') {
82
+ * return {
83
+ * notFound: true,
84
+ * };
85
+ * }
86
+ *
87
+ * return {
88
+ * props: {
89
+ * productConfig: productResult.config,
90
+ * },
91
+ * };
92
+ * };
93
+ *
94
+ * export default function ProductPage({ productConfig }: ProductPageProps) {
95
+ * return (
96
+ * <Product.Root productConfig={productConfig}>
97
+ * <Product.Name>
98
+ * {({ name }) => <h1>{name}</h1>}
99
+ * </Product.Name>
100
+ * </Product.Root>
101
+ * );
102
+ * }
103
+ * ```
104
+ */
105
+ export declare function loadProductServiceConfig(productSlug: string): Promise<SuccessProductServiceConfigResult | NotFoundProductServiceConfigResult>;
@@ -43,6 +43,82 @@ const loadProductBySlug = async (slug) => {
43
43
  });
44
44
  return productResponse;
45
45
  };
46
+ /**
47
+ * Loads product service configuration from the Wix Products API for SSR initialization.
48
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
49
+ * a specific product by slug that will be used to configure the ProductService.
50
+ *
51
+ * @param productSlug The product slug to load
52
+ * @returns Promise that resolves to ProductServiceConfigResult (success with config or notFound)
53
+ *
54
+ * @example
55
+ * ```astro
56
+ * ---
57
+ * // Astro page example - pages/product/[slug].astro
58
+ * import { loadProductServiceConfig } from '@wix/stores/services';
59
+ * import { Product } from '@wix/stores/components';
60
+ *
61
+ * // Get product slug from URL params
62
+ * const { slug } = Astro.params;
63
+ *
64
+ * // Load product data during SSR
65
+ * const productResult = await loadProductServiceConfig(slug);
66
+ *
67
+ * // Handle not found case
68
+ * if (productResult.type === 'notFound') {
69
+ * return Astro.redirect('/404');
70
+ * }
71
+ * ---
72
+ *
73
+ * <Product.Root productConfig={productResult.config}>
74
+ * <Product.Name>
75
+ * {({ name }) => <h1>{name}</h1>}
76
+ * </Product.Name>
77
+ * </Product.Root>
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```tsx
82
+ * // Next.js page example - pages/product/[slug].tsx
83
+ * import { GetServerSideProps } from 'next';
84
+ * import { loadProductServiceConfig } from '@wix/stores/services';
85
+ * import { Product } from '@wix/stores/components';
86
+ *
87
+ * interface ProductPageProps {
88
+ * productConfig: Awaited<ReturnType<typeof loadProductServiceConfig>>['config'];
89
+ * }
90
+ *
91
+ * export const getServerSideProps: GetServerSideProps<ProductPageProps> = async ({ params }) => {
92
+ * const slug = params?.slug as string;
93
+ *
94
+ * // Load product data during SSR
95
+ * const productResult = await loadProductServiceConfig(slug);
96
+ *
97
+ * // Handle not found case
98
+ * if (productResult.type === 'notFound') {
99
+ * return {
100
+ * notFound: true,
101
+ * };
102
+ * }
103
+ *
104
+ * return {
105
+ * props: {
106
+ * productConfig: productResult.config,
107
+ * },
108
+ * };
109
+ * };
110
+ *
111
+ * export default function ProductPage({ productConfig }: ProductPageProps) {
112
+ * return (
113
+ * <Product.Root productConfig={productConfig}>
114
+ * <Product.Name>
115
+ * {({ name }) => <h1>{name}</h1>}
116
+ * </Product.Name>
117
+ * </Product.Root>
118
+ * );
119
+ * }
120
+ * ```
121
+ */
46
122
  export async function loadProductServiceConfig(productSlug) {
47
123
  try {
48
124
  // Use getProductBySlug directly - single API call with comprehensive fields
@@ -6,6 +6,99 @@ export interface ProductsListServiceConfig {
6
6
  pagingMetadata: productsV3.CommonCursorPagingMetadata;
7
7
  aggregations: productsV3.AggregationData;
8
8
  }
9
+ /**
10
+ * Loads products list service configuration from the Wix Products API for SSR initialization.
11
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
12
+ * products based on search criteria that will be used to configure the ProductsListService.
13
+ *
14
+ * @param searchOptions Search options for filtering and querying products
15
+ * @returns Promise that resolves to ProductsListServiceConfig with products, metadata, and aggregations
16
+ *
17
+ * @example
18
+ * ```astro
19
+ * ---
20
+ * // Astro page example - pages/search.astro
21
+ * import { loadProductsListServiceConfig } from '@wix/stores/services';
22
+ * import { ProductsList } from '@wix/stores/components';
23
+ *
24
+ * // Get search query from URL params
25
+ * const searchQuery = Astro.url.searchParams.get('q') || '';
26
+ * const category = Astro.url.searchParams.get('category');
27
+ *
28
+ * // Build search options
29
+ * const searchOptions = {
30
+ * query: { search: searchQuery },
31
+ * filter: category ? { categories: [category] } : undefined,
32
+ * paging: { limit: 12 }
33
+ * };
34
+ *
35
+ * // Load products during SSR
36
+ * const productsListConfig = await loadProductsListServiceConfig(searchOptions);
37
+ * ---
38
+ *
39
+ * <ProductsList.Root productsListConfig={productsListConfig}>
40
+ * <ProductsList.ItemContent>
41
+ * {({ product }) => (
42
+ * <div class="product-item">
43
+ * <h3>{product.name}</h3>
44
+ * </div>
45
+ * )}
46
+ * </ProductsList.ItemContent>
47
+ * </ProductsList.Root>
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * // Next.js page example - pages/search.tsx
53
+ * import { GetServerSideProps } from 'next';
54
+ * import { loadProductsListServiceConfig } from '@wix/stores/services';
55
+ * import { ProductsList } from '@wix/stores/components';
56
+ *
57
+ * interface SearchPageProps {
58
+ * productsListConfig: Awaited<ReturnType<typeof loadProductsListServiceConfig>>;
59
+ * searchQuery: string;
60
+ * }
61
+ *
62
+ * export const getServerSideProps: GetServerSideProps<SearchPageProps> = async ({ query }) => {
63
+ * const searchQuery = (query.q as string) || '';
64
+ * const category = query.category as string;
65
+ *
66
+ * // Build search options
67
+ * const searchOptions = {
68
+ * query: { search: searchQuery },
69
+ * filter: category ? { categories: [category] } : undefined,
70
+ * paging: { limit: 12 }
71
+ * };
72
+ *
73
+ * // Load products during SSR
74
+ * const productsListConfig = await loadProductsListServiceConfig(searchOptions);
75
+ *
76
+ * return {
77
+ * props: {
78
+ * productsListConfig,
79
+ * searchQuery,
80
+ * },
81
+ * };
82
+ * };
83
+ *
84
+ * export default function SearchPage({ productsListConfig, searchQuery }: SearchPageProps) {
85
+ * return (
86
+ * <div>
87
+ * <h1>Search Results for "{searchQuery}"</h1>
88
+ * <ProductsList.Root productsListConfig={productsListConfig}>
89
+ * <ProductsList.ItemContent>
90
+ * {({ product }) => (
91
+ * <div className="product-item">
92
+ * <h3>{product.name}</h3>
93
+ * </div>
94
+ * )}
95
+ * </ProductsList.ItemContent>
96
+ * </ProductsList.Root>
97
+ * </div>
98
+ * );
99
+ * }
100
+ * ```
101
+ */
9
102
  export declare function loadProductsListServiceConfig(searchOptions: Parameters<typeof productsV3.searchProducts>[0]): Promise<ProductsListServiceConfig>;
10
103
  export declare const ProductsListServiceDefinition: string & {
11
104
  __api: {