@behio/storefront-sdk 0.1.11 → 0.3.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/README.md +67 -1340
- package/dist/{chunk-WMBSTKJR.mjs → chunk-45FTJKSW.mjs} +96 -0
- package/dist/{chunk-33DUMF3N.js → chunk-ZEPWNT56.js} +96 -0
- package/dist/index.d.mts +183 -1
- package/dist/index.d.ts +183 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/react.d.mts +502 -3
- package/dist/react.d.ts +502 -3
- package/dist/react.js +245 -58
- package/dist/react.mjs +220 -33
- 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 _chunkZEPWNT56js = require('./chunk-ZEPWNT56.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,
|
|
117
|
+
clientRef.current = new (0, _chunkZEPWNT56js.BehioStorefront)({
|
|
118
118
|
apiKey,
|
|
119
119
|
baseUrl,
|
|
120
120
|
locale,
|
|
@@ -173,11 +173,11 @@ function useProducts(query) {
|
|
|
173
173
|
enabled: enabled !== false
|
|
174
174
|
});
|
|
175
175
|
const items = _react.useMemo.call(void 0,
|
|
176
|
-
() => _nullishCoalesce(_optionalChain([infinite, 'access',
|
|
176
|
+
() => _nullishCoalesce(_optionalChain([infinite, 'access', _2 => _2.data, 'optionalAccess', _3 => _3.pages, 'access', _4 => _4.flatMap, 'call', _5 => _5((p) => p.items)]), () => ( [])),
|
|
177
177
|
[infinite.data]
|
|
178
178
|
);
|
|
179
|
-
const lastPage = _optionalChain([infinite, 'access',
|
|
180
|
-
const firstPage = _optionalChain([infinite, 'access',
|
|
179
|
+
const lastPage = _optionalChain([infinite, 'access', _6 => _6.data, 'optionalAccess', _7 => _7.pages, 'access', _8 => _8[infinite.data.pages.length - 1]]);
|
|
180
|
+
const firstPage = _optionalChain([infinite, 'access', _9 => _9.data, 'optionalAccess', _10 => _10.pages, 'access', _11 => _11[0]]);
|
|
181
181
|
const loadMore = _react.useCallback.call(void 0, () => {
|
|
182
182
|
if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
|
|
183
183
|
return infinite.fetchNextPage();
|
|
@@ -194,10 +194,10 @@ function useProducts(query) {
|
|
|
194
194
|
/** Raw React Query data with all pages */
|
|
195
195
|
data: infinite.data,
|
|
196
196
|
/** Last loaded page meta */
|
|
197
|
-
total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess',
|
|
198
|
-
totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess',
|
|
199
|
-
currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess',
|
|
200
|
-
limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess',
|
|
197
|
+
total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _12 => _12.total]), () => ( 0)),
|
|
198
|
+
totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _13 => _13.totalPages]), () => ( 0)),
|
|
199
|
+
currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _14 => _14.page]), () => ( page)),
|
|
200
|
+
limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _15 => _15.limit]), () => ( limit)), () => ( 20)),
|
|
201
201
|
// --- Pagination controls ---
|
|
202
202
|
/** Current page (manual pagination) */
|
|
203
203
|
page,
|
|
@@ -229,11 +229,11 @@ function useProduct(slug, options) {
|
|
|
229
229
|
return _reactquery.useQuery.call(void 0, {
|
|
230
230
|
queryKey: ["behio", "product", slug],
|
|
231
231
|
queryFn: () => client.catalog.getProduct(slug, {
|
|
232
|
-
locale: _optionalChain([options, 'optionalAccess',
|
|
233
|
-
currency: _optionalChain([options, 'optionalAccess',
|
|
232
|
+
locale: _optionalChain([options, 'optionalAccess', _16 => _16.locale]),
|
|
233
|
+
currency: _optionalChain([options, 'optionalAccess', _17 => _17.currency])
|
|
234
234
|
}),
|
|
235
|
-
initialData: _optionalChain([options, 'optionalAccess',
|
|
236
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
235
|
+
initialData: _optionalChain([options, 'optionalAccess', _18 => _18.initialData]),
|
|
236
|
+
enabled: _optionalChain([options, 'optionalAccess', _19 => _19.enabled]) !== false && !!slug
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
|
|
@@ -247,15 +247,15 @@ function useCategories(locale, options) {
|
|
|
247
247
|
const result = await client.catalog.getCategories(locale);
|
|
248
248
|
return result.categories;
|
|
249
249
|
},
|
|
250
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
250
|
+
enabled: _optionalChain([options, 'optionalAccess', _20 => _20.enabled]) !== false
|
|
251
251
|
});
|
|
252
252
|
}
|
|
253
253
|
function useCategory(slug, options) {
|
|
254
254
|
const { client } = useBehio();
|
|
255
255
|
return _reactquery.useQuery.call(void 0, {
|
|
256
|
-
queryKey: ["behio", "category", slug, _optionalChain([options, 'optionalAccess',
|
|
257
|
-
queryFn: () => client.catalog.getCategory(slug, _optionalChain([options, 'optionalAccess',
|
|
258
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
256
|
+
queryKey: ["behio", "category", slug, _optionalChain([options, 'optionalAccess', _21 => _21.locale])],
|
|
257
|
+
queryFn: () => client.catalog.getCategory(slug, _optionalChain([options, 'optionalAccess', _22 => _22.locale])),
|
|
258
|
+
enabled: _optionalChain([options, 'optionalAccess', _23 => _23.enabled]) !== false && !!slug
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
261
|
|
|
@@ -269,7 +269,7 @@ function useLabels(locale, options) {
|
|
|
269
269
|
const result = await client.catalog.getLabels(locale);
|
|
270
270
|
return result.labels;
|
|
271
271
|
},
|
|
272
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
272
|
+
enabled: _optionalChain([options, 'optionalAccess', _24 => _24.enabled]) !== false
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
|
|
@@ -278,13 +278,13 @@ function useLabels(locale, options) {
|
|
|
278
278
|
function useFeatured(options) {
|
|
279
279
|
const { client } = useBehio();
|
|
280
280
|
return _reactquery.useQuery.call(void 0, {
|
|
281
|
-
queryKey: ["behio", "featured", _optionalChain([options, 'optionalAccess',
|
|
281
|
+
queryKey: ["behio", "featured", _optionalChain([options, 'optionalAccess', _25 => _25.locale]), _optionalChain([options, 'optionalAccess', _26 => _26.currency])],
|
|
282
282
|
queryFn: () => client.catalog.getFeatured({
|
|
283
|
-
locale: _optionalChain([options, 'optionalAccess',
|
|
284
|
-
currency: _optionalChain([options, 'optionalAccess',
|
|
283
|
+
locale: _optionalChain([options, 'optionalAccess', _27 => _27.locale]),
|
|
284
|
+
currency: _optionalChain([options, 'optionalAccess', _28 => _28.currency])
|
|
285
285
|
}),
|
|
286
|
-
initialData: _optionalChain([options, 'optionalAccess',
|
|
287
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
286
|
+
initialData: _optionalChain([options, 'optionalAccess', _29 => _29.initialData]),
|
|
287
|
+
enabled: _optionalChain([options, 'optionalAccess', _30 => _30.enabled]) !== false
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
|
|
@@ -298,7 +298,7 @@ function useFilters(options) {
|
|
|
298
298
|
const result = await client.catalog.getFilters();
|
|
299
299
|
return result.filters;
|
|
300
300
|
},
|
|
301
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
301
|
+
enabled: _optionalChain([options, 'optionalAccess', _31 => _31.enabled]) !== false
|
|
302
302
|
});
|
|
303
303
|
}
|
|
304
304
|
|
|
@@ -307,7 +307,7 @@ function useFilters(options) {
|
|
|
307
307
|
|
|
308
308
|
function useSearch(query, options) {
|
|
309
309
|
const { client } = useBehio();
|
|
310
|
-
const debounceMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
310
|
+
const debounceMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _32 => _32.debounceMs]), () => ( 300));
|
|
311
311
|
const [debouncedQuery, setDebouncedQuery] = _react.useState.call(void 0, query);
|
|
312
312
|
_react.useEffect.call(void 0, () => {
|
|
313
313
|
if (debounceMs <= 0) {
|
|
@@ -318,12 +318,12 @@ function useSearch(query, options) {
|
|
|
318
318
|
return () => clearTimeout(timer);
|
|
319
319
|
}, [query, debounceMs]);
|
|
320
320
|
return _reactquery.useQuery.call(void 0, {
|
|
321
|
-
queryKey: ["behio", "search", debouncedQuery, _optionalChain([options, 'optionalAccess',
|
|
321
|
+
queryKey: ["behio", "search", debouncedQuery, _optionalChain([options, 'optionalAccess', _33 => _33.page]), _optionalChain([options, 'optionalAccess', _34 => _34.limit])],
|
|
322
322
|
queryFn: () => client.catalog.search(debouncedQuery, {
|
|
323
|
-
page: _optionalChain([options, 'optionalAccess',
|
|
324
|
-
limit: _optionalChain([options, 'optionalAccess',
|
|
323
|
+
page: _optionalChain([options, 'optionalAccess', _35 => _35.page]),
|
|
324
|
+
limit: _optionalChain([options, 'optionalAccess', _36 => _36.limit])
|
|
325
325
|
}),
|
|
326
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
326
|
+
enabled: _optionalChain([options, 'optionalAccess', _37 => _37.enabled]) !== false && debouncedQuery.length > 0
|
|
327
327
|
});
|
|
328
328
|
}
|
|
329
329
|
|
|
@@ -342,7 +342,7 @@ function useCart(options) {
|
|
|
342
342
|
queryKey: [...CART_KEY],
|
|
343
343
|
queryFn: () => client.cart.get(),
|
|
344
344
|
// Only fetch if we have a cart session or are logged in
|
|
345
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
345
|
+
enabled: _optionalChain([options, 'optionalAccess', _38 => _38.enabled]) !== false && (!!client.getCartSession() || !!client.getAccessToken())
|
|
346
346
|
});
|
|
347
347
|
const addMutation = _reactquery.useMutation.call(void 0, {
|
|
348
348
|
mutationFn: async ({ productId, quantity }) => {
|
|
@@ -375,7 +375,7 @@ function useCart(options) {
|
|
|
375
375
|
return { previous };
|
|
376
376
|
},
|
|
377
377
|
onError: (_err, _vars, context) => {
|
|
378
|
-
if (_optionalChain([context, 'optionalAccess',
|
|
378
|
+
if (_optionalChain([context, 'optionalAccess', _39 => _39.previous])) {
|
|
379
379
|
queryClient.setQueryData([...CART_KEY], context.previous);
|
|
380
380
|
}
|
|
381
381
|
},
|
|
@@ -401,7 +401,7 @@ function useCart(options) {
|
|
|
401
401
|
return { previous };
|
|
402
402
|
},
|
|
403
403
|
onError: (_err, _vars, context) => {
|
|
404
|
-
if (_optionalChain([context, 'optionalAccess',
|
|
404
|
+
if (_optionalChain([context, 'optionalAccess', _40 => _40.previous])) {
|
|
405
405
|
queryClient.setQueryData([...CART_KEY], context.previous);
|
|
406
406
|
}
|
|
407
407
|
},
|
|
@@ -478,7 +478,7 @@ function useCart(options) {
|
|
|
478
478
|
removeDiscount,
|
|
479
479
|
merge,
|
|
480
480
|
// Computed
|
|
481
|
-
itemCount: _nullishCoalesce(_optionalChain([cart, 'optionalAccess',
|
|
481
|
+
itemCount: _nullishCoalesce(_optionalChain([cart, 'optionalAccess', _41 => _41.itemCount]), () => ( 0)),
|
|
482
482
|
isEmpty: !cart || cart.items.length === 0,
|
|
483
483
|
// Mutation states
|
|
484
484
|
isAdding: addMutation.isPending,
|
|
@@ -497,10 +497,10 @@ function useCartCount(options) {
|
|
|
497
497
|
const { data } = _reactquery.useQuery.call(void 0, {
|
|
498
498
|
queryKey: [...CART_KEY2],
|
|
499
499
|
queryFn: () => client.cart.get(),
|
|
500
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
500
|
+
enabled: _optionalChain([options, 'optionalAccess', _42 => _42.enabled]) !== false && !cachedCart && (!!client.getCartSession() || !!client.getAccessToken())
|
|
501
501
|
});
|
|
502
502
|
const cart = _nullishCoalesce(cachedCart, () => ( data));
|
|
503
|
-
return _nullishCoalesce(_optionalChain([cart, 'optionalAccess',
|
|
503
|
+
return _nullishCoalesce(_optionalChain([cart, 'optionalAccess', _43 => _43.itemCount]), () => ( 0));
|
|
504
504
|
}
|
|
505
505
|
|
|
506
506
|
// src/react/hooks/use-auth.ts
|
|
@@ -638,7 +638,7 @@ function useCustomer(options) {
|
|
|
638
638
|
} = _reactquery.useQuery.call(void 0, {
|
|
639
639
|
queryKey: [...CUSTOMER_KEY2],
|
|
640
640
|
queryFn: () => client.customer.getProfile(),
|
|
641
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
641
|
+
enabled: _optionalChain([options, 'optionalAccess', _44 => _44.enabled]) !== false && !!client.getAccessToken()
|
|
642
642
|
});
|
|
643
643
|
const updateMutation = _reactquery.useMutation.call(void 0, {
|
|
644
644
|
mutationFn: (data2) => client.customer.updateProfile(data2),
|
|
@@ -676,7 +676,7 @@ function useAddresses(options) {
|
|
|
676
676
|
const result = await client.customer.getAddresses();
|
|
677
677
|
return result.items;
|
|
678
678
|
},
|
|
679
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
679
|
+
enabled: _optionalChain([options, 'optionalAccess', _45 => _45.enabled]) !== false && !!client.getAccessToken()
|
|
680
680
|
});
|
|
681
681
|
const createMutation = _reactquery.useMutation.call(void 0, {
|
|
682
682
|
mutationFn: (address) => client.customer.createAddress(address),
|
|
@@ -720,6 +720,70 @@ function useAddresses(options) {
|
|
|
720
720
|
};
|
|
721
721
|
}
|
|
722
722
|
|
|
723
|
+
// src/react/hooks/use-address-autocomplete.ts
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
var AC_KEY = ["behio", "address-autocomplete"];
|
|
727
|
+
function useAddressAutocomplete(options) {
|
|
728
|
+
const { country, debounce = 300, minChars = 3, enabled = true } = options;
|
|
729
|
+
const { client } = useBehio();
|
|
730
|
+
const [query, setQuery] = _react.useState.call(void 0, "");
|
|
731
|
+
const [debouncedQuery, setDebouncedQuery] = _react.useState.call(void 0, "");
|
|
732
|
+
const [selected, setSelected] = _react.useState.call(void 0, null);
|
|
733
|
+
const [isSelecting, setIsSelecting] = _react.useState.call(void 0, false);
|
|
734
|
+
const timerRef = _react.useRef.call(void 0, void 0);
|
|
735
|
+
_react.useEffect.call(void 0, () => {
|
|
736
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
737
|
+
if (query.length < minChars) {
|
|
738
|
+
setDebouncedQuery("");
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
timerRef.current = setTimeout(() => {
|
|
742
|
+
setDebouncedQuery(query);
|
|
743
|
+
}, debounce);
|
|
744
|
+
return () => {
|
|
745
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
746
|
+
};
|
|
747
|
+
}, [query, debounce, minChars]);
|
|
748
|
+
const { data, isLoading } = _reactquery.useQuery.call(void 0, {
|
|
749
|
+
queryKey: [...AC_KEY, debouncedQuery, country],
|
|
750
|
+
queryFn: () => client.addresses.autocomplete(debouncedQuery, country),
|
|
751
|
+
enabled: enabled && debouncedQuery.length >= minChars,
|
|
752
|
+
staleTime: 6e4
|
|
753
|
+
// Cache suggestions for 1 min
|
|
754
|
+
});
|
|
755
|
+
const select = _react.useCallback.call(void 0,
|
|
756
|
+
async (placeId) => {
|
|
757
|
+
setIsSelecting(true);
|
|
758
|
+
try {
|
|
759
|
+
const detail = await client.addresses.getDetail(placeId);
|
|
760
|
+
setSelected(detail);
|
|
761
|
+
setQuery(detail.formattedAddress);
|
|
762
|
+
setDebouncedQuery("");
|
|
763
|
+
return detail;
|
|
764
|
+
} finally {
|
|
765
|
+
setIsSelecting(false);
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
[client]
|
|
769
|
+
);
|
|
770
|
+
const clear = _react.useCallback.call(void 0, () => {
|
|
771
|
+
setQuery("");
|
|
772
|
+
setDebouncedQuery("");
|
|
773
|
+
setSelected(null);
|
|
774
|
+
}, []);
|
|
775
|
+
return {
|
|
776
|
+
query,
|
|
777
|
+
setQuery,
|
|
778
|
+
suggestions: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _46 => _46.suggestions]), () => ( [])),
|
|
779
|
+
isLoading: isLoading && debouncedQuery.length >= minChars,
|
|
780
|
+
select,
|
|
781
|
+
selected,
|
|
782
|
+
isSelecting,
|
|
783
|
+
clear
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
|
|
723
787
|
// src/react/hooks/use-orders.ts
|
|
724
788
|
|
|
725
789
|
|
|
@@ -736,10 +800,10 @@ function useOrders(options) {
|
|
|
736
800
|
enabled: enabled !== false && !!client.getAccessToken()
|
|
737
801
|
});
|
|
738
802
|
const items = _react.useMemo.call(void 0,
|
|
739
|
-
() => _nullishCoalesce(_optionalChain([infinite, 'access',
|
|
803
|
+
() => _nullishCoalesce(_optionalChain([infinite, 'access', _47 => _47.data, 'optionalAccess', _48 => _48.pages, 'access', _49 => _49.flatMap, 'call', _50 => _50((p) => p.items)]), () => ( [])),
|
|
740
804
|
[infinite.data]
|
|
741
805
|
);
|
|
742
|
-
const lastPage = _optionalChain([infinite, 'access',
|
|
806
|
+
const lastPage = _optionalChain([infinite, 'access', _51 => _51.data, 'optionalAccess', _52 => _52.pages, 'access', _53 => _53[infinite.data.pages.length - 1]]);
|
|
743
807
|
const loadMore = _react.useCallback.call(void 0, () => {
|
|
744
808
|
if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
|
|
745
809
|
return infinite.fetchNextPage();
|
|
@@ -752,10 +816,10 @@ function useOrders(options) {
|
|
|
752
816
|
return {
|
|
753
817
|
items,
|
|
754
818
|
data: infinite.data,
|
|
755
|
-
total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess',
|
|
756
|
-
totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess',
|
|
757
|
-
currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess',
|
|
758
|
-
limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess',
|
|
819
|
+
total: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _54 => _54.total]), () => ( 0)),
|
|
820
|
+
totalPages: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _55 => _55.totalPages]), () => ( 0)),
|
|
821
|
+
currentPage: _nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _56 => _56.page]), () => ( page)),
|
|
822
|
+
limit: _nullishCoalesce(_nullishCoalesce(_optionalChain([lastPage, 'optionalAccess', _57 => _57.limit]), () => ( limit)), () => ( 20)),
|
|
759
823
|
page,
|
|
760
824
|
setPage: goToPage,
|
|
761
825
|
loadMore,
|
|
@@ -784,7 +848,7 @@ function useOrder(orderNumber, options) {
|
|
|
784
848
|
} = _reactquery.useQuery.call(void 0, {
|
|
785
849
|
queryKey: ["behio", "order", orderNumber],
|
|
786
850
|
queryFn: () => client.orders.get(orderNumber),
|
|
787
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
851
|
+
enabled: _optionalChain([options, 'optionalAccess', _58 => _58.enabled]) !== false && !!orderNumber && !!client.getAccessToken()
|
|
788
852
|
});
|
|
789
853
|
const cancelMutation = _reactquery.useMutation.call(void 0, {
|
|
790
854
|
mutationFn: () => client.orders.cancel(orderNumber),
|
|
@@ -849,7 +913,7 @@ function usePages(locale, options) {
|
|
|
849
913
|
const result = await client.pages.list(locale);
|
|
850
914
|
return result.pages;
|
|
851
915
|
},
|
|
852
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
916
|
+
enabled: _optionalChain([options, 'optionalAccess', _59 => _59.enabled]) !== false
|
|
853
917
|
});
|
|
854
918
|
}
|
|
855
919
|
function usePage(slug, locale, options) {
|
|
@@ -857,7 +921,7 @@ function usePage(slug, locale, options) {
|
|
|
857
921
|
return _reactquery.useQuery.call(void 0, {
|
|
858
922
|
queryKey: ["behio", "page", slug, locale],
|
|
859
923
|
queryFn: () => client.pages.get(slug, locale),
|
|
860
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
924
|
+
enabled: _optionalChain([options, 'optionalAccess', _60 => _60.enabled]) !== false && !!slug
|
|
861
925
|
});
|
|
862
926
|
}
|
|
863
927
|
|
|
@@ -868,7 +932,7 @@ function useShopInfo(options) {
|
|
|
868
932
|
return _reactquery.useQuery.call(void 0, {
|
|
869
933
|
queryKey: ["behio", "shop-info"],
|
|
870
934
|
queryFn: () => client.getShopInfo(),
|
|
871
|
-
enabled: _optionalChain([options, 'optionalAccess',
|
|
935
|
+
enabled: _optionalChain([options, 'optionalAccess', _61 => _61.enabled]) !== false
|
|
872
936
|
});
|
|
873
937
|
}
|
|
874
938
|
|
|
@@ -892,8 +956,8 @@ function useBundles(options) {
|
|
|
892
956
|
return _reactquery.useQuery.call(void 0, {
|
|
893
957
|
queryKey: ["behio", "bundles"],
|
|
894
958
|
queryFn: () => client.catalog.getBundles(),
|
|
895
|
-
enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
896
|
-
initialData: _optionalChain([options, 'optionalAccess',
|
|
959
|
+
enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _62 => _62.enabled]), () => ( true)),
|
|
960
|
+
initialData: _optionalChain([options, 'optionalAccess', _63 => _63.initialData])
|
|
897
961
|
});
|
|
898
962
|
}
|
|
899
963
|
function useBundle(slug, options) {
|
|
@@ -901,8 +965,8 @@ function useBundle(slug, options) {
|
|
|
901
965
|
return _reactquery.useQuery.call(void 0, {
|
|
902
966
|
queryKey: ["behio", "bundle", slug],
|
|
903
967
|
queryFn: () => client.catalog.getBundle(slug),
|
|
904
|
-
enabled: Boolean(slug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
905
|
-
initialData: _optionalChain([options, 'optionalAccess',
|
|
968
|
+
enabled: Boolean(slug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _64 => _64.enabled]), () => ( true))),
|
|
969
|
+
initialData: _optionalChain([options, 'optionalAccess', _65 => _65.initialData])
|
|
906
970
|
});
|
|
907
971
|
}
|
|
908
972
|
|
|
@@ -913,8 +977,8 @@ function useCrossSell(productSlug, options) {
|
|
|
913
977
|
return _reactquery.useQuery.call(void 0, {
|
|
914
978
|
queryKey: ["behio", "cross-sell", productSlug],
|
|
915
979
|
queryFn: () => client.catalog.getCrossSell(productSlug),
|
|
916
|
-
enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
917
|
-
initialData: _optionalChain([options, 'optionalAccess',
|
|
980
|
+
enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _66 => _66.enabled]), () => ( true))),
|
|
981
|
+
initialData: _optionalChain([options, 'optionalAccess', _67 => _67.initialData])
|
|
918
982
|
});
|
|
919
983
|
}
|
|
920
984
|
|
|
@@ -925,8 +989,8 @@ function useProductPromotions(productSlug, options) {
|
|
|
925
989
|
return _reactquery.useQuery.call(void 0, {
|
|
926
990
|
queryKey: ["behio", "product-promotions", productSlug],
|
|
927
991
|
queryFn: () => client.catalog.getProductPromotions(productSlug),
|
|
928
|
-
enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
929
|
-
refetchInterval: _optionalChain([options, 'optionalAccess',
|
|
992
|
+
enabled: Boolean(productSlug) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.enabled]), () => ( true))),
|
|
993
|
+
refetchInterval: _optionalChain([options, 'optionalAccess', _69 => _69.refetchIntervalMs])
|
|
930
994
|
});
|
|
931
995
|
}
|
|
932
996
|
|
|
@@ -934,11 +998,124 @@ function useProductPromotions(productSlug, options) {
|
|
|
934
998
|
|
|
935
999
|
function useGiftCardBalance(code, options) {
|
|
936
1000
|
const { client } = useBehio();
|
|
937
|
-
const trimmed = _optionalChain([code, 'optionalAccess',
|
|
1001
|
+
const trimmed = _optionalChain([code, 'optionalAccess', _70 => _70.trim, 'call', _71 => _71()]);
|
|
938
1002
|
return _reactquery.useQuery.call(void 0, {
|
|
939
1003
|
queryKey: ["behio", "gift-card-balance", trimmed],
|
|
940
1004
|
queryFn: () => client.catalog.checkGiftCard(trimmed),
|
|
941
|
-
enabled: Boolean(trimmed && trimmed.length >= 6) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1005
|
+
enabled: Boolean(trimmed && trimmed.length >= 6) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.enabled]), () => ( true)))
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// src/react/hooks/use-wishlist.ts
|
|
1010
|
+
|
|
1011
|
+
function useWishlist(options) {
|
|
1012
|
+
const { client } = useBehio();
|
|
1013
|
+
const qc = _reactquery.useQueryClient.call(void 0, );
|
|
1014
|
+
const query = _reactquery.useQuery.call(void 0, {
|
|
1015
|
+
queryKey: ["behio", "wishlist"],
|
|
1016
|
+
queryFn: () => client.wishlist.get(),
|
|
1017
|
+
enabled: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _73 => _73.enabled]), () => ( true))
|
|
1018
|
+
});
|
|
1019
|
+
const addMutation = _reactquery.useMutation.call(void 0, {
|
|
1020
|
+
mutationFn: (productId) => client.wishlist.add(productId),
|
|
1021
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
1022
|
+
});
|
|
1023
|
+
const removeMutation = _reactquery.useMutation.call(void 0, {
|
|
1024
|
+
mutationFn: (productId) => client.wishlist.remove(productId),
|
|
1025
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
1026
|
+
});
|
|
1027
|
+
return {
|
|
1028
|
+
...query,
|
|
1029
|
+
add: addMutation.mutateAsync,
|
|
1030
|
+
remove: removeMutation.mutateAsync,
|
|
1031
|
+
isAdding: addMutation.isPending,
|
|
1032
|
+
isRemoving: removeMutation.isPending
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
function useIsInWishlist(productId) {
|
|
1036
|
+
const { client } = useBehio();
|
|
1037
|
+
return _reactquery.useQuery.call(void 0, {
|
|
1038
|
+
queryKey: ["behio", "wishlist-check", productId],
|
|
1039
|
+
queryFn: () => client.wishlist.isInWishlist(productId),
|
|
1040
|
+
enabled: Boolean(productId)
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// src/react/hooks/use-reviews.ts
|
|
1045
|
+
|
|
1046
|
+
function useProductReviews(productId, options) {
|
|
1047
|
+
const { client } = useBehio();
|
|
1048
|
+
return _reactquery.useQuery.call(void 0, {
|
|
1049
|
+
queryKey: ["behio", "reviews", productId, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _74 => _74.page]), () => ( 1))],
|
|
1050
|
+
queryFn: () => client.reviews.getProductReviews(productId, _optionalChain([options, 'optionalAccess', _75 => _75.page]), _optionalChain([options, 'optionalAccess', _76 => _76.limit])),
|
|
1051
|
+
enabled: Boolean(productId) && (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _77 => _77.enabled]), () => ( true)))
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
function useSubmitReview() {
|
|
1055
|
+
const { client } = useBehio();
|
|
1056
|
+
const qc = _reactquery.useQueryClient.call(void 0, );
|
|
1057
|
+
return _reactquery.useMutation.call(void 0, {
|
|
1058
|
+
mutationFn: (input) => client.reviews.submit(input),
|
|
1059
|
+
onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// src/react/hooks/use-returns.ts
|
|
1064
|
+
|
|
1065
|
+
function useSubmitReturn() {
|
|
1066
|
+
const { client } = useBehio();
|
|
1067
|
+
return _reactquery.useMutation.call(void 0, {
|
|
1068
|
+
mutationFn: (input) => client.returns.submit(input)
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
function useReturnStatus(returnId, email) {
|
|
1072
|
+
const { client } = useBehio();
|
|
1073
|
+
return _reactquery.useQuery.call(void 0, {
|
|
1074
|
+
queryKey: ["behio", "return-status", returnId],
|
|
1075
|
+
queryFn: () => client.returns.getStatus(returnId, email),
|
|
1076
|
+
enabled: Boolean(returnId && email)
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// src/react/hooks/use-consent.ts
|
|
1081
|
+
|
|
1082
|
+
function useCookieConsent(visitorId) {
|
|
1083
|
+
const { client } = useBehio();
|
|
1084
|
+
const qc = _reactquery.useQueryClient.call(void 0, );
|
|
1085
|
+
const query = _reactquery.useQuery.call(void 0, {
|
|
1086
|
+
queryKey: ["behio", "consent", visitorId],
|
|
1087
|
+
queryFn: () => client.consent.get(visitorId),
|
|
1088
|
+
enabled: Boolean(visitorId)
|
|
1089
|
+
});
|
|
1090
|
+
const recordMutation = _reactquery.useMutation.call(void 0, {
|
|
1091
|
+
mutationFn: (input) => client.consent.record(input),
|
|
1092
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
1093
|
+
});
|
|
1094
|
+
const revokeMutation = _reactquery.useMutation.call(void 0, {
|
|
1095
|
+
mutationFn: () => client.consent.revoke(visitorId),
|
|
1096
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
1097
|
+
});
|
|
1098
|
+
return {
|
|
1099
|
+
...query,
|
|
1100
|
+
record: recordMutation.mutateAsync,
|
|
1101
|
+
revoke: revokeMutation.mutateAsync
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// src/react/hooks/use-quotes.ts
|
|
1106
|
+
|
|
1107
|
+
function useSubmitQuote() {
|
|
1108
|
+
const { client } = useBehio();
|
|
1109
|
+
return _reactquery.useMutation.call(void 0, {
|
|
1110
|
+
mutationFn: (input) => client.quotes.submit(input)
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
function useQuoteStatus(quoteId) {
|
|
1114
|
+
const { client } = useBehio();
|
|
1115
|
+
return _reactquery.useQuery.call(void 0, {
|
|
1116
|
+
queryKey: ["behio", "quote-status", quoteId],
|
|
1117
|
+
queryFn: () => client.quotes.getStatus(quoteId),
|
|
1118
|
+
enabled: Boolean(quoteId)
|
|
942
1119
|
});
|
|
943
1120
|
}
|
|
944
1121
|
|
|
@@ -996,4 +1173,14 @@ function formatPrice(amount, currency, locale) {
|
|
|
996
1173
|
|
|
997
1174
|
|
|
998
1175
|
|
|
999
|
-
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
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;
|