@behio/storefront-sdk 0.3.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-45FTJKSW.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
  }
@@ -747,7 +763,7 @@ function useAddressAutocomplete(options) {
747
763
  }, [query, debounce, minChars]);
748
764
  const { data, isLoading } = useQuery12({
749
765
  queryKey: [...AC_KEY, debouncedQuery, country],
750
- queryFn: () => client.addresses.autocomplete(debouncedQuery, country),
766
+ queryFn: () => unwrap(client.addresses.autocomplete(debouncedQuery, country)),
751
767
  enabled: enabled && debouncedQuery.length >= minChars,
752
768
  staleTime: 6e4
753
769
  // Cache suggestions for 1 min
@@ -756,7 +772,7 @@ function useAddressAutocomplete(options) {
756
772
  async (placeId) => {
757
773
  setIsSelecting(true);
758
774
  try {
759
- const detail = await client.addresses.getDetail(placeId);
775
+ const detail = await unwrap(client.addresses.getDetail(placeId));
760
776
  setSelected(detail);
761
777
  setQuery(detail.formattedAddress);
762
778
  setDebouncedQuery("");
@@ -793,7 +809,7 @@ function useOrders(options) {
793
809
  const [page, setPage] = useState4(initialPage ?? 1);
794
810
  const infinite = useInfiniteQuery2({
795
811
  queryKey: ["behio", "orders", limit, page],
796
- queryFn: ({ pageParam }) => client.orders.list({ limit, page: pageParam }),
812
+ queryFn: ({ pageParam }) => unwrap(client.orders.list({ limit, page: pageParam })),
797
813
  initialPageParam: page,
798
814
  getNextPageParam: (lastPage2) => lastPage2.page < lastPage2.totalPages ? lastPage2.page + 1 : void 0,
799
815
  getPreviousPageParam: (firstPage) => firstPage.page > 1 ? firstPage.page - 1 : void 0,
@@ -847,11 +863,11 @@ function useOrder(orderNumber, options) {
847
863
  error
848
864
  } = useQuery13({
849
865
  queryKey: ["behio", "order", orderNumber],
850
- queryFn: () => client.orders.get(orderNumber),
866
+ queryFn: () => unwrap(client.orders.get(orderNumber)),
851
867
  enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
852
868
  });
853
869
  const cancelMutation = useMutation5({
854
- mutationFn: () => client.orders.cancel(orderNumber),
870
+ mutationFn: () => unwrap(client.orders.cancel(orderNumber)),
855
871
  onSuccess: (updated) => {
856
872
  queryClient.setQueryData(["behio", "order", orderNumber], updated);
857
873
  queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
@@ -878,7 +894,7 @@ function useCheckout() {
878
894
  const queryClient = useQueryClient8();
879
895
  const [order, setOrder] = useState5(null);
880
896
  const mutation = useMutation6({
881
- mutationFn: (input) => client.checkout.createOrder(input),
897
+ mutationFn: (input) => unwrap(client.checkout.createOrder(input)),
882
898
  onSuccess: (result) => {
883
899
  setOrder(result);
884
900
  storage.remove(STORAGE_KEYS.CART_SESSION);
@@ -910,7 +926,7 @@ function usePages(locale, options) {
910
926
  return useQuery14({
911
927
  queryKey: ["behio", "pages", locale],
912
928
  queryFn: async () => {
913
- const result = await client.pages.list(locale);
929
+ const result = await unwrap(client.pages.list(locale));
914
930
  return result.pages;
915
931
  },
916
932
  enabled: options?.enabled !== false
@@ -920,7 +936,7 @@ function usePage(slug, locale, options) {
920
936
  const { client } = useBehio();
921
937
  return useQuery14({
922
938
  queryKey: ["behio", "page", slug, locale],
923
- queryFn: () => client.pages.get(slug, locale),
939
+ queryFn: () => unwrap(client.pages.get(slug, locale)),
924
940
  enabled: options?.enabled !== false && !!slug
925
941
  });
926
942
  }
@@ -931,7 +947,7 @@ function useShopInfo(options) {
931
947
  const { client } = useBehio();
932
948
  return useQuery15({
933
949
  queryKey: ["behio", "shop-info"],
934
- queryFn: () => client.getShopInfo(),
950
+ queryFn: () => unwrap(client.getShopInfo()),
935
951
  enabled: options?.enabled !== false
936
952
  });
937
953
  }
@@ -943,7 +959,7 @@ function useShopSeo(options) {
943
959
  const { locale, initialData, enabled = true } = options ?? {};
944
960
  return useQuery16({
945
961
  queryKey: ["behio", "shop-seo", locale ?? "_default"],
946
- queryFn: () => client.getShopSeo(locale),
962
+ queryFn: () => unwrap(client.getShopSeo(locale)),
947
963
  initialData,
948
964
  enabled
949
965
  });
@@ -955,7 +971,7 @@ function useBundles(options) {
955
971
  const { client } = useBehio();
956
972
  return useQuery17({
957
973
  queryKey: ["behio", "bundles"],
958
- queryFn: () => client.catalog.getBundles(),
974
+ queryFn: () => unwrap(client.catalog.getBundles()),
959
975
  enabled: options?.enabled ?? true,
960
976
  initialData: options?.initialData
961
977
  });
@@ -964,7 +980,7 @@ function useBundle(slug, options) {
964
980
  const { client } = useBehio();
965
981
  return useQuery17({
966
982
  queryKey: ["behio", "bundle", slug],
967
- queryFn: () => client.catalog.getBundle(slug),
983
+ queryFn: () => unwrap(client.catalog.getBundle(slug)),
968
984
  enabled: Boolean(slug) && (options?.enabled ?? true),
969
985
  initialData: options?.initialData
970
986
  });
@@ -976,7 +992,7 @@ function useCrossSell(productSlug, options) {
976
992
  const { client } = useBehio();
977
993
  return useQuery18({
978
994
  queryKey: ["behio", "cross-sell", productSlug],
979
- queryFn: () => client.catalog.getCrossSell(productSlug),
995
+ queryFn: () => unwrap(client.catalog.getCrossSell(productSlug)),
980
996
  enabled: Boolean(productSlug) && (options?.enabled ?? true),
981
997
  initialData: options?.initialData
982
998
  });
@@ -988,7 +1004,7 @@ function useProductPromotions(productSlug, options) {
988
1004
  const { client } = useBehio();
989
1005
  return useQuery19({
990
1006
  queryKey: ["behio", "product-promotions", productSlug],
991
- queryFn: () => client.catalog.getProductPromotions(productSlug),
1007
+ queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
992
1008
  enabled: Boolean(productSlug) && (options?.enabled ?? true),
993
1009
  refetchInterval: options?.refetchIntervalMs
994
1010
  });
@@ -1001,7 +1017,7 @@ function useGiftCardBalance(code, options) {
1001
1017
  const trimmed = code?.trim();
1002
1018
  return useQuery20({
1003
1019
  queryKey: ["behio", "gift-card-balance", trimmed],
1004
- queryFn: () => client.catalog.checkGiftCard(trimmed),
1020
+ queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
1005
1021
  enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
1006
1022
  });
1007
1023
  }
@@ -1013,15 +1029,15 @@ function useWishlist(options) {
1013
1029
  const qc = useQueryClient9();
1014
1030
  const query = useQuery21({
1015
1031
  queryKey: ["behio", "wishlist"],
1016
- queryFn: () => client.wishlist.get(),
1032
+ queryFn: () => unwrap(client.wishlist.get()),
1017
1033
  enabled: options?.enabled ?? true
1018
1034
  });
1019
1035
  const addMutation = useMutation7({
1020
- mutationFn: (productId) => client.wishlist.add(productId),
1036
+ mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
1021
1037
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
1022
1038
  });
1023
1039
  const removeMutation = useMutation7({
1024
- mutationFn: (productId) => client.wishlist.remove(productId),
1040
+ mutationFn: (productId) => unwrap(client.wishlist.remove(productId)),
1025
1041
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
1026
1042
  });
1027
1043
  return {
@@ -1036,7 +1052,7 @@ function useIsInWishlist(productId) {
1036
1052
  const { client } = useBehio();
1037
1053
  return useQuery21({
1038
1054
  queryKey: ["behio", "wishlist-check", productId],
1039
- queryFn: () => client.wishlist.isInWishlist(productId),
1055
+ queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
1040
1056
  enabled: Boolean(productId)
1041
1057
  });
1042
1058
  }
@@ -1047,7 +1063,7 @@ function useProductReviews(productId, options) {
1047
1063
  const { client } = useBehio();
1048
1064
  return useQuery22({
1049
1065
  queryKey: ["behio", "reviews", productId, options?.page ?? 1],
1050
- queryFn: () => client.reviews.getProductReviews(productId, options?.page, options?.limit),
1066
+ queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
1051
1067
  enabled: Boolean(productId) && (options?.enabled ?? true)
1052
1068
  });
1053
1069
  }
@@ -1055,7 +1071,7 @@ function useSubmitReview() {
1055
1071
  const { client } = useBehio();
1056
1072
  const qc = useQueryClient10();
1057
1073
  return useMutation8({
1058
- mutationFn: (input) => client.reviews.submit(input),
1074
+ mutationFn: (input) => unwrap(client.reviews.submit(input)),
1059
1075
  onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
1060
1076
  });
1061
1077
  }
@@ -1065,14 +1081,14 @@ import { useQuery as useQuery23, useMutation as useMutation9 } from "@tanstack/r
1065
1081
  function useSubmitReturn() {
1066
1082
  const { client } = useBehio();
1067
1083
  return useMutation9({
1068
- mutationFn: (input) => client.returns.submit(input)
1084
+ mutationFn: (input) => unwrap(client.returns.submit(input))
1069
1085
  });
1070
1086
  }
1071
1087
  function useReturnStatus(returnId, email) {
1072
1088
  const { client } = useBehio();
1073
1089
  return useQuery23({
1074
1090
  queryKey: ["behio", "return-status", returnId],
1075
- queryFn: () => client.returns.getStatus(returnId, email),
1091
+ queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
1076
1092
  enabled: Boolean(returnId && email)
1077
1093
  });
1078
1094
  }
@@ -1084,15 +1100,15 @@ function useCookieConsent(visitorId) {
1084
1100
  const qc = useQueryClient11();
1085
1101
  const query = useQuery24({
1086
1102
  queryKey: ["behio", "consent", visitorId],
1087
- queryFn: () => client.consent.get(visitorId),
1103
+ queryFn: () => unwrap(client.consent.get(visitorId)),
1088
1104
  enabled: Boolean(visitorId)
1089
1105
  });
1090
1106
  const recordMutation = useMutation10({
1091
- mutationFn: (input) => client.consent.record(input),
1107
+ mutationFn: (input) => unwrap(client.consent.record(input)),
1092
1108
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
1093
1109
  });
1094
1110
  const revokeMutation = useMutation10({
1095
- mutationFn: () => client.consent.revoke(visitorId),
1111
+ mutationFn: () => unwrap(client.consent.revoke(visitorId)),
1096
1112
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
1097
1113
  });
1098
1114
  return {
@@ -1107,14 +1123,14 @@ import { useMutation as useMutation11, useQuery as useQuery25 } from "@tanstack/
1107
1123
  function useSubmitQuote() {
1108
1124
  const { client } = useBehio();
1109
1125
  return useMutation11({
1110
- mutationFn: (input) => client.quotes.submit(input)
1126
+ mutationFn: (input) => unwrap(client.quotes.submit(input))
1111
1127
  });
1112
1128
  }
1113
1129
  function useQuoteStatus(quoteId) {
1114
1130
  const { client } = useBehio();
1115
1131
  return useQuery25({
1116
1132
  queryKey: ["behio", "quote-status", quoteId],
1117
- queryFn: () => client.quotes.getStatus(quoteId),
1133
+ queryFn: () => unwrap(client.quotes.getStatus(quoteId)),
1118
1134
  enabled: Boolean(quoteId)
1119
1135
  });
1120
1136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behio/storefront-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "TypeScript SDK for Behio Headless E-Shop — core client + React hooks",
5
5
  "author": "Behio",
6
6
  "license": "MIT",