@behio/storefront-sdk 0.1.4 → 0.1.6
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 +71 -6
- package/dist/{chunk-SNODOM7L.js → chunk-GGAO5T5P.js} +17 -1
- package/dist/{chunk-DBZPF3IR.mjs → chunk-S4DOL3OV.mjs} +17 -1
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/react.d.mts +136 -16
- package/dist/react.d.ts +136 -16
- package/dist/react.js +169 -59
- package/dist/react.mjs +215 -105
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
3
|
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
-
import { BehioStorefront, ProductsQuery, PaginatedResponse, ProductListItem, ProductDetail, Category, ProductLabel, FilterField, Cart, CustomerProfile, RegisterInput, CustomerAddress, OrderListItem, OrderDetail, CheckoutInput, PageDetail, Page, ShopInfo } from './index.js';
|
|
5
|
-
export { AddToCartInput, AuthTokens, BehioApiError, CartDiscount, CartItem,
|
|
4
|
+
import { BehioStorefront, ProductsQuery, PaginatedResponse, ProductListItem, ProductDetail, Category, CategoryDetail, ProductLabel, FilterField, Cart, CustomerProfile, RegisterInput, CustomerAddress, OrderListItem, OrderDetail, CheckoutInput, PageDetail, Page, ShopInfo } from './index.js';
|
|
5
|
+
export { AddToCartInput, AuthTokens, BehioApiError, CartDiscount, CartItem, CheckoutAddress, FulfillmentStatus, LoginInput, MessageResponse, OrderItem, OrderStatus, PaymentStatus, ProductPrice, ProductVariant } from './index.js';
|
|
6
|
+
import * as _tanstack_query_core from '@tanstack/query-core';
|
|
6
7
|
|
|
7
8
|
interface StorageAdapter {
|
|
8
9
|
get(key: string): string | null;
|
|
@@ -36,7 +37,51 @@ interface UseProductsOptions extends ProductsQuery {
|
|
|
36
37
|
initialData?: PaginatedResponse<ProductListItem>;
|
|
37
38
|
enabled?: boolean;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Products hook with built-in pagination helpers.
|
|
42
|
+
*
|
|
43
|
+
* Supports both **paginated** (replace items per page) and **load more** (append items) patterns.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* const { items, loadMore, hasMore, setPage, page, totalPages } = useProducts({ page: 1, limit: 30 });
|
|
48
|
+
*
|
|
49
|
+
* // Infinite scroll pattern
|
|
50
|
+
* <button onClick={loadMore} disabled={!hasMore}>Load more</button>
|
|
51
|
+
*
|
|
52
|
+
* // Traditional pagination
|
|
53
|
+
* <button onClick={() => setPage(2)}>Go to page 2</button>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function useProducts(query?: UseProductsOptions): {
|
|
57
|
+
/** All items from all loaded pages (flat array) — for infinite scroll */
|
|
58
|
+
items: ProductListItem[];
|
|
59
|
+
/** Raw React Query data with all pages */
|
|
60
|
+
data: _tanstack_query_core.InfiniteData<PaginatedResponse<ProductListItem>, unknown>;
|
|
61
|
+
/** Last loaded page meta */
|
|
62
|
+
total: number;
|
|
63
|
+
totalPages: number;
|
|
64
|
+
currentPage: number;
|
|
65
|
+
limit: number;
|
|
66
|
+
/** Current page (manual pagination) */
|
|
67
|
+
page: number;
|
|
68
|
+
/** Change page (traditional pagination — replaces items) */
|
|
69
|
+
setPage: (newPage: number) => void;
|
|
70
|
+
/** Load next page (append to items — for infinite scroll / load more button) */
|
|
71
|
+
loadMore: () => Promise<void> | Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<PaginatedResponse<ProductListItem>, unknown>, Error>>;
|
|
72
|
+
/** Fetch previous page */
|
|
73
|
+
loadPrevious: (options?: _tanstack_query_core.FetchPreviousPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<PaginatedResponse<ProductListItem>, unknown>, Error>>;
|
|
74
|
+
/** Can load more? */
|
|
75
|
+
hasMore: boolean;
|
|
76
|
+
hasPrevious: boolean;
|
|
77
|
+
isLoading: false;
|
|
78
|
+
isFetching: boolean;
|
|
79
|
+
isLoadingMore: boolean;
|
|
80
|
+
error: Error | null;
|
|
81
|
+
isError: boolean;
|
|
82
|
+
/** Force refetch all loaded pages */
|
|
83
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<PaginatedResponse<ProductListItem>, unknown>, Error>>;
|
|
84
|
+
};
|
|
40
85
|
|
|
41
86
|
interface UseProductOptions {
|
|
42
87
|
locale?: string;
|
|
@@ -46,9 +91,20 @@ interface UseProductOptions {
|
|
|
46
91
|
}
|
|
47
92
|
declare function useProduct(slug: string, options?: UseProductOptions): _tanstack_react_query.UseQueryResult<ProductDetail, Error>;
|
|
48
93
|
|
|
49
|
-
|
|
94
|
+
interface UseCategoriesOptions {
|
|
95
|
+
enabled?: boolean;
|
|
96
|
+
}
|
|
97
|
+
declare function useCategories(locale?: string, options?: UseCategoriesOptions): _tanstack_react_query.UseQueryResult<Category[], Error>;
|
|
98
|
+
interface UseCategoryOptions {
|
|
99
|
+
locale?: string;
|
|
100
|
+
enabled?: boolean;
|
|
101
|
+
}
|
|
102
|
+
declare function useCategory(slug: string, options?: UseCategoryOptions): _tanstack_react_query.UseQueryResult<CategoryDetail, Error>;
|
|
50
103
|
|
|
51
|
-
|
|
104
|
+
interface UseLabelsOptions {
|
|
105
|
+
enabled?: boolean;
|
|
106
|
+
}
|
|
107
|
+
declare function useLabels(locale?: string, options?: UseLabelsOptions): _tanstack_react_query.UseQueryResult<ProductLabel[], Error>;
|
|
52
108
|
|
|
53
109
|
interface UseFeaturedOptions {
|
|
54
110
|
locale?: string;
|
|
@@ -58,7 +114,10 @@ interface UseFeaturedOptions {
|
|
|
58
114
|
}
|
|
59
115
|
declare function useFeatured(options?: UseFeaturedOptions): _tanstack_react_query.UseQueryResult<PaginatedResponse<ProductListItem>, Error>;
|
|
60
116
|
|
|
61
|
-
|
|
117
|
+
interface UseFiltersOptions {
|
|
118
|
+
enabled?: boolean;
|
|
119
|
+
}
|
|
120
|
+
declare function useFilters(options?: UseFiltersOptions): _tanstack_react_query.UseQueryResult<FilterField[], Error>;
|
|
62
121
|
|
|
63
122
|
interface UseSearchOptions {
|
|
64
123
|
page?: number;
|
|
@@ -68,7 +127,10 @@ interface UseSearchOptions {
|
|
|
68
127
|
}
|
|
69
128
|
declare function useSearch(query: string, options?: UseSearchOptions): _tanstack_react_query.UseQueryResult<PaginatedResponse<ProductListItem>, Error>;
|
|
70
129
|
|
|
71
|
-
|
|
130
|
+
interface UseCartOptions {
|
|
131
|
+
enabled?: boolean;
|
|
132
|
+
}
|
|
133
|
+
declare function useCart(options?: UseCartOptions): {
|
|
72
134
|
cart: Cart | null;
|
|
73
135
|
isLoading: boolean;
|
|
74
136
|
error: Error | null;
|
|
@@ -88,7 +150,10 @@ declare function useCart(): {
|
|
|
88
150
|
isRemoving: boolean;
|
|
89
151
|
};
|
|
90
152
|
|
|
91
|
-
|
|
153
|
+
interface UseCartCountOptions {
|
|
154
|
+
enabled?: boolean;
|
|
155
|
+
}
|
|
156
|
+
declare function useCartCount(options?: UseCartCountOptions): number;
|
|
92
157
|
|
|
93
158
|
declare function useAuth(): {
|
|
94
159
|
isLoggedIn: boolean;
|
|
@@ -106,7 +171,10 @@ declare function useAuth(): {
|
|
|
106
171
|
registerError: Error | null;
|
|
107
172
|
};
|
|
108
173
|
|
|
109
|
-
|
|
174
|
+
interface UseCustomerOptions {
|
|
175
|
+
enabled?: boolean;
|
|
176
|
+
}
|
|
177
|
+
declare function useCustomer(options?: UseCustomerOptions): {
|
|
110
178
|
data: CustomerProfile | null;
|
|
111
179
|
isLoading: boolean;
|
|
112
180
|
error: Error | null;
|
|
@@ -114,7 +182,10 @@ declare function useCustomer(): {
|
|
|
114
182
|
isUpdating: boolean;
|
|
115
183
|
};
|
|
116
184
|
|
|
117
|
-
|
|
185
|
+
interface UseAddressesOptions {
|
|
186
|
+
enabled?: boolean;
|
|
187
|
+
}
|
|
188
|
+
declare function useAddresses(options?: UseAddressesOptions): {
|
|
118
189
|
addresses: CustomerAddress[];
|
|
119
190
|
isLoading: boolean;
|
|
120
191
|
error: Error | null;
|
|
@@ -130,9 +201,41 @@ interface UseOrdersOptions {
|
|
|
130
201
|
limit?: number;
|
|
131
202
|
enabled?: boolean;
|
|
132
203
|
}
|
|
133
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Orders hook with built-in pagination helpers.
|
|
206
|
+
*
|
|
207
|
+
* Supports both paginated (setPage) and load-more patterns.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```tsx
|
|
211
|
+
* const { items, loadMore, hasMore, isLoadingMore } = useOrders({ page: 1, limit: 20 });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare function useOrders(options?: UseOrdersOptions): {
|
|
215
|
+
items: OrderListItem[];
|
|
216
|
+
data: _tanstack_query_core.InfiniteData<PaginatedResponse<OrderListItem>, unknown> | undefined;
|
|
217
|
+
total: number;
|
|
218
|
+
totalPages: number;
|
|
219
|
+
currentPage: number;
|
|
220
|
+
limit: number;
|
|
221
|
+
page: number;
|
|
222
|
+
setPage: (newPage: number) => void;
|
|
223
|
+
loadMore: () => Promise<void> | Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<PaginatedResponse<OrderListItem>, unknown>, Error>>;
|
|
224
|
+
loadPrevious: (options?: _tanstack_query_core.FetchPreviousPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<PaginatedResponse<OrderListItem>, unknown>, Error>>;
|
|
225
|
+
hasMore: boolean;
|
|
226
|
+
hasPrevious: boolean;
|
|
227
|
+
isLoading: boolean;
|
|
228
|
+
isFetching: boolean;
|
|
229
|
+
isLoadingMore: boolean;
|
|
230
|
+
error: Error | null;
|
|
231
|
+
isError: boolean;
|
|
232
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<PaginatedResponse<OrderListItem>, unknown>, Error>>;
|
|
233
|
+
};
|
|
134
234
|
|
|
135
|
-
|
|
235
|
+
interface UseOrderOptions {
|
|
236
|
+
enabled?: boolean;
|
|
237
|
+
}
|
|
238
|
+
declare function useOrder(orderNumber: string, options?: UseOrderOptions): {
|
|
136
239
|
data: OrderDetail | null;
|
|
137
240
|
isLoading: boolean;
|
|
138
241
|
error: Error | null;
|
|
@@ -148,10 +251,27 @@ declare function useCheckout(): {
|
|
|
148
251
|
reset: () => void;
|
|
149
252
|
};
|
|
150
253
|
|
|
151
|
-
|
|
152
|
-
|
|
254
|
+
interface UsePagesOptions {
|
|
255
|
+
enabled?: boolean;
|
|
256
|
+
}
|
|
257
|
+
declare function usePages(locale?: string, options?: UsePagesOptions): _tanstack_react_query.UseQueryResult<Page[], Error>;
|
|
258
|
+
interface UsePageOptions {
|
|
259
|
+
enabled?: boolean;
|
|
260
|
+
}
|
|
261
|
+
declare function usePage(slug: string, locale?: string, options?: UsePageOptions): _tanstack_react_query.UseQueryResult<PageDetail, Error>;
|
|
153
262
|
|
|
154
|
-
|
|
263
|
+
interface UseShopInfoOptions {
|
|
264
|
+
enabled?: boolean;
|
|
265
|
+
}
|
|
266
|
+
declare function useShopInfo(options?: UseShopInfoOptions): _tanstack_react_query.UseQueryResult<ShopInfo, Error>;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Returns the raw BehioStorefront client instance.
|
|
270
|
+
*
|
|
271
|
+
* Useful for one-off fetches outside of React Query, listening to SDK events,
|
|
272
|
+
* or any advanced use case that needs direct access to the client.
|
|
273
|
+
*/
|
|
274
|
+
declare function useBehioClient(): BehioStorefront;
|
|
155
275
|
|
|
156
276
|
/**
|
|
157
277
|
* Format a price amount with currency using Intl.NumberFormat.
|
|
@@ -163,4 +283,4 @@ declare function useShopInfo(): _tanstack_react_query.UseQueryResult<ShopInfo, E
|
|
|
163
283
|
*/
|
|
164
284
|
declare function formatPrice(amount: number, currency: string, locale?: string): string;
|
|
165
285
|
|
|
166
|
-
export { BehioProvider, type BehioProviderProps, Cart, Category, CheckoutInput, CustomerAddress, CustomerProfile, FilterField, OrderDetail, OrderListItem, Page, PageDetail, PaginatedResponse, ProductDetail, ProductLabel, ProductListItem, ProductsQuery, RegisterInput, ShopInfo, type StorageAdapter, type UseFeaturedOptions, type UseOrdersOptions, type UseProductOptions, type UseProductsOptions, type UseSearchOptions, cookieStorage, createMemoryStorage, detectStorage, formatPrice, localStorageAdapter, memoryStorage, useAddresses, useAuth, useBehio, useCart, useCartCount, useCategories, useCheckout, useCustomer, useFeatured, useFilters, useLabels, useOrder, useOrders, usePage, usePages, useProduct, useProducts, useSearch, useShopInfo };
|
|
286
|
+
export { BehioProvider, type BehioProviderProps, Cart, Category, CategoryDetail, CheckoutInput, CustomerAddress, CustomerProfile, FilterField, OrderDetail, OrderListItem, Page, PageDetail, PaginatedResponse, ProductDetail, ProductLabel, ProductListItem, ProductsQuery, RegisterInput, ShopInfo, type StorageAdapter, type UseAddressesOptions, type UseCartCountOptions, type UseCartOptions, type UseCategoriesOptions, type UseCategoryOptions, type UseCustomerOptions, type UseFeaturedOptions, type UseFiltersOptions, type UseLabelsOptions, type UseOrderOptions, type UseOrdersOptions, type UsePageOptions, type UsePagesOptions, type UseProductOptions, type UseProductsOptions, type UseSearchOptions, type UseShopInfoOptions, cookieStorage, createMemoryStorage, detectStorage, formatPrice, localStorageAdapter, memoryStorage, useAddresses, useAuth, useBehio, useBehioClient, useCart, useCartCount, useCategories, useCategory, useCheckout, useCustomer, useFeatured, useFilters, useLabels, useOrder, useOrders, usePage, usePages, useProduct, useProducts, useSearch, useShopInfo };
|