@wix/headless-stores 0.0.30 → 0.0.31

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 (69) 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 +76 -0
  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/dist/react/Category.d.ts +30 -0
  36. package/dist/react/Category.js +30 -0
  37. package/dist/react/Collection.d.ts +145 -0
  38. package/dist/react/Collection.js +145 -0
  39. package/dist/react/FilteredCollection.d.ts +134 -0
  40. package/dist/react/FilteredCollection.js +134 -0
  41. package/dist/react/Product.d.ts +43 -18
  42. package/dist/react/Product.js +43 -18
  43. package/dist/react/ProductActions.d.ts +30 -0
  44. package/dist/react/ProductActions.js +30 -0
  45. package/dist/react/ProductModifiers.d.ts +172 -0
  46. package/dist/react/ProductModifiers.js +172 -0
  47. package/dist/react/ProductVariantSelector.d.ts +118 -0
  48. package/dist/react/ProductVariantSelector.js +118 -0
  49. package/dist/react/ProductsList.d.ts +101 -0
  50. package/dist/react/ProductsList.js +101 -0
  51. package/dist/react/RelatedProducts.d.ts +55 -0
  52. package/dist/react/RelatedProducts.js +55 -0
  53. package/dist/react/SelectedVariant.d.ts +59 -0
  54. package/dist/react/SelectedVariant.js +59 -0
  55. package/dist/react/SocialSharing.d.ts +82 -0
  56. package/dist/react/SocialSharing.js +82 -0
  57. package/dist/react/Sort.d.ts +22 -0
  58. package/dist/react/Sort.js +22 -0
  59. package/dist/services/category-service.d.ts +87 -0
  60. package/dist/services/category-service.js +87 -0
  61. package/dist/services/collection-service.d.ts +89 -0
  62. package/dist/services/collection-service.js +89 -0
  63. package/dist/services/product-service.d.ts +76 -0
  64. package/dist/services/product-service.js +76 -0
  65. package/dist/services/products-list-service.d.ts +93 -0
  66. package/dist/services/products-list-service.js +93 -0
  67. package/dist/services/related-products-service.d.ts +75 -0
  68. package/dist/services/related-products-service.js +75 -0
  69. package/package.json +1 -1
@@ -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
@@ -25,4 +25,80 @@ export type ProductServiceConfigResult = {
25
25
  } | {
26
26
  type: "notFound";
27
27
  };
28
+ /**
29
+ * Loads product service configuration from the Wix Products API for SSR initialization.
30
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
31
+ * a specific product by slug that will be used to configure the ProductService.
32
+ *
33
+ * @param productSlug The product slug to load
34
+ * @returns Promise that resolves to ProductServiceConfigResult (success with config or notFound)
35
+ *
36
+ * @example
37
+ * ```astro
38
+ * ---
39
+ * // Astro page example - pages/product/[slug].astro
40
+ * import { loadProductServiceConfig } from '@wix/stores/services';
41
+ * import { Product } from '@wix/stores/components';
42
+ *
43
+ * // Get product slug from URL params
44
+ * const { slug } = Astro.params;
45
+ *
46
+ * // Load product data during SSR
47
+ * const productResult = await loadProductServiceConfig(slug);
48
+ *
49
+ * // Handle not found case
50
+ * if (productResult.type === 'notFound') {
51
+ * return Astro.redirect('/404');
52
+ * }
53
+ * ---
54
+ *
55
+ * <Product.Root productConfig={productResult.config}>
56
+ * <Product.Name>
57
+ * {({ name }) => <h1>{name}</h1>}
58
+ * </Product.Name>
59
+ * </Product.Root>
60
+ * ```
61
+ *
62
+ * @example
63
+ * ```tsx
64
+ * // Next.js page example - pages/product/[slug].tsx
65
+ * import { GetServerSideProps } from 'next';
66
+ * import { loadProductServiceConfig } from '@wix/stores/services';
67
+ * import { Product } from '@wix/stores/components';
68
+ *
69
+ * interface ProductPageProps {
70
+ * productConfig: Awaited<ReturnType<typeof loadProductServiceConfig>>['config'];
71
+ * }
72
+ *
73
+ * export const getServerSideProps: GetServerSideProps<ProductPageProps> = async ({ params }) => {
74
+ * const slug = params?.slug as string;
75
+ *
76
+ * // Load product data during SSR
77
+ * const productResult = await loadProductServiceConfig(slug);
78
+ *
79
+ * // Handle not found case
80
+ * if (productResult.type === 'notFound') {
81
+ * return {
82
+ * notFound: true,
83
+ * };
84
+ * }
85
+ *
86
+ * return {
87
+ * props: {
88
+ * productConfig: productResult.config,
89
+ * },
90
+ * };
91
+ * };
92
+ *
93
+ * export default function ProductPage({ productConfig }: ProductPageProps) {
94
+ * return (
95
+ * <Product.Root productConfig={productConfig}>
96
+ * <Product.Name>
97
+ * {({ name }) => <h1>{name}</h1>}
98
+ * </Product.Name>
99
+ * </Product.Root>
100
+ * );
101
+ * }
102
+ * ```
103
+ */
28
104
  export declare function loadProductServiceConfig(productSlug: string): Promise<ProductServiceConfigResult>;
@@ -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: {
@@ -2,6 +2,99 @@ import { defineService, implementService } from "@wix/services-definitions";
2
2
  import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
3
3
  import { productsV3 } from "@wix/stores";
4
4
  ;
5
+ /**
6
+ * Loads products list service configuration from the Wix Products API for SSR initialization.
7
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
8
+ * products based on search criteria that will be used to configure the ProductsListService.
9
+ *
10
+ * @param searchOptions Search options for filtering and querying products
11
+ * @returns Promise that resolves to ProductsListServiceConfig with products, metadata, and aggregations
12
+ *
13
+ * @example
14
+ * ```astro
15
+ * ---
16
+ * // Astro page example - pages/search.astro
17
+ * import { loadProductsListServiceConfig } from '@wix/stores/services';
18
+ * import { ProductsList } from '@wix/stores/components';
19
+ *
20
+ * // Get search query from URL params
21
+ * const searchQuery = Astro.url.searchParams.get('q') || '';
22
+ * const category = Astro.url.searchParams.get('category');
23
+ *
24
+ * // Build search options
25
+ * const searchOptions = {
26
+ * query: { search: searchQuery },
27
+ * filter: category ? { categories: [category] } : undefined,
28
+ * paging: { limit: 12 }
29
+ * };
30
+ *
31
+ * // Load products during SSR
32
+ * const productsListConfig = await loadProductsListServiceConfig(searchOptions);
33
+ * ---
34
+ *
35
+ * <ProductsList.Root productsListConfig={productsListConfig}>
36
+ * <ProductsList.ItemContent>
37
+ * {({ product }) => (
38
+ * <div class="product-item">
39
+ * <h3>{product.name}</h3>
40
+ * </div>
41
+ * )}
42
+ * </ProductsList.ItemContent>
43
+ * </ProductsList.Root>
44
+ * ```
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * // Next.js page example - pages/search.tsx
49
+ * import { GetServerSideProps } from 'next';
50
+ * import { loadProductsListServiceConfig } from '@wix/stores/services';
51
+ * import { ProductsList } from '@wix/stores/components';
52
+ *
53
+ * interface SearchPageProps {
54
+ * productsListConfig: Awaited<ReturnType<typeof loadProductsListServiceConfig>>;
55
+ * searchQuery: string;
56
+ * }
57
+ *
58
+ * export const getServerSideProps: GetServerSideProps<SearchPageProps> = async ({ query }) => {
59
+ * const searchQuery = (query.q as string) || '';
60
+ * const category = query.category as string;
61
+ *
62
+ * // Build search options
63
+ * const searchOptions = {
64
+ * query: { search: searchQuery },
65
+ * filter: category ? { categories: [category] } : undefined,
66
+ * paging: { limit: 12 }
67
+ * };
68
+ *
69
+ * // Load products during SSR
70
+ * const productsListConfig = await loadProductsListServiceConfig(searchOptions);
71
+ *
72
+ * return {
73
+ * props: {
74
+ * productsListConfig,
75
+ * searchQuery,
76
+ * },
77
+ * };
78
+ * };
79
+ *
80
+ * export default function SearchPage({ productsListConfig, searchQuery }: SearchPageProps) {
81
+ * return (
82
+ * <div>
83
+ * <h1>Search Results for "{searchQuery}"</h1>
84
+ * <ProductsList.Root productsListConfig={productsListConfig}>
85
+ * <ProductsList.ItemContent>
86
+ * {({ product }) => (
87
+ * <div className="product-item">
88
+ * <h3>{product.name}</h3>
89
+ * </div>
90
+ * )}
91
+ * </ProductsList.ItemContent>
92
+ * </ProductsList.Root>
93
+ * </div>
94
+ * );
95
+ * }
96
+ * ```
97
+ */
5
98
  export async function loadProductsListServiceConfig(searchOptions) {
6
99
  const result = await productsV3.searchProducts(searchOptions);
7
100
  return {
@@ -22,4 +22,79 @@ export declare const RelatedProductsService: import("@wix/services-definitions")
22
22
  __config: {};
23
23
  isServiceDefinition?: boolean;
24
24
  } & RelatedProductsServiceAPI, RelatedProductsServiceConfig>;
25
+ /**
26
+ * Loads related products service configuration for SSR initialization.
27
+ * This function is designed to be used during Server-Side Rendering (SSR) to create
28
+ * configuration that tells the RelatedProductsService which product to load related products for.
29
+ * Unlike other loaders, this creates configuration rather than fetching data during SSR.
30
+ *
31
+ * @param productId The ID of the product to find related products for
32
+ * @param limit Optional number of related products to load (default: 4)
33
+ * @returns Promise that resolves to RelatedProductsServiceConfig
34
+ *
35
+ * @example
36
+ * ```astro
37
+ * ---
38
+ * // Astro page example - pages/product/[slug].astro
39
+ * import { loadRelatedProductsServiceConfig } from '@wix/stores/services';
40
+ * import { RelatedProducts } from '@wix/stores/components';
41
+ *
42
+ * // Create related products config for a specific product
43
+ * const relatedProductsConfig = await loadRelatedProductsServiceConfig(
44
+ * 'product-id-123',
45
+ * 6
46
+ * );
47
+ * ---
48
+ *
49
+ * <RelatedProducts.Root relatedProductsConfig={relatedProductsConfig}>
50
+ * <RelatedProducts.List>
51
+ * {({ products, isLoading }) => (
52
+ * <div>
53
+ * {isLoading ? 'Loading...' : `${products.length} related products`}
54
+ * </div>
55
+ * )}
56
+ * </RelatedProducts.List>
57
+ * </RelatedProducts.Root>
58
+ * ```
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * // Next.js page example - pages/product/[slug].tsx
63
+ * import { GetServerSideProps } from 'next';
64
+ * import { loadRelatedProductsServiceConfig } from '@wix/stores/services';
65
+ * import { RelatedProducts } from '@wix/stores/components';
66
+ *
67
+ * interface ProductPageProps {
68
+ * relatedProductsConfig: Awaited<ReturnType<typeof loadRelatedProductsServiceConfig>>;
69
+ * }
70
+ *
71
+ * export const getServerSideProps: GetServerSideProps<ProductPageProps> = async () => {
72
+ * // Create related products config for a specific product
73
+ * const relatedProductsConfig = await loadRelatedProductsServiceConfig(
74
+ * 'product-id-123',
75
+ * 6
76
+ * );
77
+ *
78
+ * return {
79
+ * props: {
80
+ * relatedProductsConfig,
81
+ * },
82
+ * };
83
+ * };
84
+ *
85
+ * export default function ProductPage({ relatedProductsConfig }: ProductPageProps) {
86
+ * return (
87
+ * <RelatedProducts.Root relatedProductsConfig={relatedProductsConfig}>
88
+ * <RelatedProducts.List>
89
+ * {({ products, isLoading }) => (
90
+ * <div>
91
+ * {isLoading ? 'Loading...' : `${products.length} related products`}
92
+ * </div>
93
+ * )}
94
+ * </RelatedProducts.List>
95
+ * </RelatedProducts.Root>
96
+ * );
97
+ * }
98
+ * ```
99
+ */
25
100
  export declare function loadRelatedProductsServiceConfig(productId: string, limit?: number): Promise<RelatedProductsServiceConfig>;
@@ -44,6 +44,81 @@ export const RelatedProductsService = implementService.withConfig()(RelatedProdu
44
44
  refreshRelatedProducts,
45
45
  };
46
46
  });
47
+ /**
48
+ * Loads related products service configuration for SSR initialization.
49
+ * This function is designed to be used during Server-Side Rendering (SSR) to create
50
+ * configuration that tells the RelatedProductsService which product to load related products for.
51
+ * Unlike other loaders, this creates configuration rather than fetching data during SSR.
52
+ *
53
+ * @param productId The ID of the product to find related products for
54
+ * @param limit Optional number of related products to load (default: 4)
55
+ * @returns Promise that resolves to RelatedProductsServiceConfig
56
+ *
57
+ * @example
58
+ * ```astro
59
+ * ---
60
+ * // Astro page example - pages/product/[slug].astro
61
+ * import { loadRelatedProductsServiceConfig } from '@wix/stores/services';
62
+ * import { RelatedProducts } from '@wix/stores/components';
63
+ *
64
+ * // Create related products config for a specific product
65
+ * const relatedProductsConfig = await loadRelatedProductsServiceConfig(
66
+ * 'product-id-123',
67
+ * 6
68
+ * );
69
+ * ---
70
+ *
71
+ * <RelatedProducts.Root relatedProductsConfig={relatedProductsConfig}>
72
+ * <RelatedProducts.List>
73
+ * {({ products, isLoading }) => (
74
+ * <div>
75
+ * {isLoading ? 'Loading...' : `${products.length} related products`}
76
+ * </div>
77
+ * )}
78
+ * </RelatedProducts.List>
79
+ * </RelatedProducts.Root>
80
+ * ```
81
+ *
82
+ * @example
83
+ * ```tsx
84
+ * // Next.js page example - pages/product/[slug].tsx
85
+ * import { GetServerSideProps } from 'next';
86
+ * import { loadRelatedProductsServiceConfig } from '@wix/stores/services';
87
+ * import { RelatedProducts } from '@wix/stores/components';
88
+ *
89
+ * interface ProductPageProps {
90
+ * relatedProductsConfig: Awaited<ReturnType<typeof loadRelatedProductsServiceConfig>>;
91
+ * }
92
+ *
93
+ * export const getServerSideProps: GetServerSideProps<ProductPageProps> = async () => {
94
+ * // Create related products config for a specific product
95
+ * const relatedProductsConfig = await loadRelatedProductsServiceConfig(
96
+ * 'product-id-123',
97
+ * 6
98
+ * );
99
+ *
100
+ * return {
101
+ * props: {
102
+ * relatedProductsConfig,
103
+ * },
104
+ * };
105
+ * };
106
+ *
107
+ * export default function ProductPage({ relatedProductsConfig }: ProductPageProps) {
108
+ * return (
109
+ * <RelatedProducts.Root relatedProductsConfig={relatedProductsConfig}>
110
+ * <RelatedProducts.List>
111
+ * {({ products, isLoading }) => (
112
+ * <div>
113
+ * {isLoading ? 'Loading...' : `${products.length} related products`}
114
+ * </div>
115
+ * )}
116
+ * </RelatedProducts.List>
117
+ * </RelatedProducts.Root>
118
+ * );
119
+ * }
120
+ * ```
121
+ */
47
122
  export async function loadRelatedProductsServiceConfig(productId, limit = 4) {
48
123
  return {
49
124
  productId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",