@simpleapps-com/augur-hooks 0.1.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.
@@ -0,0 +1,674 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import * as zustand from 'zustand';
4
+ import * as _simpleapps_com_augur_utils from '@simpleapps-com/augur-utils';
5
+ import { TCartLine, TItemsFilters, TPriceData, TInvMastDoc, TCategory, TItemDetails, TProductCategory, TProductItem } from '@simpleapps-com/augur-utils';
6
+ import * as _tanstack_react_query from '@tanstack/react-query';
7
+ import { QueryKey } from '@tanstack/react-query';
8
+
9
+ /**
10
+ * Minimal type for the augur-api SDK instance.
11
+ * Consumers provide their concrete AugurAPI instance; we keep the type
12
+ * loose so augur-hooks doesn't need to depend directly on the SDK package.
13
+ */
14
+ type AugurApiClient = any;
15
+ interface AugurHooksProviderProps {
16
+ api: AugurApiClient;
17
+ children: ReactNode;
18
+ }
19
+ /**
20
+ * Provides the augur-api SDK instance to all hooks in the tree.
21
+ *
22
+ * ```tsx
23
+ * import { AugurAPI } from "@simpleapps-com/augur-api";
24
+ * const api = new AugurAPI({ baseUrl: "...", token: "..." });
25
+ *
26
+ * <AugurHooksProvider api={api}>
27
+ * <App />
28
+ * </AugurHooksProvider>
29
+ * ```
30
+ */
31
+ declare function AugurHooksProvider({ api, children }: AugurHooksProviderProps): react_jsx_runtime.JSX.Element;
32
+ /**
33
+ * Returns the augur-api SDK instance from context.
34
+ * Throws if called outside of `<AugurHooksProvider>`.
35
+ */
36
+ declare function useAugurApi(): AugurApiClient;
37
+
38
+ /**
39
+ * Hook-specific types that don't belong in augur-utils.
40
+ * These describe hook parameters and API response shapes.
41
+ */
42
+ /** Parameters for product search queries. */
43
+ type PageData = {
44
+ categoryIdList?: string;
45
+ filters?: any;
46
+ limit: number;
47
+ page: number;
48
+ offset: number;
49
+ q: string;
50
+ sortBy: string;
51
+ tagslist?: string;
52
+ itemCategoryUid?: number;
53
+ };
54
+ /** A single search suggestion from OpenSearch. */
55
+ type SearchSuggestion = {
56
+ suggestionsUid: number;
57
+ queryStringUid: number;
58
+ suggestionsString: string;
59
+ suggestionsMetaphone: string | null;
60
+ avgTotalResults: number;
61
+ dateCreated: string;
62
+ dateLastModified: string;
63
+ updateCd: number;
64
+ statusCd: number;
65
+ processCd: number;
66
+ score: number;
67
+ };
68
+ /** Response shape from the search suggestions endpoint. */
69
+ type SearchSuggestionsResponse = {
70
+ count: number;
71
+ data: SearchSuggestion[];
72
+ message: string;
73
+ options: unknown[];
74
+ params: unknown[];
75
+ status: number;
76
+ total: number;
77
+ totalResults: number;
78
+ };
79
+ /** API options for item category queries. */
80
+ interface GetItemCategoryApiOptions {
81
+ childrenFilter?: string;
82
+ childrenLimit?: number;
83
+ childrenOffset?: number;
84
+ classId5List?: string;
85
+ filters?: Record<string, any>;
86
+ orderBy?: string;
87
+ path?: string;
88
+ productCollection?: string;
89
+ rootItemCategoryId?: string;
90
+ }
91
+
92
+ interface CartState {
93
+ cartHdrUid: number | string | undefined;
94
+ cartLines: TCartLine[];
95
+ cartItemCount: number;
96
+ setCartHdrUid: (cartHdrUid: number | string | undefined) => void;
97
+ setCartLines: (cartLines: TCartLine[]) => void;
98
+ }
99
+ declare const useCartStore: zustand.UseBoundStore<Omit<zustand.StoreApi<CartState>, "setState" | "devtools"> & {
100
+ setState(partial: CartState | Partial<CartState> | ((state: CartState) => CartState | Partial<CartState>), replace?: false | undefined, action?: (string | {
101
+ [x: string]: unknown;
102
+ [x: number]: unknown;
103
+ [x: symbol]: unknown;
104
+ type: string;
105
+ }) | undefined): void;
106
+ setState(state: CartState | ((state: CartState) => CartState), replace: true, action?: (string | {
107
+ [x: string]: unknown;
108
+ [x: number]: unknown;
109
+ [x: symbol]: unknown;
110
+ type: string;
111
+ }) | undefined): void;
112
+ devtools: {
113
+ cleanup: () => void;
114
+ };
115
+ }>;
116
+ declare const useCartHdrUid: () => string | number | undefined;
117
+ declare const useCartLines: () => TCartLine[];
118
+ declare const useCartItemCount: () => number;
119
+ declare const useSetCartHdrUid: () => (cartHdrUid: number | string | undefined) => void;
120
+ declare const useSetCartLines: () => (cartLines: TCartLine[]) => void;
121
+
122
+ interface ItemsFiltersState {
123
+ initialFiltersState: TItemsFilters;
124
+ itemsFilters: TItemsFilters;
125
+ setItemsFilters: (itemFilters: TItemsFilters) => void;
126
+ }
127
+ declare const useItemFiltersStore: zustand.UseBoundStore<Omit<zustand.StoreApi<ItemsFiltersState>, "setState" | "devtools"> & {
128
+ setState(partial: ItemsFiltersState | Partial<ItemsFiltersState> | ((state: ItemsFiltersState) => ItemsFiltersState | Partial<ItemsFiltersState>), replace?: false | undefined, action?: (string | {
129
+ [x: string]: unknown;
130
+ [x: number]: unknown;
131
+ [x: symbol]: unknown;
132
+ type: string;
133
+ }) | undefined): void;
134
+ setState(state: ItemsFiltersState | ((state: ItemsFiltersState) => ItemsFiltersState), replace: true, action?: (string | {
135
+ [x: string]: unknown;
136
+ [x: number]: unknown;
137
+ [x: symbol]: unknown;
138
+ type: string;
139
+ }) | undefined): void;
140
+ devtools: {
141
+ cleanup: () => void;
142
+ };
143
+ }>;
144
+
145
+ /**
146
+ * Debounces a rapidly-changing value.
147
+ * Returns the latest value only after `delay` ms of inactivity.
148
+ */
149
+ declare function useDebounce<T>(value: T, delay?: number): T;
150
+
151
+ /**
152
+ * Hook that returns a price formatter.
153
+ * Wraps Intl.NumberFormat with configurable locale/currency.
154
+ */
155
+ declare function useFormatPrice(locale?: string, currency?: string): {
156
+ formatPrice: (price: number) => string;
157
+ };
158
+
159
+ interface UseItemPriceOptions {
160
+ enabled?: boolean;
161
+ /** Override the default queryFn (e.g. with a cached server action). */
162
+ queryFn?: () => Promise<TPriceData>;
163
+ }
164
+ declare const PRICE_CACHE_OPTIONS: {
165
+ readonly refetchOnReconnect: true;
166
+ readonly refetchOnWindowFocus: false;
167
+ readonly meta: {
168
+ readonly persist: true;
169
+ };
170
+ readonly staleTime: number;
171
+ readonly gcTime: number;
172
+ };
173
+ /**
174
+ * Generates a consistent query key for item price queries.
175
+ * Usable in both client hooks and server-side prefetch.
176
+ */
177
+ declare const getItemPriceKey: (itemId: string | undefined, customerId: string | number | undefined, quantity?: number) => readonly ["price", string, string | number | undefined, number];
178
+ /**
179
+ * Query options for item price. Accepts the SDK instance so it works
180
+ * in both client (via provider) and server (via direct construction).
181
+ */
182
+ declare const getItemPriceOptions: (api: AugurApiClient, itemId: string | undefined, customerId: string | number | undefined, quantity?: number) => {
183
+ refetchOnReconnect: true;
184
+ refetchOnWindowFocus: false;
185
+ meta: {
186
+ readonly persist: true;
187
+ };
188
+ staleTime: number;
189
+ gcTime: number;
190
+ queryKey: readonly ["price", string, string | number | undefined, number];
191
+ queryFn: () => Promise<TPriceData>;
192
+ };
193
+ /**
194
+ * Fetches and caches item pricing via the augur-api SDK.
195
+ *
196
+ * Pass `options.queryFn` to override with a cached server action:
197
+ * ```ts
198
+ * useItemPrice(itemId, customerId, 1, {
199
+ * queryFn: () => getItemPriceCached(itemId, customerId, 1),
200
+ * });
201
+ * ```
202
+ */
203
+ declare function useItemPrice(itemId: string | undefined, customerId: string | number | undefined, quantity?: number, options?: UseItemPriceOptions): _tanstack_react_query.UseQueryResult<TPriceData, Error>;
204
+
205
+ interface UseInvMastDocOptions {
206
+ enabled?: boolean;
207
+ includePricing?: "Y" | "N";
208
+ /** Initial data from server -- enables instant render without loading state. */
209
+ initialData?: TInvMastDoc;
210
+ /** Override the default queryFn (e.g. with a cached server action). */
211
+ queryFn?: () => Promise<TInvMastDoc>;
212
+ }
213
+ declare const INV_MAST_DOC_CACHE_OPTIONS: {
214
+ readonly staleTime: number;
215
+ readonly gcTime: number;
216
+ };
217
+ /**
218
+ * Generates a consistent query key for inv mast doc queries.
219
+ * Usable in both client hooks and server-side prefetch.
220
+ */
221
+ declare const getInvMastDocKey: (invMastUid: number, itemId: string, includePricing: "Y" | "N") => readonly ["invMastDoc", number, string, "Y" | "N"];
222
+ /**
223
+ * Query options for inv mast doc. Accepts the SDK instance so it works
224
+ * in both client (via provider) and server (via direct construction).
225
+ */
226
+ declare const getInvMastDocOptions: (api: AugurApiClient, invMastUid: number, itemId: string, includePricing: "Y" | "N") => {
227
+ staleTime: number;
228
+ gcTime: number;
229
+ queryKey: readonly ["invMastDoc", number, string, "Y" | "N"];
230
+ queryFn: () => Promise<TInvMastDoc>;
231
+ };
232
+ /**
233
+ * Fetches and caches an inventory master document via the augur-api SDK.
234
+ */
235
+ declare function useInvMastDoc(invMastUid: number, itemId: string, options?: UseInvMastDocOptions): {
236
+ item: TInvMastDoc | undefined;
237
+ isLoading: boolean;
238
+ error: Error | null;
239
+ };
240
+
241
+ interface UseItemCategoryOptions {
242
+ enabled?: boolean;
243
+ apiOptions?: GetItemCategoryApiOptions;
244
+ /** Override the default queryFn (e.g. with a cached server action). */
245
+ queryFn?: () => Promise<TCategory>;
246
+ }
247
+ declare const CATEGORY_CACHE_OPTIONS: {
248
+ readonly staleTime: number;
249
+ readonly gcTime: number;
250
+ };
251
+ type ItemCategoryQueryKey = readonly [
252
+ "itemCategory",
253
+ number,
254
+ GetItemCategoryApiOptions | undefined
255
+ ];
256
+ /**
257
+ * Generates a consistent query key for item category queries.
258
+ * Usable in both client hooks and server-side prefetch.
259
+ */
260
+ declare const getItemCategoryKey: (itemCategoryUid: number, apiOptions?: GetItemCategoryApiOptions) => ItemCategoryQueryKey;
261
+ /**
262
+ * Query options for item category. Accepts the SDK instance so it works
263
+ * in both client (via provider) and server (via direct construction).
264
+ */
265
+ declare const getItemCategoryOptions: (api: AugurApiClient, itemCategoryUid: number, apiOptions?: GetItemCategoryApiOptions) => {
266
+ staleTime: number;
267
+ gcTime: number;
268
+ queryKey: ItemCategoryQueryKey;
269
+ queryFn: () => Promise<TCategory>;
270
+ };
271
+ /**
272
+ * Fetches and caches item category data via the augur-api SDK.
273
+ */
274
+ declare function useItemCategory(itemCategoryUid: number, options?: UseItemCategoryOptions): {
275
+ category: TCategory | undefined;
276
+ isLoading: boolean;
277
+ error: Error | null;
278
+ };
279
+
280
+ interface UseInvMastOptions {
281
+ enabled?: boolean;
282
+ queryFn?: () => Promise<TItemDetails>;
283
+ }
284
+ declare const INV_MAST_CACHE_OPTIONS: {
285
+ readonly staleTime: number;
286
+ readonly gcTime: number;
287
+ };
288
+ declare const getInvMastKey: (invMastUid: number, itemId: string) => readonly ["invMast", number, string];
289
+ declare const getInvMastOptions: (api: AugurApiClient, invMastUid: number, itemId: string) => {
290
+ staleTime: number;
291
+ gcTime: number;
292
+ queryKey: readonly ["invMast", number, string];
293
+ queryFn: () => Promise<TItemDetails>;
294
+ };
295
+ declare function useInvMast(invMastUid: number, itemId: string, options?: UseInvMastOptions): {
296
+ item: TItemDetails | undefined;
297
+ isLoading: boolean;
298
+ error: Error | null;
299
+ };
300
+
301
+ interface UseInvMastStockOptions {
302
+ enabled?: boolean;
303
+ queryFn?: () => Promise<number>;
304
+ }
305
+ declare const getInvMastStockKey: (invMastUid: number | string) => readonly ["invMastStock", string | number];
306
+ declare const getInvMastStockOptions: (api: AugurApiClient, invMastUid: number | string) => {
307
+ staleTime: number;
308
+ gcTime: number;
309
+ queryKey: readonly ["invMastStock", string | number];
310
+ queryFn: () => Promise<number>;
311
+ };
312
+ declare function useInvMastStock(invMastUid: number | string, options?: UseInvMastStockOptions): {
313
+ qtyOnHand: number | null;
314
+ loading: boolean;
315
+ error: Error | null;
316
+ };
317
+
318
+ type ProductCategoryResponse = {
319
+ itemCategoryDesc: string;
320
+ childrenTotal: number;
321
+ children: TProductCategory[];
322
+ categoryImage: string | null;
323
+ };
324
+ interface UseProductCategoryOptions {
325
+ enabled?: boolean;
326
+ queryFn?: () => Promise<ProductCategoryResponse>;
327
+ }
328
+ declare const getProductCategoryKey: (itemCategoryUid: number | string | null) => readonly ["productCategory", string | number | null];
329
+ declare const getProductCategoryOptions: (api: AugurApiClient, itemCategoryUid: number | string) => {
330
+ staleTime: number;
331
+ gcTime: number;
332
+ queryKey: readonly ["productCategory", string | number | null];
333
+ queryFn: () => Promise<ProductCategoryResponse>;
334
+ };
335
+ declare function useProductCategory(itemCategoryUid: number | string | null, options?: UseProductCategoryOptions): {
336
+ childrenTotal: number;
337
+ itemCategoryDesc: string;
338
+ productCategories: TProductCategory[] | null;
339
+ productCategoryImage: string | null;
340
+ loading: boolean;
341
+ error: Error | null;
342
+ };
343
+
344
+ interface UseItemDetailsOptions {
345
+ enabled?: boolean;
346
+ queryFn?: () => Promise<TItemDetails>;
347
+ }
348
+ declare const getItemDetailsKey: (itemId: number | string) => readonly ["itemDetails", string | number];
349
+ declare const getItemDetailsOptions: (api: AugurApiClient, itemId: number | string) => {
350
+ staleTime: number;
351
+ gcTime: number;
352
+ queryKey: readonly ["itemDetails", string | number];
353
+ queryFn: () => Promise<TItemDetails>;
354
+ };
355
+ declare function useItemDetails(itemId: number | string | undefined, options?: UseItemDetailsOptions): {
356
+ itemCategoryUid: number | null | undefined;
357
+ itemDetails: TItemDetails | null;
358
+ loading: boolean;
359
+ error: Error | null;
360
+ };
361
+
362
+ interface UseItemAttributesOptions {
363
+ enabled?: boolean;
364
+ queryFn?: () => Promise<{
365
+ attributes: any[];
366
+ }>;
367
+ }
368
+ declare const getItemAttributesKey: (itemCategoryUid: number | string | null) => readonly ["itemAttributes", string | number | null];
369
+ declare const getItemAttributesOptions: (api: AugurApiClient, itemCategoryUid: number | string) => {
370
+ staleTime: number;
371
+ gcTime: number;
372
+ queryKey: readonly ["itemAttributes", string | number | null];
373
+ queryFn: () => Promise<any>;
374
+ };
375
+ declare function useItemAttributes(itemCategoryUid: number | string | null, options?: UseItemAttributesOptions): {
376
+ attributes: any;
377
+ loading: boolean;
378
+ error: Error | null;
379
+ };
380
+
381
+ type ProductSearchResponse = {
382
+ items: TProductItem[];
383
+ totalResults: number;
384
+ };
385
+ interface UseProductSearchOptions {
386
+ /** Override the default queryFn (e.g. with a cached server action). */
387
+ queryFn?: () => Promise<ProductSearchResponse>;
388
+ }
389
+ /**
390
+ * Generates a consistent query key for product search queries.
391
+ */
392
+ declare const getProductSearchKey: (pageData: PageData) => readonly ["productSearch", string, number, number, string, number | undefined];
393
+ /**
394
+ * Query options for product search. Accepts the SDK instance so it works
395
+ * in both client (via provider) and server (via direct construction).
396
+ */
397
+ declare const getProductSearchOptions: (api: AugurApiClient, pageData: PageData) => {
398
+ staleTime: number;
399
+ gcTime: number;
400
+ queryKey: readonly ["productSearch", string, number, number, string, number | undefined];
401
+ queryFn: () => Promise<ProductSearchResponse>;
402
+ };
403
+ /**
404
+ * Searches products via the augur-api OpenSearch endpoint.
405
+ * Replaces the ampro-online pattern of fetching from a Next.js API route.
406
+ */
407
+ declare function useProductSearch(pageData: PageData, options?: UseProductSearchOptions): {
408
+ productItems: TProductItem[] | null;
409
+ total: number;
410
+ loading: boolean;
411
+ error: Error | null;
412
+ };
413
+
414
+ interface UseSearchSuggestionsOptions {
415
+ enabled?: boolean;
416
+ limit?: number;
417
+ offset?: number;
418
+ /** Override the default queryFn (e.g. with a cached server action). */
419
+ queryFn?: () => Promise<SearchSuggestionsResponse>;
420
+ }
421
+ /**
422
+ * Generates a consistent query key for search suggestion queries.
423
+ */
424
+ declare const getSearchSuggestionsKey: (query: string, limit: number, offset: number) => readonly ["searchSuggestions", string, number, number];
425
+ /**
426
+ * Query options for search suggestions. Accepts the SDK instance so it works
427
+ * in both client (via provider) and server (via direct construction).
428
+ */
429
+ declare const getSearchSuggestionsOptions: (api: AugurApiClient, query: string, limit?: number, offset?: number) => {
430
+ staleTime: number;
431
+ gcTime: number;
432
+ queryKey: readonly ["searchSuggestions", string, number, number];
433
+ queryFn: () => Promise<SearchSuggestionsResponse>;
434
+ };
435
+ /**
436
+ * Fetches search suggestions via the augur-api OpenSearch endpoint.
437
+ * Replaces the ampro-online pattern of fetching from a Next.js API route.
438
+ */
439
+ declare function useSearchSuggestions(query: string, options?: UseSearchSuggestionsOptions): {
440
+ suggestions: SearchSuggestion[];
441
+ total: number;
442
+ isLoading: boolean;
443
+ error: Error | null;
444
+ };
445
+
446
+ type CartLineInput = Pick<TCartLine, "invMastUid" | "quantity" | "unitOfMeasure"> & {
447
+ cartHdrUid?: number | string | undefined;
448
+ };
449
+ /** Site-specific callbacks injected into useCartActions. */
450
+ interface CartActionCallbacks {
451
+ /** Add items to cart via API. Returns true on success. */
452
+ addToCart: (cartHdrUid: number, items: Array<{
453
+ cartHdrUid: number;
454
+ invMastUid: number;
455
+ quantity: number;
456
+ unitOfMeasure: string;
457
+ }>) => Promise<boolean | unknown>;
458
+ /** Update cart lines via API. Returns true on success. */
459
+ updateCartLines: (cartHdrUid: number, lines: TCartLine[]) => Promise<boolean | unknown>;
460
+ /** Delete all items from cart via API. Returns true on success. */
461
+ deleteItemsFromCart: (cartHdrUid: number) => Promise<boolean | unknown>;
462
+ /** Optional toast notification callback. */
463
+ toast?: {
464
+ info?: (message: string) => void;
465
+ error?: (message: string) => void;
466
+ success?: (message: string) => void;
467
+ };
468
+ }
469
+ interface CartActionOptions {
470
+ showToast?: boolean;
471
+ itemId?: string;
472
+ onSuccess?: () => void;
473
+ onError?: (error: Error) => void;
474
+ }
475
+ /**
476
+ * Optimistic cart actions hook with automatic rollback on failure.
477
+ *
478
+ * Accepts site-specific server action callbacks so the hook itself
479
+ * has no dependency on any particular server action implementation.
480
+ *
481
+ * @example
482
+ * ```tsx
483
+ * import { useCartActions } from "@simpleapps-com/augur-hooks";
484
+ * import { addToCart, updateCartLines, deleteItemsFromCart } from "@/lib/actions/commerce";
485
+ * import { toast } from "react-toastify";
486
+ *
487
+ * const cart = useCartActions({
488
+ * addToCart, updateCartLines, deleteItemsFromCart,
489
+ * toast: { info: toast.info, error: toast.error },
490
+ * });
491
+ *
492
+ * await cart.addToCart({ invMastUid: 123, quantity: 1, unitOfMeasure: "EA" });
493
+ * ```
494
+ */
495
+ declare function useCartActions(callbacks: CartActionCallbacks): {
496
+ addToCart: (item: CartLineInput, options?: CartActionOptions) => Promise<boolean>;
497
+ updateQuantity: (invMastUid: number, newQuantity: number, options?: CartActionOptions) => Promise<boolean>;
498
+ removeFromCart: (invMastUid: number, options?: CartActionOptions) => Promise<boolean>;
499
+ clearCart: (options?: Omit<CartActionOptions, "itemId">) => Promise<boolean>;
500
+ isInCart: (invMastUid: number) => boolean;
501
+ getItemQuantity: (invMastUid: number) => number;
502
+ cartHdrUid: string | number | undefined;
503
+ cartLines: TCartLine[];
504
+ invalidateCartCache: () => void;
505
+ };
506
+
507
+ /** Session info passed from the consumer's auth system. */
508
+ interface CartSessionInfo {
509
+ /** Auth status: "loading" | "authenticated" | "unauthenticated" */
510
+ status: "loading" | "authenticated" | "unauthenticated";
511
+ /** User's ID (e.g., Joomla user ID). Undefined if not authenticated. */
512
+ userId?: string | number;
513
+ /** Cart header UID from the auth session, if available. */
514
+ cartHdrUid?: number;
515
+ }
516
+ /** Site-specific callbacks injected into useCartInitialization. */
517
+ interface CartInitCallbacks {
518
+ /** Look up or create a cart header. Returns { cartHdrUid, cartToken? }. */
519
+ cartHdrLookup: (userId: string | number, cartToken: string) => Promise<{
520
+ cartHdrUid: number;
521
+ cartToken?: string;
522
+ } | null>;
523
+ /** Fetch cart line items for a given cart header UID. */
524
+ getCartLines: (cartHdrUid: number) => Promise<TCartLine[]>;
525
+ /** Get the current cart token from cookies. */
526
+ getCartToken: () => string | null;
527
+ /** Save cart token to cookies. */
528
+ saveCartToken: (token: string) => void;
529
+ /** Generate a new unique cart token (e.g., uuidv4). */
530
+ generateCartToken: () => string;
531
+ }
532
+ /**
533
+ * Initialize cart state from session (authenticated) or cookie (guest).
534
+ * Call once in the root layout.
535
+ *
536
+ * @example
537
+ * ```tsx
538
+ * import { useCartInitialization } from "@simpleapps-com/augur-hooks";
539
+ * import { useSession } from "next-auth/react";
540
+ * import { cartHdrLookup, getCartLines } from "@/lib/actions/commerce";
541
+ * import { getCookie, setCookie } from "cookies-next/client";
542
+ * import { v4 as uuidv4 } from "uuid";
543
+ *
544
+ * function CartInitializer() {
545
+ * const { data: session, status } = useSession();
546
+ *
547
+ * useCartInitialization(
548
+ * {
549
+ * status,
550
+ * userId: session?.user?.id,
551
+ * cartHdrUid: session?.user?.cartHdrUid,
552
+ * },
553
+ * {
554
+ * cartHdrLookup,
555
+ * getCartLines,
556
+ * getCartToken: () => getCookie("cartToken") as string | null,
557
+ * saveCartToken: (token) => setCookie("cartToken", token, { maxAge: 604800, path: "/" }),
558
+ * generateCartToken: uuidv4,
559
+ * },
560
+ * );
561
+ *
562
+ * return null;
563
+ * }
564
+ * ```
565
+ */
566
+ declare function useCartInitialization(session: CartSessionInfo, callbacks: CartInitCallbacks): {
567
+ cartHdrUid: string | number | undefined;
568
+ isInitializing: boolean;
569
+ retryCount: number;
570
+ };
571
+
572
+ interface CartPriceData {
573
+ unitPrice: number;
574
+ priceData: Record<string, unknown> | null;
575
+ }
576
+ interface CartPricingResult {
577
+ /** Map of itemId -> price data (with quantity-specific pricing) */
578
+ prices: Record<string, CartPriceData>;
579
+ /** Get unit price for an item (returns 0 if not found) */
580
+ getUnitPrice: (itemId: string) => number;
581
+ /** Get total price for an item (unitPrice * quantity) */
582
+ getItemTotal: (itemId: string, quantity: number) => number;
583
+ /** Cart subtotal (sum of all item totals) */
584
+ subtotal: number;
585
+ /** True if any price is still loading */
586
+ isLoading: boolean;
587
+ /** True if all prices loaded successfully */
588
+ isSuccess: boolean;
589
+ /** True if any price failed to load */
590
+ isError: boolean;
591
+ }
592
+ interface UseCartPricingOptions {
593
+ customerId?: string | number;
594
+ }
595
+ /**
596
+ * Centralized hook for cart/checkout pricing.
597
+ *
598
+ * Fetches prices for ALL cart items with their actual quantities
599
+ * to support quantity-based price breaks. React Query dedupes
600
+ * identical calls across components.
601
+ */
602
+ declare function useCartPricing(options?: UseCartPricingOptions): CartPricingResult;
603
+ /**
604
+ * Get cart pricing query options for prefetching or parent components.
605
+ */
606
+ declare function getCartPricingQueryOptions(api: ReturnType<typeof useAugurApi>, cartLines: Array<{
607
+ itemId: string;
608
+ quantity: number;
609
+ }>, customerId: string | number | undefined): {
610
+ enabled: boolean;
611
+ refetchOnReconnect: true;
612
+ refetchOnWindowFocus: false;
613
+ meta: {
614
+ readonly persist: true;
615
+ };
616
+ staleTime: number;
617
+ gcTime: number;
618
+ queryKey: readonly ["price", string, string | number | undefined, number];
619
+ queryFn: () => Promise<_simpleapps_com_augur_utils.TPriceData>;
620
+ }[];
621
+
622
+ interface UsePaginationPrefetchOptions {
623
+ /** Query key for the paginated data */
624
+ queryKey: QueryKey;
625
+ /** Function to fetch a page of data */
626
+ queryFn: (offset: number) => Promise<unknown>;
627
+ /** Number of items per page */
628
+ pageSize: number;
629
+ /** Stale time in ms (defaults to 10 minutes) */
630
+ staleTime?: number;
631
+ /** GC time in ms (defaults to 30 minutes) */
632
+ gcTime?: number;
633
+ enabled?: boolean;
634
+ }
635
+ /**
636
+ * Prefetch adjacent pages on hover for instant pagination.
637
+ * Accepts a generic queryFn so it works with any paginated resource.
638
+ */
639
+ declare const usePaginationPrefetch: ({ queryKey, queryFn, pageSize, staleTime, gcTime, enabled, }: UsePaginationPrefetchOptions) => {
640
+ prefetchPage: (page: number) => Promise<void>;
641
+ handlePaginationHover: (page: number) => () => void;
642
+ };
643
+
644
+ interface CategoryItemsInfiniteResponse {
645
+ data: TProductItem[];
646
+ total: number;
647
+ nextCursor?: number;
648
+ }
649
+ interface UseCategoryItemsInfiniteOptions {
650
+ enabled?: boolean;
651
+ }
652
+ declare const getCategoryItemsInfiniteKey: (itemCategoryUid: number, itemsFilters: TItemsFilters) => readonly ["categoryItemsInfinite", number, string];
653
+ /**
654
+ * Infinite scroll for category product listings.
655
+ * Fetches pages of products via the augur-api SDK.
656
+ */
657
+ declare function useCategoryItemsInfinite(itemCategoryUid: number, itemsFilters: TItemsFilters, options?: UseCategoryItemsInfiniteOptions): _tanstack_react_query.UseInfiniteQueryResult<_tanstack_react_query.InfiniteData<CategoryItemsInfiniteResponse, unknown>, Error>;
658
+
659
+ interface ItemSearchInfiniteResponse {
660
+ data: TProductItem[];
661
+ total: number;
662
+ nextCursor?: number;
663
+ }
664
+ interface UseItemSearchInfiniteOptions {
665
+ enabled?: boolean;
666
+ }
667
+ declare const getItemSearchInfiniteKey: (itemsFilters: TItemsFilters, itemCategoryUid?: number | string) => readonly ["itemSearchInfinite", string, string | number | undefined];
668
+ /**
669
+ * Infinite scroll for search results.
670
+ * Fetches pages of products via the augur-api SDK OpenSearch endpoint.
671
+ */
672
+ declare function useItemSearchInfinite(itemsFilters: TItemsFilters, itemCategoryUid?: number | string, options?: UseItemSearchInfiniteOptions): _tanstack_react_query.UseInfiniteQueryResult<_tanstack_react_query.InfiniteData<ItemSearchInfiniteResponse, unknown>, Error>;
673
+
674
+ export { type AugurApiClient, AugurHooksProvider, CATEGORY_CACHE_OPTIONS, type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type GetItemCategoryApiOptions, INV_MAST_CACHE_OPTIONS, INV_MAST_DOC_CACHE_OPTIONS, PRICE_CACHE_OPTIONS, type PageData, type SearchSuggestion, type SearchSuggestionsResponse, getCartPricingQueryOptions, getCategoryItemsInfiniteKey, getInvMastDocKey, getInvMastDocOptions, getInvMastKey, getInvMastOptions, getInvMastStockKey, getInvMastStockOptions, getItemAttributesKey, getItemAttributesOptions, getItemCategoryKey, getItemCategoryOptions, getItemDetailsKey, getItemDetailsOptions, getItemPriceKey, getItemPriceOptions, getItemSearchInfiniteKey, getProductCategoryKey, getProductCategoryOptions, getProductSearchKey, getProductSearchOptions, getSearchSuggestionsKey, getSearchSuggestionsOptions, useAugurApi, useCartActions, useCartHdrUid, useCartInitialization, useCartItemCount, useCartLines, useCartPricing, useCartStore, useCategoryItemsInfinite, useDebounce, useFormatPrice, useInvMast, useInvMastDoc, useInvMastStock, useItemAttributes, useItemCategory, useItemDetails, useItemFiltersStore, useItemPrice, useItemSearchInfinite, usePaginationPrefetch, useProductCategory, useProductSearch, useSearchSuggestions, useSetCartHdrUid, useSetCartLines };