@simpleapps-com/augur-hooks 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/dist/index.js CHANGED
@@ -1,9 +1,53 @@
1
+ import {
2
+ CATEGORY_CACHE_OPTIONS,
3
+ INV_MAST_CACHE_OPTIONS,
4
+ INV_MAST_DOC_CACHE_OPTIONS,
5
+ PRICE_CACHE_OPTIONS,
6
+ SEARCH_SUGGESTIONS_CACHE_OPTIONS,
7
+ getCartPricingQueryOptions,
8
+ getCategoryItemsInfiniteKey,
9
+ getCategoryItemsInfiniteOptions,
10
+ getInvMastDocKey,
11
+ getInvMastDocOptions,
12
+ getInvMastKey,
13
+ getInvMastOptions,
14
+ getInvMastStockKey,
15
+ getInvMastStockOptions,
16
+ getItemAttributesKey,
17
+ getItemAttributesOptions,
18
+ getItemCategoryKey,
19
+ getItemCategoryOptions,
20
+ getItemDetailsKey,
21
+ getItemDetailsOptions,
22
+ getItemPriceKey,
23
+ getItemPriceOptions,
24
+ getItemSearchInfiniteKey,
25
+ getItemSearchInfiniteOptions,
26
+ getProductCategoryKey,
27
+ getProductCategoryOptions,
28
+ getProductSearchKey,
29
+ getProductSearchOptions,
30
+ getSearchSuggestionsKey,
31
+ getSearchSuggestionsOptions
32
+ } from "./chunk-DS2ECDHJ.js";
33
+
1
34
  // src/provider.tsx
2
35
  import { createContext, useContext } from "react";
3
36
  import { jsx } from "react/jsx-runtime";
4
37
  var AugurApiContext = createContext(null);
5
- function AugurHooksProvider({ api, children }) {
6
- return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api, children });
38
+ var AugurCallbacksContext = createContext(
39
+ void 0
40
+ );
41
+ var AugurAuthReactContext = createContext(
42
+ void 0
43
+ );
44
+ function AugurHooksProvider({
45
+ api,
46
+ callbacks,
47
+ auth,
48
+ children
49
+ }) {
50
+ return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api, children: /* @__PURE__ */ jsx(AugurCallbacksContext.Provider, { value: callbacks, children: /* @__PURE__ */ jsx(AugurAuthReactContext.Provider, { value: auth, children }) }) });
7
51
  }
8
52
  function useAugurApi() {
9
53
  const api = useContext(AugurApiContext);
@@ -14,6 +58,12 @@ function useAugurApi() {
14
58
  }
15
59
  return api;
16
60
  }
61
+ function useAugurCallbacks() {
62
+ return useContext(AugurCallbacksContext);
63
+ }
64
+ function useAugurAuth() {
65
+ return useContext(AugurAuthReactContext);
66
+ }
17
67
 
18
68
  // src/stores/cart-store.ts
19
69
  import { create } from "zustand";
@@ -102,64 +152,26 @@ function useFormatPrice(locale = "en-US", currency = "USD") {
102
152
 
103
153
  // src/hooks/use-item-price.ts
104
154
  import { useQuery } from "@tanstack/react-query";
105
- import { CACHE_CONFIG } from "@simpleapps-com/augur-utils";
106
- var PRICE_CACHE_OPTIONS = {
107
- ...CACHE_CONFIG.SEMI_STATIC,
108
- refetchOnReconnect: true,
109
- refetchOnWindowFocus: false,
110
- meta: { persist: true }
111
- };
112
- var getItemPriceKey = (itemId, customerId, quantity = 1) => {
113
- return ["price", itemId?.toUpperCase() || "", customerId, quantity];
114
- };
115
- var getItemPriceOptions = (api, itemId, customerId, quantity = 1) => ({
116
- queryKey: getItemPriceKey(itemId, customerId, quantity),
117
- queryFn: async () => {
118
- const response = await api.pricing.priceEngine.get({
119
- itemId: itemId?.toUpperCase() || "",
120
- customerId: Number(customerId),
121
- quantity
122
- });
123
- return response.data;
124
- },
125
- ...PRICE_CACHE_OPTIONS
126
- });
127
155
  function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
128
156
  const api = useAugurApi();
129
- const defaultOptions = getItemPriceOptions(api, itemId, customerId, quantity);
157
+ const callbacks = useAugurCallbacks();
158
+ const auth = useAugurAuth();
159
+ const effectiveCustomerId = customerId ?? auth?.customerId;
160
+ const defaultOptions = getItemPriceOptions(api, itemId, effectiveCustomerId, quantity);
161
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getItemPrice ? () => callbacks.getItemPrice(itemId, effectiveCustomerId, quantity) : void 0);
130
162
  return useQuery({
131
163
  ...defaultOptions,
132
- ...options.queryFn ? { queryFn: options.queryFn } : {},
133
- enabled: options.enabled ?? (Boolean(itemId) && Boolean(customerId)),
164
+ ...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
165
+ enabled: options.enabled ?? (Boolean(itemId) && Boolean(effectiveCustomerId)),
134
166
  retry: 3
135
167
  });
136
168
  }
137
169
 
138
170
  // src/hooks/use-inv-mast-doc.ts
139
171
  import { useQuery as useQuery2 } from "@tanstack/react-query";
140
- import { CACHE_CONFIG as CACHE_CONFIG2 } from "@simpleapps-com/augur-utils";
141
- var INV_MAST_DOC_CACHE_OPTIONS = CACHE_CONFIG2.STATIC;
142
- var getInvMastDocKey = (invMastUid, itemId, includePricing) => {
143
- return [
144
- "invMastDoc",
145
- invMastUid,
146
- itemId.toUpperCase(),
147
- includePricing
148
- ];
149
- };
150
- var getInvMastDocOptions = (api, invMastUid, itemId, includePricing) => ({
151
- queryKey: getInvMastDocKey(invMastUid, itemId, includePricing),
152
- queryFn: async () => {
153
- const response = await api.items.invMast.doc.list(invMastUid, {
154
- includePricing
155
- });
156
- if (!response.data) throw new Error("Item not found");
157
- return response.data;
158
- },
159
- ...INV_MAST_DOC_CACHE_OPTIONS
160
- });
161
172
  function useInvMastDoc(invMastUid, itemId, options = {}) {
162
173
  const api = useAugurApi();
174
+ const callbacks = useAugurCallbacks();
163
175
  const queryOpts = getInvMastDocOptions(
164
176
  api,
165
177
  invMastUid,
@@ -168,7 +180,7 @@ function useInvMastDoc(invMastUid, itemId, options = {}) {
168
180
  );
169
181
  const { data, isLoading, error } = useQuery2({
170
182
  ...queryOpts,
171
- ...options.queryFn ? { queryFn: options.queryFn } : {},
183
+ ...options.queryFn ?? callbacks?.getInvMastDoc ? { queryFn: options.queryFn ?? (() => callbacks.getInvMastDoc(invMastUid, itemId, options.includePricing ?? "N")) } : {},
172
184
  enabled: options.enabled ?? true,
173
185
  initialData: options.initialData
174
186
  });
@@ -177,25 +189,9 @@ function useInvMastDoc(invMastUid, itemId, options = {}) {
177
189
 
178
190
  // src/hooks/use-item-category.ts
179
191
  import { useQuery as useQuery3 } from "@tanstack/react-query";
180
- import { CACHE_CONFIG as CACHE_CONFIG3 } from "@simpleapps-com/augur-utils";
181
- var CATEGORY_CACHE_OPTIONS = CACHE_CONFIG3.STATIC;
182
- var getItemCategoryKey = (itemCategoryUid, apiOptions) => {
183
- return ["itemCategory", itemCategoryUid, apiOptions];
184
- };
185
- var getItemCategoryOptions = (api, itemCategoryUid, apiOptions) => ({
186
- queryKey: getItemCategoryKey(itemCategoryUid, apiOptions),
187
- queryFn: async () => {
188
- const response = await api.items.itemCategory.get(
189
- itemCategoryUid,
190
- apiOptions
191
- );
192
- if (!response.data) throw new Error("Item category not found");
193
- return response.data;
194
- },
195
- ...CATEGORY_CACHE_OPTIONS
196
- });
197
192
  function useItemCategory(itemCategoryUid, options = {}) {
198
193
  const api = useAugurApi();
194
+ const callbacks = useAugurCallbacks();
199
195
  const queryOpts = getItemCategoryOptions(
200
196
  api,
201
197
  itemCategoryUid,
@@ -203,7 +199,7 @@ function useItemCategory(itemCategoryUid, options = {}) {
203
199
  );
204
200
  const { data, isLoading, error } = useQuery3({
205
201
  ...queryOpts,
206
- ...options.queryFn ? { queryFn: options.queryFn } : {},
202
+ ...options.queryFn ?? callbacks?.getItemCategory ? { queryFn: options.queryFn ?? (() => callbacks.getItemCategory(itemCategoryUid, options.apiOptions)) } : {},
207
203
  enabled: options.enabled ?? true
208
204
  });
209
205
  return { category: data, isLoading, error };
@@ -211,26 +207,13 @@ function useItemCategory(itemCategoryUid, options = {}) {
211
207
 
212
208
  // src/hooks/use-inv-mast.ts
213
209
  import { useQuery as useQuery4 } from "@tanstack/react-query";
214
- import { CACHE_CONFIG as CACHE_CONFIG4 } from "@simpleapps-com/augur-utils";
215
- var INV_MAST_CACHE_OPTIONS = CACHE_CONFIG4.STATIC;
216
- var getInvMastKey = (invMastUid, itemId) => {
217
- return ["invMast", invMastUid, itemId.toUpperCase()];
218
- };
219
- var getInvMastOptions = (api, invMastUid, itemId) => ({
220
- queryKey: getInvMastKey(invMastUid, itemId),
221
- queryFn: async () => {
222
- const response = await api.items.invMast.get(invMastUid);
223
- if (!response.data) throw new Error("Item not found");
224
- return response.data;
225
- },
226
- ...INV_MAST_CACHE_OPTIONS
227
- });
228
210
  function useInvMast(invMastUid, itemId, options = {}) {
229
211
  const api = useAugurApi();
212
+ const callbacks = useAugurCallbacks();
230
213
  const queryOpts = getInvMastOptions(api, invMastUid, itemId);
231
214
  const { data, isLoading, error } = useQuery4({
232
215
  ...queryOpts,
233
- ...options.queryFn ? { queryFn: options.queryFn } : {},
216
+ ...options.queryFn ?? callbacks?.getInvMast ? { queryFn: options.queryFn ?? (() => callbacks.getInvMast(invMastUid, itemId)) } : {},
234
217
  enabled: options.enabled ?? true
235
218
  });
236
219
  return { item: data, isLoading, error };
@@ -238,28 +221,13 @@ function useInvMast(invMastUid, itemId, options = {}) {
238
221
 
239
222
  // src/hooks/use-inv-mast-stock.ts
240
223
  import { useQuery as useQuery5 } from "@tanstack/react-query";
241
- import { CACHE_CONFIG as CACHE_CONFIG5 } from "@simpleapps-com/augur-utils";
242
- var getInvMastStockKey = (invMastUid) => {
243
- return ["invMastStock", invMastUid];
244
- };
245
- var getInvMastStockOptions = (api, invMastUid) => ({
246
- queryKey: getInvMastStockKey(invMastUid),
247
- queryFn: async () => {
248
- const response = await api.items.invMast.stock.list(Number(invMastUid));
249
- const stockData = response.data?.stockData ?? [];
250
- return stockData.reduce(
251
- (qty, stock) => qty + stock.qtyOnHand,
252
- 0
253
- );
254
- },
255
- ...CACHE_CONFIG5.SEMI_STATIC
256
- });
257
224
  function useInvMastStock(invMastUid, options = {}) {
258
225
  const api = useAugurApi();
226
+ const callbacks = useAugurCallbacks();
259
227
  const queryOpts = getInvMastStockOptions(api, invMastUid);
260
228
  const { data, isLoading, error } = useQuery5({
261
229
  ...queryOpts,
262
- ...options.queryFn ? { queryFn: options.queryFn } : {},
230
+ ...options.queryFn ?? callbacks?.getInvMastStock ? { queryFn: options.queryFn ?? (() => callbacks.getInvMastStock(invMastUid)) } : {},
263
231
  enabled: (options.enabled ?? true) && !!invMastUid,
264
232
  retry: 3,
265
233
  /* v8 ignore start */
@@ -275,29 +243,26 @@ function useInvMastStock(invMastUid, options = {}) {
275
243
 
276
244
  // src/hooks/use-product-category.ts
277
245
  import { useQuery as useQuery6 } from "@tanstack/react-query";
278
- import { CACHE_CONFIG as CACHE_CONFIG6 } from "@simpleapps-com/augur-utils";
279
- var getProductCategoryKey = (itemCategoryUid) => {
280
- return ["productCategory", itemCategoryUid];
281
- };
282
- var getProductCategoryOptions = (api, itemCategoryUid) => ({
283
- queryKey: getProductCategoryKey(itemCategoryUid),
284
- queryFn: async () => {
285
- const response = await api.items.itemCategory.get(
286
- Number(itemCategoryUid)
287
- );
288
- return response.data;
289
- },
290
- ...CACHE_CONFIG6.STATIC
291
- });
246
+ function resolveData(data) {
247
+ return {
248
+ childrenTotal: data?.childrenTotal ?? 0,
249
+ itemCategoryDesc: data?.itemCategoryDesc ?? "",
250
+ productCategories: data?.children ?? null,
251
+ productCategoryImage: data?.categoryImage ?? null
252
+ };
253
+ }
292
254
  function useProductCategory(itemCategoryUid, options = {}) {
293
255
  const api = useAugurApi();
256
+ const callbacks = useAugurCallbacks();
257
+ const baseOptions = itemCategoryUid ? getProductCategoryOptions(api, itemCategoryUid) : {
258
+ queryKey: getProductCategoryKey(null),
259
+ /* v8 ignore next */
260
+ queryFn: () => Promise.reject()
261
+ };
262
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getProductCategory ? () => callbacks.getProductCategory(itemCategoryUid) : void 0);
294
263
  const { data, isLoading, error } = useQuery6({
295
- ...itemCategoryUid ? getProductCategoryOptions(api, itemCategoryUid) : {
296
- queryKey: getProductCategoryKey(null),
297
- /* v8 ignore next */
298
- queryFn: () => Promise.reject()
299
- },
300
- ...options.queryFn ? { queryFn: options.queryFn } : {},
264
+ ...baseOptions,
265
+ ...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
301
266
  enabled: (options.enabled ?? true) && !!itemCategoryUid,
302
267
  retry: 3,
303
268
  /* v8 ignore start */
@@ -305,10 +270,7 @@ function useProductCategory(itemCategoryUid, options = {}) {
305
270
  /* v8 ignore stop */
306
271
  });
307
272
  return {
308
- childrenTotal: data?.childrenTotal ?? 0,
309
- itemCategoryDesc: data?.itemCategoryDesc ?? "",
310
- productCategories: data?.children ?? null,
311
- productCategoryImage: data?.categoryImage ?? null,
273
+ ...resolveData(data),
312
274
  loading: isLoading,
313
275
  error
314
276
  };
@@ -316,28 +278,16 @@ function useProductCategory(itemCategoryUid, options = {}) {
316
278
 
317
279
  // src/hooks/use-item-details.ts
318
280
  import { useQuery as useQuery7 } from "@tanstack/react-query";
319
- import { CACHE_CONFIG as CACHE_CONFIG7 } from "@simpleapps-com/augur-utils";
320
- var getItemDetailsKey = (itemId) => {
321
- return ["itemDetails", itemId];
322
- };
323
- var getItemDetailsOptions = (api, itemId) => ({
324
- queryKey: getItemDetailsKey(itemId),
325
- queryFn: async () => {
326
- const response = await api.items.invMast.doc.list(Number(itemId));
327
- if (!response.data) throw new Error("Item not found");
328
- return response.data;
329
- },
330
- ...CACHE_CONFIG7.STATIC
331
- });
332
281
  function useItemDetails(itemId, options = {}) {
333
282
  const api = useAugurApi();
283
+ const callbacks = useAugurCallbacks();
334
284
  const { data, isLoading, error } = useQuery7({
335
285
  ...itemId ? getItemDetailsOptions(api, itemId) : {
336
286
  queryKey: getItemDetailsKey(""),
337
287
  /* v8 ignore next */
338
288
  queryFn: () => Promise.reject()
339
289
  },
340
- ...options.queryFn ? { queryFn: options.queryFn } : {},
290
+ ...options.queryFn ?? callbacks?.getItemDetails ? { queryFn: options.queryFn ?? (() => callbacks.getItemDetails(itemId)) } : {},
341
291
  enabled: (options.enabled ?? true) && !!itemId,
342
292
  retry: 3,
343
293
  /* v8 ignore start */
@@ -355,31 +305,16 @@ function useItemDetails(itemId, options = {}) {
355
305
 
356
306
  // src/hooks/use-item-attributes.ts
357
307
  import { useQuery as useQuery8 } from "@tanstack/react-query";
358
- import { CACHE_CONFIG as CACHE_CONFIG8 } from "@simpleapps-com/augur-utils";
359
- var getItemAttributesKey = (itemCategoryUid) => {
360
- return ["itemAttributes", itemCategoryUid];
361
- };
362
- var getItemAttributesOptions = (api, itemCategoryUid) => ({
363
- queryKey: getItemAttributesKey(itemCategoryUid),
364
- queryFn: async () => {
365
- const response = await api.openSearch.itemSearch.attributes.list({
366
- q: "",
367
- searchType: "query",
368
- classId5List: String(itemCategoryUid)
369
- });
370
- return response.data;
371
- },
372
- ...CACHE_CONFIG8.STATIC
373
- });
374
308
  function useItemAttributes(itemCategoryUid, options = {}) {
375
309
  const api = useAugurApi();
310
+ const callbacks = useAugurCallbacks();
376
311
  const { data, isLoading, error } = useQuery8({
377
312
  ...itemCategoryUid ? getItemAttributesOptions(api, itemCategoryUid) : {
378
313
  queryKey: getItemAttributesKey(null),
379
314
  /* v8 ignore next */
380
315
  queryFn: () => Promise.reject()
381
316
  },
382
- ...options.queryFn ? { queryFn: options.queryFn } : {},
317
+ ...options.queryFn ?? callbacks?.getItemAttributes ? { queryFn: options.queryFn ?? (() => callbacks.getItemAttributes(itemCategoryUid)) } : {},
383
318
  enabled: (options.enabled ?? true) && !!itemCategoryUid,
384
319
  retry: 3,
385
320
  /* v8 ignore start */
@@ -395,38 +330,13 @@ function useItemAttributes(itemCategoryUid, options = {}) {
395
330
 
396
331
  // src/hooks/use-product-search.ts
397
332
  import { useQuery as useQuery9 } from "@tanstack/react-query";
398
- import { CACHE_CONFIG as CACHE_CONFIG9 } from "@simpleapps-com/augur-utils";
399
- var getProductSearchKey = (pageData) => {
400
- return [
401
- "productSearch",
402
- pageData.q,
403
- pageData.limit,
404
- pageData.offset,
405
- pageData.sortBy,
406
- pageData.itemCategoryUid
407
- ];
408
- };
409
- var getProductSearchOptions = (api, pageData) => ({
410
- queryKey: getProductSearchKey(pageData),
411
- queryFn: async () => {
412
- const response = await api.openSearch.itemSearch.list({
413
- q: pageData.q,
414
- searchType: "query",
415
- size: pageData.limit,
416
- from: pageData.offset,
417
- classId5List: pageData.itemCategoryUid ? String(pageData.itemCategoryUid) : void 0,
418
- filters: pageData.filters ? JSON.stringify(pageData.filters) : void 0
419
- });
420
- return response.data;
421
- },
422
- ...CACHE_CONFIG9.SEMI_STATIC
423
- });
424
333
  function useProductSearch(pageData, options = {}) {
425
334
  const api = useAugurApi();
335
+ const callbacks = useAugurCallbacks();
426
336
  const defaultOptions = getProductSearchOptions(api, pageData);
427
337
  const { data, isLoading, error } = useQuery9({
428
338
  ...defaultOptions,
429
- ...options.queryFn ? { queryFn: options.queryFn } : {},
339
+ ...options.queryFn ?? callbacks?.getProductSearch ? { queryFn: options.queryFn ?? (() => callbacks.getProductSearch(pageData)) } : {},
430
340
  retry: 3,
431
341
  /* v8 ignore start */
432
342
  retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
@@ -442,30 +352,16 @@ function useProductSearch(pageData, options = {}) {
442
352
 
443
353
  // src/hooks/use-search-suggestions.ts
444
354
  import { useQuery as useQuery10 } from "@tanstack/react-query";
445
- import { CACHE_CONFIG as CACHE_CONFIG10 } from "@simpleapps-com/augur-utils";
446
- var SEARCH_SUGGESTIONS_CACHE_OPTIONS = CACHE_CONFIG10.STATIC;
447
- var getSearchSuggestionsKey = (query, limit, offset) => {
448
- return ["searchSuggestions", query, limit, offset];
449
- };
450
- var getSearchSuggestionsOptions = (api, query, limit = 10, offset = 0) => ({
451
- queryKey: getSearchSuggestionsKey(query, limit, offset),
452
- queryFn: async () => {
453
- const response = await api.openSearch.suggestions.suggest.list({
454
- q: query
455
- });
456
- return response.data;
457
- },
458
- ...SEARCH_SUGGESTIONS_CACHE_OPTIONS
459
- });
460
355
  function useSearchSuggestions(query, options = {}) {
461
356
  const api = useAugurApi();
357
+ const callbacks = useAugurCallbacks();
462
358
  const limit = options.limit ?? 10;
463
359
  const offset = options.offset ?? 0;
464
360
  const enabled = (options.enabled ?? true) && query.trim().length > 0;
465
361
  const defaultOptions = getSearchSuggestionsOptions(api, query, limit, offset);
466
362
  const { data, isLoading, error } = useQuery10({
467
363
  ...defaultOptions,
468
- ...options.queryFn ? { queryFn: options.queryFn } : {},
364
+ ...options.queryFn ?? callbacks?.getSearchSuggestions ? { queryFn: options.queryFn ?? (() => callbacks.getSearchSuggestions(query, limit, offset)) } : {},
469
365
  enabled
470
366
  });
471
367
  return {
@@ -660,36 +556,44 @@ function useCartActions(callbacks) {
660
556
  }
661
557
 
662
558
  // src/hooks/use-cart-initialization.ts
663
- import { useEffect as useEffect2, useRef } from "react";
559
+ import { useEffect as useEffect2, useMemo, useRef } from "react";
664
560
  import { useQuery as useQuery11, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
665
- import { CACHE_CONFIG as CACHE_CONFIG11 } from "@simpleapps-com/augur-utils";
561
+ import { CACHE_CONFIG } from "@simpleapps-com/augur-utils";
666
562
  var MAX_RETRY_ATTEMPTS = 7;
667
563
  var RETRY_DELAY_MS = 1e3;
668
564
  function useCartInitialization(session, callbacks) {
565
+ const auth = useAugurAuth();
669
566
  const cartHdrUid = useCartHdrUid();
670
567
  const setCartHdrUid = useSetCartHdrUid();
671
568
  const setCartLines = useSetCartLines();
672
569
  const clearCart = useClearCart();
673
570
  const queryClient = useQueryClient2();
571
+ const effectiveStatus = session.status;
572
+ const effectiveUserId = session.userId ?? auth?.userId;
573
+ const effectiveCartHdrUid = session.cartHdrUid ?? auth?.cartHdrUid;
574
+ const effectiveSession = useMemo(
575
+ () => ({ status: effectiveStatus, userId: effectiveUserId, cartHdrUid: effectiveCartHdrUid }),
576
+ [effectiveStatus, effectiveUserId, effectiveCartHdrUid]
577
+ );
674
578
  const retryCountRef = useRef(0);
675
579
  const isInitializingRef = useRef(false);
676
- const prevStatusRef = useRef(session.status);
580
+ const prevStatusRef = useRef(effectiveSession.status);
677
581
  useEffect2(() => {
678
582
  const prevStatus = prevStatusRef.current;
679
- prevStatusRef.current = session.status;
680
- if (prevStatus === "authenticated" && session.status === "unauthenticated") {
583
+ prevStatusRef.current = effectiveSession.status;
584
+ if (prevStatus === "authenticated" && effectiveSession.status === "unauthenticated") {
681
585
  clearCart();
682
586
  queryClient.removeQueries({ queryKey: ["cartLines"] });
683
587
  queryClient.removeQueries({ queryKey: ["cart-also-bought"] });
684
588
  }
685
- }, [session.status, clearCart, queryClient]);
589
+ }, [effectiveSession.status, clearCart, queryClient]);
686
590
  useEffect2(() => {
687
- if (cartHdrUid || session.status === "loading") return;
688
- if (session.cartHdrUid && session.status === "authenticated") {
689
- setCartHdrUid(session.cartHdrUid);
591
+ if (cartHdrUid || effectiveSession.status === "loading") return;
592
+ if (effectiveSession.cartHdrUid && effectiveSession.status === "authenticated") {
593
+ setCartHdrUid(effectiveSession.cartHdrUid);
690
594
  return;
691
595
  }
692
- if (session.status === "unauthenticated" && !isInitializingRef.current) {
596
+ if (effectiveSession.status === "unauthenticated" && !isInitializingRef.current) {
693
597
  isInitializingRef.current = true;
694
598
  retryCountRef.current = 0;
695
599
  const initializeGuestCart = async () => {
@@ -734,12 +638,12 @@ function useCartInitialization(session, callbacks) {
734
638
  };
735
639
  initializeGuestCart();
736
640
  }
737
- }, [session, cartHdrUid, setCartHdrUid, callbacks]);
641
+ }, [effectiveSession, cartHdrUid, setCartHdrUid, callbacks]);
738
642
  const { data: cartLinesData } = useQuery11({
739
643
  queryKey: ["cartLines", cartHdrUid],
740
- queryFn: () => callbacks.getCartLines(Number(cartHdrUid)),
644
+ queryFn: async () => await callbacks.getCartLines(Number(cartHdrUid)) ?? [],
741
645
  enabled: !!cartHdrUid,
742
- ...CACHE_CONFIG11.CART
646
+ ...CACHE_CONFIG.CART
743
647
  });
744
648
  useEffect2(() => {
745
649
  if (cartLinesData) {
@@ -754,19 +658,29 @@ function useCartInitialization(session, callbacks) {
754
658
  }
755
659
 
756
660
  // src/hooks/use-cart-pricing.ts
757
- import { useMemo } from "react";
661
+ import { useMemo as useMemo2 } from "react";
758
662
  import { useQueries } from "@tanstack/react-query";
759
663
  function useCartPricing(options = {}) {
760
664
  const api = useAugurApi();
665
+ const callbacks = useAugurCallbacks();
666
+ const auth = useAugurAuth();
761
667
  const cartLines = useCartLines();
762
- const { customerId } = options;
668
+ const customerId = options.customerId ?? auth?.customerId;
669
+ const priceFn = options.queryFn ?? callbacks?.getItemPrice;
763
670
  const priceQueries = useQueries({
764
- queries: cartLines.map((line) => ({
765
- ...getItemPriceOptions(api, line.itemId, customerId, line.quantity),
766
- enabled: !!customerId && !!line.itemId
767
- }))
671
+ queries: cartLines.map((line) => {
672
+ const base = priceFn ? {
673
+ queryKey: getItemPriceKey(line.itemId, customerId, line.quantity),
674
+ queryFn: () => priceFn(line.itemId, customerId, line.quantity),
675
+ ...PRICE_CACHE_OPTIONS
676
+ } : getItemPriceOptions(api, line.itemId, customerId, line.quantity);
677
+ return {
678
+ ...base,
679
+ enabled: !!customerId && !!line.itemId
680
+ };
681
+ })
768
682
  });
769
- const prices = useMemo(() => {
683
+ const prices = useMemo2(() => {
770
684
  const map = {};
771
685
  cartLines.forEach((line, index) => {
772
686
  const queryResult = priceQueries[index];
@@ -779,17 +693,17 @@ function useCartPricing(options = {}) {
779
693
  });
780
694
  return map;
781
695
  }, [cartLines, priceQueries]);
782
- const getUnitPrice = useMemo(() => {
696
+ const getUnitPrice = useMemo2(() => {
783
697
  return (itemId) => {
784
698
  return prices[itemId?.toUpperCase()]?.unitPrice ?? 0;
785
699
  };
786
700
  }, [prices]);
787
- const getItemTotal = useMemo(() => {
701
+ const getItemTotal = useMemo2(() => {
788
702
  return (itemId, quantity) => {
789
703
  return getUnitPrice(itemId) * quantity;
790
704
  };
791
705
  }, [getUnitPrice]);
792
- const subtotal = useMemo(() => {
706
+ const subtotal = useMemo2(() => {
793
707
  return cartLines.reduce((sum, line) => {
794
708
  const unitPrice = prices[line.itemId.toUpperCase()]?.unitPrice ?? 0;
795
709
  return sum + unitPrice * line.quantity;
@@ -808,12 +722,6 @@ function useCartPricing(options = {}) {
808
722
  isError
809
723
  };
810
724
  }
811
- function getCartPricingQueryOptions(api, cartLines, customerId) {
812
- return cartLines.map((line) => ({
813
- ...getItemPriceOptions(api, line.itemId, customerId, line.quantity),
814
- enabled: !!customerId && !!line.itemId
815
- }));
816
- }
817
725
 
818
726
  // src/hooks/use-pagination-prefetch.ts
819
727
  import { useQueryClient as useQueryClient3 } from "@tanstack/react-query";
@@ -859,86 +767,51 @@ var usePaginationPrefetch = ({
859
767
 
860
768
  // src/hooks/use-category-items-infinite.ts
861
769
  import { useInfiniteQuery } from "@tanstack/react-query";
862
- import {
863
- CACHE_CONFIG as CACHE_CONFIG12
864
- } from "@simpleapps-com/augur-utils";
865
- var getCategoryItemsInfiniteKey = (itemCategoryUid, itemsFilters) => {
866
- return [
867
- "categoryItemsInfinite",
868
- itemCategoryUid,
869
- JSON.stringify(itemsFilters)
870
- ];
871
- };
872
770
  function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
873
771
  const api = useAugurApi();
772
+ const callbacks = useAugurCallbacks();
874
773
  const { enabled = true } = options;
774
+ const defaultOptions = getCategoryItemsInfiniteOptions(
775
+ api,
776
+ itemCategoryUid,
777
+ itemsFilters
778
+ );
779
+ const cb = callbacks?.getCategoryItemsInfinite;
780
+ const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
781
+ itemCategoryUid,
782
+ itemsFilters,
783
+ /* v8 ignore next */
784
+ pageParam: pageParam ?? 0
785
+ }) : void 0);
875
786
  return useInfiniteQuery({
876
- queryKey: getCategoryItemsInfiniteKey(itemCategoryUid, itemsFilters),
877
- queryFn: async ({ pageParam = 0 }) => {
878
- const response = await api.openSearch.itemSearch.list({
879
- q: itemsFilters.q || "",
880
- searchType: "query",
881
- size: itemsFilters.limit,
882
- from: pageParam,
883
- classId5List: String(itemCategoryUid),
884
- filters: itemsFilters.filters?.length ? JSON.stringify(itemsFilters.filters) : void 0
885
- });
886
- const items = response.data?.items ?? [];
887
- const total = response.data?.totalResults ?? 0;
888
- const nextOffset = pageParam + itemsFilters.limit;
889
- return {
890
- data: items,
891
- total,
892
- nextCursor: nextOffset < total ? nextOffset : void 0
893
- };
894
- },
895
- initialPageParam: 0,
896
- getNextPageParam: (lastPage) => lastPage.nextCursor,
897
- ...CACHE_CONFIG12.SEMI_STATIC,
787
+ ...defaultOptions,
788
+ ...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
898
789
  enabled: enabled && !!itemCategoryUid
899
790
  });
900
791
  }
901
792
 
902
793
  // src/hooks/use-item-search-infinite.ts
903
794
  import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
904
- import {
905
- CACHE_CONFIG as CACHE_CONFIG13
906
- } from "@simpleapps-com/augur-utils";
907
- var getItemSearchInfiniteKey = (itemsFilters, itemCategoryUid) => {
908
- return [
909
- "itemSearchInfinite",
910
- JSON.stringify(itemsFilters),
911
- itemCategoryUid
912
- ];
913
- };
914
795
  function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
915
796
  const api = useAugurApi();
797
+ const callbacks = useAugurCallbacks();
916
798
  const { enabled = true } = options;
799
+ const defaultOptions = getItemSearchInfiniteOptions(
800
+ api,
801
+ itemsFilters,
802
+ itemCategoryUid
803
+ );
804
+ const cb = callbacks?.getItemSearchInfinite;
805
+ const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
806
+ itemsFilters,
807
+ itemCategoryUid,
808
+ /* v8 ignore next */
809
+ pageParam: pageParam ?? 0
810
+ }) : void 0);
917
811
  return useInfiniteQuery2({
918
- queryKey: getItemSearchInfiniteKey(itemsFilters, itemCategoryUid),
919
- queryFn: async ({ pageParam = 0 }) => {
920
- const response = await api.openSearch.itemSearch.list({
921
- q: itemsFilters.q,
922
- searchType: "query",
923
- size: itemsFilters.limit,
924
- from: pageParam,
925
- classId5List: itemCategoryUid ? String(itemCategoryUid) : void 0,
926
- filters: itemsFilters.filters?.length ? JSON.stringify(itemsFilters.filters) : void 0
927
- });
928
- const items = response.data?.items ?? [];
929
- const total = response.data?.totalResults ?? 0;
930
- const nextOffset = pageParam + itemsFilters.limit;
931
- return {
932
- data: items,
933
- total,
934
- nextCursor: nextOffset < total ? nextOffset : void 0
935
- };
936
- },
937
- initialPageParam: 0,
938
- getNextPageParam: (lastPage) => lastPage.nextCursor,
939
- ...CACHE_CONFIG13.SEMI_STATIC,
940
- enabled: enabled && !!itemsFilters.q,
941
- meta: { persist: true }
812
+ ...defaultOptions,
813
+ ...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
814
+ enabled: enabled && !!itemsFilters.q
942
815
  });
943
816
  }
944
817
  export {
@@ -947,8 +820,10 @@ export {
947
820
  INV_MAST_CACHE_OPTIONS,
948
821
  INV_MAST_DOC_CACHE_OPTIONS,
949
822
  PRICE_CACHE_OPTIONS,
823
+ SEARCH_SUGGESTIONS_CACHE_OPTIONS,
950
824
  getCartPricingQueryOptions,
951
825
  getCategoryItemsInfiniteKey,
826
+ getCategoryItemsInfiniteOptions,
952
827
  getInvMastDocKey,
953
828
  getInvMastDocOptions,
954
829
  getInvMastKey,
@@ -964,6 +839,7 @@ export {
964
839
  getItemPriceKey,
965
840
  getItemPriceOptions,
966
841
  getItemSearchInfiniteKey,
842
+ getItemSearchInfiniteOptions,
967
843
  getProductCategoryKey,
968
844
  getProductCategoryOptions,
969
845
  getProductSearchKey,
@@ -971,6 +847,7 @@ export {
971
847
  getSearchSuggestionsKey,
972
848
  getSearchSuggestionsOptions,
973
849
  useAugurApi,
850
+ useAugurAuth,
974
851
  useCartActions,
975
852
  useCartHdrUid,
976
853
  useCartInitialization,