@behio/storefront-sdk 0.1.3 → 0.1.5

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/react.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BehioStorefront
3
- } from "./chunk-DBZPF3IR.mjs";
3
+ } from "./chunk-S4DOL3OV.mjs";
4
4
 
5
5
  // src/react/provider.tsx
6
6
  import { useRef, useEffect, useMemo } from "react";
@@ -156,95 +156,159 @@ function BehioProvider({
156
156
  }
157
157
 
158
158
  // src/react/hooks/use-products.ts
159
- import { useQuery } from "@tanstack/react-query";
159
+ import { useCallback, useMemo as useMemo2, useState } from "react";
160
+ import { useInfiniteQuery } from "@tanstack/react-query";
160
161
  function useProducts(query) {
161
162
  const { client } = useBehio();
162
- const { initialData, enabled, ...productsQuery } = query ?? {};
163
- const serializedQuery = JSON.stringify(productsQuery);
164
- return useQuery({
165
- queryKey: ["behio", "products", serializedQuery],
166
- queryFn: () => client.catalog.getProducts(productsQuery),
167
- initialData,
168
- enabled
169
- });
163
+ const { initialData, enabled, page: initialPage, limit, ...filters } = query ?? {};
164
+ const [page, setPage] = useState(initialPage ?? 1);
165
+ const serializedFilters = useMemo2(() => JSON.stringify({ ...filters, limit }), [filters, limit]);
166
+ const infinite = useInfiniteQuery({
167
+ queryKey: ["behio", "products", serializedFilters, page],
168
+ queryFn: ({ pageParam }) => client.catalog.getProducts({ ...filters, limit, page: pageParam }),
169
+ initialPageParam: page,
170
+ getNextPageParam: (lastPage2) => lastPage2.page < lastPage2.totalPages ? lastPage2.page + 1 : void 0,
171
+ getPreviousPageParam: (firstPage2) => firstPage2.page > 1 ? firstPage2.page - 1 : void 0,
172
+ initialData: initialData ? { pages: [initialData], pageParams: [initialData.page] } : void 0,
173
+ enabled: enabled !== false
174
+ });
175
+ const items = useMemo2(
176
+ () => infinite.data?.pages.flatMap((p) => p.items) ?? [],
177
+ [infinite.data]
178
+ );
179
+ const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
180
+ const firstPage = infinite.data?.pages[0];
181
+ const loadMore = useCallback(() => {
182
+ if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
183
+ return infinite.fetchNextPage();
184
+ }
185
+ return Promise.resolve();
186
+ }, [infinite]);
187
+ const goToPage = useCallback((newPage) => {
188
+ setPage(newPage);
189
+ }, []);
190
+ return {
191
+ // --- Data ---
192
+ /** All items from all loaded pages (flat array) — for infinite scroll */
193
+ items,
194
+ /** Raw React Query data with all pages */
195
+ data: infinite.data,
196
+ /** Last loaded page meta */
197
+ total: lastPage?.total ?? 0,
198
+ totalPages: lastPage?.totalPages ?? 0,
199
+ currentPage: lastPage?.page ?? page,
200
+ limit: lastPage?.limit ?? limit ?? 20,
201
+ // --- Pagination controls ---
202
+ /** Current page (manual pagination) */
203
+ page,
204
+ /** Change page (traditional pagination — replaces items) */
205
+ setPage: goToPage,
206
+ /** Load next page (append to items — for infinite scroll / load more button) */
207
+ loadMore,
208
+ /** Fetch previous page */
209
+ loadPrevious: infinite.fetchPreviousPage,
210
+ /** Can load more? */
211
+ hasMore: infinite.hasNextPage ?? false,
212
+ hasPrevious: infinite.hasPreviousPage ?? false,
213
+ // --- States ---
214
+ isLoading: infinite.isLoading,
215
+ isFetching: infinite.isFetching,
216
+ isLoadingMore: infinite.isFetchingNextPage,
217
+ error: infinite.error,
218
+ isError: infinite.isError,
219
+ // --- Manual control ---
220
+ /** Force refetch all loaded pages */
221
+ refetch: infinite.refetch
222
+ };
170
223
  }
171
224
 
172
225
  // src/react/hooks/use-product.ts
173
- import { useQuery as useQuery2 } from "@tanstack/react-query";
226
+ import { useQuery } from "@tanstack/react-query";
174
227
  function useProduct(slug, options) {
175
228
  const { client } = useBehio();
176
- return useQuery2({
229
+ return useQuery({
177
230
  queryKey: ["behio", "product", slug],
178
231
  queryFn: () => client.catalog.getProduct(slug, {
179
232
  locale: options?.locale,
180
233
  currency: options?.currency
181
234
  }),
182
235
  initialData: options?.initialData,
183
- enabled: options?.enabled ?? !!slug
236
+ enabled: options?.enabled !== false && !!slug
184
237
  });
185
238
  }
186
239
 
187
240
  // src/react/hooks/use-categories.ts
188
- import { useQuery as useQuery3 } from "@tanstack/react-query";
189
- function useCategories(locale) {
241
+ import { useQuery as useQuery2 } from "@tanstack/react-query";
242
+ function useCategories(locale, options) {
190
243
  const { client } = useBehio();
191
- return useQuery3({
244
+ return useQuery2({
192
245
  queryKey: ["behio", "categories", locale],
193
246
  queryFn: async () => {
194
247
  const result = await client.catalog.getCategories(locale);
195
248
  return result.categories;
196
- }
249
+ },
250
+ enabled: options?.enabled !== false
251
+ });
252
+ }
253
+ function useCategory(slug, options) {
254
+ const { client } = useBehio();
255
+ return useQuery2({
256
+ queryKey: ["behio", "category", slug, options?.locale],
257
+ queryFn: () => client.catalog.getCategory(slug, options?.locale),
258
+ enabled: options?.enabled !== false && !!slug
197
259
  });
198
260
  }
199
261
 
200
262
  // src/react/hooks/use-labels.ts
201
- import { useQuery as useQuery4 } from "@tanstack/react-query";
202
- function useLabels(locale) {
263
+ import { useQuery as useQuery3 } from "@tanstack/react-query";
264
+ function useLabels(locale, options) {
203
265
  const { client } = useBehio();
204
- return useQuery4({
266
+ return useQuery3({
205
267
  queryKey: ["behio", "labels", locale],
206
268
  queryFn: async () => {
207
269
  const result = await client.catalog.getLabels(locale);
208
270
  return result.labels;
209
- }
271
+ },
272
+ enabled: options?.enabled !== false
210
273
  });
211
274
  }
212
275
 
213
276
  // src/react/hooks/use-featured.ts
214
- import { useQuery as useQuery5 } from "@tanstack/react-query";
277
+ import { useQuery as useQuery4 } from "@tanstack/react-query";
215
278
  function useFeatured(options) {
216
279
  const { client } = useBehio();
217
- return useQuery5({
280
+ return useQuery4({
218
281
  queryKey: ["behio", "featured", options?.locale, options?.currency],
219
282
  queryFn: () => client.catalog.getFeatured({
220
283
  locale: options?.locale,
221
284
  currency: options?.currency
222
285
  }),
223
286
  initialData: options?.initialData,
224
- enabled: options?.enabled
287
+ enabled: options?.enabled !== false
225
288
  });
226
289
  }
227
290
 
228
291
  // src/react/hooks/use-filters.ts
229
- import { useQuery as useQuery6 } from "@tanstack/react-query";
230
- function useFilters() {
292
+ import { useQuery as useQuery5 } from "@tanstack/react-query";
293
+ function useFilters(options) {
231
294
  const { client } = useBehio();
232
- return useQuery6({
295
+ return useQuery5({
233
296
  queryKey: ["behio", "filters"],
234
297
  queryFn: async () => {
235
298
  const result = await client.catalog.getFilters();
236
299
  return result.filters;
237
- }
300
+ },
301
+ enabled: options?.enabled !== false
238
302
  });
239
303
  }
240
304
 
241
305
  // src/react/hooks/use-search.ts
242
- import { useState, useEffect as useEffect2 } from "react";
243
- import { useQuery as useQuery7 } from "@tanstack/react-query";
306
+ import { useState as useState2, useEffect as useEffect2 } from "react";
307
+ import { useQuery as useQuery6 } from "@tanstack/react-query";
244
308
  function useSearch(query, options) {
245
309
  const { client } = useBehio();
246
310
  const debounceMs = options?.debounceMs ?? 300;
247
- const [debouncedQuery, setDebouncedQuery] = useState(query);
311
+ const [debouncedQuery, setDebouncedQuery] = useState2(query);
248
312
  useEffect2(() => {
249
313
  if (debounceMs <= 0) {
250
314
  setDebouncedQuery(query);
@@ -253,32 +317,32 @@ function useSearch(query, options) {
253
317
  const timer = setTimeout(() => setDebouncedQuery(query), debounceMs);
254
318
  return () => clearTimeout(timer);
255
319
  }, [query, debounceMs]);
256
- return useQuery7({
320
+ return useQuery6({
257
321
  queryKey: ["behio", "search", debouncedQuery, options?.page, options?.limit],
258
322
  queryFn: () => client.catalog.search(debouncedQuery, {
259
323
  page: options?.page,
260
324
  limit: options?.limit
261
325
  }),
262
- enabled: (options?.enabled ?? true) && debouncedQuery.length > 0
326
+ enabled: options?.enabled !== false && debouncedQuery.length > 0
263
327
  });
264
328
  }
265
329
 
266
330
  // src/react/hooks/use-cart.ts
267
- import { useCallback } from "react";
268
- import { useQuery as useQuery8, useMutation, useQueryClient } from "@tanstack/react-query";
331
+ import { useCallback as useCallback2 } from "react";
332
+ import { useQuery as useQuery7, useMutation, useQueryClient } from "@tanstack/react-query";
269
333
  var CART_KEY = ["behio", "cart"];
270
- function useCart() {
334
+ function useCart(options) {
271
335
  const { client, storage } = useBehio();
272
336
  const queryClient = useQueryClient();
273
337
  const {
274
338
  data: cart,
275
339
  isLoading,
276
340
  error
277
- } = useQuery8({
341
+ } = useQuery7({
278
342
  queryKey: [...CART_KEY],
279
343
  queryFn: () => client.cart.get(),
280
344
  // Only fetch if we have a cart session or are logged in
281
- enabled: !!client.getCartSession() || !!client.getAccessToken()
345
+ enabled: options?.enabled !== false && (!!client.getCartSession() || !!client.getAccessToken())
282
346
  });
283
347
  const addMutation = useMutation({
284
348
  mutationFn: async ({ productId, quantity }) => {
@@ -373,31 +437,31 @@ function useCart() {
373
437
  storage.remove(STORAGE_KEYS.CART_SESSION);
374
438
  }
375
439
  });
376
- const addItem = useCallback(
440
+ const addItem = useCallback2(
377
441
  (productId, quantity) => addMutation.mutateAsync({ productId, quantity }),
378
442
  [addMutation]
379
443
  );
380
- const updateQuantity = useCallback(
444
+ const updateQuantity = useCallback2(
381
445
  (itemId, quantity) => updateMutation.mutateAsync({ itemId, quantity }),
382
446
  [updateMutation]
383
447
  );
384
- const removeItem = useCallback(
448
+ const removeItem = useCallback2(
385
449
  (itemId) => removeMutation.mutateAsync(itemId),
386
450
  [removeMutation]
387
451
  );
388
- const clear = useCallback(
452
+ const clear = useCallback2(
389
453
  () => clearMutation.mutateAsync(),
390
454
  [clearMutation]
391
455
  );
392
- const applyDiscount = useCallback(
456
+ const applyDiscount = useCallback2(
393
457
  (code) => applyDiscountMutation.mutateAsync(code),
394
458
  [applyDiscountMutation]
395
459
  );
396
- const removeDiscount = useCallback(
460
+ const removeDiscount = useCallback2(
397
461
  () => removeDiscountMutation.mutateAsync(),
398
462
  [removeDiscountMutation]
399
463
  );
400
- const merge = useCallback(
464
+ const merge = useCallback2(
401
465
  () => mergeMutation.mutateAsync(),
402
466
  [mergeMutation]
403
467
  );
@@ -424,24 +488,24 @@ function useCart() {
424
488
  }
425
489
 
426
490
  // src/react/hooks/use-cart-count.ts
427
- import { useQuery as useQuery9, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
491
+ import { useQuery as useQuery8, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
428
492
  var CART_KEY2 = ["behio", "cart"];
429
- function useCartCount() {
493
+ function useCartCount(options) {
430
494
  const { client } = useBehio();
431
495
  const queryClient = useQueryClient2();
432
496
  const cachedCart = queryClient.getQueryData([...CART_KEY2]);
433
- const { data } = useQuery9({
497
+ const { data } = useQuery8({
434
498
  queryKey: [...CART_KEY2],
435
499
  queryFn: () => client.cart.get(),
436
- enabled: !cachedCart && (!!client.getCartSession() || !!client.getAccessToken())
500
+ enabled: options?.enabled !== false && !cachedCart && (!!client.getCartSession() || !!client.getAccessToken())
437
501
  });
438
502
  const cart = cachedCart ?? data;
439
503
  return cart?.itemCount ?? 0;
440
504
  }
441
505
 
442
506
  // src/react/hooks/use-auth.ts
443
- import { useCallback as useCallback2 } from "react";
444
- import { useQuery as useQuery10, useMutation as useMutation2, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
507
+ import { useCallback as useCallback3 } from "react";
508
+ import { useQuery as useQuery9, useMutation as useMutation2, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
445
509
  var CUSTOMER_KEY = ["behio", "customer"];
446
510
  var CART_KEY3 = ["behio", "cart"];
447
511
  function useAuth() {
@@ -451,12 +515,12 @@ function useAuth() {
451
515
  const {
452
516
  data: customer,
453
517
  isLoading
454
- } = useQuery10({
518
+ } = useQuery9({
455
519
  queryKey: [...CUSTOMER_KEY],
456
520
  queryFn: () => client.customer.getProfile(),
457
521
  enabled: isLoggedIn
458
522
  });
459
- const persistTokens = useCallback2(
523
+ const persistTokens = useCallback3(
460
524
  (tokens) => {
461
525
  client.setTokens(tokens);
462
526
  storage.set(STORAGE_KEYS.ACCESS_TOKEN, tokens.accessToken);
@@ -464,7 +528,7 @@ function useAuth() {
464
528
  },
465
529
  [client, storage]
466
530
  );
467
- const clearAuth = useCallback2(() => {
531
+ const clearAuth = useCallback3(() => {
468
532
  client.clearTokens();
469
533
  storage.remove(STORAGE_KEYS.ACCESS_TOKEN);
470
534
  storage.remove(STORAGE_KEYS.REFRESH_TOKEN);
@@ -472,7 +536,7 @@ function useAuth() {
472
536
  queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
473
537
  queryClient.invalidateQueries({ queryKey: ["behio", "addresses"] });
474
538
  }, [client, storage, queryClient]);
475
- const postAuth = useCallback2(async () => {
539
+ const postAuth = useCallback3(async () => {
476
540
  await queryClient.invalidateQueries({ queryKey: [...CUSTOMER_KEY] });
477
541
  if (client.getCartSession()) {
478
542
  try {
@@ -517,27 +581,27 @@ function useAuth() {
517
581
  const verifyEmailMutation = useMutation2({
518
582
  mutationFn: (token) => client.auth.verifyEmail(token)
519
583
  });
520
- const login = useCallback2(
584
+ const login = useCallback3(
521
585
  (email, password) => loginMutation.mutateAsync({ email, password }).then(() => void 0),
522
586
  [loginMutation]
523
587
  );
524
- const register = useCallback2(
588
+ const register = useCallback3(
525
589
  (input) => registerMutation.mutateAsync(input).then(() => void 0),
526
590
  [registerMutation]
527
591
  );
528
- const logout = useCallback2(
592
+ const logout = useCallback3(
529
593
  () => logoutMutation.mutateAsync().then(() => void 0),
530
594
  [logoutMutation]
531
595
  );
532
- const forgotPassword = useCallback2(
596
+ const forgotPassword = useCallback3(
533
597
  (email) => forgotPasswordMutation.mutateAsync(email).then(() => void 0),
534
598
  [forgotPasswordMutation]
535
599
  );
536
- const resetPassword = useCallback2(
600
+ const resetPassword = useCallback3(
537
601
  (token, newPassword) => resetPasswordMutation.mutateAsync({ token, newPassword }).then(() => void 0),
538
602
  [resetPasswordMutation]
539
603
  );
540
- const verifyEmail = useCallback2(
604
+ const verifyEmail = useCallback3(
541
605
  (token) => verifyEmailMutation.mutateAsync(token).then(() => void 0),
542
606
  [verifyEmailMutation]
543
607
  );
@@ -561,20 +625,20 @@ function useAuth() {
561
625
  }
562
626
 
563
627
  // src/react/hooks/use-customer.ts
564
- import { useCallback as useCallback3 } from "react";
565
- import { useQuery as useQuery11, useMutation as useMutation3, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
628
+ import { useCallback as useCallback4 } from "react";
629
+ import { useQuery as useQuery10, useMutation as useMutation3, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
566
630
  var CUSTOMER_KEY2 = ["behio", "customer"];
567
- function useCustomer() {
631
+ function useCustomer(options) {
568
632
  const { client } = useBehio();
569
633
  const queryClient = useQueryClient4();
570
634
  const {
571
635
  data,
572
636
  isLoading,
573
637
  error
574
- } = useQuery11({
638
+ } = useQuery10({
575
639
  queryKey: [...CUSTOMER_KEY2],
576
640
  queryFn: () => client.customer.getProfile(),
577
- enabled: !!client.getAccessToken()
641
+ enabled: options?.enabled !== false && !!client.getAccessToken()
578
642
  });
579
643
  const updateMutation = useMutation3({
580
644
  mutationFn: (data2) => client.customer.updateProfile(data2),
@@ -582,7 +646,7 @@ function useCustomer() {
582
646
  queryClient.setQueryData([...CUSTOMER_KEY2], updated);
583
647
  }
584
648
  });
585
- const updateProfile = useCallback3(
649
+ const updateProfile = useCallback4(
586
650
  (profileData) => updateMutation.mutateAsync(profileData),
587
651
  [updateMutation]
588
652
  );
@@ -596,23 +660,23 @@ function useCustomer() {
596
660
  }
597
661
 
598
662
  // src/react/hooks/use-addresses.ts
599
- import { useCallback as useCallback4 } from "react";
600
- import { useQuery as useQuery12, useMutation as useMutation4, useQueryClient as useQueryClient5 } from "@tanstack/react-query";
663
+ import { useCallback as useCallback5 } from "react";
664
+ import { useQuery as useQuery11, useMutation as useMutation4, useQueryClient as useQueryClient5 } from "@tanstack/react-query";
601
665
  var ADDRESSES_KEY = ["behio", "addresses"];
602
- function useAddresses() {
666
+ function useAddresses(options) {
603
667
  const { client } = useBehio();
604
668
  const queryClient = useQueryClient5();
605
669
  const {
606
670
  data,
607
671
  isLoading,
608
672
  error
609
- } = useQuery12({
673
+ } = useQuery11({
610
674
  queryKey: [...ADDRESSES_KEY],
611
675
  queryFn: async () => {
612
676
  const result = await client.customer.getAddresses();
613
677
  return result.items;
614
678
  },
615
- enabled: !!client.getAccessToken()
679
+ enabled: options?.enabled !== false && !!client.getAccessToken()
616
680
  });
617
681
  const createMutation = useMutation4({
618
682
  mutationFn: (address) => client.customer.createAddress(address),
@@ -632,15 +696,15 @@ function useAddresses() {
632
696
  queryClient.invalidateQueries({ queryKey: [...ADDRESSES_KEY] });
633
697
  }
634
698
  });
635
- const createAddress = useCallback4(
699
+ const createAddress = useCallback5(
636
700
  (address) => createMutation.mutateAsync(address),
637
701
  [createMutation]
638
702
  );
639
- const updateAddress = useCallback4(
703
+ const updateAddress = useCallback5(
640
704
  (addressId, addressData) => updateMutation.mutateAsync({ addressId, data: addressData }),
641
705
  [updateMutation]
642
706
  );
643
- const deleteAddress = useCallback4(
707
+ const deleteAddress = useCallback5(
644
708
  (addressId) => deleteMutation.mutateAsync(addressId),
645
709
  [deleteMutation]
646
710
  );
@@ -657,33 +721,70 @@ function useAddresses() {
657
721
  }
658
722
 
659
723
  // src/react/hooks/use-orders.ts
660
- import { useQuery as useQuery13 } from "@tanstack/react-query";
724
+ import { useCallback as useCallback6, useMemo as useMemo3, useState as useState3 } from "react";
725
+ import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
661
726
  function useOrders(options) {
662
727
  const { client } = useBehio();
663
- return useQuery13({
664
- queryKey: ["behio", "orders", options?.page, options?.limit],
665
- queryFn: () => client.orders.list({
666
- page: options?.page,
667
- limit: options?.limit
668
- }),
669
- enabled: (options?.enabled ?? true) && !!client.getAccessToken()
670
- });
728
+ const { page: initialPage, limit, enabled } = options ?? {};
729
+ const [page, setPage] = useState3(initialPage ?? 1);
730
+ const infinite = useInfiniteQuery2({
731
+ queryKey: ["behio", "orders", limit, page],
732
+ queryFn: ({ pageParam }) => client.orders.list({ limit, page: pageParam }),
733
+ initialPageParam: page,
734
+ getNextPageParam: (lastPage2) => lastPage2.page < lastPage2.totalPages ? lastPage2.page + 1 : void 0,
735
+ getPreviousPageParam: (firstPage) => firstPage.page > 1 ? firstPage.page - 1 : void 0,
736
+ enabled: enabled !== false && !!client.getAccessToken()
737
+ });
738
+ const items = useMemo3(
739
+ () => infinite.data?.pages.flatMap((p) => p.items) ?? [],
740
+ [infinite.data]
741
+ );
742
+ const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
743
+ const loadMore = useCallback6(() => {
744
+ if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
745
+ return infinite.fetchNextPage();
746
+ }
747
+ return Promise.resolve();
748
+ }, [infinite]);
749
+ const goToPage = useCallback6((newPage) => {
750
+ setPage(newPage);
751
+ }, []);
752
+ return {
753
+ items,
754
+ data: infinite.data,
755
+ total: lastPage?.total ?? 0,
756
+ totalPages: lastPage?.totalPages ?? 0,
757
+ currentPage: lastPage?.page ?? page,
758
+ limit: lastPage?.limit ?? limit ?? 20,
759
+ page,
760
+ setPage: goToPage,
761
+ loadMore,
762
+ loadPrevious: infinite.fetchPreviousPage,
763
+ hasMore: infinite.hasNextPage ?? false,
764
+ hasPrevious: infinite.hasPreviousPage ?? false,
765
+ isLoading: infinite.isLoading,
766
+ isFetching: infinite.isFetching,
767
+ isLoadingMore: infinite.isFetchingNextPage,
768
+ error: infinite.error,
769
+ isError: infinite.isError,
770
+ refetch: infinite.refetch
771
+ };
671
772
  }
672
773
 
673
774
  // src/react/hooks/use-order.ts
674
- import { useCallback as useCallback5 } from "react";
675
- import { useQuery as useQuery14, useMutation as useMutation5, useQueryClient as useQueryClient6 } from "@tanstack/react-query";
676
- function useOrder(orderNumber) {
775
+ import { useCallback as useCallback7 } from "react";
776
+ import { useQuery as useQuery12, useMutation as useMutation5, useQueryClient as useQueryClient6 } from "@tanstack/react-query";
777
+ function useOrder(orderNumber, options) {
677
778
  const { client } = useBehio();
678
779
  const queryClient = useQueryClient6();
679
780
  const {
680
781
  data,
681
782
  isLoading,
682
783
  error
683
- } = useQuery14({
784
+ } = useQuery12({
684
785
  queryKey: ["behio", "order", orderNumber],
685
786
  queryFn: () => client.orders.get(orderNumber),
686
- enabled: !!orderNumber && !!client.getAccessToken()
787
+ enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
687
788
  });
688
789
  const cancelMutation = useMutation5({
689
790
  mutationFn: () => client.orders.cancel(orderNumber),
@@ -692,7 +793,7 @@ function useOrder(orderNumber) {
692
793
  queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
693
794
  }
694
795
  });
695
- const cancel = useCallback5(
796
+ const cancel = useCallback7(
696
797
  () => cancelMutation.mutateAsync(),
697
798
  [cancelMutation]
698
799
  );
@@ -706,12 +807,12 @@ function useOrder(orderNumber) {
706
807
  }
707
808
 
708
809
  // src/react/hooks/use-checkout.ts
709
- import { useState as useState2, useCallback as useCallback6 } from "react";
810
+ import { useState as useState4, useCallback as useCallback8 } from "react";
710
811
  import { useMutation as useMutation6, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
711
812
  function useCheckout() {
712
813
  const { client, storage } = useBehio();
713
814
  const queryClient = useQueryClient7();
714
- const [order, setOrder] = useState2(null);
815
+ const [order, setOrder] = useState4(null);
715
816
  const mutation = useMutation6({
716
817
  mutationFn: (input) => client.checkout.createOrder(input),
717
818
  onSuccess: (result) => {
@@ -721,11 +822,11 @@ function useCheckout() {
721
822
  queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
722
823
  }
723
824
  });
724
- const createOrder = useCallback6(
825
+ const createOrder = useCallback8(
725
826
  (input) => mutation.mutateAsync(input),
726
827
  [mutation]
727
828
  );
728
- const reset = useCallback6(() => {
829
+ const reset = useCallback8(() => {
729
830
  setOrder(null);
730
831
  mutation.reset();
731
832
  }, [mutation]);
@@ -739,36 +840,43 @@ function useCheckout() {
739
840
  }
740
841
 
741
842
  // src/react/hooks/use-pages.ts
742
- import { useQuery as useQuery15 } from "@tanstack/react-query";
743
- function usePages(locale) {
843
+ import { useQuery as useQuery13 } from "@tanstack/react-query";
844
+ function usePages(locale, options) {
744
845
  const { client } = useBehio();
745
- return useQuery15({
846
+ return useQuery13({
746
847
  queryKey: ["behio", "pages", locale],
747
848
  queryFn: async () => {
748
849
  const result = await client.pages.list(locale);
749
850
  return result.pages;
750
- }
851
+ },
852
+ enabled: options?.enabled !== false
751
853
  });
752
854
  }
753
- function usePage(slug, locale) {
855
+ function usePage(slug, locale, options) {
754
856
  const { client } = useBehio();
755
- return useQuery15({
857
+ return useQuery13({
756
858
  queryKey: ["behio", "page", slug, locale],
757
859
  queryFn: () => client.pages.get(slug, locale),
758
- enabled: !!slug
860
+ enabled: options?.enabled !== false && !!slug
759
861
  });
760
862
  }
761
863
 
762
864
  // src/react/hooks/use-shop-info.ts
763
- import { useQuery as useQuery16 } from "@tanstack/react-query";
764
- function useShopInfo() {
865
+ import { useQuery as useQuery14 } from "@tanstack/react-query";
866
+ function useShopInfo(options) {
765
867
  const { client } = useBehio();
766
- return useQuery16({
868
+ return useQuery14({
767
869
  queryKey: ["behio", "shop-info"],
768
- queryFn: () => client.getShopInfo()
870
+ queryFn: () => client.getShopInfo(),
871
+ enabled: options?.enabled !== false
769
872
  });
770
873
  }
771
874
 
875
+ // src/react/hooks/use-behio-client.ts
876
+ function useBehioClient() {
877
+ return useBehio().client;
878
+ }
879
+
772
880
  // src/react/utils/format-price.ts
773
881
  function formatPrice(amount, currency, locale) {
774
882
  const resolvedLocale = locale ?? "cs";
@@ -794,9 +902,11 @@ export {
794
902
  useAddresses,
795
903
  useAuth,
796
904
  useBehio,
905
+ useBehioClient,
797
906
  useCart,
798
907
  useCartCount,
799
908
  useCategories,
909
+ useCategory,
800
910
  useCheckout,
801
911
  useCustomer,
802
912
  useFeatured,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behio/storefront-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "TypeScript SDK for Behio Headless E-Shop — core client + React hooks",
5
5
  "author": "Behio",
6
6
  "license": "MIT",