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