@diffsome/react 1.1.2 → 1.1.3

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
@@ -17,24 +17,75 @@ declare function DiffsomeProvider({ children, config }: DiffsomeProviderProps):
17
17
  declare function useDiffsome(): DiffsomeContextValue;
18
18
  declare function useClient(): Diffsome;
19
19
 
20
+ /**
21
+ * Return type for the useAuth hook
22
+ */
20
23
  interface UseAuthReturn {
24
+ /** Currently logged in user, or null if not authenticated */
21
25
  user: Member | null;
26
+ /** Whether the user is currently authenticated */
22
27
  isAuthenticated: boolean;
28
+ /** Whether an auth operation is in progress */
23
29
  loading: boolean;
30
+ /** Error from the last auth operation, if any */
24
31
  error: Error | null;
32
+ /**
33
+ * Log in with email and password
34
+ * @param credentials - { email: string, password: string }
35
+ * @returns AuthResponse with user and token
36
+ */
25
37
  login: (credentials: LoginCredentials) => Promise<AuthResponse>;
38
+ /**
39
+ * Register a new account
40
+ * @param data - { name: string, email: string, password: string, password_confirmation: string }
41
+ * @returns AuthResponse with user and token
42
+ */
26
43
  register: (data: RegisterData) => Promise<AuthResponse>;
44
+ /** Log out and clear session */
27
45
  logout: () => Promise<void>;
46
+ /** Fetch current user profile */
28
47
  getProfile: () => Promise<Member>;
48
+ /**
49
+ * Update user profile
50
+ * @param data - { name?: string, email?: string, phone?: string, avatar?: File }
51
+ */
29
52
  updateProfile: (data: UpdateProfileData) => Promise<Member>;
53
+ /**
54
+ * Send password reset email
55
+ * @param email - User's email address
56
+ */
30
57
  forgotPassword: (email: string) => Promise<{
31
58
  message: string;
32
59
  }>;
60
+ /**
61
+ * Reset password with token
62
+ * @param data - { token: string, email: string, password: string, password_confirmation: string }
63
+ */
33
64
  resetPassword: (data: ResetPasswordData) => Promise<{
34
65
  message: string;
35
66
  }>;
36
- refresh: () => Promise<void>;
37
- }
67
+ /** Refresh user profile from server */
68
+ refresh: () => Promise<void>;
69
+ }
70
+ /**
71
+ * Hook for user authentication - login, register, logout, profile management
72
+ *
73
+ * @example
74
+ * ```tsx
75
+ * const { user, login, logout, loading } = useAuth();
76
+ *
77
+ * // Login
78
+ * await login({ email: 'user@example.com', password: 'secret' });
79
+ *
80
+ * // Check auth state
81
+ * if (user) {
82
+ * console.log('Logged in as:', user.name);
83
+ * }
84
+ *
85
+ * // Logout
86
+ * await logout();
87
+ * ```
88
+ */
38
89
  declare function useAuth(): UseAuthReturn;
39
90
 
40
91
  interface UseSocialAuthReturn {
@@ -47,24 +98,90 @@ interface UseSocialAuthReturn {
47
98
  }
48
99
  declare function useSocialAuth(): UseSocialAuthReturn;
49
100
 
101
+ /**
102
+ * Return type for the useCart hook
103
+ */
50
104
  interface UseCartReturn {
105
+ /** Full cart object with metadata */
51
106
  cart: Cart | null;
107
+ /** Array of cart items */
52
108
  items: CartItem[];
109
+ /** Number of unique items in cart */
53
110
  itemCount: number;
111
+ /** Total quantity of all items */
54
112
  totalQuantity: number;
113
+ /** Cart subtotal before shipping */
55
114
  subtotal: number;
115
+ /** Shipping fee */
56
116
  shippingFee: number;
117
+ /** Cart total including shipping */
57
118
  total: number;
58
- loading: boolean;
59
- error: Error | null;
119
+ /** Whether cart is loading */
120
+ loading: boolean;
121
+ /** Error from last cart operation */
122
+ error: Error | null;
123
+ /**
124
+ * Add product to cart
125
+ * @param productId - Product ID to add
126
+ * @param quantity - Quantity to add (default: 1)
127
+ * @param variantId - Optional variant ID for variable products
128
+ * @param options - Optional custom options
129
+ * @returns Updated cart
130
+ */
60
131
  addToCart: (productId: number, quantity?: number, variantId?: number, options?: Record<string, string>) => Promise<Cart>;
132
+ /**
133
+ * Update item quantity
134
+ * @param itemId - Cart item ID
135
+ * @param quantity - New quantity
136
+ */
61
137
  updateItem: (itemId: number, quantity: number) => Promise<Cart>;
138
+ /**
139
+ * Remove item from cart
140
+ * @param itemId - Cart item ID to remove
141
+ */
62
142
  removeItem: (itemId: number) => Promise<Cart>;
143
+ /** Clear all items from cart */
63
144
  clearCart: () => Promise<void>;
145
+ /** Refresh cart from server */
64
146
  refresh: () => Promise<void>;
147
+ /**
148
+ * Check if product is in cart
149
+ * @param productId - Product ID
150
+ * @param variantId - Optional variant ID
151
+ */
65
152
  isInCart: (productId: number, variantId?: number) => boolean;
153
+ /**
154
+ * Get quantity of product in cart
155
+ * @param productId - Product ID
156
+ * @param variantId - Optional variant ID
157
+ * @returns Quantity in cart (0 if not in cart)
158
+ */
66
159
  getItemQuantity: (productId: number, variantId?: number) => number;
67
160
  }
161
+ /**
162
+ * Hook for shopping cart management
163
+ *
164
+ * @example
165
+ * ```tsx
166
+ * const { items, total, addToCart, removeItem, clearCart } = useCart();
167
+ *
168
+ * // Add to cart
169
+ * await addToCart(123, 2); // Add product ID 123, quantity 2
170
+ *
171
+ * // With variant
172
+ * await addToCart(123, 1, 456); // Product 123, variant 456
173
+ *
174
+ * // Display cart
175
+ * items.map(item => (
176
+ * <div key={item.id}>
177
+ * {item.product_name} x {item.quantity} = ${item.subtotal}
178
+ * </div>
179
+ * ));
180
+ *
181
+ * // Total
182
+ * console.log('Total:', total);
183
+ * ```
184
+ */
68
185
  declare function useCart(): UseCartReturn;
69
186
 
70
187
  interface UseWishlistReturn {
@@ -83,26 +200,96 @@ interface UseWishlistReturn {
83
200
  }
84
201
  declare function useWishlist(): UseWishlistReturn;
85
202
 
203
+ /**
204
+ * Return type for the useProducts hook
205
+ */
86
206
  interface UseProductsReturn {
207
+ /** Array of products */
87
208
  products: Product[];
209
+ /** Pagination metadata (current_page, last_page, total, per_page) */
88
210
  meta: PaginationMeta | null;
211
+ /** Whether products are loading */
89
212
  loading: boolean;
213
+ /** Error from last operation */
90
214
  error: Error | null;
215
+ /** Whether more pages are available */
91
216
  hasMore: boolean;
217
+ /** Load next page of products (appends to list) */
92
218
  loadMore: () => Promise<void>;
219
+ /** Refresh products from server */
93
220
  refresh: () => Promise<void>;
221
+ /**
222
+ * Search products by query
223
+ * @param query - Search term
224
+ */
94
225
  search: (query: string) => Promise<void>;
95
226
  }
227
+ /**
228
+ * Options for useProducts hook
229
+ */
96
230
  interface UseProductsOptions extends ProductListParams {
231
+ /** Whether to fetch products on mount (default: true) */
97
232
  autoFetch?: boolean;
98
233
  }
234
+ /**
235
+ * Hook for fetching products with pagination, filtering, and search
236
+ *
237
+ * @param options - Filtering and pagination options
238
+ * @example
239
+ * ```tsx
240
+ * // Basic usage
241
+ * const { products, loading } = useProducts();
242
+ *
243
+ * // With filters
244
+ * const { products } = useProducts({
245
+ * category: 'electronics',
246
+ * per_page: 20,
247
+ * sort: 'price_low',
248
+ * min_price: 10,
249
+ * max_price: 100,
250
+ * });
251
+ *
252
+ * // Infinite scroll
253
+ * const { products, hasMore, loadMore } = useProducts({ per_page: 12 });
254
+ * // Call loadMore() when user scrolls to bottom
255
+ *
256
+ * // Search
257
+ * const { products, search } = useProducts();
258
+ * await search('laptop'); // Searches products
259
+ * ```
260
+ */
99
261
  declare function useProducts(options?: UseProductsOptions): UseProductsReturn;
262
+ /**
263
+ * Return type for the useProduct hook
264
+ */
100
265
  interface UseProductReturn {
266
+ /** Product data, or null if not loaded */
101
267
  product: Product | null;
102
- loading: boolean;
103
- error: Error | null;
104
- refresh: () => Promise<void>;
105
- }
268
+ /** Whether product is loading */
269
+ loading: boolean;
270
+ /** Error from last operation */
271
+ error: Error | null;
272
+ /** Refresh product from server */
273
+ refresh: () => Promise<void>;
274
+ }
275
+ /**
276
+ * Hook for fetching a single product by ID or slug
277
+ *
278
+ * @param idOrSlug - Product ID (number) or slug (string)
279
+ * @example
280
+ * ```tsx
281
+ * // By slug (recommended)
282
+ * const { product, loading } = useProduct('wireless-headphones');
283
+ *
284
+ * // By ID
285
+ * const { product } = useProduct(123);
286
+ *
287
+ * // Display product
288
+ * if (product) {
289
+ * console.log(product.name, product.sale_price, product.images);
290
+ * }
291
+ * ```
292
+ */
106
293
  declare function useProduct(idOrSlug: number | string): UseProductReturn;
107
294
  interface UseCategoriesReturn {
108
295
  categories: ProductCategory[];
package/dist/index.d.ts CHANGED
@@ -17,24 +17,75 @@ declare function DiffsomeProvider({ children, config }: DiffsomeProviderProps):
17
17
  declare function useDiffsome(): DiffsomeContextValue;
18
18
  declare function useClient(): Diffsome;
19
19
 
20
+ /**
21
+ * Return type for the useAuth hook
22
+ */
20
23
  interface UseAuthReturn {
24
+ /** Currently logged in user, or null if not authenticated */
21
25
  user: Member | null;
26
+ /** Whether the user is currently authenticated */
22
27
  isAuthenticated: boolean;
28
+ /** Whether an auth operation is in progress */
23
29
  loading: boolean;
30
+ /** Error from the last auth operation, if any */
24
31
  error: Error | null;
32
+ /**
33
+ * Log in with email and password
34
+ * @param credentials - { email: string, password: string }
35
+ * @returns AuthResponse with user and token
36
+ */
25
37
  login: (credentials: LoginCredentials) => Promise<AuthResponse>;
38
+ /**
39
+ * Register a new account
40
+ * @param data - { name: string, email: string, password: string, password_confirmation: string }
41
+ * @returns AuthResponse with user and token
42
+ */
26
43
  register: (data: RegisterData) => Promise<AuthResponse>;
44
+ /** Log out and clear session */
27
45
  logout: () => Promise<void>;
46
+ /** Fetch current user profile */
28
47
  getProfile: () => Promise<Member>;
48
+ /**
49
+ * Update user profile
50
+ * @param data - { name?: string, email?: string, phone?: string, avatar?: File }
51
+ */
29
52
  updateProfile: (data: UpdateProfileData) => Promise<Member>;
53
+ /**
54
+ * Send password reset email
55
+ * @param email - User's email address
56
+ */
30
57
  forgotPassword: (email: string) => Promise<{
31
58
  message: string;
32
59
  }>;
60
+ /**
61
+ * Reset password with token
62
+ * @param data - { token: string, email: string, password: string, password_confirmation: string }
63
+ */
33
64
  resetPassword: (data: ResetPasswordData) => Promise<{
34
65
  message: string;
35
66
  }>;
36
- refresh: () => Promise<void>;
37
- }
67
+ /** Refresh user profile from server */
68
+ refresh: () => Promise<void>;
69
+ }
70
+ /**
71
+ * Hook for user authentication - login, register, logout, profile management
72
+ *
73
+ * @example
74
+ * ```tsx
75
+ * const { user, login, logout, loading } = useAuth();
76
+ *
77
+ * // Login
78
+ * await login({ email: 'user@example.com', password: 'secret' });
79
+ *
80
+ * // Check auth state
81
+ * if (user) {
82
+ * console.log('Logged in as:', user.name);
83
+ * }
84
+ *
85
+ * // Logout
86
+ * await logout();
87
+ * ```
88
+ */
38
89
  declare function useAuth(): UseAuthReturn;
39
90
 
40
91
  interface UseSocialAuthReturn {
@@ -47,24 +98,90 @@ interface UseSocialAuthReturn {
47
98
  }
48
99
  declare function useSocialAuth(): UseSocialAuthReturn;
49
100
 
101
+ /**
102
+ * Return type for the useCart hook
103
+ */
50
104
  interface UseCartReturn {
105
+ /** Full cart object with metadata */
51
106
  cart: Cart | null;
107
+ /** Array of cart items */
52
108
  items: CartItem[];
109
+ /** Number of unique items in cart */
53
110
  itemCount: number;
111
+ /** Total quantity of all items */
54
112
  totalQuantity: number;
113
+ /** Cart subtotal before shipping */
55
114
  subtotal: number;
115
+ /** Shipping fee */
56
116
  shippingFee: number;
117
+ /** Cart total including shipping */
57
118
  total: number;
58
- loading: boolean;
59
- error: Error | null;
119
+ /** Whether cart is loading */
120
+ loading: boolean;
121
+ /** Error from last cart operation */
122
+ error: Error | null;
123
+ /**
124
+ * Add product to cart
125
+ * @param productId - Product ID to add
126
+ * @param quantity - Quantity to add (default: 1)
127
+ * @param variantId - Optional variant ID for variable products
128
+ * @param options - Optional custom options
129
+ * @returns Updated cart
130
+ */
60
131
  addToCart: (productId: number, quantity?: number, variantId?: number, options?: Record<string, string>) => Promise<Cart>;
132
+ /**
133
+ * Update item quantity
134
+ * @param itemId - Cart item ID
135
+ * @param quantity - New quantity
136
+ */
61
137
  updateItem: (itemId: number, quantity: number) => Promise<Cart>;
138
+ /**
139
+ * Remove item from cart
140
+ * @param itemId - Cart item ID to remove
141
+ */
62
142
  removeItem: (itemId: number) => Promise<Cart>;
143
+ /** Clear all items from cart */
63
144
  clearCart: () => Promise<void>;
145
+ /** Refresh cart from server */
64
146
  refresh: () => Promise<void>;
147
+ /**
148
+ * Check if product is in cart
149
+ * @param productId - Product ID
150
+ * @param variantId - Optional variant ID
151
+ */
65
152
  isInCart: (productId: number, variantId?: number) => boolean;
153
+ /**
154
+ * Get quantity of product in cart
155
+ * @param productId - Product ID
156
+ * @param variantId - Optional variant ID
157
+ * @returns Quantity in cart (0 if not in cart)
158
+ */
66
159
  getItemQuantity: (productId: number, variantId?: number) => number;
67
160
  }
161
+ /**
162
+ * Hook for shopping cart management
163
+ *
164
+ * @example
165
+ * ```tsx
166
+ * const { items, total, addToCart, removeItem, clearCart } = useCart();
167
+ *
168
+ * // Add to cart
169
+ * await addToCart(123, 2); // Add product ID 123, quantity 2
170
+ *
171
+ * // With variant
172
+ * await addToCart(123, 1, 456); // Product 123, variant 456
173
+ *
174
+ * // Display cart
175
+ * items.map(item => (
176
+ * <div key={item.id}>
177
+ * {item.product_name} x {item.quantity} = ${item.subtotal}
178
+ * </div>
179
+ * ));
180
+ *
181
+ * // Total
182
+ * console.log('Total:', total);
183
+ * ```
184
+ */
68
185
  declare function useCart(): UseCartReturn;
69
186
 
70
187
  interface UseWishlistReturn {
@@ -83,26 +200,96 @@ interface UseWishlistReturn {
83
200
  }
84
201
  declare function useWishlist(): UseWishlistReturn;
85
202
 
203
+ /**
204
+ * Return type for the useProducts hook
205
+ */
86
206
  interface UseProductsReturn {
207
+ /** Array of products */
87
208
  products: Product[];
209
+ /** Pagination metadata (current_page, last_page, total, per_page) */
88
210
  meta: PaginationMeta | null;
211
+ /** Whether products are loading */
89
212
  loading: boolean;
213
+ /** Error from last operation */
90
214
  error: Error | null;
215
+ /** Whether more pages are available */
91
216
  hasMore: boolean;
217
+ /** Load next page of products (appends to list) */
92
218
  loadMore: () => Promise<void>;
219
+ /** Refresh products from server */
93
220
  refresh: () => Promise<void>;
221
+ /**
222
+ * Search products by query
223
+ * @param query - Search term
224
+ */
94
225
  search: (query: string) => Promise<void>;
95
226
  }
227
+ /**
228
+ * Options for useProducts hook
229
+ */
96
230
  interface UseProductsOptions extends ProductListParams {
231
+ /** Whether to fetch products on mount (default: true) */
97
232
  autoFetch?: boolean;
98
233
  }
234
+ /**
235
+ * Hook for fetching products with pagination, filtering, and search
236
+ *
237
+ * @param options - Filtering and pagination options
238
+ * @example
239
+ * ```tsx
240
+ * // Basic usage
241
+ * const { products, loading } = useProducts();
242
+ *
243
+ * // With filters
244
+ * const { products } = useProducts({
245
+ * category: 'electronics',
246
+ * per_page: 20,
247
+ * sort: 'price_low',
248
+ * min_price: 10,
249
+ * max_price: 100,
250
+ * });
251
+ *
252
+ * // Infinite scroll
253
+ * const { products, hasMore, loadMore } = useProducts({ per_page: 12 });
254
+ * // Call loadMore() when user scrolls to bottom
255
+ *
256
+ * // Search
257
+ * const { products, search } = useProducts();
258
+ * await search('laptop'); // Searches products
259
+ * ```
260
+ */
99
261
  declare function useProducts(options?: UseProductsOptions): UseProductsReturn;
262
+ /**
263
+ * Return type for the useProduct hook
264
+ */
100
265
  interface UseProductReturn {
266
+ /** Product data, or null if not loaded */
101
267
  product: Product | null;
102
- loading: boolean;
103
- error: Error | null;
104
- refresh: () => Promise<void>;
105
- }
268
+ /** Whether product is loading */
269
+ loading: boolean;
270
+ /** Error from last operation */
271
+ error: Error | null;
272
+ /** Refresh product from server */
273
+ refresh: () => Promise<void>;
274
+ }
275
+ /**
276
+ * Hook for fetching a single product by ID or slug
277
+ *
278
+ * @param idOrSlug - Product ID (number) or slug (string)
279
+ * @example
280
+ * ```tsx
281
+ * // By slug (recommended)
282
+ * const { product, loading } = useProduct('wireless-headphones');
283
+ *
284
+ * // By ID
285
+ * const { product } = useProduct(123);
286
+ *
287
+ * // Display product
288
+ * if (product) {
289
+ * console.log(product.name, product.sale_price, product.images);
290
+ * }
291
+ * ```
292
+ */
106
293
  declare function useProduct(idOrSlug: number | string): UseProductReturn;
107
294
  interface UseCategoriesReturn {
108
295
  categories: ProductCategory[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffsome/react",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "React hooks and providers for Diffsome SDK - Headless e-commerce & CMS",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",