@behio/storefront-sdk 0.2.0 → 0.4.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/react.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BehioStorefront
3
- } from "./chunk-EFFPOXWL.mjs";
3
+ } from "./chunk-L5KVNLTD.mjs";
4
4
 
5
5
  // src/react/provider.tsx
6
6
  import { useRef, useEffect, useMemo } from "react";
@@ -158,6 +158,22 @@ function BehioProvider({
158
158
  // src/react/hooks/use-products.ts
159
159
  import { useCallback, useMemo as useMemo2, useState } from "react";
160
160
  import { useInfiniteQuery } from "@tanstack/react-query";
161
+
162
+ // src/react/utils/unwrap.ts
163
+ var UnwrappedError = class extends Error {
164
+ constructor(sdkError) {
165
+ super(sdkError.message);
166
+ this.name = "UnwrappedError";
167
+ this.sdkError = sdkError;
168
+ }
169
+ };
170
+ async function unwrap(p) {
171
+ const res = await p;
172
+ if (res.error) throw new UnwrappedError(res.error);
173
+ return res.data;
174
+ }
175
+
176
+ // src/react/hooks/use-products.ts
161
177
  function useProducts(query) {
162
178
  const { client } = useBehio();
163
179
  const { initialData, enabled, page: initialPage, limit, ...filters } = query ?? {};
@@ -165,7 +181,7 @@ function useProducts(query) {
165
181
  const serializedFilters = useMemo2(() => JSON.stringify({ ...filters, limit }), [filters, limit]);
166
182
  const infinite = useInfiniteQuery({
167
183
  queryKey: ["behio", "products", serializedFilters, page],
168
- queryFn: ({ pageParam }) => client.catalog.getProducts({ ...filters, limit, page: pageParam }),
184
+ queryFn: ({ pageParam }) => unwrap(client.catalog.getProducts({ ...filters, limit, page: pageParam })),
169
185
  initialPageParam: page,
170
186
  getNextPageParam: (lastPage2) => lastPage2.page < lastPage2.totalPages ? lastPage2.page + 1 : void 0,
171
187
  getPreviousPageParam: (firstPage2) => firstPage2.page > 1 ? firstPage2.page - 1 : void 0,
@@ -228,10 +244,10 @@ function useProduct(slug, options) {
228
244
  const { client } = useBehio();
229
245
  return useQuery({
230
246
  queryKey: ["behio", "product", slug],
231
- queryFn: () => client.catalog.getProduct(slug, {
247
+ queryFn: () => unwrap(client.catalog.getProduct(slug, {
232
248
  locale: options?.locale,
233
249
  currency: options?.currency
234
- }),
250
+ })),
235
251
  initialData: options?.initialData,
236
252
  enabled: options?.enabled !== false && !!slug
237
253
  });
@@ -244,7 +260,7 @@ function useCategories(locale, options) {
244
260
  return useQuery2({
245
261
  queryKey: ["behio", "categories", locale],
246
262
  queryFn: async () => {
247
- const result = await client.catalog.getCategories(locale);
263
+ const result = await unwrap(client.catalog.getCategories(locale));
248
264
  return result.categories;
249
265
  },
250
266
  enabled: options?.enabled !== false
@@ -254,7 +270,7 @@ function useCategory(slug, options) {
254
270
  const { client } = useBehio();
255
271
  return useQuery2({
256
272
  queryKey: ["behio", "category", slug, options?.locale],
257
- queryFn: () => client.catalog.getCategory(slug, options?.locale),
273
+ queryFn: () => unwrap(client.catalog.getCategory(slug, options?.locale)),
258
274
  enabled: options?.enabled !== false && !!slug
259
275
  });
260
276
  }
@@ -266,7 +282,7 @@ function useLabels(locale, options) {
266
282
  return useQuery3({
267
283
  queryKey: ["behio", "labels", locale],
268
284
  queryFn: async () => {
269
- const result = await client.catalog.getLabels(locale);
285
+ const result = await unwrap(client.catalog.getLabels(locale));
270
286
  return result.labels;
271
287
  },
272
288
  enabled: options?.enabled !== false
@@ -279,10 +295,10 @@ function useFeatured(options) {
279
295
  const { client } = useBehio();
280
296
  return useQuery4({
281
297
  queryKey: ["behio", "featured", options?.locale, options?.currency],
282
- queryFn: () => client.catalog.getFeatured({
298
+ queryFn: () => unwrap(client.catalog.getFeatured({
283
299
  locale: options?.locale,
284
300
  currency: options?.currency
285
- }),
301
+ })),
286
302
  initialData: options?.initialData,
287
303
  enabled: options?.enabled !== false
288
304
  });
@@ -295,7 +311,7 @@ function useFilters(options) {
295
311
  return useQuery5({
296
312
  queryKey: ["behio", "filters"],
297
313
  queryFn: async () => {
298
- const result = await client.catalog.getFilters();
314
+ const result = await unwrap(client.catalog.getFilters());
299
315
  return result.filters;
300
316
  },
301
317
  enabled: options?.enabled !== false
@@ -319,10 +335,10 @@ function useSearch(query, options) {
319
335
  }, [query, debounceMs]);
320
336
  return useQuery6({
321
337
  queryKey: ["behio", "search", debouncedQuery, options?.page, options?.limit],
322
- queryFn: () => client.catalog.search(debouncedQuery, {
338
+ queryFn: () => unwrap(client.catalog.search(debouncedQuery, {
323
339
  page: options?.page,
324
340
  limit: options?.limit
325
- }),
341
+ })),
326
342
  enabled: options?.enabled !== false && debouncedQuery.length > 0
327
343
  });
328
344
  }
@@ -340,13 +356,13 @@ function useCart(options) {
340
356
  error
341
357
  } = useQuery7({
342
358
  queryKey: [...CART_KEY],
343
- queryFn: () => client.cart.get(),
359
+ queryFn: () => unwrap(client.cart.get()),
344
360
  // Only fetch if we have a cart session or are logged in
345
361
  enabled: options?.enabled !== false && (!!client.getCartSession() || !!client.getAccessToken())
346
362
  });
347
363
  const addMutation = useMutation({
348
364
  mutationFn: async ({ productId, quantity }) => {
349
- return client.cart.addItem({ productId, quantity: quantity ?? 1 });
365
+ return unwrap(client.cart.addItem({ productId, quantity: quantity ?? 1 }));
350
366
  },
351
367
  onSuccess: (result) => {
352
368
  if (result.newSessionToken) {
@@ -357,7 +373,7 @@ function useCart(options) {
357
373
  });
358
374
  const updateMutation = useMutation({
359
375
  mutationFn: async ({ itemId, quantity }) => {
360
- return client.cart.updateQuantity(itemId, quantity);
376
+ return unwrap(client.cart.updateQuantity(itemId, quantity));
361
377
  },
362
378
  onMutate: async ({ itemId, quantity }) => {
363
379
  await queryClient.cancelQueries({ queryKey: [...CART_KEY] });
@@ -385,7 +401,7 @@ function useCart(options) {
385
401
  });
386
402
  const removeMutation = useMutation({
387
403
  mutationFn: async (itemId) => {
388
- return client.cart.removeItem(itemId);
404
+ return unwrap(client.cart.removeItem(itemId));
389
405
  },
390
406
  onMutate: async (itemId) => {
391
407
  await queryClient.cancelQueries({ queryKey: [...CART_KEY] });
@@ -410,7 +426,7 @@ function useCart(options) {
410
426
  }
411
427
  });
412
428
  const clearMutation = useMutation({
413
- mutationFn: () => client.cart.clear(),
429
+ mutationFn: () => unwrap(client.cart.clear()),
414
430
  onSuccess: () => {
415
431
  queryClient.setQueryData([...CART_KEY], null);
416
432
  client.clearCartSession();
@@ -418,19 +434,19 @@ function useCart(options) {
418
434
  }
419
435
  });
420
436
  const applyDiscountMutation = useMutation({
421
- mutationFn: (code) => client.cart.applyDiscount(code),
437
+ mutationFn: (code) => unwrap(client.cart.applyDiscount(code)),
422
438
  onSuccess: (result) => {
423
439
  queryClient.setQueryData([...CART_KEY], result);
424
440
  }
425
441
  });
426
442
  const removeDiscountMutation = useMutation({
427
- mutationFn: () => client.cart.removeDiscount(),
443
+ mutationFn: () => unwrap(client.cart.removeDiscount()),
428
444
  onSuccess: (result) => {
429
445
  queryClient.setQueryData([...CART_KEY], result);
430
446
  }
431
447
  });
432
448
  const mergeMutation = useMutation({
433
- mutationFn: () => client.cart.merge(),
449
+ mutationFn: () => unwrap(client.cart.merge()),
434
450
  onSuccess: (result) => {
435
451
  queryClient.setQueryData([...CART_KEY], result);
436
452
  client.clearCartSession();
@@ -496,7 +512,7 @@ function useCartCount(options) {
496
512
  const cachedCart = queryClient.getQueryData([...CART_KEY2]);
497
513
  const { data } = useQuery8({
498
514
  queryKey: [...CART_KEY2],
499
- queryFn: () => client.cart.get(),
515
+ queryFn: () => unwrap(client.cart.get()),
500
516
  enabled: options?.enabled !== false && !cachedCart && (!!client.getCartSession() || !!client.getAccessToken())
501
517
  });
502
518
  const cart = cachedCart ?? data;
@@ -517,7 +533,7 @@ function useAuth() {
517
533
  isLoading
518
534
  } = useQuery9({
519
535
  queryKey: [...CUSTOMER_KEY],
520
- queryFn: () => client.customer.getProfile(),
536
+ queryFn: () => unwrap(client.customer.getProfile()),
521
537
  enabled: isLoggedIn
522
538
  });
523
539
  const persistTokens = useCallback3(
@@ -540,7 +556,7 @@ function useAuth() {
540
556
  await queryClient.invalidateQueries({ queryKey: [...CUSTOMER_KEY] });
541
557
  if (client.getCartSession()) {
542
558
  try {
543
- await client.cart.merge();
559
+ await unwrap(client.cart.merge());
544
560
  client.clearCartSession();
545
561
  storage.remove(STORAGE_KEYS.CART_SESSION);
546
562
  } catch {
@@ -550,7 +566,7 @@ function useAuth() {
550
566
  }, [client, storage, queryClient]);
551
567
  const loginMutation = useMutation2({
552
568
  mutationFn: async ({ email, password }) => {
553
- return client.auth.login({ email, password });
569
+ return unwrap(client.auth.login({ email, password }));
554
570
  },
555
571
  onSuccess: async (tokens) => {
556
572
  persistTokens(tokens);
@@ -559,7 +575,7 @@ function useAuth() {
559
575
  });
560
576
  const registerMutation = useMutation2({
561
577
  mutationFn: async (input) => {
562
- return client.auth.register(input);
578
+ return unwrap(client.auth.register(input));
563
579
  },
564
580
  onSuccess: async (tokens) => {
565
581
  persistTokens(tokens);
@@ -567,19 +583,19 @@ function useAuth() {
567
583
  }
568
584
  });
569
585
  const logoutMutation = useMutation2({
570
- mutationFn: () => client.auth.logout(),
586
+ mutationFn: () => unwrap(client.auth.logout()),
571
587
  onSettled: () => {
572
588
  clearAuth();
573
589
  }
574
590
  });
575
591
  const forgotPasswordMutation = useMutation2({
576
- mutationFn: (email) => client.auth.forgotPassword(email)
592
+ mutationFn: (email) => unwrap(client.auth.forgotPassword(email))
577
593
  });
578
594
  const resetPasswordMutation = useMutation2({
579
- mutationFn: ({ token, newPassword }) => client.auth.resetPassword(token, newPassword)
595
+ mutationFn: ({ token, newPassword }) => unwrap(client.auth.resetPassword(token, newPassword))
580
596
  });
581
597
  const verifyEmailMutation = useMutation2({
582
- mutationFn: (token) => client.auth.verifyEmail(token)
598
+ mutationFn: (token) => unwrap(client.auth.verifyEmail(token))
583
599
  });
584
600
  const login = useCallback3(
585
601
  (email, password) => loginMutation.mutateAsync({ email, password }).then(() => void 0),
@@ -637,11 +653,11 @@ function useCustomer(options) {
637
653
  error
638
654
  } = useQuery10({
639
655
  queryKey: [...CUSTOMER_KEY2],
640
- queryFn: () => client.customer.getProfile(),
656
+ queryFn: () => unwrap(client.customer.getProfile()),
641
657
  enabled: options?.enabled !== false && !!client.getAccessToken()
642
658
  });
643
659
  const updateMutation = useMutation3({
644
- mutationFn: (data2) => client.customer.updateProfile(data2),
660
+ mutationFn: (data2) => unwrap(client.customer.updateProfile(data2)),
645
661
  onSuccess: (updated) => {
646
662
  queryClient.setQueryData([...CUSTOMER_KEY2], updated);
647
663
  }
@@ -673,25 +689,25 @@ function useAddresses(options) {
673
689
  } = useQuery11({
674
690
  queryKey: [...ADDRESSES_KEY],
675
691
  queryFn: async () => {
676
- const result = await client.customer.getAddresses();
692
+ const result = await unwrap(client.customer.getAddresses());
677
693
  return result.items;
678
694
  },
679
695
  enabled: options?.enabled !== false && !!client.getAccessToken()
680
696
  });
681
697
  const createMutation = useMutation4({
682
- mutationFn: (address) => client.customer.createAddress(address),
698
+ mutationFn: (address) => unwrap(client.customer.createAddress(address)),
683
699
  onSuccess: () => {
684
700
  queryClient.invalidateQueries({ queryKey: [...ADDRESSES_KEY] });
685
701
  }
686
702
  });
687
703
  const updateMutation = useMutation4({
688
- mutationFn: ({ addressId, data: data2 }) => client.customer.updateAddress(addressId, data2),
704
+ mutationFn: ({ addressId, data: data2 }) => unwrap(client.customer.updateAddress(addressId, data2)),
689
705
  onSuccess: () => {
690
706
  queryClient.invalidateQueries({ queryKey: [...ADDRESSES_KEY] });
691
707
  }
692
708
  });
693
709
  const deleteMutation = useMutation4({
694
- mutationFn: (addressId) => client.customer.deleteAddress(addressId),
710
+ mutationFn: (addressId) => unwrap(client.customer.deleteAddress(addressId)),
695
711
  onSuccess: () => {
696
712
  queryClient.invalidateQueries({ queryKey: [...ADDRESSES_KEY] });
697
713
  }
@@ -720,16 +736,80 @@ function useAddresses(options) {
720
736
  };
721
737
  }
722
738
 
739
+ // src/react/hooks/use-address-autocomplete.ts
740
+ import { useState as useState3, useEffect as useEffect3, useRef as useRef2, useCallback as useCallback6 } from "react";
741
+ import { useQuery as useQuery12 } from "@tanstack/react-query";
742
+ var AC_KEY = ["behio", "address-autocomplete"];
743
+ function useAddressAutocomplete(options) {
744
+ const { country, debounce = 300, minChars = 3, enabled = true } = options;
745
+ const { client } = useBehio();
746
+ const [query, setQuery] = useState3("");
747
+ const [debouncedQuery, setDebouncedQuery] = useState3("");
748
+ const [selected, setSelected] = useState3(null);
749
+ const [isSelecting, setIsSelecting] = useState3(false);
750
+ const timerRef = useRef2(void 0);
751
+ useEffect3(() => {
752
+ if (timerRef.current) clearTimeout(timerRef.current);
753
+ if (query.length < minChars) {
754
+ setDebouncedQuery("");
755
+ return;
756
+ }
757
+ timerRef.current = setTimeout(() => {
758
+ setDebouncedQuery(query);
759
+ }, debounce);
760
+ return () => {
761
+ if (timerRef.current) clearTimeout(timerRef.current);
762
+ };
763
+ }, [query, debounce, minChars]);
764
+ const { data, isLoading } = useQuery12({
765
+ queryKey: [...AC_KEY, debouncedQuery, country],
766
+ queryFn: () => unwrap(client.addresses.autocomplete(debouncedQuery, country)),
767
+ enabled: enabled && debouncedQuery.length >= minChars,
768
+ staleTime: 6e4
769
+ // Cache suggestions for 1 min
770
+ });
771
+ const select = useCallback6(
772
+ async (placeId) => {
773
+ setIsSelecting(true);
774
+ try {
775
+ const detail = await unwrap(client.addresses.getDetail(placeId));
776
+ setSelected(detail);
777
+ setQuery(detail.formattedAddress);
778
+ setDebouncedQuery("");
779
+ return detail;
780
+ } finally {
781
+ setIsSelecting(false);
782
+ }
783
+ },
784
+ [client]
785
+ );
786
+ const clear = useCallback6(() => {
787
+ setQuery("");
788
+ setDebouncedQuery("");
789
+ setSelected(null);
790
+ }, []);
791
+ return {
792
+ query,
793
+ setQuery,
794
+ suggestions: data?.suggestions ?? [],
795
+ isLoading: isLoading && debouncedQuery.length >= minChars,
796
+ select,
797
+ selected,
798
+ isSelecting,
799
+ clear
800
+ };
801
+ }
802
+
723
803
  // src/react/hooks/use-orders.ts
724
- import { useCallback as useCallback6, useMemo as useMemo3, useState as useState3 } from "react";
804
+ import { useCallback as useCallback7, useMemo as useMemo3, useState as useState4 } from "react";
725
805
  import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
726
806
  function useOrders(options) {
727
807
  const { client } = useBehio();
728
808
  const { page: initialPage, limit, enabled } = options ?? {};
729
- const [page, setPage] = useState3(initialPage ?? 1);
809
+ const [page, setPage] = useState4(initialPage ?? 1);
730
810
  const infinite = useInfiniteQuery2({
731
811
  queryKey: ["behio", "orders", limit, page],
732
- queryFn: ({ pageParam }) => client.orders.list({ limit, page: pageParam }),
812
+ queryFn: ({ pageParam }) => unwrap(client.orders.list({ limit, page: pageParam })),
733
813
  initialPageParam: page,
734
814
  getNextPageParam: (lastPage2) => lastPage2.page < lastPage2.totalPages ? lastPage2.page + 1 : void 0,
735
815
  getPreviousPageParam: (firstPage) => firstPage.page > 1 ? firstPage.page - 1 : void 0,
@@ -740,13 +820,13 @@ function useOrders(options) {
740
820
  [infinite.data]
741
821
  );
742
822
  const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
743
- const loadMore = useCallback6(() => {
823
+ const loadMore = useCallback7(() => {
744
824
  if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
745
825
  return infinite.fetchNextPage();
746
826
  }
747
827
  return Promise.resolve();
748
828
  }, [infinite]);
749
- const goToPage = useCallback6((newPage) => {
829
+ const goToPage = useCallback7((newPage) => {
750
830
  setPage(newPage);
751
831
  }, []);
752
832
  return {
@@ -772,28 +852,28 @@ function useOrders(options) {
772
852
  }
773
853
 
774
854
  // src/react/hooks/use-order.ts
775
- import { useCallback as useCallback7 } from "react";
776
- import { useQuery as useQuery12, useMutation as useMutation5, useQueryClient as useQueryClient6 } from "@tanstack/react-query";
855
+ import { useCallback as useCallback8 } from "react";
856
+ import { useQuery as useQuery13, useMutation as useMutation5, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
777
857
  function useOrder(orderNumber, options) {
778
858
  const { client } = useBehio();
779
- const queryClient = useQueryClient6();
859
+ const queryClient = useQueryClient7();
780
860
  const {
781
861
  data,
782
862
  isLoading,
783
863
  error
784
- } = useQuery12({
864
+ } = useQuery13({
785
865
  queryKey: ["behio", "order", orderNumber],
786
- queryFn: () => client.orders.get(orderNumber),
866
+ queryFn: () => unwrap(client.orders.get(orderNumber)),
787
867
  enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
788
868
  });
789
869
  const cancelMutation = useMutation5({
790
- mutationFn: () => client.orders.cancel(orderNumber),
870
+ mutationFn: () => unwrap(client.orders.cancel(orderNumber)),
791
871
  onSuccess: (updated) => {
792
872
  queryClient.setQueryData(["behio", "order", orderNumber], updated);
793
873
  queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
794
874
  }
795
875
  });
796
- const cancel = useCallback7(
876
+ const cancel = useCallback8(
797
877
  () => cancelMutation.mutateAsync(),
798
878
  [cancelMutation]
799
879
  );
@@ -807,14 +887,14 @@ function useOrder(orderNumber, options) {
807
887
  }
808
888
 
809
889
  // src/react/hooks/use-checkout.ts
810
- import { useState as useState4, useCallback as useCallback8 } from "react";
811
- import { useMutation as useMutation6, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
890
+ import { useState as useState5, useCallback as useCallback9 } from "react";
891
+ import { useMutation as useMutation6, useQueryClient as useQueryClient8 } from "@tanstack/react-query";
812
892
  function useCheckout() {
813
893
  const { client, storage } = useBehio();
814
- const queryClient = useQueryClient7();
815
- const [order, setOrder] = useState4(null);
894
+ const queryClient = useQueryClient8();
895
+ const [order, setOrder] = useState5(null);
816
896
  const mutation = useMutation6({
817
- mutationFn: (input) => client.checkout.createOrder(input),
897
+ mutationFn: (input) => unwrap(client.checkout.createOrder(input)),
818
898
  onSuccess: (result) => {
819
899
  setOrder(result);
820
900
  storage.remove(STORAGE_KEYS.CART_SESSION);
@@ -822,11 +902,11 @@ function useCheckout() {
822
902
  queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
823
903
  }
824
904
  });
825
- const createOrder = useCallback8(
905
+ const createOrder = useCallback9(
826
906
  (input) => mutation.mutateAsync(input),
827
907
  [mutation]
828
908
  );
829
- const reset = useCallback8(() => {
909
+ const reset = useCallback9(() => {
830
910
  setOrder(null);
831
911
  mutation.reset();
832
912
  }, [mutation]);
@@ -840,13 +920,13 @@ function useCheckout() {
840
920
  }
841
921
 
842
922
  // src/react/hooks/use-pages.ts
843
- import { useQuery as useQuery13 } from "@tanstack/react-query";
923
+ import { useQuery as useQuery14 } from "@tanstack/react-query";
844
924
  function usePages(locale, options) {
845
925
  const { client } = useBehio();
846
- return useQuery13({
926
+ return useQuery14({
847
927
  queryKey: ["behio", "pages", locale],
848
928
  queryFn: async () => {
849
- const result = await client.pages.list(locale);
929
+ const result = await unwrap(client.pages.list(locale));
850
930
  return result.pages;
851
931
  },
852
932
  enabled: options?.enabled !== false
@@ -854,110 +934,110 @@ function usePages(locale, options) {
854
934
  }
855
935
  function usePage(slug, locale, options) {
856
936
  const { client } = useBehio();
857
- return useQuery13({
937
+ return useQuery14({
858
938
  queryKey: ["behio", "page", slug, locale],
859
- queryFn: () => client.pages.get(slug, locale),
939
+ queryFn: () => unwrap(client.pages.get(slug, locale)),
860
940
  enabled: options?.enabled !== false && !!slug
861
941
  });
862
942
  }
863
943
 
864
944
  // src/react/hooks/use-shop-info.ts
865
- import { useQuery as useQuery14 } from "@tanstack/react-query";
945
+ import { useQuery as useQuery15 } from "@tanstack/react-query";
866
946
  function useShopInfo(options) {
867
947
  const { client } = useBehio();
868
- return useQuery14({
948
+ return useQuery15({
869
949
  queryKey: ["behio", "shop-info"],
870
- queryFn: () => client.getShopInfo(),
950
+ queryFn: () => unwrap(client.getShopInfo()),
871
951
  enabled: options?.enabled !== false
872
952
  });
873
953
  }
874
954
 
875
955
  // src/react/hooks/use-shop-seo.ts
876
- import { useQuery as useQuery15 } from "@tanstack/react-query";
956
+ import { useQuery as useQuery16 } from "@tanstack/react-query";
877
957
  function useShopSeo(options) {
878
958
  const { client } = useBehio();
879
959
  const { locale, initialData, enabled = true } = options ?? {};
880
- return useQuery15({
960
+ return useQuery16({
881
961
  queryKey: ["behio", "shop-seo", locale ?? "_default"],
882
- queryFn: () => client.getShopSeo(locale),
962
+ queryFn: () => unwrap(client.getShopSeo(locale)),
883
963
  initialData,
884
964
  enabled
885
965
  });
886
966
  }
887
967
 
888
968
  // src/react/hooks/use-bundles.ts
889
- import { useQuery as useQuery16 } from "@tanstack/react-query";
969
+ import { useQuery as useQuery17 } from "@tanstack/react-query";
890
970
  function useBundles(options) {
891
971
  const { client } = useBehio();
892
- return useQuery16({
972
+ return useQuery17({
893
973
  queryKey: ["behio", "bundles"],
894
- queryFn: () => client.catalog.getBundles(),
974
+ queryFn: () => unwrap(client.catalog.getBundles()),
895
975
  enabled: options?.enabled ?? true,
896
976
  initialData: options?.initialData
897
977
  });
898
978
  }
899
979
  function useBundle(slug, options) {
900
980
  const { client } = useBehio();
901
- return useQuery16({
981
+ return useQuery17({
902
982
  queryKey: ["behio", "bundle", slug],
903
- queryFn: () => client.catalog.getBundle(slug),
983
+ queryFn: () => unwrap(client.catalog.getBundle(slug)),
904
984
  enabled: Boolean(slug) && (options?.enabled ?? true),
905
985
  initialData: options?.initialData
906
986
  });
907
987
  }
908
988
 
909
989
  // src/react/hooks/use-cross-sell.ts
910
- import { useQuery as useQuery17 } from "@tanstack/react-query";
990
+ import { useQuery as useQuery18 } from "@tanstack/react-query";
911
991
  function useCrossSell(productSlug, options) {
912
992
  const { client } = useBehio();
913
- return useQuery17({
993
+ return useQuery18({
914
994
  queryKey: ["behio", "cross-sell", productSlug],
915
- queryFn: () => client.catalog.getCrossSell(productSlug),
995
+ queryFn: () => unwrap(client.catalog.getCrossSell(productSlug)),
916
996
  enabled: Boolean(productSlug) && (options?.enabled ?? true),
917
997
  initialData: options?.initialData
918
998
  });
919
999
  }
920
1000
 
921
1001
  // src/react/hooks/use-product-promotions.ts
922
- import { useQuery as useQuery18 } from "@tanstack/react-query";
1002
+ import { useQuery as useQuery19 } from "@tanstack/react-query";
923
1003
  function useProductPromotions(productSlug, options) {
924
1004
  const { client } = useBehio();
925
- return useQuery18({
1005
+ return useQuery19({
926
1006
  queryKey: ["behio", "product-promotions", productSlug],
927
- queryFn: () => client.catalog.getProductPromotions(productSlug),
1007
+ queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
928
1008
  enabled: Boolean(productSlug) && (options?.enabled ?? true),
929
1009
  refetchInterval: options?.refetchIntervalMs
930
1010
  });
931
1011
  }
932
1012
 
933
1013
  // src/react/hooks/use-gift-card.ts
934
- import { useQuery as useQuery19 } from "@tanstack/react-query";
1014
+ import { useQuery as useQuery20 } from "@tanstack/react-query";
935
1015
  function useGiftCardBalance(code, options) {
936
1016
  const { client } = useBehio();
937
1017
  const trimmed = code?.trim();
938
- return useQuery19({
1018
+ return useQuery20({
939
1019
  queryKey: ["behio", "gift-card-balance", trimmed],
940
- queryFn: () => client.catalog.checkGiftCard(trimmed),
1020
+ queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
941
1021
  enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
942
1022
  });
943
1023
  }
944
1024
 
945
1025
  // src/react/hooks/use-wishlist.ts
946
- import { useQuery as useQuery20, useMutation as useMutation7, useQueryClient as useQueryClient8 } from "@tanstack/react-query";
1026
+ import { useQuery as useQuery21, useMutation as useMutation7, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
947
1027
  function useWishlist(options) {
948
1028
  const { client } = useBehio();
949
- const qc = useQueryClient8();
950
- const query = useQuery20({
1029
+ const qc = useQueryClient9();
1030
+ const query = useQuery21({
951
1031
  queryKey: ["behio", "wishlist"],
952
- queryFn: () => client.wishlist.get(),
1032
+ queryFn: () => unwrap(client.wishlist.get()),
953
1033
  enabled: options?.enabled ?? true
954
1034
  });
955
1035
  const addMutation = useMutation7({
956
- mutationFn: (productId) => client.wishlist.add(productId),
1036
+ mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
957
1037
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
958
1038
  });
959
1039
  const removeMutation = useMutation7({
960
- mutationFn: (productId) => client.wishlist.remove(productId),
1040
+ mutationFn: (productId) => unwrap(client.wishlist.remove(productId)),
961
1041
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
962
1042
  });
963
1043
  return {
@@ -970,65 +1050,65 @@ function useWishlist(options) {
970
1050
  }
971
1051
  function useIsInWishlist(productId) {
972
1052
  const { client } = useBehio();
973
- return useQuery20({
1053
+ return useQuery21({
974
1054
  queryKey: ["behio", "wishlist-check", productId],
975
- queryFn: () => client.wishlist.isInWishlist(productId),
1055
+ queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
976
1056
  enabled: Boolean(productId)
977
1057
  });
978
1058
  }
979
1059
 
980
1060
  // src/react/hooks/use-reviews.ts
981
- import { useQuery as useQuery21, useMutation as useMutation8, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
1061
+ import { useQuery as useQuery22, useMutation as useMutation8, useQueryClient as useQueryClient10 } from "@tanstack/react-query";
982
1062
  function useProductReviews(productId, options) {
983
1063
  const { client } = useBehio();
984
- return useQuery21({
1064
+ return useQuery22({
985
1065
  queryKey: ["behio", "reviews", productId, options?.page ?? 1],
986
- queryFn: () => client.reviews.getProductReviews(productId, options?.page, options?.limit),
1066
+ queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
987
1067
  enabled: Boolean(productId) && (options?.enabled ?? true)
988
1068
  });
989
1069
  }
990
1070
  function useSubmitReview() {
991
1071
  const { client } = useBehio();
992
- const qc = useQueryClient9();
1072
+ const qc = useQueryClient10();
993
1073
  return useMutation8({
994
- mutationFn: (input) => client.reviews.submit(input),
1074
+ mutationFn: (input) => unwrap(client.reviews.submit(input)),
995
1075
  onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
996
1076
  });
997
1077
  }
998
1078
 
999
1079
  // src/react/hooks/use-returns.ts
1000
- import { useQuery as useQuery22, useMutation as useMutation9 } from "@tanstack/react-query";
1080
+ import { useQuery as useQuery23, useMutation as useMutation9 } from "@tanstack/react-query";
1001
1081
  function useSubmitReturn() {
1002
1082
  const { client } = useBehio();
1003
1083
  return useMutation9({
1004
- mutationFn: (input) => client.returns.submit(input)
1084
+ mutationFn: (input) => unwrap(client.returns.submit(input))
1005
1085
  });
1006
1086
  }
1007
1087
  function useReturnStatus(returnId, email) {
1008
1088
  const { client } = useBehio();
1009
- return useQuery22({
1089
+ return useQuery23({
1010
1090
  queryKey: ["behio", "return-status", returnId],
1011
- queryFn: () => client.returns.getStatus(returnId, email),
1091
+ queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
1012
1092
  enabled: Boolean(returnId && email)
1013
1093
  });
1014
1094
  }
1015
1095
 
1016
1096
  // src/react/hooks/use-consent.ts
1017
- import { useQuery as useQuery23, useMutation as useMutation10, useQueryClient as useQueryClient10 } from "@tanstack/react-query";
1097
+ import { useQuery as useQuery24, useMutation as useMutation10, useQueryClient as useQueryClient11 } from "@tanstack/react-query";
1018
1098
  function useCookieConsent(visitorId) {
1019
1099
  const { client } = useBehio();
1020
- const qc = useQueryClient10();
1021
- const query = useQuery23({
1100
+ const qc = useQueryClient11();
1101
+ const query = useQuery24({
1022
1102
  queryKey: ["behio", "consent", visitorId],
1023
- queryFn: () => client.consent.get(visitorId),
1103
+ queryFn: () => unwrap(client.consent.get(visitorId)),
1024
1104
  enabled: Boolean(visitorId)
1025
1105
  });
1026
1106
  const recordMutation = useMutation10({
1027
- mutationFn: (input) => client.consent.record(input),
1107
+ mutationFn: (input) => unwrap(client.consent.record(input)),
1028
1108
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
1029
1109
  });
1030
1110
  const revokeMutation = useMutation10({
1031
- mutationFn: () => client.consent.revoke(visitorId),
1111
+ mutationFn: () => unwrap(client.consent.revoke(visitorId)),
1032
1112
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
1033
1113
  });
1034
1114
  return {
@@ -1039,18 +1119,18 @@ function useCookieConsent(visitorId) {
1039
1119
  }
1040
1120
 
1041
1121
  // src/react/hooks/use-quotes.ts
1042
- import { useMutation as useMutation11, useQuery as useQuery24 } from "@tanstack/react-query";
1122
+ import { useMutation as useMutation11, useQuery as useQuery25 } from "@tanstack/react-query";
1043
1123
  function useSubmitQuote() {
1044
1124
  const { client } = useBehio();
1045
1125
  return useMutation11({
1046
- mutationFn: (input) => client.quotes.submit(input)
1126
+ mutationFn: (input) => unwrap(client.quotes.submit(input))
1047
1127
  });
1048
1128
  }
1049
1129
  function useQuoteStatus(quoteId) {
1050
1130
  const { client } = useBehio();
1051
- return useQuery24({
1131
+ return useQuery25({
1052
1132
  queryKey: ["behio", "quote-status", quoteId],
1053
- queryFn: () => client.quotes.getStatus(quoteId),
1133
+ queryFn: () => unwrap(client.quotes.getStatus(quoteId)),
1054
1134
  enabled: Boolean(quoteId)
1055
1135
  });
1056
1136
  }
@@ -1082,6 +1162,7 @@ export {
1082
1162
  formatPrice,
1083
1163
  localStorageAdapter,
1084
1164
  memoryStorage,
1165
+ useAddressAutocomplete,
1085
1166
  useAddresses,
1086
1167
  useAuth,
1087
1168
  useBehio,