@wix/headless-stores 0.0.35 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/cjs/dist/react/Category.d.ts +83 -31
  2. package/cjs/dist/react/Category.js +68 -35
  3. package/cjs/dist/react/CategoryList.d.ts +184 -0
  4. package/cjs/dist/react/CategoryList.js +174 -0
  5. package/cjs/dist/react/Product.d.ts +3 -3
  6. package/cjs/dist/react/Product.js +6 -6
  7. package/cjs/dist/react/ProductActions.d.ts +1 -1
  8. package/cjs/dist/react/ProductActions.js +2 -2
  9. package/{dist/react/ProductsList.d.ts → cjs/dist/react/ProductList.d.ts} +71 -38
  10. package/{dist/react/ProductsList.js → cjs/dist/react/ProductList.js} +30 -26
  11. package/cjs/dist/react/ProductListFilters.d.ts +244 -0
  12. package/cjs/dist/react/ProductListFilters.js +216 -0
  13. package/cjs/dist/react/ProductListPagination.d.ts +246 -0
  14. package/cjs/dist/react/ProductListPagination.js +207 -0
  15. package/cjs/dist/react/ProductListSort.d.ts +87 -0
  16. package/cjs/dist/react/ProductListSort.js +85 -0
  17. package/cjs/dist/react/ProductModifiers.d.ts +5 -5
  18. package/cjs/dist/react/ProductModifiers.js +10 -10
  19. package/cjs/dist/react/ProductVariantSelector.d.ts +5 -5
  20. package/cjs/dist/react/ProductVariantSelector.js +13 -10
  21. package/cjs/dist/react/SelectedVariant.d.ts +3 -3
  22. package/cjs/dist/react/SelectedVariant.js +6 -6
  23. package/cjs/dist/react/index.d.ts +7 -9
  24. package/cjs/dist/react/index.js +7 -9
  25. package/cjs/dist/services/buy-now-service.d.ts +208 -0
  26. package/cjs/dist/services/buy-now-service.js +132 -1
  27. package/cjs/dist/services/categories-list-service.d.ts +163 -0
  28. package/cjs/dist/services/categories-list-service.js +148 -0
  29. package/cjs/dist/services/category-service.d.ts +115 -70
  30. package/cjs/dist/services/category-service.js +101 -110
  31. package/cjs/dist/services/index.d.ts +6 -7
  32. package/cjs/dist/services/index.js +5 -16
  33. package/cjs/dist/services/pay-now-service.d.ts +146 -0
  34. package/cjs/dist/services/pay-now-service.js +112 -1
  35. package/cjs/dist/services/product-service.d.ts +71 -0
  36. package/cjs/dist/services/product-service.js +47 -0
  37. package/cjs/dist/services/products-list-filters-service.d.ts +292 -0
  38. package/cjs/dist/services/products-list-filters-service.js +446 -0
  39. package/cjs/dist/services/products-list-pagination-service.d.ts +186 -0
  40. package/cjs/dist/services/products-list-pagination-service.js +179 -0
  41. package/cjs/dist/services/products-list-service.d.ts +138 -52
  42. package/cjs/dist/services/products-list-service.js +98 -51
  43. package/cjs/dist/services/products-list-sort-service.d.ts +117 -0
  44. package/cjs/dist/services/products-list-sort-service.js +144 -0
  45. package/cjs/dist/services/selected-variant-service.js +0 -1
  46. package/cjs/dist/utils/url-params.d.ts +68 -0
  47. package/cjs/dist/utils/url-params.js +72 -4
  48. package/dist/react/Category.d.ts +83 -31
  49. package/dist/react/Category.js +68 -35
  50. package/dist/react/CategoryList.d.ts +184 -0
  51. package/dist/react/CategoryList.js +174 -0
  52. package/dist/react/Product.d.ts +3 -3
  53. package/dist/react/Product.js +6 -6
  54. package/dist/react/ProductActions.d.ts +1 -1
  55. package/dist/react/ProductActions.js +2 -2
  56. package/{cjs/dist/react/ProductsList.d.ts → dist/react/ProductList.d.ts} +71 -38
  57. package/{cjs/dist/react/ProductsList.js → dist/react/ProductList.js} +30 -26
  58. package/dist/react/ProductListFilters.d.ts +244 -0
  59. package/dist/react/ProductListFilters.js +216 -0
  60. package/dist/react/ProductListPagination.d.ts +246 -0
  61. package/dist/react/ProductListPagination.js +207 -0
  62. package/dist/react/ProductListSort.d.ts +87 -0
  63. package/dist/react/ProductListSort.js +85 -0
  64. package/dist/react/ProductModifiers.d.ts +5 -5
  65. package/dist/react/ProductModifiers.js +10 -10
  66. package/dist/react/ProductVariantSelector.d.ts +5 -5
  67. package/dist/react/ProductVariantSelector.js +13 -10
  68. package/dist/react/SelectedVariant.d.ts +3 -3
  69. package/dist/react/SelectedVariant.js +6 -6
  70. package/dist/react/index.d.ts +7 -9
  71. package/dist/react/index.js +7 -9
  72. package/dist/services/buy-now-service.d.ts +208 -0
  73. package/dist/services/buy-now-service.js +132 -1
  74. package/dist/services/categories-list-service.d.ts +163 -0
  75. package/dist/services/categories-list-service.js +148 -0
  76. package/dist/services/category-service.d.ts +115 -70
  77. package/dist/services/category-service.js +101 -110
  78. package/dist/services/index.d.ts +6 -7
  79. package/dist/services/index.js +5 -16
  80. package/dist/services/pay-now-service.d.ts +146 -0
  81. package/dist/services/pay-now-service.js +112 -1
  82. package/dist/services/product-service.d.ts +71 -0
  83. package/dist/services/product-service.js +47 -0
  84. package/dist/services/products-list-filters-service.d.ts +292 -0
  85. package/dist/services/products-list-filters-service.js +446 -0
  86. package/dist/services/products-list-pagination-service.d.ts +186 -0
  87. package/dist/services/products-list-pagination-service.js +179 -0
  88. package/dist/services/products-list-service.d.ts +138 -52
  89. package/dist/services/products-list-service.js +98 -51
  90. package/dist/services/products-list-sort-service.d.ts +117 -0
  91. package/dist/services/products-list-sort-service.js +144 -0
  92. package/dist/services/selected-variant-service.js +0 -1
  93. package/dist/utils/url-params.d.ts +68 -0
  94. package/dist/utils/url-params.js +72 -4
  95. package/package.json +3 -3
  96. package/cjs/dist/react/Collection.d.ts +0 -294
  97. package/cjs/dist/react/Collection.js +0 -345
  98. package/cjs/dist/react/FilteredCollection.d.ts +0 -216
  99. package/cjs/dist/react/FilteredCollection.js +0 -256
  100. package/cjs/dist/react/RelatedProducts.d.ts +0 -169
  101. package/cjs/dist/react/RelatedProducts.js +0 -180
  102. package/cjs/dist/react/Sort.d.ts +0 -37
  103. package/cjs/dist/react/Sort.js +0 -36
  104. package/cjs/dist/services/catalog-service.d.ts +0 -36
  105. package/cjs/dist/services/catalog-service.js +0 -193
  106. package/cjs/dist/services/collection-service.d.ts +0 -124
  107. package/cjs/dist/services/collection-service.js +0 -628
  108. package/cjs/dist/services/filter-service.d.ts +0 -35
  109. package/cjs/dist/services/filter-service.js +0 -119
  110. package/cjs/dist/services/related-products-service.d.ts +0 -100
  111. package/cjs/dist/services/related-products-service.js +0 -127
  112. package/cjs/dist/services/sort-service.d.ts +0 -20
  113. package/cjs/dist/services/sort-service.js +0 -27
  114. package/dist/react/Collection.d.ts +0 -294
  115. package/dist/react/Collection.js +0 -345
  116. package/dist/react/FilteredCollection.d.ts +0 -216
  117. package/dist/react/FilteredCollection.js +0 -256
  118. package/dist/react/RelatedProducts.d.ts +0 -169
  119. package/dist/react/RelatedProducts.js +0 -180
  120. package/dist/react/Sort.d.ts +0 -37
  121. package/dist/react/Sort.js +0 -36
  122. package/dist/services/catalog-service.d.ts +0 -36
  123. package/dist/services/catalog-service.js +0 -193
  124. package/dist/services/collection-service.d.ts +0 -124
  125. package/dist/services/collection-service.js +0 -628
  126. package/dist/services/filter-service.d.ts +0 -35
  127. package/dist/services/filter-service.js +0 -119
  128. package/dist/services/related-products-service.d.ts +0 -100
  129. package/dist/services/related-products-service.js +0 -127
  130. package/dist/services/sort-service.d.ts +0 -20
  131. package/dist/services/sort-service.js +0 -27
@@ -1,57 +1,155 @@
1
1
  import { type Signal } from "@wix/services-definitions/core-services/signals";
2
+ /**
3
+ * Service definition for the Buy Now service.
4
+ * This defines the reactive API contract for managing buy now functionality.
5
+ *
6
+ * @constant
7
+ */
2
8
  export declare const BuyNowServiceDefinition: string & {
3
9
  __api: {
10
+ /** Function to redirect to checkout with the current product */
4
11
  redirectToCheckout: () => Promise<void>;
12
+ /** Reactive signal indicating if a checkout redirect is in progress */
5
13
  loadingSignal: Signal<boolean>;
14
+ /** Reactive signal containing any error message, or null if no error */
6
15
  errorSignal: Signal<string | null>;
16
+ /** Reactive signal indicating if the product is in stock */
7
17
  inStockSignal: Signal<boolean>;
18
+ /** Reactive signal indicating if pre-order is available */
8
19
  preOrderAvailableSignal: Signal<boolean>;
20
+ /** The name of the product */
9
21
  productName: string;
22
+ /** The price of the product as a string */
10
23
  price: string;
24
+ /** The currency code for the product price */
11
25
  currency: string;
12
26
  };
13
27
  __config: {};
14
28
  isServiceDefinition?: boolean;
15
29
  } & {
30
+ /** Function to redirect to checkout with the current product */
16
31
  redirectToCheckout: () => Promise<void>;
32
+ /** Reactive signal indicating if a checkout redirect is in progress */
17
33
  loadingSignal: Signal<boolean>;
34
+ /** Reactive signal containing any error message, or null if no error */
18
35
  errorSignal: Signal<string | null>;
36
+ /** Reactive signal indicating if the product is in stock */
19
37
  inStockSignal: Signal<boolean>;
38
+ /** Reactive signal indicating if pre-order is available */
20
39
  preOrderAvailableSignal: Signal<boolean>;
40
+ /** The name of the product */
21
41
  productName: string;
42
+ /** The price of the product as a string */
22
43
  price: string;
44
+ /** The currency code for the product price */
23
45
  currency: string;
24
46
  };
47
+ /**
48
+ * Configuration interface for the Buy Now service.
49
+ * Contains all the product information needed to initialize the buy now functionality.
50
+ *
51
+ * @interface BuyNowServiceConfig
52
+ */
25
53
  export interface BuyNowServiceConfig {
54
+ /** The unique product ID */
26
55
  productId: string;
56
+ /** The optional variant ID if a specific variant is selected */
27
57
  variantId?: string;
58
+ /** The display name of the product */
28
59
  productName: string;
60
+ /** The price of the product as a string */
29
61
  price: string;
62
+ /** The currency code for the product price */
30
63
  currency: string;
64
+ /** Whether the product is currently in stock */
31
65
  inStock: boolean;
66
+ /** Whether pre-order is available for this product */
32
67
  preOrderAvailable: boolean;
33
68
  }
69
+ /**
70
+ * Implementation of the Buy Now service that manages buy now functionality.
71
+ * This service provides signals for loading state, stock status, and error handling,
72
+ * along with a method to redirect directly to checkout.
73
+ *
74
+ * @example
75
+ * ```tsx
76
+ * import { BuyNowServiceImplementation, BuyNowServiceDefinition } from '@wix/stores/services';
77
+ * import { useService } from '@wix/services-manager-react';
78
+ *
79
+ * function BuyNowComponent({ buyNowConfig }) {
80
+ * return (
81
+ * <ServiceProvider services={createServicesMap([
82
+ * [BuyNowServiceDefinition, BuyNowServiceImplementation.withConfig(buyNowConfig)]
83
+ * ])}>
84
+ * <BuyNowButton />
85
+ * </ServiceProvider>
86
+ * );
87
+ * }
88
+ *
89
+ * function BuyNowButton() {
90
+ * const buyNowService = useService(BuyNowServiceDefinition);
91
+ * const isLoading = buyNowService.loadingSignal.get();
92
+ * const error = buyNowService.errorSignal.get();
93
+ * const inStock = buyNowService.inStockSignal.get();
94
+ *
95
+ * const handleBuyNow = async () => {
96
+ * await buyNowService.redirectToCheckout();
97
+ * };
98
+ *
99
+ * return (
100
+ * <div>
101
+ * {error && <div className="error">{error}</div>}
102
+ * <button
103
+ * onClick={handleBuyNow}
104
+ * disabled={!inStock || isLoading}
105
+ * className={`buy-now-btn ${!inStock ? 'out-of-stock' : ''}`}
106
+ * >
107
+ * {isLoading ? 'Processing...' :
108
+ * !inStock ? 'Out of Stock' :
109
+ * `Buy Now - ${buyNowService.currency}${buyNowService.price}`}
110
+ * </button>
111
+ * </div>
112
+ * );
113
+ * }
114
+ * ```
115
+ */
34
116
  export declare const BuyNowServiceImplementation: import("@wix/services-definitions").ServiceFactory<string & {
35
117
  __api: {
118
+ /** Function to redirect to checkout with the current product */
36
119
  redirectToCheckout: () => Promise<void>;
120
+ /** Reactive signal indicating if a checkout redirect is in progress */
37
121
  loadingSignal: Signal<boolean>;
122
+ /** Reactive signal containing any error message, or null if no error */
38
123
  errorSignal: Signal<string | null>;
124
+ /** Reactive signal indicating if the product is in stock */
39
125
  inStockSignal: Signal<boolean>;
126
+ /** Reactive signal indicating if pre-order is available */
40
127
  preOrderAvailableSignal: Signal<boolean>;
128
+ /** The name of the product */
41
129
  productName: string;
130
+ /** The price of the product as a string */
42
131
  price: string;
132
+ /** The currency code for the product price */
43
133
  currency: string;
44
134
  };
45
135
  __config: {};
46
136
  isServiceDefinition?: boolean;
47
137
  } & {
138
+ /** Function to redirect to checkout with the current product */
48
139
  redirectToCheckout: () => Promise<void>;
140
+ /** Reactive signal indicating if a checkout redirect is in progress */
49
141
  loadingSignal: Signal<boolean>;
142
+ /** Reactive signal containing any error message, or null if no error */
50
143
  errorSignal: Signal<string | null>;
144
+ /** Reactive signal indicating if the product is in stock */
51
145
  inStockSignal: Signal<boolean>;
146
+ /** Reactive signal indicating if pre-order is available */
52
147
  preOrderAvailableSignal: Signal<boolean>;
148
+ /** The name of the product */
53
149
  productName: string;
150
+ /** The price of the product as a string */
54
151
  price: string;
152
+ /** The currency code for the product price */
55
153
  currency: string;
56
154
  }, {
57
155
  productId: string;
@@ -62,6 +160,58 @@ export declare const BuyNowServiceImplementation: import("@wix/services-definiti
62
160
  inStock: boolean;
63
161
  preOrderAvailable: boolean;
64
162
  }>;
163
+ /**
164
+ * Loads buy now service initial data from the Wix Stores API for SSR initialization.
165
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
166
+ * product data required for the buy now functionality.
167
+ *
168
+ * @param {string} productSlug - The product slug to load data for
169
+ * @param {string} [variantId] - Optional variant ID if a specific variant should be used
170
+ * @returns {Promise} Promise that resolves to the buy now service configuration data
171
+ *
172
+ * @example
173
+ * ```astro
174
+ * ---
175
+ * // Astro page example - pages/product/[slug].astro
176
+ * import { loadBuyNowServiceInitialData } from '@wix/stores/services';
177
+ * import { BuyNow } from '@wix/stores/components';
178
+ *
179
+ * const { slug } = Astro.params;
180
+ * const variantId = Astro.url.searchParams.get('variant');
181
+ *
182
+ * // Load buy now data during SSR
183
+ * const buyNowData = await loadBuyNowServiceInitialData(slug, variantId);
184
+ * ---
185
+ *
186
+ * <BuyNow.BuyNow buyNowConfig={buyNowData.BuyNow}>
187
+ * {({ redirectToCheckout, isLoading, inStock, price, currency }) => (
188
+ * <button onClick={redirectToCheckout} disabled={!inStock || isLoading}>
189
+ * {isLoading ? 'Loading...' : `Buy Now ${currency}${price}`}
190
+ * </button>
191
+ * )}
192
+ * </BuyNow.BuyNow>
193
+ * ```
194
+ *
195
+ * @example
196
+ * ```tsx
197
+ * // Next.js page example
198
+ * import { GetServerSideProps } from 'next';
199
+ * import { loadBuyNowServiceInitialData } from '@wix/stores/services';
200
+ *
201
+ * export const getServerSideProps: GetServerSideProps = async ({ params, query }) => {
202
+ * const slug = params?.slug as string;
203
+ * const variantId = query.variant as string | undefined;
204
+ *
205
+ * const buyNowData = await loadBuyNowServiceInitialData(slug, variantId);
206
+ *
207
+ * return {
208
+ * props: {
209
+ * buyNowData,
210
+ * },
211
+ * };
212
+ * };
213
+ * ```
214
+ */
65
215
  export declare const loadBuyNowServiceInitialData: (productSlug: string, variantId?: string) => Promise<{
66
216
  [BuyNowServiceDefinition]: {
67
217
  productId: string;
@@ -73,51 +223,109 @@ export declare const loadBuyNowServiceInitialData: (productSlug: string, variant
73
223
  preOrderAvailable: boolean | undefined;
74
224
  };
75
225
  }>;
226
+ /**
227
+ * Helper function to create a buy now service binding with configuration.
228
+ * This function simplifies the process of binding the buy now service with its configuration
229
+ * and allows for additional configuration overrides.
230
+ *
231
+ * @template T - Type of the services configurations object
232
+ * @param {T} servicesConfigs - Object containing service configurations
233
+ * @param {Partial<BuyNowServiceConfig>} [additionalConfig={}] - Additional configuration to override defaults
234
+ * @returns Tuple containing service definition, implementation, and merged configuration
235
+ *
236
+ * @example
237
+ * ```tsx
238
+ * import { buyNowServiceBinding, loadBuyNowServiceInitialData } from '@wix/stores/services';
239
+ *
240
+ * // Load initial data
241
+ * const initialData = await loadBuyNowServiceInitialData('my-product-slug');
242
+ *
243
+ * // Create service binding with additional config
244
+ * const buyNowBinding = buyNowServiceBinding(initialData, {
245
+ * inStock: false, // Override stock status
246
+ * });
247
+ *
248
+ * // Use in service provider
249
+ * const services = createServicesMap([buyNowBinding]);
250
+ * ```
251
+ */
76
252
  export declare const buyNowServiceBinding: <T extends {
77
253
  [key: string]: Awaited<ReturnType<typeof loadBuyNowServiceInitialData>>[typeof BuyNowServiceDefinition];
78
254
  }>(servicesConfigs: T, additionalConfig?: Partial<BuyNowServiceConfig>) => readonly [string & {
79
255
  __api: {
256
+ /** Function to redirect to checkout with the current product */
80
257
  redirectToCheckout: () => Promise<void>;
258
+ /** Reactive signal indicating if a checkout redirect is in progress */
81
259
  loadingSignal: Signal<boolean>;
260
+ /** Reactive signal containing any error message, or null if no error */
82
261
  errorSignal: Signal<string | null>;
262
+ /** Reactive signal indicating if the product is in stock */
83
263
  inStockSignal: Signal<boolean>;
264
+ /** Reactive signal indicating if pre-order is available */
84
265
  preOrderAvailableSignal: Signal<boolean>;
266
+ /** The name of the product */
85
267
  productName: string;
268
+ /** The price of the product as a string */
86
269
  price: string;
270
+ /** The currency code for the product price */
87
271
  currency: string;
88
272
  };
89
273
  __config: {};
90
274
  isServiceDefinition?: boolean;
91
275
  } & {
276
+ /** Function to redirect to checkout with the current product */
92
277
  redirectToCheckout: () => Promise<void>;
278
+ /** Reactive signal indicating if a checkout redirect is in progress */
93
279
  loadingSignal: Signal<boolean>;
280
+ /** Reactive signal containing any error message, or null if no error */
94
281
  errorSignal: Signal<string | null>;
282
+ /** Reactive signal indicating if the product is in stock */
95
283
  inStockSignal: Signal<boolean>;
284
+ /** Reactive signal indicating if pre-order is available */
96
285
  preOrderAvailableSignal: Signal<boolean>;
286
+ /** The name of the product */
97
287
  productName: string;
288
+ /** The price of the product as a string */
98
289
  price: string;
290
+ /** The currency code for the product price */
99
291
  currency: string;
100
292
  }, import("@wix/services-definitions").ServiceFactory<string & {
101
293
  __api: {
294
+ /** Function to redirect to checkout with the current product */
102
295
  redirectToCheckout: () => Promise<void>;
296
+ /** Reactive signal indicating if a checkout redirect is in progress */
103
297
  loadingSignal: Signal<boolean>;
298
+ /** Reactive signal containing any error message, or null if no error */
104
299
  errorSignal: Signal<string | null>;
300
+ /** Reactive signal indicating if the product is in stock */
105
301
  inStockSignal: Signal<boolean>;
302
+ /** Reactive signal indicating if pre-order is available */
106
303
  preOrderAvailableSignal: Signal<boolean>;
304
+ /** The name of the product */
107
305
  productName: string;
306
+ /** The price of the product as a string */
108
307
  price: string;
308
+ /** The currency code for the product price */
109
309
  currency: string;
110
310
  };
111
311
  __config: {};
112
312
  isServiceDefinition?: boolean;
113
313
  } & {
314
+ /** Function to redirect to checkout with the current product */
114
315
  redirectToCheckout: () => Promise<void>;
316
+ /** Reactive signal indicating if a checkout redirect is in progress */
115
317
  loadingSignal: Signal<boolean>;
318
+ /** Reactive signal containing any error message, or null if no error */
116
319
  errorSignal: Signal<string | null>;
320
+ /** Reactive signal indicating if the product is in stock */
117
321
  inStockSignal: Signal<boolean>;
322
+ /** Reactive signal indicating if pre-order is available */
118
323
  preOrderAvailableSignal: Signal<boolean>;
324
+ /** The name of the product */
119
325
  productName: string;
326
+ /** The price of the product as a string */
120
327
  price: string;
328
+ /** The currency code for the product price */
121
329
  currency: string;
122
330
  }, {
123
331
  productId: string;
@@ -1,8 +1,61 @@
1
- import { defineService, implementService, } from "@wix/services-definitions";
1
+ import { defineService, implementService } from "@wix/services-definitions";
2
2
  import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
3
3
  import { getCheckoutUrlForProduct } from "../utils/index.js";
4
4
  import { getProductBySlug } from "@wix/auto_sdk_stores_products-v-3";
5
+ /**
6
+ * Service definition for the Buy Now service.
7
+ * This defines the reactive API contract for managing buy now functionality.
8
+ *
9
+ * @constant
10
+ */
5
11
  export const BuyNowServiceDefinition = defineService("BuyNow");
12
+ /**
13
+ * Implementation of the Buy Now service that manages buy now functionality.
14
+ * This service provides signals for loading state, stock status, and error handling,
15
+ * along with a method to redirect directly to checkout.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * import { BuyNowServiceImplementation, BuyNowServiceDefinition } from '@wix/stores/services';
20
+ * import { useService } from '@wix/services-manager-react';
21
+ *
22
+ * function BuyNowComponent({ buyNowConfig }) {
23
+ * return (
24
+ * <ServiceProvider services={createServicesMap([
25
+ * [BuyNowServiceDefinition, BuyNowServiceImplementation.withConfig(buyNowConfig)]
26
+ * ])}>
27
+ * <BuyNowButton />
28
+ * </ServiceProvider>
29
+ * );
30
+ * }
31
+ *
32
+ * function BuyNowButton() {
33
+ * const buyNowService = useService(BuyNowServiceDefinition);
34
+ * const isLoading = buyNowService.loadingSignal.get();
35
+ * const error = buyNowService.errorSignal.get();
36
+ * const inStock = buyNowService.inStockSignal.get();
37
+ *
38
+ * const handleBuyNow = async () => {
39
+ * await buyNowService.redirectToCheckout();
40
+ * };
41
+ *
42
+ * return (
43
+ * <div>
44
+ * {error && <div className="error">{error}</div>}
45
+ * <button
46
+ * onClick={handleBuyNow}
47
+ * disabled={!inStock || isLoading}
48
+ * className={`buy-now-btn ${!inStock ? 'out-of-stock' : ''}`}
49
+ * >
50
+ * {isLoading ? 'Processing...' :
51
+ * !inStock ? 'Out of Stock' :
52
+ * `Buy Now - ${buyNowService.currency}${buyNowService.price}`}
53
+ * </button>
54
+ * </div>
55
+ * );
56
+ * }
57
+ * ```
58
+ */
6
59
  export const BuyNowServiceImplementation = implementService.withConfig()(BuyNowServiceDefinition, ({ getService, config }) => {
7
60
  const signalsService = getService(SignalsServiceDefinition);
8
61
  const loadingSignal = signalsService.signal(false);
@@ -30,6 +83,58 @@ export const BuyNowServiceImplementation = implementService.withConfig()(BuyNowS
30
83
  currency: config.currency,
31
84
  };
32
85
  });
86
+ /**
87
+ * Loads buy now service initial data from the Wix Stores API for SSR initialization.
88
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
89
+ * product data required for the buy now functionality.
90
+ *
91
+ * @param {string} productSlug - The product slug to load data for
92
+ * @param {string} [variantId] - Optional variant ID if a specific variant should be used
93
+ * @returns {Promise} Promise that resolves to the buy now service configuration data
94
+ *
95
+ * @example
96
+ * ```astro
97
+ * ---
98
+ * // Astro page example - pages/product/[slug].astro
99
+ * import { loadBuyNowServiceInitialData } from '@wix/stores/services';
100
+ * import { BuyNow } from '@wix/stores/components';
101
+ *
102
+ * const { slug } = Astro.params;
103
+ * const variantId = Astro.url.searchParams.get('variant');
104
+ *
105
+ * // Load buy now data during SSR
106
+ * const buyNowData = await loadBuyNowServiceInitialData(slug, variantId);
107
+ * ---
108
+ *
109
+ * <BuyNow.BuyNow buyNowConfig={buyNowData.BuyNow}>
110
+ * {({ redirectToCheckout, isLoading, inStock, price, currency }) => (
111
+ * <button onClick={redirectToCheckout} disabled={!inStock || isLoading}>
112
+ * {isLoading ? 'Loading...' : `Buy Now ${currency}${price}`}
113
+ * </button>
114
+ * )}
115
+ * </BuyNow.BuyNow>
116
+ * ```
117
+ *
118
+ * @example
119
+ * ```tsx
120
+ * // Next.js page example
121
+ * import { GetServerSideProps } from 'next';
122
+ * import { loadBuyNowServiceInitialData } from '@wix/stores/services';
123
+ *
124
+ * export const getServerSideProps: GetServerSideProps = async ({ params, query }) => {
125
+ * const slug = params?.slug as string;
126
+ * const variantId = query.variant as string | undefined;
127
+ *
128
+ * const buyNowData = await loadBuyNowServiceInitialData(slug, variantId);
129
+ *
130
+ * return {
131
+ * props: {
132
+ * buyNowData,
133
+ * },
134
+ * };
135
+ * };
136
+ * ```
137
+ */
33
138
  export const loadBuyNowServiceInitialData = async (productSlug, variantId) => {
34
139
  const res = await getProductBySlug(productSlug, {
35
140
  fields: ["CURRENCY"],
@@ -54,6 +159,32 @@ export const loadBuyNowServiceInitialData = async (productSlug, variantId) => {
54
159
  },
55
160
  };
56
161
  };
162
+ /**
163
+ * Helper function to create a buy now service binding with configuration.
164
+ * This function simplifies the process of binding the buy now service with its configuration
165
+ * and allows for additional configuration overrides.
166
+ *
167
+ * @template T - Type of the services configurations object
168
+ * @param {T} servicesConfigs - Object containing service configurations
169
+ * @param {Partial<BuyNowServiceConfig>} [additionalConfig={}] - Additional configuration to override defaults
170
+ * @returns Tuple containing service definition, implementation, and merged configuration
171
+ *
172
+ * @example
173
+ * ```tsx
174
+ * import { buyNowServiceBinding, loadBuyNowServiceInitialData } from '@wix/stores/services';
175
+ *
176
+ * // Load initial data
177
+ * const initialData = await loadBuyNowServiceInitialData('my-product-slug');
178
+ *
179
+ * // Create service binding with additional config
180
+ * const buyNowBinding = buyNowServiceBinding(initialData, {
181
+ * inStock: false, // Override stock status
182
+ * });
183
+ *
184
+ * // Use in service provider
185
+ * const services = createServicesMap([buyNowBinding]);
186
+ * ```
187
+ */
57
188
  export const buyNowServiceBinding = (servicesConfigs, additionalConfig = {}) => {
58
189
  return [
59
190
  BuyNowServiceDefinition,
@@ -0,0 +1,163 @@
1
+ import { type Signal } from "@wix/services-definitions/core-services/signals";
2
+ import { categories } from "@wix/categories";
3
+ /**
4
+ * Configuration interface for the Categories List service.
5
+ * Contains the initial categories data that will be loaded into the service.
6
+ *
7
+ * @interface CategoriesListServiceConfig
8
+ */
9
+ export type CategoriesListServiceConfig = {
10
+ /** Array of category objects to initialize the service with */
11
+ categories: categories.Category[];
12
+ };
13
+ /**
14
+ * Service definition for the Categories List service.
15
+ * This defines the reactive API contract for managing a list of product categories.
16
+ *
17
+ * @constant
18
+ */
19
+ export declare const CategoriesListServiceDefinition: string & {
20
+ __api: {
21
+ /** Reactive signal containing the list of categories */
22
+ categories: Signal<categories.Category[]>;
23
+ /** Reactive signal indicating if categories are currently being loaded */
24
+ isLoading: Signal<boolean>;
25
+ /** Reactive signal containing any error message, or null if no error */
26
+ error: Signal<string | null>;
27
+ };
28
+ __config: CategoriesListServiceConfig;
29
+ isServiceDefinition?: boolean;
30
+ } & {
31
+ /** Reactive signal containing the list of categories */
32
+ categories: Signal<categories.Category[]>;
33
+ /** Reactive signal indicating if categories are currently being loaded */
34
+ isLoading: Signal<boolean>;
35
+ /** Reactive signal containing any error message, or null if no error */
36
+ error: Signal<string | null>;
37
+ };
38
+ /**
39
+ * Implementation of the Categories List service that manages reactive categories data.
40
+ * This service provides signals for categories data, loading state, and error handling.
41
+ * The service is initialized with pre-loaded categories and maintains them in reactive signals.
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * import { CategoriesListService, CategoriesListServiceDefinition } from '@wix/stores/services';
46
+ * import { useService } from '@wix/services-manager-react';
47
+ *
48
+ * function CategoriesComponent({ categoriesConfig }) {
49
+ * return (
50
+ * <ServiceProvider services={createServicesMap([
51
+ * [CategoriesListServiceDefinition, CategoriesListService.withConfig(categoriesConfig)]
52
+ * ])}>
53
+ * <CategoriesDisplay />
54
+ * </ServiceProvider>
55
+ * );
56
+ * }
57
+ *
58
+ * function CategoriesDisplay() {
59
+ * const categoriesService = useService(CategoriesListServiceDefinition);
60
+ * const categories = categoriesService.categories.get();
61
+ * const isLoading = categoriesService.isLoading.get();
62
+ * const error = categoriesService.error.get();
63
+ *
64
+ * if (isLoading) return <div>Loading categories...</div>;
65
+ * if (error) return <div>Error: {error}</div>;
66
+ *
67
+ * return (
68
+ * <ul>
69
+ * {categories.map(category => (
70
+ * <li key={category._id}>{category.name}</li>
71
+ * ))}
72
+ * </ul>
73
+ * );
74
+ * }
75
+ * ```
76
+ */
77
+ export declare const CategoriesListService: import("@wix/services-definitions").ServiceFactory<string & {
78
+ __api: {
79
+ /** Reactive signal containing the list of categories */
80
+ categories: Signal<categories.Category[]>;
81
+ /** Reactive signal indicating if categories are currently being loaded */
82
+ isLoading: Signal<boolean>;
83
+ /** Reactive signal containing any error message, or null if no error */
84
+ error: Signal<string | null>;
85
+ };
86
+ __config: CategoriesListServiceConfig;
87
+ isServiceDefinition?: boolean;
88
+ } & {
89
+ /** Reactive signal containing the list of categories */
90
+ categories: Signal<categories.Category[]>;
91
+ /** Reactive signal indicating if categories are currently being loaded */
92
+ isLoading: Signal<boolean>;
93
+ /** Reactive signal containing any error message, or null if no error */
94
+ error: Signal<string | null>;
95
+ }, CategoriesListServiceConfig>;
96
+ /**
97
+ * Loads categories list service configuration from the Wix Categories API for SSR initialization.
98
+ * This function is designed to be used during Server-Side Rendering (SSR) to preload
99
+ * all visible product categories. The "all-products" category is automatically moved to the front of the list.
100
+ *
101
+ * @returns {Promise<CategoriesListServiceConfig>} Promise that resolves to the categories configuration
102
+ *
103
+ * @example
104
+ * ```astro
105
+ * ---
106
+ * // Astro page example - pages/categories.astro
107
+ * import { loadCategoriesListServiceConfig } from '@wix/stores/services';
108
+ * import { CategoryList } from '@wix/stores/components';
109
+ *
110
+ * // Load categories data during SSR
111
+ * const categoriesConfig = await loadCategoriesListServiceConfig();
112
+ * ---
113
+ *
114
+ * <CategoryList.Root categoriesConfig={categoriesConfig}>
115
+ * <CategoryList.ItemContent>
116
+ * {({ category }) => (
117
+ * <div>
118
+ * <h3>{category.name}</h3>
119
+ * <p>{category.description}</p>
120
+ * </div>
121
+ * )}
122
+ * </CategoryList.ItemContent>
123
+ * </CategoryList.Root>
124
+ * ```
125
+ *
126
+ * @example
127
+ * ```tsx
128
+ * // Next.js page example - pages/categories.tsx
129
+ * import { GetServerSideProps } from 'next';
130
+ * import { loadCategoriesListServiceConfig } from '@wix/stores/services';
131
+ * import { CategoryList } from '@wix/stores/components';
132
+ *
133
+ * interface CategoriesPageProps {
134
+ * categoriesConfig: Awaited<ReturnType<typeof loadCategoriesListServiceConfig>>;
135
+ * }
136
+ *
137
+ * export const getServerSideProps: GetServerSideProps<CategoriesPageProps> = async () => {
138
+ * const categoriesConfig = await loadCategoriesListServiceConfig();
139
+ *
140
+ * return {
141
+ * props: {
142
+ * categoriesConfig,
143
+ * },
144
+ * };
145
+ * };
146
+ *
147
+ * export default function CategoriesPage({ categoriesConfig }: CategoriesPageProps) {
148
+ * return (
149
+ * <CategoryList.Root categoriesConfig={categoriesConfig}>
150
+ * <CategoryList.ItemContent>
151
+ * {({ category }) => (
152
+ * <div>
153
+ * <h3>{category.name}</h3>
154
+ * <p>{category.description}</p>
155
+ * </div>
156
+ * )}
157
+ * </CategoryList.ItemContent>
158
+ * </CategoryList.Root>
159
+ * );
160
+ * }
161
+ * ```
162
+ */
163
+ export declare function loadCategoriesListServiceConfig(): Promise<CategoriesListServiceConfig>;