@diffsome/react 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,12 +1,20 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode } from 'react';
4
- import { Diffsome, DiffsomeConfig, Member, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider, Cart, CartItem, WishlistItem, WishlistToggleResult, WishlistMoveToCartResult, BundlePricing, ProductCategory, Product, PaginationMeta, ProductListParams, ProductType, CreateOrderData, Order, OrderListParams, PaymentStatusResponse, StripeCheckoutResponse, StripeVerifyResponse, TossPaymentReadyResponse, TossPaymentConfirmResponse, Coupon, CouponValidation, MemberSubscription, DigitalDownloadLink, CanReviewResponse, CreateProductReviewData, ProductReview, UpdateProductReviewData, ProductReviewStats, ProductReviewListParams, BlogCategory, BlogListParams, BlogPost, BoardPost, Board, CreateBoardPostData, BoardPostListParams, BoardListParams, Comment, CreateCommentData, Form, FormSubmissionData, FormSubmission, ReservationSlot, CreateReservationData, Reservation, ReservationService, ReservationSettings, ReservationStaff, ReservationListParams, Media, CustomEntity, EntityRecord, EntityListParams } from '@diffsome/sdk';
4
+ import { Diffsome, Cart, WishlistItem, DiffsomeConfig, Member, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider, WishlistToggleResult, WishlistMoveToCartResult, BundlePricing, ProductCategory, Product, PaginationMeta, ProductListParams, ProductType, CreateOrderData, Order, OrderListParams, PaymentStatusResponse, StripeCheckoutResponse, StripeVerifyResponse, TossPaymentReadyResponse, TossPaymentConfirmResponse, Coupon, CouponValidation, MemberSubscription, DigitalDownloadLink, CanReviewResponse, CreateProductReviewData, ProductReview, UpdateProductReviewData, ProductReviewStats, ProductReviewListParams, BlogCategory, BlogListParams, BlogPost, BoardPost, Board, CreateBoardPostData, BoardPostListParams, BoardListParams, Comment, CreateCommentData, Form, FormSubmissionData, FormSubmission, ReservationSlot, CreateReservationData, Reservation, ReservationService, ReservationSettings, ReservationStaff, ReservationListParams, Media, CustomEntity, EntityRecord, EntityListParams } from '@diffsome/sdk';
5
5
  export { AddToCartData, AuthResponse, BlogCategory, BlogListParams, BlogPost, Board, BoardListParams, BoardPost, BoardPostListParams, CanReviewResponse, Cart, CartItem, Comment, Coupon, CouponType, CouponValidation, CreateBoardPostData, CreateCommentData, CreateOrderData, CreateProductReviewData, CreateReservationData, CustomEntity, DiffsomeConfig, DigitalDownloadLink, DigitalFile, EntityField, EntityListParams, EntityRecord, EntitySchema, Form, FormSubmission, FormSubmissionData, ListResponse, LoginCredentials, Media, Member, MemberSubscription, Order, OrderItem, OrderListParams, OrderStatus, PaginatedResponse, PaginationMeta, Payment, PaymentMethod, PaymentStatus, PaymentStatusResponse, Product, ProductCategory, ProductListParams, ProductReview, ProductReviewStats, ProductType, ProductVariant, RegisterData, Reservation, ReservationService, ReservationSettings, ReservationSlot, ReservationStaff, ResetPasswordData, SocialAuthUrl, SocialProvider, StripeCheckoutResponse, StripeVerifyResponse, SubscriptionInterval, SubscriptionPlan, SubscriptionStatus, TossPaymentConfirmResponse, TossPaymentReadyResponse, UpdateProfileData, WishlistItem, WishlistMoveToCartResult, WishlistToggleResult } from '@diffsome/sdk';
6
6
 
7
7
  interface DiffsomeContextValue {
8
8
  client: Diffsome;
9
9
  isReady: boolean;
10
+ cart: Cart | null;
11
+ cartLoading: boolean;
12
+ setCart: (cart: Cart | null) => void;
13
+ refreshCart: () => Promise<void>;
14
+ wishlistItems: WishlistItem[];
15
+ wishlistLoading: boolean;
16
+ setWishlistItems: (items: WishlistItem[]) => void;
17
+ refreshWishlist: () => Promise<void>;
10
18
  }
11
19
  declare const DiffsomeContext: react.Context<DiffsomeContextValue | null>;
12
20
  interface DiffsomeProviderProps {
@@ -17,24 +25,75 @@ declare function DiffsomeProvider({ children, config }: DiffsomeProviderProps):
17
25
  declare function useDiffsome(): DiffsomeContextValue;
18
26
  declare function useClient(): Diffsome;
19
27
 
28
+ /**
29
+ * Return type for the useAuth hook
30
+ */
20
31
  interface UseAuthReturn {
32
+ /** Currently logged in user, or null if not authenticated */
21
33
  user: Member | null;
34
+ /** Whether the user is currently authenticated */
22
35
  isAuthenticated: boolean;
36
+ /** Whether an auth operation is in progress */
23
37
  loading: boolean;
38
+ /** Error from the last auth operation, if any */
24
39
  error: Error | null;
40
+ /**
41
+ * Log in with email and password
42
+ * @param credentials - { email: string, password: string }
43
+ * @returns AuthResponse with user and token
44
+ */
25
45
  login: (credentials: LoginCredentials) => Promise<AuthResponse>;
46
+ /**
47
+ * Register a new account
48
+ * @param data - { name: string, email: string, password: string, password_confirmation: string }
49
+ * @returns AuthResponse with user and token
50
+ */
26
51
  register: (data: RegisterData) => Promise<AuthResponse>;
52
+ /** Log out and clear session */
27
53
  logout: () => Promise<void>;
54
+ /** Fetch current user profile */
28
55
  getProfile: () => Promise<Member>;
56
+ /**
57
+ * Update user profile
58
+ * @param data - { name?: string, email?: string, phone?: string, avatar?: File }
59
+ */
29
60
  updateProfile: (data: UpdateProfileData) => Promise<Member>;
61
+ /**
62
+ * Send password reset email
63
+ * @param email - User's email address
64
+ */
30
65
  forgotPassword: (email: string) => Promise<{
31
66
  message: string;
32
67
  }>;
68
+ /**
69
+ * Reset password with token
70
+ * @param data - { token: string, email: string, password: string, password_confirmation: string }
71
+ */
33
72
  resetPassword: (data: ResetPasswordData) => Promise<{
34
73
  message: string;
35
74
  }>;
36
- refresh: () => Promise<void>;
37
- }
75
+ /** Refresh user profile from server */
76
+ refresh: () => Promise<void>;
77
+ }
78
+ /**
79
+ * Hook for user authentication - login, register, logout, profile management
80
+ *
81
+ * @example
82
+ * ```tsx
83
+ * const { user, login, logout, loading } = useAuth();
84
+ *
85
+ * // Login
86
+ * await login({ email: 'user@example.com', password: 'secret' });
87
+ *
88
+ * // Check auth state
89
+ * if (user) {
90
+ * console.log('Logged in as:', user.name);
91
+ * }
92
+ *
93
+ * // Logout
94
+ * await logout();
95
+ * ```
96
+ */
38
97
  declare function useAuth(): UseAuthReturn;
39
98
 
40
99
  interface UseSocialAuthReturn {
@@ -47,24 +106,89 @@ interface UseSocialAuthReturn {
47
106
  }
48
107
  declare function useSocialAuth(): UseSocialAuthReturn;
49
108
 
109
+ /**
110
+ * Return type for the useCart hook
111
+ */
50
112
  interface UseCartReturn {
113
+ /** Full cart object with metadata */
51
114
  cart: Cart | null;
52
- items: CartItem[];
115
+ /** Array of cart items */
116
+ items: Cart['items'];
117
+ /** Number of unique items in cart */
53
118
  itemCount: number;
119
+ /** Total quantity of all items */
54
120
  totalQuantity: number;
121
+ /** Cart subtotal before shipping */
55
122
  subtotal: number;
123
+ /** Shipping fee */
56
124
  shippingFee: number;
125
+ /** Cart total including shipping */
57
126
  total: number;
58
- loading: boolean;
59
- error: Error | null;
127
+ /** Whether cart is loading */
128
+ loading: boolean;
129
+ /**
130
+ * Add product to cart
131
+ * @param productId - Product ID to add
132
+ * @param quantity - Quantity to add (default: 1)
133
+ * @param variantId - Optional variant ID for variable products
134
+ * @param options - Optional custom options
135
+ * @returns Updated cart
136
+ */
60
137
  addToCart: (productId: number, quantity?: number, variantId?: number, options?: Record<string, string>) => Promise<Cart>;
138
+ /**
139
+ * Update item quantity
140
+ * @param itemId - Cart item ID
141
+ * @param quantity - New quantity
142
+ */
61
143
  updateItem: (itemId: number, quantity: number) => Promise<Cart>;
144
+ /**
145
+ * Remove item from cart
146
+ * @param itemId - Cart item ID to remove
147
+ */
62
148
  removeItem: (itemId: number) => Promise<Cart>;
149
+ /** Clear all items from cart */
63
150
  clearCart: () => Promise<void>;
151
+ /** Refresh cart from server */
64
152
  refresh: () => Promise<void>;
153
+ /**
154
+ * Check if product is in cart
155
+ * @param productId - Product ID
156
+ * @param variantId - Optional variant ID
157
+ */
65
158
  isInCart: (productId: number, variantId?: number) => boolean;
159
+ /**
160
+ * Get quantity of product in cart
161
+ * @param productId - Product ID
162
+ * @param variantId - Optional variant ID
163
+ * @returns Quantity in cart (0 if not in cart)
164
+ */
66
165
  getItemQuantity: (productId: number, variantId?: number) => number;
67
166
  }
167
+ /**
168
+ * Hook for shopping cart management
169
+ * Uses global state from DiffsomeProvider for consistent cart across all components
170
+ *
171
+ * @example
172
+ * ```tsx
173
+ * const { items, total, addToCart, removeItem, clearCart } = useCart();
174
+ *
175
+ * // Add to cart
176
+ * await addToCart(123, 2); // Add product ID 123, quantity 2
177
+ *
178
+ * // With variant
179
+ * await addToCart(123, 1, 456); // Product 123, variant 456
180
+ *
181
+ * // Display cart
182
+ * items.map(item => (
183
+ * <div key={item.id}>
184
+ * {item.product_name} x {item.quantity} = ${item.subtotal}
185
+ * </div>
186
+ * ));
187
+ *
188
+ * // Total
189
+ * console.log('Total:', total);
190
+ * ```
191
+ */
68
192
  declare function useCart(): UseCartReturn;
69
193
 
70
194
  interface UseWishlistReturn {
@@ -83,26 +207,96 @@ interface UseWishlistReturn {
83
207
  }
84
208
  declare function useWishlist(): UseWishlistReturn;
85
209
 
210
+ /**
211
+ * Return type for the useProducts hook
212
+ */
86
213
  interface UseProductsReturn {
214
+ /** Array of products */
87
215
  products: Product[];
216
+ /** Pagination metadata (current_page, last_page, total, per_page) */
88
217
  meta: PaginationMeta | null;
218
+ /** Whether products are loading */
89
219
  loading: boolean;
220
+ /** Error from last operation */
90
221
  error: Error | null;
222
+ /** Whether more pages are available */
91
223
  hasMore: boolean;
224
+ /** Load next page of products (appends to list) */
92
225
  loadMore: () => Promise<void>;
226
+ /** Refresh products from server */
93
227
  refresh: () => Promise<void>;
228
+ /**
229
+ * Search products by query
230
+ * @param query - Search term
231
+ */
94
232
  search: (query: string) => Promise<void>;
95
233
  }
234
+ /**
235
+ * Options for useProducts hook
236
+ */
96
237
  interface UseProductsOptions extends ProductListParams {
238
+ /** Whether to fetch products on mount (default: true) */
97
239
  autoFetch?: boolean;
98
240
  }
241
+ /**
242
+ * Hook for fetching products with pagination, filtering, and search
243
+ *
244
+ * @param options - Filtering and pagination options
245
+ * @example
246
+ * ```tsx
247
+ * // Basic usage
248
+ * const { products, loading } = useProducts();
249
+ *
250
+ * // With filters
251
+ * const { products } = useProducts({
252
+ * category: 'electronics',
253
+ * per_page: 20,
254
+ * sort: 'price_low',
255
+ * min_price: 10,
256
+ * max_price: 100,
257
+ * });
258
+ *
259
+ * // Infinite scroll
260
+ * const { products, hasMore, loadMore } = useProducts({ per_page: 12 });
261
+ * // Call loadMore() when user scrolls to bottom
262
+ *
263
+ * // Search
264
+ * const { products, search } = useProducts();
265
+ * await search('laptop'); // Searches products
266
+ * ```
267
+ */
99
268
  declare function useProducts(options?: UseProductsOptions): UseProductsReturn;
269
+ /**
270
+ * Return type for the useProduct hook
271
+ */
100
272
  interface UseProductReturn {
273
+ /** Product data, or null if not loaded */
101
274
  product: Product | null;
102
- loading: boolean;
103
- error: Error | null;
104
- refresh: () => Promise<void>;
105
- }
275
+ /** Whether product is loading */
276
+ loading: boolean;
277
+ /** Error from last operation */
278
+ error: Error | null;
279
+ /** Refresh product from server */
280
+ refresh: () => Promise<void>;
281
+ }
282
+ /**
283
+ * Hook for fetching a single product by ID or slug
284
+ *
285
+ * @param idOrSlug - Product ID (number) or slug (string)
286
+ * @example
287
+ * ```tsx
288
+ * // By slug (recommended)
289
+ * const { product, loading } = useProduct('wireless-headphones');
290
+ *
291
+ * // By ID
292
+ * const { product } = useProduct(123);
293
+ *
294
+ * // Display product
295
+ * if (product) {
296
+ * console.log(product.name, product.sale_price, product.images);
297
+ * }
298
+ * ```
299
+ */
106
300
  declare function useProduct(idOrSlug: number | string): UseProductReturn;
107
301
  interface UseCategoriesReturn {
108
302
  categories: ProductCategory[];
package/dist/index.d.ts CHANGED
@@ -1,12 +1,20 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode } from 'react';
4
- import { Diffsome, DiffsomeConfig, Member, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider, Cart, CartItem, WishlistItem, WishlistToggleResult, WishlistMoveToCartResult, BundlePricing, ProductCategory, Product, PaginationMeta, ProductListParams, ProductType, CreateOrderData, Order, OrderListParams, PaymentStatusResponse, StripeCheckoutResponse, StripeVerifyResponse, TossPaymentReadyResponse, TossPaymentConfirmResponse, Coupon, CouponValidation, MemberSubscription, DigitalDownloadLink, CanReviewResponse, CreateProductReviewData, ProductReview, UpdateProductReviewData, ProductReviewStats, ProductReviewListParams, BlogCategory, BlogListParams, BlogPost, BoardPost, Board, CreateBoardPostData, BoardPostListParams, BoardListParams, Comment, CreateCommentData, Form, FormSubmissionData, FormSubmission, ReservationSlot, CreateReservationData, Reservation, ReservationService, ReservationSettings, ReservationStaff, ReservationListParams, Media, CustomEntity, EntityRecord, EntityListParams } from '@diffsome/sdk';
4
+ import { Diffsome, Cart, WishlistItem, DiffsomeConfig, Member, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider, WishlistToggleResult, WishlistMoveToCartResult, BundlePricing, ProductCategory, Product, PaginationMeta, ProductListParams, ProductType, CreateOrderData, Order, OrderListParams, PaymentStatusResponse, StripeCheckoutResponse, StripeVerifyResponse, TossPaymentReadyResponse, TossPaymentConfirmResponse, Coupon, CouponValidation, MemberSubscription, DigitalDownloadLink, CanReviewResponse, CreateProductReviewData, ProductReview, UpdateProductReviewData, ProductReviewStats, ProductReviewListParams, BlogCategory, BlogListParams, BlogPost, BoardPost, Board, CreateBoardPostData, BoardPostListParams, BoardListParams, Comment, CreateCommentData, Form, FormSubmissionData, FormSubmission, ReservationSlot, CreateReservationData, Reservation, ReservationService, ReservationSettings, ReservationStaff, ReservationListParams, Media, CustomEntity, EntityRecord, EntityListParams } from '@diffsome/sdk';
5
5
  export { AddToCartData, AuthResponse, BlogCategory, BlogListParams, BlogPost, Board, BoardListParams, BoardPost, BoardPostListParams, CanReviewResponse, Cart, CartItem, Comment, Coupon, CouponType, CouponValidation, CreateBoardPostData, CreateCommentData, CreateOrderData, CreateProductReviewData, CreateReservationData, CustomEntity, DiffsomeConfig, DigitalDownloadLink, DigitalFile, EntityField, EntityListParams, EntityRecord, EntitySchema, Form, FormSubmission, FormSubmissionData, ListResponse, LoginCredentials, Media, Member, MemberSubscription, Order, OrderItem, OrderListParams, OrderStatus, PaginatedResponse, PaginationMeta, Payment, PaymentMethod, PaymentStatus, PaymentStatusResponse, Product, ProductCategory, ProductListParams, ProductReview, ProductReviewStats, ProductType, ProductVariant, RegisterData, Reservation, ReservationService, ReservationSettings, ReservationSlot, ReservationStaff, ResetPasswordData, SocialAuthUrl, SocialProvider, StripeCheckoutResponse, StripeVerifyResponse, SubscriptionInterval, SubscriptionPlan, SubscriptionStatus, TossPaymentConfirmResponse, TossPaymentReadyResponse, UpdateProfileData, WishlistItem, WishlistMoveToCartResult, WishlistToggleResult } from '@diffsome/sdk';
6
6
 
7
7
  interface DiffsomeContextValue {
8
8
  client: Diffsome;
9
9
  isReady: boolean;
10
+ cart: Cart | null;
11
+ cartLoading: boolean;
12
+ setCart: (cart: Cart | null) => void;
13
+ refreshCart: () => Promise<void>;
14
+ wishlistItems: WishlistItem[];
15
+ wishlistLoading: boolean;
16
+ setWishlistItems: (items: WishlistItem[]) => void;
17
+ refreshWishlist: () => Promise<void>;
10
18
  }
11
19
  declare const DiffsomeContext: react.Context<DiffsomeContextValue | null>;
12
20
  interface DiffsomeProviderProps {
@@ -17,24 +25,75 @@ declare function DiffsomeProvider({ children, config }: DiffsomeProviderProps):
17
25
  declare function useDiffsome(): DiffsomeContextValue;
18
26
  declare function useClient(): Diffsome;
19
27
 
28
+ /**
29
+ * Return type for the useAuth hook
30
+ */
20
31
  interface UseAuthReturn {
32
+ /** Currently logged in user, or null if not authenticated */
21
33
  user: Member | null;
34
+ /** Whether the user is currently authenticated */
22
35
  isAuthenticated: boolean;
36
+ /** Whether an auth operation is in progress */
23
37
  loading: boolean;
38
+ /** Error from the last auth operation, if any */
24
39
  error: Error | null;
40
+ /**
41
+ * Log in with email and password
42
+ * @param credentials - { email: string, password: string }
43
+ * @returns AuthResponse with user and token
44
+ */
25
45
  login: (credentials: LoginCredentials) => Promise<AuthResponse>;
46
+ /**
47
+ * Register a new account
48
+ * @param data - { name: string, email: string, password: string, password_confirmation: string }
49
+ * @returns AuthResponse with user and token
50
+ */
26
51
  register: (data: RegisterData) => Promise<AuthResponse>;
52
+ /** Log out and clear session */
27
53
  logout: () => Promise<void>;
54
+ /** Fetch current user profile */
28
55
  getProfile: () => Promise<Member>;
56
+ /**
57
+ * Update user profile
58
+ * @param data - { name?: string, email?: string, phone?: string, avatar?: File }
59
+ */
29
60
  updateProfile: (data: UpdateProfileData) => Promise<Member>;
61
+ /**
62
+ * Send password reset email
63
+ * @param email - User's email address
64
+ */
30
65
  forgotPassword: (email: string) => Promise<{
31
66
  message: string;
32
67
  }>;
68
+ /**
69
+ * Reset password with token
70
+ * @param data - { token: string, email: string, password: string, password_confirmation: string }
71
+ */
33
72
  resetPassword: (data: ResetPasswordData) => Promise<{
34
73
  message: string;
35
74
  }>;
36
- refresh: () => Promise<void>;
37
- }
75
+ /** Refresh user profile from server */
76
+ refresh: () => Promise<void>;
77
+ }
78
+ /**
79
+ * Hook for user authentication - login, register, logout, profile management
80
+ *
81
+ * @example
82
+ * ```tsx
83
+ * const { user, login, logout, loading } = useAuth();
84
+ *
85
+ * // Login
86
+ * await login({ email: 'user@example.com', password: 'secret' });
87
+ *
88
+ * // Check auth state
89
+ * if (user) {
90
+ * console.log('Logged in as:', user.name);
91
+ * }
92
+ *
93
+ * // Logout
94
+ * await logout();
95
+ * ```
96
+ */
38
97
  declare function useAuth(): UseAuthReturn;
39
98
 
40
99
  interface UseSocialAuthReturn {
@@ -47,24 +106,89 @@ interface UseSocialAuthReturn {
47
106
  }
48
107
  declare function useSocialAuth(): UseSocialAuthReturn;
49
108
 
109
+ /**
110
+ * Return type for the useCart hook
111
+ */
50
112
  interface UseCartReturn {
113
+ /** Full cart object with metadata */
51
114
  cart: Cart | null;
52
- items: CartItem[];
115
+ /** Array of cart items */
116
+ items: Cart['items'];
117
+ /** Number of unique items in cart */
53
118
  itemCount: number;
119
+ /** Total quantity of all items */
54
120
  totalQuantity: number;
121
+ /** Cart subtotal before shipping */
55
122
  subtotal: number;
123
+ /** Shipping fee */
56
124
  shippingFee: number;
125
+ /** Cart total including shipping */
57
126
  total: number;
58
- loading: boolean;
59
- error: Error | null;
127
+ /** Whether cart is loading */
128
+ loading: boolean;
129
+ /**
130
+ * Add product to cart
131
+ * @param productId - Product ID to add
132
+ * @param quantity - Quantity to add (default: 1)
133
+ * @param variantId - Optional variant ID for variable products
134
+ * @param options - Optional custom options
135
+ * @returns Updated cart
136
+ */
60
137
  addToCart: (productId: number, quantity?: number, variantId?: number, options?: Record<string, string>) => Promise<Cart>;
138
+ /**
139
+ * Update item quantity
140
+ * @param itemId - Cart item ID
141
+ * @param quantity - New quantity
142
+ */
61
143
  updateItem: (itemId: number, quantity: number) => Promise<Cart>;
144
+ /**
145
+ * Remove item from cart
146
+ * @param itemId - Cart item ID to remove
147
+ */
62
148
  removeItem: (itemId: number) => Promise<Cart>;
149
+ /** Clear all items from cart */
63
150
  clearCart: () => Promise<void>;
151
+ /** Refresh cart from server */
64
152
  refresh: () => Promise<void>;
153
+ /**
154
+ * Check if product is in cart
155
+ * @param productId - Product ID
156
+ * @param variantId - Optional variant ID
157
+ */
65
158
  isInCart: (productId: number, variantId?: number) => boolean;
159
+ /**
160
+ * Get quantity of product in cart
161
+ * @param productId - Product ID
162
+ * @param variantId - Optional variant ID
163
+ * @returns Quantity in cart (0 if not in cart)
164
+ */
66
165
  getItemQuantity: (productId: number, variantId?: number) => number;
67
166
  }
167
+ /**
168
+ * Hook for shopping cart management
169
+ * Uses global state from DiffsomeProvider for consistent cart across all components
170
+ *
171
+ * @example
172
+ * ```tsx
173
+ * const { items, total, addToCart, removeItem, clearCart } = useCart();
174
+ *
175
+ * // Add to cart
176
+ * await addToCart(123, 2); // Add product ID 123, quantity 2
177
+ *
178
+ * // With variant
179
+ * await addToCart(123, 1, 456); // Product 123, variant 456
180
+ *
181
+ * // Display cart
182
+ * items.map(item => (
183
+ * <div key={item.id}>
184
+ * {item.product_name} x {item.quantity} = ${item.subtotal}
185
+ * </div>
186
+ * ));
187
+ *
188
+ * // Total
189
+ * console.log('Total:', total);
190
+ * ```
191
+ */
68
192
  declare function useCart(): UseCartReturn;
69
193
 
70
194
  interface UseWishlistReturn {
@@ -83,26 +207,96 @@ interface UseWishlistReturn {
83
207
  }
84
208
  declare function useWishlist(): UseWishlistReturn;
85
209
 
210
+ /**
211
+ * Return type for the useProducts hook
212
+ */
86
213
  interface UseProductsReturn {
214
+ /** Array of products */
87
215
  products: Product[];
216
+ /** Pagination metadata (current_page, last_page, total, per_page) */
88
217
  meta: PaginationMeta | null;
218
+ /** Whether products are loading */
89
219
  loading: boolean;
220
+ /** Error from last operation */
90
221
  error: Error | null;
222
+ /** Whether more pages are available */
91
223
  hasMore: boolean;
224
+ /** Load next page of products (appends to list) */
92
225
  loadMore: () => Promise<void>;
226
+ /** Refresh products from server */
93
227
  refresh: () => Promise<void>;
228
+ /**
229
+ * Search products by query
230
+ * @param query - Search term
231
+ */
94
232
  search: (query: string) => Promise<void>;
95
233
  }
234
+ /**
235
+ * Options for useProducts hook
236
+ */
96
237
  interface UseProductsOptions extends ProductListParams {
238
+ /** Whether to fetch products on mount (default: true) */
97
239
  autoFetch?: boolean;
98
240
  }
241
+ /**
242
+ * Hook for fetching products with pagination, filtering, and search
243
+ *
244
+ * @param options - Filtering and pagination options
245
+ * @example
246
+ * ```tsx
247
+ * // Basic usage
248
+ * const { products, loading } = useProducts();
249
+ *
250
+ * // With filters
251
+ * const { products } = useProducts({
252
+ * category: 'electronics',
253
+ * per_page: 20,
254
+ * sort: 'price_low',
255
+ * min_price: 10,
256
+ * max_price: 100,
257
+ * });
258
+ *
259
+ * // Infinite scroll
260
+ * const { products, hasMore, loadMore } = useProducts({ per_page: 12 });
261
+ * // Call loadMore() when user scrolls to bottom
262
+ *
263
+ * // Search
264
+ * const { products, search } = useProducts();
265
+ * await search('laptop'); // Searches products
266
+ * ```
267
+ */
99
268
  declare function useProducts(options?: UseProductsOptions): UseProductsReturn;
269
+ /**
270
+ * Return type for the useProduct hook
271
+ */
100
272
  interface UseProductReturn {
273
+ /** Product data, or null if not loaded */
101
274
  product: Product | null;
102
- loading: boolean;
103
- error: Error | null;
104
- refresh: () => Promise<void>;
105
- }
275
+ /** Whether product is loading */
276
+ loading: boolean;
277
+ /** Error from last operation */
278
+ error: Error | null;
279
+ /** Refresh product from server */
280
+ refresh: () => Promise<void>;
281
+ }
282
+ /**
283
+ * Hook for fetching a single product by ID or slug
284
+ *
285
+ * @param idOrSlug - Product ID (number) or slug (string)
286
+ * @example
287
+ * ```tsx
288
+ * // By slug (recommended)
289
+ * const { product, loading } = useProduct('wireless-headphones');
290
+ *
291
+ * // By ID
292
+ * const { product } = useProduct(123);
293
+ *
294
+ * // Display product
295
+ * if (product) {
296
+ * console.log(product.name, product.sale_price, product.images);
297
+ * }
298
+ * ```
299
+ */
106
300
  declare function useProduct(idOrSlug: number | string): UseProductReturn;
107
301
  interface UseCategoriesReturn {
108
302
  categories: ProductCategory[];