@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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkR7H7E5BXjs = require('./chunk-R7H7E5BX.js');
3
+ var _chunkYLKO3SURjs = require('./chunk-YLKO3SUR.js');
4
4
 
5
5
  // src/react/provider.tsx
6
6
  var _react = require('react');
@@ -114,7 +114,7 @@ function BehioProvider({
114
114
  const storageAdapter = _react.useMemo.call(void 0, () => resolveStorage(storageOption), [storageOption]);
115
115
  const clientRef = _react.useRef.call(void 0, null);
116
116
  if (!clientRef.current) {
117
- clientRef.current = new (0, _chunkR7H7E5BXjs.BehioStorefront)({
117
+ clientRef.current = new (0, _chunkYLKO3SURjs.BehioStorefront)({
118
118
  apiKey,
119
119
  baseUrl,
120
120
  locale,
@@ -158,6 +158,22 @@ function BehioProvider({
158
158
  // src/react/hooks/use-products.ts
159
159
 
160
160
 
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 } = _nullishCoalesce(query, () => ( {}));
@@ -165,7 +181,7 @@ function useProducts(query) {
165
181
  const serializedFilters = _react.useMemo.call(void 0, () => JSON.stringify({ ...filters, limit }), [filters, limit]);
166
182
  const infinite = _reactquery.useInfiniteQuery.call(void 0, {
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 _reactquery.useQuery.call(void 0, {
230
246
  queryKey: ["behio", "product", slug],
231
- queryFn: () => client.catalog.getProduct(slug, {
247
+ queryFn: () => unwrap(client.catalog.getProduct(slug, {
232
248
  locale: _optionalChain([options, 'optionalAccess', _16 => _16.locale]),
233
249
  currency: _optionalChain([options, 'optionalAccess', _17 => _17.currency])
234
- }),
250
+ })),
235
251
  initialData: _optionalChain([options, 'optionalAccess', _18 => _18.initialData]),
236
252
  enabled: _optionalChain([options, 'optionalAccess', _19 => _19.enabled]) !== false && !!slug
237
253
  });
@@ -244,7 +260,7 @@ function useCategories(locale, options) {
244
260
  return _reactquery.useQuery.call(void 0, {
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: _optionalChain([options, 'optionalAccess', _20 => _20.enabled]) !== false
@@ -254,7 +270,7 @@ function useCategory(slug, options) {
254
270
  const { client } = useBehio();
255
271
  return _reactquery.useQuery.call(void 0, {
256
272
  queryKey: ["behio", "category", slug, _optionalChain([options, 'optionalAccess', _21 => _21.locale])],
257
- queryFn: () => client.catalog.getCategory(slug, _optionalChain([options, 'optionalAccess', _22 => _22.locale])),
273
+ queryFn: () => unwrap(client.catalog.getCategory(slug, _optionalChain([options, 'optionalAccess', _22 => _22.locale]))),
258
274
  enabled: _optionalChain([options, 'optionalAccess', _23 => _23.enabled]) !== false && !!slug
259
275
  });
260
276
  }
@@ -266,7 +282,7 @@ function useLabels(locale, options) {
266
282
  return _reactquery.useQuery.call(void 0, {
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: _optionalChain([options, 'optionalAccess', _24 => _24.enabled]) !== false
@@ -279,10 +295,10 @@ function useFeatured(options) {
279
295
  const { client } = useBehio();
280
296
  return _reactquery.useQuery.call(void 0, {
281
297
  queryKey: ["behio", "featured", _optionalChain([options, 'optionalAccess', _25 => _25.locale]), _optionalChain([options, 'optionalAccess', _26 => _26.currency])],
282
- queryFn: () => client.catalog.getFeatured({
298
+ queryFn: () => unwrap(client.catalog.getFeatured({
283
299
  locale: _optionalChain([options, 'optionalAccess', _27 => _27.locale]),
284
300
  currency: _optionalChain([options, 'optionalAccess', _28 => _28.currency])
285
- }),
301
+ })),
286
302
  initialData: _optionalChain([options, 'optionalAccess', _29 => _29.initialData]),
287
303
  enabled: _optionalChain([options, 'optionalAccess', _30 => _30.enabled]) !== false
288
304
  });
@@ -295,7 +311,7 @@ function useFilters(options) {
295
311
  return _reactquery.useQuery.call(void 0, {
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: _optionalChain([options, 'optionalAccess', _31 => _31.enabled]) !== false
@@ -319,10 +335,10 @@ function useSearch(query, options) {
319
335
  }, [query, debounceMs]);
320
336
  return _reactquery.useQuery.call(void 0, {
321
337
  queryKey: ["behio", "search", debouncedQuery, _optionalChain([options, 'optionalAccess', _33 => _33.page]), _optionalChain([options, 'optionalAccess', _34 => _34.limit])],
322
- queryFn: () => client.catalog.search(debouncedQuery, {
338
+ queryFn: () => unwrap(client.catalog.search(debouncedQuery, {
323
339
  page: _optionalChain([options, 'optionalAccess', _35 => _35.page]),
324
340
  limit: _optionalChain([options, 'optionalAccess', _36 => _36.limit])
325
- }),
341
+ })),
326
342
  enabled: _optionalChain([options, 'optionalAccess', _37 => _37.enabled]) !== false && debouncedQuery.length > 0
327
343
  });
328
344
  }
@@ -340,13 +356,13 @@ function useCart(options) {
340
356
  error
341
357
  } = _reactquery.useQuery.call(void 0, {
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: _optionalChain([options, 'optionalAccess', _38 => _38.enabled]) !== false && (!!client.getCartSession() || !!client.getAccessToken())
346
362
  });
347
363
  const addMutation = _reactquery.useMutation.call(void 0, {
348
364
  mutationFn: async ({ productId, quantity }) => {
349
- return client.cart.addItem({ productId, quantity: _nullishCoalesce(quantity, () => ( 1)) });
365
+ return unwrap(client.cart.addItem({ productId, quantity: _nullishCoalesce(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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 } = _reactquery.useQuery.call(void 0, {
498
514
  queryKey: [...CART_KEY2],
499
- queryFn: () => client.cart.get(),
515
+ queryFn: () => unwrap(client.cart.get()),
500
516
  enabled: _optionalChain([options, 'optionalAccess', _42 => _42.enabled]) !== false && !cachedCart && (!!client.getCartSession() || !!client.getAccessToken())
501
517
  });
502
518
  const cart = _nullishCoalesce(cachedCart, () => ( data));
@@ -517,7 +533,7 @@ function useAuth() {
517
533
  isLoading
518
534
  } = _reactquery.useQuery.call(void 0, {
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 = _react.useCallback.call(void 0,
@@ -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 (e4) {
@@ -550,7 +566,7 @@ function useAuth() {
550
566
  }, [client, storage, queryClient]);
551
567
  const loginMutation = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
576
- mutationFn: (email) => client.auth.forgotPassword(email)
592
+ mutationFn: (email) => unwrap(client.auth.forgotPassword(email))
577
593
  });
578
594
  const resetPasswordMutation = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
582
- mutationFn: (token) => client.auth.verifyEmail(token)
598
+ mutationFn: (token) => unwrap(client.auth.verifyEmail(token))
583
599
  });
584
600
  const login = _react.useCallback.call(void 0,
585
601
  (email, password) => loginMutation.mutateAsync({ email, password }).then(() => void 0),
@@ -637,11 +653,11 @@ function useCustomer(options) {
637
653
  error
638
654
  } = _reactquery.useQuery.call(void 0, {
639
655
  queryKey: [...CUSTOMER_KEY2],
640
- queryFn: () => client.customer.getProfile(),
656
+ queryFn: () => unwrap(client.customer.getProfile()),
641
657
  enabled: _optionalChain([options, 'optionalAccess', _44 => _44.enabled]) !== false && !!client.getAccessToken()
642
658
  });
643
659
  const updateMutation = _reactquery.useMutation.call(void 0, {
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
  } = _reactquery.useQuery.call(void 0, {
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: _optionalChain([options, 'optionalAccess', _45 => _45.enabled]) !== false && !!client.getAccessToken()
680
696
  });
681
697
  const createMutation = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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,6 +736,70 @@ function useAddresses(options) {
720
736
  };
721
737
  }
722
738
 
739
+ // src/react/hooks/use-address-autocomplete.ts
740
+
741
+
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] = _react.useState.call(void 0, "");
747
+ const [debouncedQuery, setDebouncedQuery] = _react.useState.call(void 0, "");
748
+ const [selected, setSelected] = _react.useState.call(void 0, null);
749
+ const [isSelecting, setIsSelecting] = _react.useState.call(void 0, false);
750
+ const timerRef = _react.useRef.call(void 0, void 0);
751
+ _react.useEffect.call(void 0, () => {
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 } = _reactquery.useQuery.call(void 0, {
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 = _react.useCallback.call(void 0,
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 = _react.useCallback.call(void 0, () => {
787
+ setQuery("");
788
+ setDebouncedQuery("");
789
+ setSelected(null);
790
+ }, []);
791
+ return {
792
+ query,
793
+ setQuery,
794
+ suggestions: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _46 => _46.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
804
 
725
805
 
@@ -729,17 +809,17 @@ function useOrders(options) {
729
809
  const [page, setPage] = _react.useState.call(void 0, _nullishCoalesce(initialPage, () => ( 1)));
730
810
  const infinite = _reactquery.useInfiniteQuery.call(void 0, {
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,
736
816
  enabled: enabled !== false && !!client.getAccessToken()
737
817
  });
738
818
  const items = _react.useMemo.call(void 0,
739
- () => _nullishCoalesce(_optionalChain([infinite, 'access', _46 => _46.data, 'optionalAccess', _47 => _47.pages, 'access', _48 => _48.flatMap, 'call', _49 => _49((p) => p.items)]), () => ( [])),
819
+ () => _nullishCoalesce(_optionalChain([infinite, 'access', _47 => _47.data, 'optionalAccess', _48 => _48.pages, 'access', _49 => _49.flatMap, 'call', _50 => _50((p) => p.items)]), () => ( [])),
740
820
  [infinite.data]
741
821
  );
742
- const lastPage = _optionalChain([infinite, 'access', _50 => _50.data, 'optionalAccess', _51 => _51.pages, 'access', _52 => _52[infinite.data.pages.length - 1]]);
822
+ const lastPage = _optionalChain([infinite, 'access', _51 => _51.data, 'optionalAccess', _52 => _52.pages, 'access', _53 => _53[infinite.data.pages.length - 1]]);
743
823
  const loadMore = _react.useCallback.call(void 0, () => {
744
824
  if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
745
825
  return infinite.fetchNextPage();
@@ -752,10 +832,10 @@ function useOrders(options) {
752
832
  return {
753
833
  items,
754
834
  data: infinite.data,
755
- total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _53 => _53.total]), () => ( 0)),
756
- totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _54 => _54.totalPages]), () => ( 0)),
757
- currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _55 => _55.page]), () => ( page)),
758
- limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _56 => _56.limit]), () => ( limit)), () => ( 20)),
835
+ total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _54 => _54.total]), () => ( 0)),
836
+ totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _55 => _55.totalPages]), () => ( 0)),
837
+ currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _56 => _56.page]), () => ( page)),
838
+ limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _57 => _57.limit]), () => ( limit)), () => ( 20)),
759
839
  page,
760
840
  setPage: goToPage,
761
841
  loadMore,
@@ -783,11 +863,11 @@ function useOrder(orderNumber, options) {
783
863
  error
784
864
  } = _reactquery.useQuery.call(void 0, {
785
865
  queryKey: ["behio", "order", orderNumber],
786
- queryFn: () => client.orders.get(orderNumber),
787
- enabled: _optionalChain([options, 'optionalAccess', _57 => _57.enabled]) !== false && !!orderNumber && !!client.getAccessToken()
866
+ queryFn: () => unwrap(client.orders.get(orderNumber)),
867
+ enabled: _optionalChain([options, 'optionalAccess', _58 => _58.enabled]) !== false && !!orderNumber && !!client.getAccessToken()
788
868
  });
789
869
  const cancelMutation = _reactquery.useMutation.call(void 0, {
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"] });
@@ -814,7 +894,7 @@ function useCheckout() {
814
894
  const queryClient = _reactquery.useQueryClient.call(void 0, );
815
895
  const [order, setOrder] = _react.useState.call(void 0, null);
816
896
  const mutation = _reactquery.useMutation.call(void 0, {
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);
@@ -846,18 +926,18 @@ function usePages(locale, options) {
846
926
  return _reactquery.useQuery.call(void 0, {
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
- enabled: _optionalChain([options, 'optionalAccess', _58 => _58.enabled]) !== false
932
+ enabled: _optionalChain([options, 'optionalAccess', _59 => _59.enabled]) !== false
853
933
  });
854
934
  }
855
935
  function usePage(slug, locale, options) {
856
936
  const { client } = useBehio();
857
937
  return _reactquery.useQuery.call(void 0, {
858
938
  queryKey: ["behio", "page", slug, locale],
859
- queryFn: () => client.pages.get(slug, locale),
860
- enabled: _optionalChain([options, 'optionalAccess', _59 => _59.enabled]) !== false && !!slug
939
+ queryFn: () => unwrap(client.pages.get(slug, locale)),
940
+ enabled: _optionalChain([options, 'optionalAccess', _60 => _60.enabled]) !== false && !!slug
861
941
  });
862
942
  }
863
943
 
@@ -867,8 +947,8 @@ function useShopInfo(options) {
867
947
  const { client } = useBehio();
868
948
  return _reactquery.useQuery.call(void 0, {
869
949
  queryKey: ["behio", "shop-info"],
870
- queryFn: () => client.getShopInfo(),
871
- enabled: _optionalChain([options, 'optionalAccess', _60 => _60.enabled]) !== false
950
+ queryFn: () => unwrap(client.getShopInfo()),
951
+ enabled: _optionalChain([options, 'optionalAccess', _61 => _61.enabled]) !== false
872
952
  });
873
953
  }
874
954
 
@@ -879,7 +959,7 @@ function useShopSeo(options) {
879
959
  const { locale, initialData, enabled = true } = _nullishCoalesce(options, () => ( {}));
880
960
  return _reactquery.useQuery.call(void 0, {
881
961
  queryKey: ["behio", "shop-seo", _nullishCoalesce(locale, () => ( "_default"))],
882
- queryFn: () => client.getShopSeo(locale),
962
+ queryFn: () => unwrap(client.getShopSeo(locale)),
883
963
  initialData,
884
964
  enabled
885
965
  });
@@ -891,18 +971,18 @@ function useBundles(options) {
891
971
  const { client } = useBehio();
892
972
  return _reactquery.useQuery.call(void 0, {
893
973
  queryKey: ["behio", "bundles"],
894
- queryFn: () => client.catalog.getBundles(),
895
- enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _61 => _61.enabled]), () => ( true)),
896
- initialData: _optionalChain([options, 'optionalAccess', _62 => _62.initialData])
974
+ queryFn: () => unwrap(client.catalog.getBundles()),
975
+ enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _62 => _62.enabled]), () => ( true)),
976
+ initialData: _optionalChain([options, 'optionalAccess', _63 => _63.initialData])
897
977
  });
898
978
  }
899
979
  function useBundle(slug, options) {
900
980
  const { client } = useBehio();
901
981
  return _reactquery.useQuery.call(void 0, {
902
982
  queryKey: ["behio", "bundle", slug],
903
- queryFn: () => client.catalog.getBundle(slug),
904
- enabled: Boolean(slug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _63 => _63.enabled]), () => ( true))),
905
- initialData: _optionalChain([options, 'optionalAccess', _64 => _64.initialData])
983
+ queryFn: () => unwrap(client.catalog.getBundle(slug)),
984
+ enabled: Boolean(slug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _64 => _64.enabled]), () => ( true))),
985
+ initialData: _optionalChain([options, 'optionalAccess', _65 => _65.initialData])
906
986
  });
907
987
  }
908
988
 
@@ -912,9 +992,9 @@ function useCrossSell(productSlug, options) {
912
992
  const { client } = useBehio();
913
993
  return _reactquery.useQuery.call(void 0, {
914
994
  queryKey: ["behio", "cross-sell", productSlug],
915
- queryFn: () => client.catalog.getCrossSell(productSlug),
916
- enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _65 => _65.enabled]), () => ( true))),
917
- initialData: _optionalChain([options, 'optionalAccess', _66 => _66.initialData])
995
+ queryFn: () => unwrap(client.catalog.getCrossSell(productSlug)),
996
+ enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _66 => _66.enabled]), () => ( true))),
997
+ initialData: _optionalChain([options, 'optionalAccess', _67 => _67.initialData])
918
998
  });
919
999
  }
920
1000
 
@@ -924,9 +1004,9 @@ function useProductPromotions(productSlug, options) {
924
1004
  const { client } = useBehio();
925
1005
  return _reactquery.useQuery.call(void 0, {
926
1006
  queryKey: ["behio", "product-promotions", productSlug],
927
- queryFn: () => client.catalog.getProductPromotions(productSlug),
928
- enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _67 => _67.enabled]), () => ( true))),
929
- refetchInterval: _optionalChain([options, 'optionalAccess', _68 => _68.refetchIntervalMs])
1007
+ queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
1008
+ enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.enabled]), () => ( true))),
1009
+ refetchInterval: _optionalChain([options, 'optionalAccess', _69 => _69.refetchIntervalMs])
930
1010
  });
931
1011
  }
932
1012
 
@@ -934,11 +1014,11 @@ function useProductPromotions(productSlug, options) {
934
1014
 
935
1015
  function useGiftCardBalance(code, options) {
936
1016
  const { client } = useBehio();
937
- const trimmed = _optionalChain([code, 'optionalAccess', _69 => _69.trim, 'call', _70 => _70()]);
1017
+ const trimmed = _optionalChain([code, 'optionalAccess', _70 => _70.trim, 'call', _71 => _71()]);
938
1018
  return _reactquery.useQuery.call(void 0, {
939
1019
  queryKey: ["behio", "gift-card-balance", trimmed],
940
- queryFn: () => client.catalog.checkGiftCard(trimmed),
941
- enabled: Boolean(trimmed && trimmed.length >= 6) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.enabled]), () => ( true)))
1020
+ queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
1021
+ enabled: Boolean(trimmed && trimmed.length >= 6) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.enabled]), () => ( true)))
942
1022
  });
943
1023
  }
944
1024
 
@@ -949,15 +1029,15 @@ function useWishlist(options) {
949
1029
  const qc = _reactquery.useQueryClient.call(void 0, );
950
1030
  const query = _reactquery.useQuery.call(void 0, {
951
1031
  queryKey: ["behio", "wishlist"],
952
- queryFn: () => client.wishlist.get(),
953
- enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.enabled]), () => ( true))
1032
+ queryFn: () => unwrap(client.wishlist.get()),
1033
+ enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _73 => _73.enabled]), () => ( true))
954
1034
  });
955
1035
  const addMutation = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 {
@@ -972,7 +1052,7 @@ function useIsInWishlist(productId) {
972
1052
  const { client } = useBehio();
973
1053
  return _reactquery.useQuery.call(void 0, {
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
  }
@@ -982,16 +1062,16 @@ function useIsInWishlist(productId) {
982
1062
  function useProductReviews(productId, options) {
983
1063
  const { client } = useBehio();
984
1064
  return _reactquery.useQuery.call(void 0, {
985
- queryKey: ["behio", "reviews", productId, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _73 => _73.page]), () => ( 1))],
986
- queryFn: () => client.reviews.getProductReviews(productId, _optionalChain([options, 'optionalAccess', _74 => _74.page]), _optionalChain([options, 'optionalAccess', _75 => _75.limit])),
987
- enabled: Boolean(productId) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _76 => _76.enabled]), () => ( true)))
1065
+ queryKey: ["behio", "reviews", productId, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _74 => _74.page]), () => ( 1))],
1066
+ queryFn: () => unwrap(client.reviews.getProductReviews(productId, _optionalChain([options, 'optionalAccess', _75 => _75.page]), _optionalChain([options, 'optionalAccess', _76 => _76.limit]))),
1067
+ enabled: Boolean(productId) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _77 => _77.enabled]), () => ( true)))
988
1068
  });
989
1069
  }
990
1070
  function useSubmitReview() {
991
1071
  const { client } = useBehio();
992
1072
  const qc = _reactquery.useQueryClient.call(void 0, );
993
1073
  return _reactquery.useMutation.call(void 0, {
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
  }
@@ -1001,14 +1081,14 @@ function useSubmitReview() {
1001
1081
  function useSubmitReturn() {
1002
1082
  const { client } = useBehio();
1003
1083
  return _reactquery.useMutation.call(void 0, {
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
1089
  return _reactquery.useQuery.call(void 0, {
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
  }
@@ -1020,15 +1100,15 @@ function useCookieConsent(visitorId) {
1020
1100
  const qc = _reactquery.useQueryClient.call(void 0, );
1021
1101
  const query = _reactquery.useQuery.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 = _reactquery.useMutation.call(void 0, {
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 {
@@ -1043,14 +1123,14 @@ function useCookieConsent(visitorId) {
1043
1123
  function useSubmitQuote() {
1044
1124
  const { client } = useBehio();
1045
1125
  return _reactquery.useMutation.call(void 0, {
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
1131
  return _reactquery.useQuery.call(void 0, {
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
  }
@@ -1118,4 +1198,5 @@ function formatPrice(amount, currency, locale) {
1118
1198
 
1119
1199
 
1120
1200
 
1121
- exports.BehioProvider = BehioProvider; exports.cookieStorage = cookieStorage; exports.createMemoryStorage = createMemoryStorage; exports.detectStorage = detectStorage; exports.formatPrice = formatPrice; exports.localStorageAdapter = localStorageAdapter; exports.memoryStorage = memoryStorage; exports.useAddresses = useAddresses; exports.useAuth = useAuth; exports.useBehio = useBehio; exports.useBehioClient = useBehioClient; exports.useBundle = useBundle; exports.useBundles = useBundles; exports.useCart = useCart; exports.useCartCount = useCartCount; exports.useCategories = useCategories; exports.useCategory = useCategory; exports.useCheckout = useCheckout; exports.useCookieConsent = useCookieConsent; exports.useCrossSell = useCrossSell; exports.useCustomer = useCustomer; exports.useFeatured = useFeatured; exports.useFilters = useFilters; exports.useGiftCardBalance = useGiftCardBalance; exports.useIsInWishlist = useIsInWishlist; exports.useLabels = useLabels; exports.useOrder = useOrder; exports.useOrders = useOrders; exports.usePage = usePage; exports.usePages = usePages; exports.useProduct = useProduct; exports.useProductPromotions = useProductPromotions; exports.useProductReviews = useProductReviews; exports.useProducts = useProducts; exports.useQuoteStatus = useQuoteStatus; exports.useReturnStatus = useReturnStatus; exports.useSearch = useSearch; exports.useShopInfo = useShopInfo; exports.useShopSeo = useShopSeo; exports.useSubmitQuote = useSubmitQuote; exports.useSubmitReturn = useSubmitReturn; exports.useSubmitReview = useSubmitReview; exports.useWishlist = useWishlist;
1201
+
1202
+ exports.BehioProvider = BehioProvider; exports.cookieStorage = cookieStorage; exports.createMemoryStorage = createMemoryStorage; exports.detectStorage = detectStorage; exports.formatPrice = formatPrice; exports.localStorageAdapter = localStorageAdapter; exports.memoryStorage = memoryStorage; exports.useAddressAutocomplete = useAddressAutocomplete; exports.useAddresses = useAddresses; exports.useAuth = useAuth; exports.useBehio = useBehio; exports.useBehioClient = useBehioClient; exports.useBundle = useBundle; exports.useBundles = useBundles; exports.useCart = useCart; exports.useCartCount = useCartCount; exports.useCategories = useCategories; exports.useCategory = useCategory; exports.useCheckout = useCheckout; exports.useCookieConsent = useCookieConsent; exports.useCrossSell = useCrossSell; exports.useCustomer = useCustomer; exports.useFeatured = useFeatured; exports.useFilters = useFilters; exports.useGiftCardBalance = useGiftCardBalance; exports.useIsInWishlist = useIsInWishlist; exports.useLabels = useLabels; exports.useOrder = useOrder; exports.useOrders = useOrders; exports.usePage = usePage; exports.usePages = usePages; exports.useProduct = useProduct; exports.useProductPromotions = useProductPromotions; exports.useProductReviews = useProductReviews; exports.useProducts = useProducts; exports.useQuoteStatus = useQuoteStatus; exports.useReturnStatus = useReturnStatus; exports.useSearch = useSearch; exports.useShopInfo = useShopInfo; exports.useShopSeo = useShopSeo; exports.useSubmitQuote = useSubmitQuote; exports.useSubmitReturn = useSubmitReturn; exports.useSubmitReview = useSubmitReview; exports.useWishlist = useWishlist;