@behio/storefront-sdk 0.10.0 → 0.13.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,9 @@
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 _chunkLNSFBNPJjs = require('./chunk-LNSFBNPJ.js');
3
+ var _chunkXWYDXBLGjs = require('./chunk-XWYDXBLG.js');
4
+
5
+
6
+ var _chunkGGUHYQNFjs = require('./chunk-GGUHYQNF.js');
4
7
 
5
8
  // src/react/provider.tsx
6
9
  var _react = require('react');
@@ -41,20 +44,20 @@ var localStorageAdapter = {
41
44
  get(key) {
42
45
  try {
43
46
  return window.localStorage.getItem(key);
44
- } catch (e) {
47
+ } catch (e2) {
45
48
  return null;
46
49
  }
47
50
  },
48
51
  set(key, value) {
49
52
  try {
50
53
  window.localStorage.setItem(key, value);
51
- } catch (e2) {
54
+ } catch (e3) {
52
55
  }
53
56
  },
54
57
  remove(key) {
55
58
  try {
56
59
  window.localStorage.removeItem(key);
57
- } catch (e3) {
60
+ } catch (e4) {
58
61
  }
59
62
  }
60
63
  };
@@ -97,7 +100,9 @@ function resolveStorage(option) {
97
100
  var STORAGE_KEYS = {
98
101
  ACCESS_TOKEN: "behio_access_token",
99
102
  REFRESH_TOKEN: "behio_refresh_token",
100
- CART_SESSION: "behio_cart_session"
103
+ CART_SESSION: "behio_cart_session",
104
+ /** Shopper's chosen currency. Cookie so SSR (getBehio) reads the same value. */
105
+ CURRENCY: "behio_currency"
101
106
  };
102
107
 
103
108
  // src/react/provider.tsx
@@ -105,20 +110,37 @@ var _jsxruntime = require('react/jsx-runtime');
105
110
  function BehioProvider({
106
111
  apiKey,
107
112
  baseUrl,
113
+ shopDomain,
108
114
  locale,
109
115
  currency,
116
+ defaultCurrency,
117
+ currencies,
118
+ onCurrencyChange,
119
+ persistCurrency = true,
120
+ currencyCookieName = STORAGE_KEYS.CURRENCY,
110
121
  storage: storageOption,
111
122
  queryClient: externalQueryClient,
112
123
  children
113
124
  }) {
114
125
  const storageAdapter = _react.useMemo.call(void 0, () => resolveStorage(storageOption), [storageOption]);
126
+ const resolveInitialCurrency = () => {
127
+ if (persistCurrency) {
128
+ const stored = cookieStorage.get(currencyCookieName);
129
+ if (stored) return stored;
130
+ }
131
+ return currency;
132
+ };
133
+ const [activeCurrency, setActiveCurrency] = _react.useState.call(void 0, resolveInitialCurrency);
115
134
  const clientRef = _react.useRef.call(void 0, null);
116
135
  if (!clientRef.current) {
117
- clientRef.current = new (0, _chunkLNSFBNPJjs.BehioStorefront)({
136
+ clientRef.current = new (0, _chunkGGUHYQNFjs.BehioStorefront)({
118
137
  apiKey,
119
138
  baseUrl,
139
+ ...shopDomain ? { shopDomain } : {},
120
140
  locale,
121
- currency
141
+ // Seed with the resolved active currency so the very first request (even
142
+ // before effects run) carries it.
143
+ ...activeCurrency ? { currency: activeCurrency } : {}
122
144
  });
123
145
  }
124
146
  const client = clientRef.current;
@@ -133,6 +155,20 @@ function BehioProvider({
133
155
  client.setCartSession(cartSession);
134
156
  }
135
157
  }, [client, storageAdapter]);
158
+ _react.useEffect.call(void 0, () => {
159
+ if (!persistCurrency) return;
160
+ const stored = cookieStorage.get(currencyCookieName);
161
+ if (stored && stored !== activeCurrency) {
162
+ setActiveCurrency(stored);
163
+ client.setCurrency(stored);
164
+ }
165
+ }, []);
166
+ _react.useEffect.call(void 0, () => {
167
+ if (currency !== void 0 && currency !== activeCurrency) {
168
+ setActiveCurrency(currency);
169
+ client.setCurrency(currency);
170
+ }
171
+ }, [currency]);
136
172
  const queryClientRef = _react.useRef.call(void 0, null);
137
173
  const qc = _react.useMemo.call(void 0, () => {
138
174
  if (externalQueryClient) return externalQueryClient;
@@ -148,9 +184,29 @@ function BehioProvider({
148
184
  }
149
185
  return queryClientRef.current;
150
186
  }, [externalQueryClient]);
187
+ const setCurrency = _react.useCallback.call(void 0,
188
+ (next) => {
189
+ setActiveCurrency(next);
190
+ client.setCurrency(next);
191
+ if (persistCurrency) {
192
+ if (next) cookieStorage.set(currencyCookieName, next);
193
+ else cookieStorage.remove(currencyCookieName);
194
+ }
195
+ _optionalChain([onCurrencyChange, 'optionalCall', _2 => _2(next)]);
196
+ void qc.invalidateQueries({ queryKey: ["behio"] });
197
+ },
198
+ [client, qc, persistCurrency, currencyCookieName, onCurrencyChange]
199
+ );
151
200
  const ctxValue = _react.useMemo.call(void 0,
152
- () => ({ client, storage: storageAdapter }),
153
- [client, storageAdapter]
201
+ () => ({
202
+ client,
203
+ storage: storageAdapter,
204
+ currency: activeCurrency,
205
+ setCurrency,
206
+ configuredDefaultCurrency: defaultCurrency,
207
+ configuredCurrencies: currencies
208
+ }),
209
+ [client, storageAdapter, activeCurrency, setCurrency, defaultCurrency, currencies]
154
210
  );
155
211
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: qc, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BehioContext.Provider, { value: ctxValue, children }) });
156
212
  }
@@ -189,11 +245,11 @@ function useProducts(query) {
189
245
  enabled: enabled !== false
190
246
  });
191
247
  const items = _react.useMemo.call(void 0,
192
- () => _nullishCoalesce(_optionalChain([infinite, 'access', _2 => _2.data, 'optionalAccess', _3 => _3.pages, 'access', _4 => _4.flatMap, 'call', _5 => _5((p) => p.items)]), () => ( [])),
248
+ () => _nullishCoalesce(_optionalChain([infinite, 'access', _3 => _3.data, 'optionalAccess', _4 => _4.pages, 'access', _5 => _5.flatMap, 'call', _6 => _6((p) => p.items)]), () => ( [])),
193
249
  [infinite.data]
194
250
  );
195
- const lastPage = _optionalChain([infinite, 'access', _6 => _6.data, 'optionalAccess', _7 => _7.pages, 'access', _8 => _8[infinite.data.pages.length - 1]]);
196
- const firstPage = _optionalChain([infinite, 'access', _9 => _9.data, 'optionalAccess', _10 => _10.pages, 'access', _11 => _11[0]]);
251
+ const lastPage = _optionalChain([infinite, 'access', _7 => _7.data, 'optionalAccess', _8 => _8.pages, 'access', _9 => _9[infinite.data.pages.length - 1]]);
252
+ const firstPage = _optionalChain([infinite, 'access', _10 => _10.data, 'optionalAccess', _11 => _11.pages, 'access', _12 => _12[0]]);
197
253
  const loadMore = _react.useCallback.call(void 0, () => {
198
254
  if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
199
255
  return infinite.fetchNextPage();
@@ -210,10 +266,10 @@ function useProducts(query) {
210
266
  /** Raw React Query data with all pages */
211
267
  data: infinite.data,
212
268
  /** Last loaded page meta */
213
- total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _12 => _12.total]), () => ( 0)),
214
- totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _13 => _13.totalPages]), () => ( 0)),
215
- currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _14 => _14.page]), () => ( page)),
216
- limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _15 => _15.limit]), () => ( limit)), () => ( 20)),
269
+ total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _13 => _13.total]), () => ( 0)),
270
+ totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _14 => _14.totalPages]), () => ( 0)),
271
+ currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _15 => _15.page]), () => ( page)),
272
+ limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _16 => _16.limit]), () => ( limit)), () => ( 20)),
217
273
  // --- Pagination controls ---
218
274
  /** Current page (manual pagination) */
219
275
  page,
@@ -243,13 +299,15 @@ function useProducts(query) {
243
299
  function useProduct(slug, options) {
244
300
  const { client } = useBehio();
245
301
  return _reactquery.useQuery.call(void 0, {
246
- queryKey: ["behio", "product", slug],
302
+ // currency + locale belong in the key so switching either refetches the
303
+ // price/translation instead of serving a stale cache hit.
304
+ queryKey: ["behio", "product", slug, _optionalChain([options, 'optionalAccess', _17 => _17.locale]), _optionalChain([options, 'optionalAccess', _18 => _18.currency])],
247
305
  queryFn: () => unwrap(client.catalog.getProduct(slug, {
248
- locale: _optionalChain([options, 'optionalAccess', _16 => _16.locale]),
249
- currency: _optionalChain([options, 'optionalAccess', _17 => _17.currency])
306
+ locale: _optionalChain([options, 'optionalAccess', _19 => _19.locale]),
307
+ currency: _optionalChain([options, 'optionalAccess', _20 => _20.currency])
250
308
  })),
251
- initialData: _optionalChain([options, 'optionalAccess', _18 => _18.initialData]),
252
- enabled: _optionalChain([options, 'optionalAccess', _19 => _19.enabled]) !== false && !!slug
309
+ initialData: _optionalChain([options, 'optionalAccess', _21 => _21.initialData]),
310
+ enabled: _optionalChain([options, 'optionalAccess', _22 => _22.enabled]) !== false && !!slug
253
311
  });
254
312
  }
255
313
 
@@ -263,15 +321,15 @@ function useCategories(locale, options) {
263
321
  const result = await unwrap(client.catalog.getCategories(locale));
264
322
  return result.categories;
265
323
  },
266
- enabled: _optionalChain([options, 'optionalAccess', _20 => _20.enabled]) !== false
324
+ enabled: _optionalChain([options, 'optionalAccess', _23 => _23.enabled]) !== false
267
325
  });
268
326
  }
269
327
  function useCategory(slug, options) {
270
328
  const { client } = useBehio();
271
329
  return _reactquery.useQuery.call(void 0, {
272
- queryKey: ["behio", "category", slug, _optionalChain([options, 'optionalAccess', _21 => _21.locale])],
273
- queryFn: () => unwrap(client.catalog.getCategory(slug, _optionalChain([options, 'optionalAccess', _22 => _22.locale]))),
274
- enabled: _optionalChain([options, 'optionalAccess', _23 => _23.enabled]) !== false && !!slug
330
+ queryKey: ["behio", "category", slug, _optionalChain([options, 'optionalAccess', _24 => _24.locale])],
331
+ queryFn: () => unwrap(client.catalog.getCategory(slug, _optionalChain([options, 'optionalAccess', _25 => _25.locale]))),
332
+ enabled: _optionalChain([options, 'optionalAccess', _26 => _26.enabled]) !== false && !!slug
275
333
  });
276
334
  }
277
335
 
@@ -285,7 +343,7 @@ function useLabels(locale, options) {
285
343
  const result = await unwrap(client.catalog.getLabels(locale));
286
344
  return result.labels;
287
345
  },
288
- enabled: _optionalChain([options, 'optionalAccess', _24 => _24.enabled]) !== false
346
+ enabled: _optionalChain([options, 'optionalAccess', _27 => _27.enabled]) !== false
289
347
  });
290
348
  }
291
349
 
@@ -294,13 +352,13 @@ function useLabels(locale, options) {
294
352
  function useFeatured(options) {
295
353
  const { client } = useBehio();
296
354
  return _reactquery.useQuery.call(void 0, {
297
- queryKey: ["behio", "featured", _optionalChain([options, 'optionalAccess', _25 => _25.locale]), _optionalChain([options, 'optionalAccess', _26 => _26.currency])],
355
+ queryKey: ["behio", "featured", _optionalChain([options, 'optionalAccess', _28 => _28.locale]), _optionalChain([options, 'optionalAccess', _29 => _29.currency])],
298
356
  queryFn: () => unwrap(client.catalog.getFeatured({
299
- locale: _optionalChain([options, 'optionalAccess', _27 => _27.locale]),
300
- currency: _optionalChain([options, 'optionalAccess', _28 => _28.currency])
357
+ locale: _optionalChain([options, 'optionalAccess', _30 => _30.locale]),
358
+ currency: _optionalChain([options, 'optionalAccess', _31 => _31.currency])
301
359
  })),
302
- initialData: _optionalChain([options, 'optionalAccess', _29 => _29.initialData]),
303
- enabled: _optionalChain([options, 'optionalAccess', _30 => _30.enabled]) !== false
360
+ initialData: _optionalChain([options, 'optionalAccess', _32 => _32.initialData]),
361
+ enabled: _optionalChain([options, 'optionalAccess', _33 => _33.enabled]) !== false
304
362
  });
305
363
  }
306
364
 
@@ -314,7 +372,7 @@ function useFilters(options) {
314
372
  const result = await unwrap(client.catalog.getFilters());
315
373
  return result.filters;
316
374
  },
317
- enabled: _optionalChain([options, 'optionalAccess', _31 => _31.enabled]) !== false
375
+ enabled: _optionalChain([options, 'optionalAccess', _34 => _34.enabled]) !== false
318
376
  });
319
377
  }
320
378
 
@@ -323,7 +381,7 @@ function useFilters(options) {
323
381
 
324
382
  function useSearch(query, options) {
325
383
  const { client } = useBehio();
326
- const debounceMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _32 => _32.debounceMs]), () => ( 300));
384
+ const debounceMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _35 => _35.debounceMs]), () => ( 300));
327
385
  const [debouncedQuery, setDebouncedQuery] = _react.useState.call(void 0, query);
328
386
  _react.useEffect.call(void 0, () => {
329
387
  if (debounceMs <= 0) {
@@ -334,12 +392,12 @@ function useSearch(query, options) {
334
392
  return () => clearTimeout(timer);
335
393
  }, [query, debounceMs]);
336
394
  return _reactquery.useQuery.call(void 0, {
337
- queryKey: ["behio", "search", debouncedQuery, _optionalChain([options, 'optionalAccess', _33 => _33.page]), _optionalChain([options, 'optionalAccess', _34 => _34.limit])],
395
+ queryKey: ["behio", "search", debouncedQuery, _optionalChain([options, 'optionalAccess', _36 => _36.page]), _optionalChain([options, 'optionalAccess', _37 => _37.limit])],
338
396
  queryFn: () => unwrap(client.catalog.search(debouncedQuery, {
339
- page: _optionalChain([options, 'optionalAccess', _35 => _35.page]),
340
- limit: _optionalChain([options, 'optionalAccess', _36 => _36.limit])
397
+ page: _optionalChain([options, 'optionalAccess', _38 => _38.page]),
398
+ limit: _optionalChain([options, 'optionalAccess', _39 => _39.limit])
341
399
  })),
342
- enabled: _optionalChain([options, 'optionalAccess', _37 => _37.enabled]) !== false && debouncedQuery.length > 0
400
+ enabled: _optionalChain([options, 'optionalAccess', _40 => _40.enabled]) !== false && debouncedQuery.length > 0
343
401
  });
344
402
  }
345
403
 
@@ -358,7 +416,7 @@ function useCart(options) {
358
416
  queryKey: [...CART_KEY],
359
417
  queryFn: () => unwrap(client.cart.get()),
360
418
  // Only fetch if we have a cart session or are logged in
361
- enabled: _optionalChain([options, 'optionalAccess', _38 => _38.enabled]) !== false && (!!client.getCartSession() || !!client.getAccessToken())
419
+ enabled: _optionalChain([options, 'optionalAccess', _41 => _41.enabled]) !== false && (!!client.getCartSession() || !!client.getAccessToken())
362
420
  });
363
421
  const addMutation = _reactquery.useMutation.call(void 0, {
364
422
  mutationFn: async ({ productId, quantity }) => {
@@ -391,7 +449,7 @@ function useCart(options) {
391
449
  return { previous };
392
450
  },
393
451
  onError: (_err, _vars, context) => {
394
- if (_optionalChain([context, 'optionalAccess', _39 => _39.previous])) {
452
+ if (_optionalChain([context, 'optionalAccess', _42 => _42.previous])) {
395
453
  queryClient.setQueryData([...CART_KEY], context.previous);
396
454
  }
397
455
  },
@@ -417,7 +475,7 @@ function useCart(options) {
417
475
  return { previous };
418
476
  },
419
477
  onError: (_err, _vars, context) => {
420
- if (_optionalChain([context, 'optionalAccess', _40 => _40.previous])) {
478
+ if (_optionalChain([context, 'optionalAccess', _43 => _43.previous])) {
421
479
  queryClient.setQueryData([...CART_KEY], context.previous);
422
480
  }
423
481
  },
@@ -494,7 +552,7 @@ function useCart(options) {
494
552
  removeDiscount,
495
553
  merge,
496
554
  // Computed
497
- itemCount: _nullishCoalesce(_optionalChain([cart, 'optionalAccess', _41 => _41.itemCount]), () => ( 0)),
555
+ itemCount: _nullishCoalesce(_optionalChain([cart, 'optionalAccess', _44 => _44.itemCount]), () => ( 0)),
498
556
  isEmpty: !cart || cart.items.length === 0,
499
557
  // Mutation states
500
558
  isAdding: addMutation.isPending,
@@ -513,10 +571,10 @@ function useCartCount(options) {
513
571
  const { data } = _reactquery.useQuery.call(void 0, {
514
572
  queryKey: [...CART_KEY2],
515
573
  queryFn: () => unwrap(client.cart.get()),
516
- enabled: _optionalChain([options, 'optionalAccess', _42 => _42.enabled]) !== false && !cachedCart && (!!client.getCartSession() || !!client.getAccessToken())
574
+ enabled: _optionalChain([options, 'optionalAccess', _45 => _45.enabled]) !== false && !cachedCart && (!!client.getCartSession() || !!client.getAccessToken())
517
575
  });
518
576
  const cart = _nullishCoalesce(cachedCart, () => ( data));
519
- return _nullishCoalesce(_optionalChain([cart, 'optionalAccess', _43 => _43.itemCount]), () => ( 0));
577
+ return _nullishCoalesce(_optionalChain([cart, 'optionalAccess', _46 => _46.itemCount]), () => ( 0));
520
578
  }
521
579
 
522
580
  // src/react/hooks/use-auth.ts
@@ -559,7 +617,7 @@ function useAuth() {
559
617
  await unwrap(client.cart.merge());
560
618
  client.clearCartSession();
561
619
  storage.remove(STORAGE_KEYS.CART_SESSION);
562
- } catch (e4) {
620
+ } catch (e5) {
563
621
  }
564
622
  }
565
623
  queryClient.invalidateQueries({ queryKey: [...CART_KEY3] });
@@ -654,7 +712,7 @@ function useCustomer(options) {
654
712
  } = _reactquery.useQuery.call(void 0, {
655
713
  queryKey: [...CUSTOMER_KEY2],
656
714
  queryFn: () => unwrap(client.customer.getProfile()),
657
- enabled: _optionalChain([options, 'optionalAccess', _44 => _44.enabled]) !== false && !!client.getAccessToken()
715
+ enabled: _optionalChain([options, 'optionalAccess', _47 => _47.enabled]) !== false && !!client.getAccessToken()
658
716
  });
659
717
  const updateMutation = _reactquery.useMutation.call(void 0, {
660
718
  mutationFn: (data2) => unwrap(client.customer.updateProfile(data2)),
@@ -692,7 +750,7 @@ function useAddresses(options) {
692
750
  const result = await unwrap(client.customer.getAddresses());
693
751
  return result.items;
694
752
  },
695
- enabled: _optionalChain([options, 'optionalAccess', _45 => _45.enabled]) !== false && !!client.getAccessToken()
753
+ enabled: _optionalChain([options, 'optionalAccess', _48 => _48.enabled]) !== false && !!client.getAccessToken()
696
754
  });
697
755
  const createMutation = _reactquery.useMutation.call(void 0, {
698
756
  mutationFn: (address) => unwrap(client.customer.createAddress(address)),
@@ -791,7 +849,7 @@ function useAddressAutocomplete(options) {
791
849
  return {
792
850
  query,
793
851
  setQuery,
794
- suggestions: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _46 => _46.suggestions]), () => ( [])),
852
+ suggestions: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _49 => _49.suggestions]), () => ( [])),
795
853
  isLoading: isLoading && debouncedQuery.length >= minChars,
796
854
  select,
797
855
  selected,
@@ -816,10 +874,10 @@ function useOrders(options) {
816
874
  enabled: enabled !== false && !!client.getAccessToken()
817
875
  });
818
876
  const items = _react.useMemo.call(void 0,
819
- () => _nullishCoalesce(_optionalChain([infinite, 'access', _47 => _47.data, 'optionalAccess', _48 => _48.pages, 'access', _49 => _49.flatMap, 'call', _50 => _50((p) => p.items)]), () => ( [])),
877
+ () => _nullishCoalesce(_optionalChain([infinite, 'access', _50 => _50.data, 'optionalAccess', _51 => _51.pages, 'access', _52 => _52.flatMap, 'call', _53 => _53((p) => p.items)]), () => ( [])),
820
878
  [infinite.data]
821
879
  );
822
- const lastPage = _optionalChain([infinite, 'access', _51 => _51.data, 'optionalAccess', _52 => _52.pages, 'access', _53 => _53[infinite.data.pages.length - 1]]);
880
+ const lastPage = _optionalChain([infinite, 'access', _54 => _54.data, 'optionalAccess', _55 => _55.pages, 'access', _56 => _56[infinite.data.pages.length - 1]]);
823
881
  const loadMore = _react.useCallback.call(void 0, () => {
824
882
  if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
825
883
  return infinite.fetchNextPage();
@@ -832,10 +890,10 @@ function useOrders(options) {
832
890
  return {
833
891
  items,
834
892
  data: infinite.data,
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)),
893
+ total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _57 => _57.total]), () => ( 0)),
894
+ totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _58 => _58.totalPages]), () => ( 0)),
895
+ currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _59 => _59.page]), () => ( page)),
896
+ limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _60 => _60.limit]), () => ( limit)), () => ( 20)),
839
897
  page,
840
898
  setPage: goToPage,
841
899
  loadMore,
@@ -864,7 +922,7 @@ function useOrder(orderNumber, options) {
864
922
  } = _reactquery.useQuery.call(void 0, {
865
923
  queryKey: ["behio", "order", orderNumber],
866
924
  queryFn: () => unwrap(client.orders.get(orderNumber)),
867
- enabled: _optionalChain([options, 'optionalAccess', _58 => _58.enabled]) !== false && !!orderNumber && !!client.getAccessToken()
925
+ enabled: _optionalChain([options, 'optionalAccess', _61 => _61.enabled]) !== false && !!orderNumber && !!client.getAccessToken()
868
926
  });
869
927
  const cancelMutation = _reactquery.useMutation.call(void 0, {
870
928
  mutationFn: () => unwrap(client.orders.cancel(orderNumber)),
@@ -989,7 +1047,7 @@ function usePages(locale, options) {
989
1047
  const result = await unwrap(client.pages.list(locale));
990
1048
  return result.pages;
991
1049
  },
992
- enabled: _optionalChain([options, 'optionalAccess', _59 => _59.enabled]) !== false
1050
+ enabled: _optionalChain([options, 'optionalAccess', _62 => _62.enabled]) !== false
993
1051
  });
994
1052
  }
995
1053
  function usePage(slug, locale, options) {
@@ -997,7 +1055,7 @@ function usePage(slug, locale, options) {
997
1055
  return _reactquery.useQuery.call(void 0, {
998
1056
  queryKey: ["behio", "page", slug, locale],
999
1057
  queryFn: () => unwrap(client.pages.get(slug, locale)),
1000
- enabled: _optionalChain([options, 'optionalAccess', _60 => _60.enabled]) !== false && !!slug
1058
+ enabled: _optionalChain([options, 'optionalAccess', _63 => _63.enabled]) !== false && !!slug
1001
1059
  });
1002
1060
  }
1003
1061
 
@@ -1008,7 +1066,7 @@ function useShopInfo(options) {
1008
1066
  return _reactquery.useQuery.call(void 0, {
1009
1067
  queryKey: ["behio", "shop-info"],
1010
1068
  queryFn: () => unwrap(client.getShopInfo()),
1011
- enabled: _optionalChain([options, 'optionalAccess', _61 => _61.enabled]) !== false
1069
+ enabled: _optionalChain([options, 'optionalAccess', _64 => _64.enabled]) !== false
1012
1070
  });
1013
1071
  }
1014
1072
 
@@ -1025,6 +1083,57 @@ function useShopSeo(options) {
1025
1083
  });
1026
1084
  }
1027
1085
 
1086
+ // src/react/hooks/use-currency.ts
1087
+ function dedupe(values) {
1088
+ const out = [];
1089
+ for (const v of values) {
1090
+ if (v && !out.includes(v)) out.push(v);
1091
+ }
1092
+ return out;
1093
+ }
1094
+ function useCurrency() {
1095
+ const { currency, setCurrency, configuredDefaultCurrency, configuredCurrencies } = useBehio();
1096
+ const { data: shop, isLoading } = useShopInfo();
1097
+ const defaultCurrency = _nullishCoalesce(configuredDefaultCurrency, () => ( _optionalChain([shop, 'optionalAccess', _65 => _65.defaultCurrency])));
1098
+ const currencies = configuredCurrencies && configuredCurrencies.length > 0 ? dedupe(configuredCurrencies) : dedupe([defaultCurrency, ..._nullishCoalesce(_optionalChain([shop, 'optionalAccess', _66 => _66.supportedCurrencies]), () => ( []))]);
1099
+ return {
1100
+ currency,
1101
+ effectiveCurrency: _nullishCoalesce(currency, () => ( defaultCurrency)),
1102
+ setCurrency,
1103
+ currencies,
1104
+ defaultCurrency,
1105
+ isLoading
1106
+ };
1107
+ }
1108
+
1109
+ // src/react/components/currency-switcher.tsx
1110
+
1111
+ function CurrencySwitcher({
1112
+ className,
1113
+ labels,
1114
+ showWhenSingle = false,
1115
+ ariaLabel = "Currency",
1116
+ children
1117
+ }) {
1118
+ const { currencies, effectiveCurrency, setCurrency } = useCurrency();
1119
+ if (currencies.length === 0) return null;
1120
+ if (currencies.length <= 1 && !showWhenSingle) return null;
1121
+ const label = (code) => _nullishCoalesce(_optionalChain([labels, 'optionalAccess', _67 => _67[code]]), () => ( code));
1122
+ if (children) {
1123
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: children({ currencies, value: effectiveCurrency, setCurrency, label }) });
1124
+ }
1125
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1126
+ "select",
1127
+ {
1128
+ className,
1129
+ "aria-label": ariaLabel,
1130
+ value: _nullishCoalesce(effectiveCurrency, () => ( "")),
1131
+ onChange: (e) => setCurrency(e.target.value),
1132
+ children: currencies.map((code) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "option", { value: code, children: label(code) }, code))
1133
+ }
1134
+ );
1135
+ }
1136
+
1028
1137
  // src/react/hooks/use-bundles.ts
1029
1138
 
1030
1139
  function useBundles(options) {
@@ -1032,8 +1141,8 @@ function useBundles(options) {
1032
1141
  return _reactquery.useQuery.call(void 0, {
1033
1142
  queryKey: ["behio", "bundles"],
1034
1143
  queryFn: () => unwrap(client.catalog.getBundles()),
1035
- enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _62 => _62.enabled]), () => ( true)),
1036
- initialData: _optionalChain([options, 'optionalAccess', _63 => _63.initialData])
1144
+ enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.enabled]), () => ( true)),
1145
+ initialData: _optionalChain([options, 'optionalAccess', _69 => _69.initialData])
1037
1146
  });
1038
1147
  }
1039
1148
  function useBundle(slug, options) {
@@ -1041,8 +1150,8 @@ function useBundle(slug, options) {
1041
1150
  return _reactquery.useQuery.call(void 0, {
1042
1151
  queryKey: ["behio", "bundle", slug],
1043
1152
  queryFn: () => unwrap(client.catalog.getBundle(slug)),
1044
- enabled: Boolean(slug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _64 => _64.enabled]), () => ( true))),
1045
- initialData: _optionalChain([options, 'optionalAccess', _65 => _65.initialData])
1153
+ enabled: Boolean(slug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _70 => _70.enabled]), () => ( true))),
1154
+ initialData: _optionalChain([options, 'optionalAccess', _71 => _71.initialData])
1046
1155
  });
1047
1156
  }
1048
1157
 
@@ -1053,8 +1162,8 @@ function useCrossSell(productSlug, options) {
1053
1162
  return _reactquery.useQuery.call(void 0, {
1054
1163
  queryKey: ["behio", "cross-sell", productSlug],
1055
1164
  queryFn: () => unwrap(client.catalog.getCrossSell(productSlug)),
1056
- enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _66 => _66.enabled]), () => ( true))),
1057
- initialData: _optionalChain([options, 'optionalAccess', _67 => _67.initialData])
1165
+ enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.enabled]), () => ( true))),
1166
+ initialData: _optionalChain([options, 'optionalAccess', _73 => _73.initialData])
1058
1167
  });
1059
1168
  }
1060
1169
 
@@ -1065,8 +1174,8 @@ function useProductPromotions(productSlug, options) {
1065
1174
  return _reactquery.useQuery.call(void 0, {
1066
1175
  queryKey: ["behio", "product-promotions", productSlug],
1067
1176
  queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
1068
- enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.enabled]), () => ( true))),
1069
- refetchInterval: _optionalChain([options, 'optionalAccess', _69 => _69.refetchIntervalMs])
1177
+ enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _74 => _74.enabled]), () => ( true))),
1178
+ refetchInterval: _optionalChain([options, 'optionalAccess', _75 => _75.refetchIntervalMs])
1070
1179
  });
1071
1180
  }
1072
1181
 
@@ -1074,11 +1183,11 @@ function useProductPromotions(productSlug, options) {
1074
1183
 
1075
1184
  function useGiftCardBalance(code, options) {
1076
1185
  const { client } = useBehio();
1077
- const trimmed = _optionalChain([code, 'optionalAccess', _70 => _70.trim, 'call', _71 => _71()]);
1186
+ const trimmed = _optionalChain([code, 'optionalAccess', _76 => _76.trim, 'call', _77 => _77()]);
1078
1187
  return _reactquery.useQuery.call(void 0, {
1079
1188
  queryKey: ["behio", "gift-card-balance", trimmed],
1080
1189
  queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
1081
- enabled: Boolean(trimmed && trimmed.length >= 6) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.enabled]), () => ( true)))
1190
+ enabled: Boolean(trimmed && trimmed.length >= 6) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _78 => _78.enabled]), () => ( true)))
1082
1191
  });
1083
1192
  }
1084
1193
 
@@ -1090,7 +1199,7 @@ function useWishlist(options) {
1090
1199
  const query = _reactquery.useQuery.call(void 0, {
1091
1200
  queryKey: ["behio", "wishlist"],
1092
1201
  queryFn: () => unwrap(client.wishlist.get()),
1093
- enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _73 => _73.enabled]), () => ( true))
1202
+ enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _79 => _79.enabled]), () => ( true))
1094
1203
  });
1095
1204
  const addMutation = _reactquery.useMutation.call(void 0, {
1096
1205
  mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
@@ -1122,9 +1231,9 @@ function useIsInWishlist(productId) {
1122
1231
  function useProductReviews(productId, options) {
1123
1232
  const { client } = useBehio();
1124
1233
  return _reactquery.useQuery.call(void 0, {
1125
- queryKey: ["behio", "reviews", productId, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _74 => _74.page]), () => ( 1))],
1126
- queryFn: () => unwrap(client.reviews.getProductReviews(productId, _optionalChain([options, 'optionalAccess', _75 => _75.page]), _optionalChain([options, 'optionalAccess', _76 => _76.limit]))),
1127
- enabled: Boolean(productId) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _77 => _77.enabled]), () => ( true)))
1234
+ queryKey: ["behio", "reviews", productId, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _80 => _80.page]), () => ( 1))],
1235
+ queryFn: () => unwrap(client.reviews.getProductReviews(productId, _optionalChain([options, 'optionalAccess', _81 => _81.page]), _optionalChain([options, 'optionalAccess', _82 => _82.limit]))),
1236
+ enabled: Boolean(productId) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _83 => _83.enabled]), () => ( true)))
1128
1237
  });
1129
1238
  }
1130
1239
  function useSubmitReview() {
@@ -1215,20 +1324,6 @@ function useBehioClient() {
1215
1324
  return useBehio().client;
1216
1325
  }
1217
1326
 
1218
- // src/react/utils/format-price.ts
1219
- function formatPrice(amount, currency, locale) {
1220
- const resolvedLocale = _nullishCoalesce(locale, () => ( "cs"));
1221
- try {
1222
- return new Intl.NumberFormat(resolvedLocale, {
1223
- style: "currency",
1224
- currency,
1225
- minimumFractionDigits: Number.isInteger(amount) ? 0 : 2,
1226
- maximumFractionDigits: 2
1227
- }).format(amount);
1228
- } catch (e5) {
1229
- return `${amount} ${currency}`;
1230
- }
1231
- }
1232
1327
 
1233
1328
 
1234
1329
 
@@ -1277,4 +1372,5 @@ function formatPrice(amount, currency, locale) {
1277
1372
 
1278
1373
 
1279
1374
 
1280
- 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.useLookupReturnableOrder = useLookupReturnableOrder; exports.useNotifyWhenAvailable = useNotifyWhenAvailable; exports.useOrder = useOrder; exports.useOrderAccess = useOrderAccess; 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;
1375
+
1376
+ exports.BehioProvider = BehioProvider; exports.CurrencySwitcher = CurrencySwitcher; exports.cookieStorage = cookieStorage; exports.createMemoryStorage = createMemoryStorage; exports.detectStorage = detectStorage; exports.formatPrice = _chunkXWYDXBLGjs.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.useCurrency = useCurrency; exports.useCustomer = useCustomer; exports.useFeatured = useFeatured; exports.useFilters = useFilters; exports.useGiftCardBalance = useGiftCardBalance; exports.useIsInWishlist = useIsInWishlist; exports.useLabels = useLabels; exports.useLookupReturnableOrder = useLookupReturnableOrder; exports.useNotifyWhenAvailable = useNotifyWhenAvailable; exports.useOrder = useOrder; exports.useOrderAccess = useOrderAccess; 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;