@simpleapps-com/augur-hooks 1.0.7 → 1.0.9

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
@@ -40,8 +40,10 @@ import {
40
40
  getProductSearchKey,
41
41
  getProductSearchOptions,
42
42
  getSearchSuggestionsKey,
43
- getSearchSuggestionsOptions
44
- } from "./chunk-CPPFLOLS.js";
43
+ getSearchSuggestionsOptions,
44
+ getStockKey,
45
+ getStockOptions
46
+ } from "./chunk-DDN6MAPI.js";
45
47
  import {
46
48
  useImageWithFallback
47
49
  } from "./chunk-LTBEP4MC.js";
@@ -59,11 +61,13 @@ var AugurAuthReactContext = createContext(
59
61
  );
60
62
  var AugurCacheContext = createContext(void 0);
61
63
  var AugurOptionsContext = createContext(null);
64
+ var AugurSiteContext = createContext(void 0);
62
65
  function AugurHooksProvider({
63
66
  api,
64
67
  callbacks,
65
68
  auth,
66
69
  cache,
70
+ site,
67
71
  children
68
72
  }) {
69
73
  if (process.env.NODE_ENV === "development" && !api && !callbacks) {
@@ -77,7 +81,7 @@ function AugurHooksProvider({
77
81
  // eslint-disable-next-line react-hooks/exhaustive-deps
78
82
  [api]
79
83
  );
80
- return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api ?? null, children: /* @__PURE__ */ jsx(AugurCallbacksContext.Provider, { value: callbacks, children: /* @__PURE__ */ jsx(AugurAuthReactContext.Provider, { value: auth, children: /* @__PURE__ */ jsx(AugurCacheContext.Provider, { value: cache, children: /* @__PURE__ */ jsx(AugurOptionsContext.Provider, { value: options, children }) }) }) }) });
84
+ return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api ?? null, children: /* @__PURE__ */ jsx(AugurCallbacksContext.Provider, { value: callbacks, children: /* @__PURE__ */ jsx(AugurAuthReactContext.Provider, { value: auth, children: /* @__PURE__ */ jsx(AugurCacheContext.Provider, { value: cache, children: /* @__PURE__ */ jsx(AugurSiteContext.Provider, { value: site, children: /* @__PURE__ */ jsx(AugurOptionsContext.Provider, { value: options, children }) }) }) }) }) });
81
85
  }
82
86
  function useAugurOptions() {
83
87
  const options = useContext(AugurOptionsContext);
@@ -109,6 +113,9 @@ function useAugurAuth() {
109
113
  function useAugurCache() {
110
114
  return useContext(AugurCacheContext);
111
115
  }
116
+ function useAugurSite() {
117
+ return useContext(AugurSiteContext);
118
+ }
112
119
 
113
120
  // src/stores/cart-store.ts
114
121
  import { create } from "zustand";
@@ -187,13 +194,36 @@ function useDebounce(value, delay = 500) {
187
194
  }
188
195
 
189
196
  // src/hooks/use-format-price.ts
190
- function useFormatPrice(locale = "en-US", currency = "USD") {
191
- const formatPrice = (price) => {
197
+ function normaliseOptions(optionsOrLocale, legacyCurrency) {
198
+ if (typeof optionsOrLocale === "string") {
199
+ return { locale: optionsOrLocale, currency: legacyCurrency };
200
+ }
201
+ return optionsOrLocale ?? {};
202
+ }
203
+ function resolveFormatting(opts, siteFormatting) {
204
+ return {
205
+ locale: opts.locale ?? siteFormatting?.locale ?? "en-US",
206
+ currency: opts.currency ?? siteFormatting?.currency ?? "USD",
207
+ precision: opts.precision ?? siteFormatting?.precision ?? 2,
208
+ zeroLabel: opts.zeroLabel ?? siteFormatting?.zeroLabel
209
+ };
210
+ }
211
+ function useFormatPrice(optionsOrLocale, legacyCurrency) {
212
+ const site = useAugurSite();
213
+ const opts = normaliseOptions(optionsOrLocale, legacyCurrency);
214
+ const { locale, currency, precision: basePrecision, zeroLabel } = resolveFormatting(opts, site?.formatting);
215
+ const formatPrice = (price, callOptions) => {
216
+ const effectiveValue = price * (callOptions?.quantity ?? 1);
217
+ if (effectiveValue === 0 && zeroLabel !== void 0) {
218
+ return zeroLabel;
219
+ }
220
+ const precision = callOptions?.precision ?? basePrecision;
192
221
  return new Intl.NumberFormat(locale, {
193
222
  style: "currency",
194
223
  currency,
195
- minimumFractionDigits: 2
196
- }).format(price);
224
+ minimumFractionDigits: precision,
225
+ maximumFractionDigits: precision
226
+ }).format(effectiveValue);
197
227
  };
198
228
  return { formatPrice };
199
229
  }
@@ -207,7 +237,8 @@ function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
207
237
  const callbacks = useAugurCallbacks();
208
238
  const auth = useAugurAuth();
209
239
  const cache = useAugurCache();
210
- const effectiveCustomerId = customerId ?? auth?.customerId;
240
+ const site = useAugurSite();
241
+ const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
211
242
  const defaultOptions = getItemPriceOptions(api, itemId, effectiveCustomerId, quantity, cache);
212
243
  const resolvedQueryFn = options.queryFn ?? (callbacks?.getItemPrice ? () => callbacks.getItemPrice(itemId, effectiveCustomerId, quantity) : void 0);
213
244
  const query = useQuery({
@@ -303,8 +334,45 @@ function useInvMastStock(invMastUid, options = {}) {
303
334
  };
304
335
  }
305
336
 
337
+ // src/hooks/use-stock.ts
338
+ import { useMemo as useMemo3 } from "react";
339
+ import { useQuery as useQuery6 } from "@tanstack/react-query";
340
+ import { resolveStock } from "@simpleapps-com/augur-utils";
341
+ function useStock(invMastUid, options = {}) {
342
+ const api = useAugurApiOptional();
343
+ const callbacks = useAugurCallbacks();
344
+ const cache = useAugurCache();
345
+ const queryOpts = getStockOptions(api, invMastUid, cache);
346
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getStock ? () => callbacks.getStock(invMastUid) : void 0);
347
+ const query = useQuery6({
348
+ ...queryOpts,
349
+ ...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
350
+ enabled: (options.enabled ?? true) && !!invMastUid,
351
+ retry: 3,
352
+ /* v8 ignore start */
353
+ retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
354
+ /* v8 ignore stop */
355
+ });
356
+ const resolved = useMemo3(
357
+ () => resolveStock({
358
+ stock: query.data ?? null,
359
+ companyKey: options.companyKey,
360
+ round: options.round,
361
+ lowStockThreshold: options.lowStockThreshold,
362
+ showQuantity: options.showQuantity
363
+ }),
364
+ [query.data, options.companyKey, options.round, options.lowStockThreshold, options.showQuantity]
365
+ );
366
+ return {
367
+ stock: query.data ?? null,
368
+ resolved,
369
+ loading: query.isLoading,
370
+ error: query.error
371
+ };
372
+ }
373
+
306
374
  // src/hooks/use-batch-inv-mast-doc.ts
307
- import { useQuery as useQuery6, useQueryClient } from "@tanstack/react-query";
375
+ import { useQuery as useQuery7, useQueryClient } from "@tanstack/react-query";
308
376
  function useBatchInvMastDoc(params, options = {}) {
309
377
  const api = useAugurApiOptional();
310
378
  const callbacks = useAugurCallbacks();
@@ -322,7 +390,7 @@ function useBatchInvMastDoc(params, options = {}) {
322
390
  const fallbackOpts = getBatchInvMastDocOptions(api, uncached, includePricing, cache);
323
391
  return fallbackOpts.queryFn();
324
392
  };
325
- const { data, isLoading, error } = useQuery6({
393
+ const { data, isLoading, error } = useQuery7({
326
394
  queryKey: batchOpts.queryKey,
327
395
  queryFn: () => executeBatchQuery({
328
396
  params,
@@ -340,7 +408,7 @@ function useBatchInvMastDoc(params, options = {}) {
340
408
  }
341
409
 
342
410
  // src/hooks/use-product-category.ts
343
- import { useQuery as useQuery7 } from "@tanstack/react-query";
411
+ import { useQuery as useQuery8 } from "@tanstack/react-query";
344
412
  function resolveData(data) {
345
413
  return {
346
414
  childrenTotal: data?.childrenTotal ?? 0,
@@ -359,7 +427,7 @@ function useProductCategory(itemCategoryUid, options = {}) {
359
427
  queryFn: () => Promise.reject()
360
428
  };
361
429
  const resolvedQueryFn = options.queryFn ?? (callbacks?.getProductCategory ? () => callbacks.getProductCategory(itemCategoryUid) : void 0);
362
- const { data, isLoading, error } = useQuery7({
430
+ const { data, isLoading, error } = useQuery8({
363
431
  ...baseOptions,
364
432
  ...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
365
433
  enabled: (options.enabled ?? true) && !!itemCategoryUid,
@@ -376,12 +444,12 @@ function useProductCategory(itemCategoryUid, options = {}) {
376
444
  }
377
445
 
378
446
  // src/hooks/use-item-details.ts
379
- import { useQuery as useQuery8 } from "@tanstack/react-query";
447
+ import { useQuery as useQuery9 } from "@tanstack/react-query";
380
448
  function useItemDetails(itemId, options = {}) {
381
449
  const api = useAugurApiOptional();
382
450
  const callbacks = useAugurCallbacks();
383
451
  const cache = useAugurCache();
384
- const { data, isLoading, error } = useQuery8({
452
+ const { data, isLoading, error } = useQuery9({
385
453
  ...itemId ? getItemDetailsOptions(api, itemId, cache) : {
386
454
  queryKey: getItemDetailsKey(""),
387
455
  /* v8 ignore next */
@@ -404,12 +472,12 @@ function useItemDetails(itemId, options = {}) {
404
472
  }
405
473
 
406
474
  // src/hooks/use-item-attributes.ts
407
- import { useQuery as useQuery9 } from "@tanstack/react-query";
475
+ import { useQuery as useQuery10 } from "@tanstack/react-query";
408
476
  function useItemAttributes(itemCategoryUid, options = {}) {
409
477
  const api = useAugurApiOptional();
410
478
  const callbacks = useAugurCallbacks();
411
479
  const cache = useAugurCache();
412
- const { data, isLoading, error } = useQuery9({
480
+ const { data, isLoading, error } = useQuery10({
413
481
  ...itemCategoryUid ? getItemAttributesOptions(api, itemCategoryUid, cache) : {
414
482
  queryKey: getItemAttributesKey(null),
415
483
  /* v8 ignore next */
@@ -430,13 +498,13 @@ function useItemAttributes(itemCategoryUid, options = {}) {
430
498
  }
431
499
 
432
500
  // src/hooks/use-product-search.ts
433
- import { useQuery as useQuery10 } from "@tanstack/react-query";
501
+ import { useQuery as useQuery11 } from "@tanstack/react-query";
434
502
  function useProductSearch(pageData, options = {}) {
435
503
  const api = useAugurApiOptional();
436
504
  const callbacks = useAugurCallbacks();
437
505
  const cache = useAugurCache();
438
506
  const defaultOptions = getProductSearchOptions(api, pageData, cache);
439
- const { data, isLoading, error } = useQuery10({
507
+ const { data, isLoading, error } = useQuery11({
440
508
  ...defaultOptions,
441
509
  ...options.queryFn ?? callbacks?.getProductSearch ? { queryFn: options.queryFn ?? (() => callbacks.getProductSearch(pageData)) } : {},
442
510
  retry: 3,
@@ -453,7 +521,7 @@ function useProductSearch(pageData, options = {}) {
453
521
  }
454
522
 
455
523
  // src/hooks/use-search-suggestions.ts
456
- import { useQuery as useQuery11 } from "@tanstack/react-query";
524
+ import { useQuery as useQuery12 } from "@tanstack/react-query";
457
525
  function useSearchSuggestions(query, options = {}) {
458
526
  const api = useAugurApiOptional();
459
527
  const callbacks = useAugurCallbacks();
@@ -462,7 +530,7 @@ function useSearchSuggestions(query, options = {}) {
462
530
  const offset = options.offset ?? 0;
463
531
  const enabled = (options.enabled ?? true) && query.trim().length > 0;
464
532
  const defaultOptions = getSearchSuggestionsOptions(api, query, limit, offset, cache);
465
- const { data, isLoading, error } = useQuery11({
533
+ const { data, isLoading, error } = useQuery12({
466
534
  ...defaultOptions,
467
535
  ...options.queryFn ?? callbacks?.getSearchSuggestions ? { queryFn: options.queryFn ?? (() => callbacks.getSearchSuggestions(query, limit, offset)) } : {},
468
536
  enabled
@@ -659,8 +727,8 @@ function useCartActions(callbacks) {
659
727
  }
660
728
 
661
729
  // src/hooks/use-cart-initialization.ts
662
- import { useEffect as useEffect2, useMemo as useMemo3, useRef } from "react";
663
- import { useQuery as useQuery12, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
730
+ import { useEffect as useEffect2, useMemo as useMemo4, useRef } from "react";
731
+ import { useQuery as useQuery13, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
664
732
  var MAX_RETRY_ATTEMPTS = 7;
665
733
  var RETRY_DELAY_MS = 1e3;
666
734
  function useCartInitialization(session, callbacks) {
@@ -673,7 +741,7 @@ function useCartInitialization(session, callbacks) {
673
741
  const effectiveStatus = session.status;
674
742
  const effectiveUserId = session.userId ?? auth?.userId;
675
743
  const effectiveCartHdrUid = session.cartHdrUid ?? auth?.cartHdrUid;
676
- const effectiveSession = useMemo3(
744
+ const effectiveSession = useMemo4(
677
745
  () => ({ status: effectiveStatus, userId: effectiveUserId, cartHdrUid: effectiveCartHdrUid }),
678
746
  [effectiveStatus, effectiveUserId, effectiveCartHdrUid]
679
747
  );
@@ -741,7 +809,7 @@ function useCartInitialization(session, callbacks) {
741
809
  initializeGuestCart();
742
810
  }
743
811
  }, [effectiveSession, cartHdrUid, setCartHdrUid, callbacks]);
744
- const { data: cartLinesData } = useQuery12({
812
+ const { data: cartLinesData } = useQuery13({
745
813
  queryKey: ["cartLines", cartHdrUid],
746
814
  queryFn: async () => await callbacks.getCartLines(Number(cartHdrUid)) ?? [],
747
815
  enabled: !!cartHdrUid
@@ -759,7 +827,7 @@ function useCartInitialization(session, callbacks) {
759
827
  }
760
828
 
761
829
  // src/hooks/use-cart-pricing.ts
762
- import { useMemo as useMemo4 } from "react";
830
+ import { useMemo as useMemo5 } from "react";
763
831
  import { useQueries } from "@tanstack/react-query";
764
832
  import { derivePrice as derivePrice2 } from "@simpleapps-com/augur-utils";
765
833
  function useCartPricing(options = {}) {
@@ -767,8 +835,9 @@ function useCartPricing(options = {}) {
767
835
  const callbacks = useAugurCallbacks();
768
836
  const auth = useAugurAuth();
769
837
  const cache = useAugurCache();
838
+ const site = useAugurSite();
770
839
  const cartLines = useCartLines();
771
- const customerId = options.customerId ?? auth?.customerId;
840
+ const customerId = options.customerId ?? auth?.customerId ?? site?.defaults?.customerId;
772
841
  const priceFn = options.queryFn ?? callbacks?.getItemPrice;
773
842
  const priceQueries = useQueries({
774
843
  queries: cartLines.map((line) => {
@@ -785,7 +854,7 @@ function useCartPricing(options = {}) {
785
854
  };
786
855
  })
787
856
  });
788
- const prices = useMemo4(() => {
857
+ const prices = useMemo5(() => {
789
858
  const map = {};
790
859
  cartLines.forEach((line, index) => {
791
860
  const queryResult = priceQueries[index];
@@ -799,17 +868,17 @@ function useCartPricing(options = {}) {
799
868
  });
800
869
  return map;
801
870
  }, [cartLines, priceQueries]);
802
- const getUnitPrice = useMemo4(() => {
871
+ const getUnitPrice = useMemo5(() => {
803
872
  return (itemId) => {
804
873
  return prices[itemId?.toUpperCase()]?.unitPrice ?? 0;
805
874
  };
806
875
  }, [prices]);
807
- const getItemTotal = useMemo4(() => {
876
+ const getItemTotal = useMemo5(() => {
808
877
  return (itemId, quantity) => {
809
878
  return getUnitPrice(itemId) * quantity;
810
879
  };
811
880
  }, [getUnitPrice]);
812
- const subtotal = useMemo4(() => {
881
+ const subtotal = useMemo5(() => {
813
882
  return cartLines.reduce((sum, line) => {
814
883
  const unitPrice = prices[line.itemId.toUpperCase()]?.unitPrice ?? 0;
815
884
  return sum + unitPrice * line.quantity;
@@ -927,12 +996,12 @@ function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
927
996
  }
928
997
 
929
998
  // src/hooks/use-joomla-content.ts
930
- import { useQuery as useQuery13 } from "@tanstack/react-query";
999
+ import { useQuery as useQuery14 } from "@tanstack/react-query";
931
1000
  function useJoomlaContent(articleId, options = {}) {
932
1001
  const api = useAugurApiOptional();
933
1002
  const callbacks = useAugurCallbacks();
934
1003
  const cache = useAugurCache();
935
- const { data, isLoading, error } = useQuery13({
1004
+ const { data, isLoading, error } = useQuery14({
936
1005
  ...articleId ? getJoomlaContentOptions(api, articleId, cache) : {
937
1006
  queryKey: getJoomlaContentKey(""),
938
1007
  /* v8 ignore next */
@@ -949,12 +1018,12 @@ function useJoomlaContent(articleId, options = {}) {
949
1018
  }
950
1019
 
951
1020
  // src/hooks/use-joomla-content-list.ts
952
- import { useQuery as useQuery14 } from "@tanstack/react-query";
1021
+ import { useQuery as useQuery15 } from "@tanstack/react-query";
953
1022
  function useJoomlaContentList(categoryId, options = {}) {
954
1023
  const api = useAugurApiOptional();
955
1024
  const callbacks = useAugurCallbacks();
956
1025
  const cache = useAugurCache();
957
- const { data, isLoading, error } = useQuery14({
1026
+ const { data, isLoading, error } = useQuery15({
958
1027
  ...categoryId ? getJoomlaContentListOptions(api, categoryId, options.filters, cache) : {
959
1028
  queryKey: getJoomlaContentListKey(""),
960
1029
  /* v8 ignore next */
@@ -973,12 +1042,12 @@ function useJoomlaContentList(categoryId, options = {}) {
973
1042
  }
974
1043
 
975
1044
  // src/hooks/use-joomla-menu.ts
976
- import { useQuery as useQuery15 } from "@tanstack/react-query";
1045
+ import { useQuery as useQuery16 } from "@tanstack/react-query";
977
1046
  function useJoomlaMenu(options = {}) {
978
1047
  const api = useAugurApiOptional();
979
1048
  const callbacks = useAugurCallbacks();
980
1049
  const cache = useAugurCache();
981
- const { data, isLoading, error } = useQuery15({
1050
+ const { data, isLoading, error } = useQuery16({
982
1051
  ...getJoomlaMenuOptions(api, options.filters, cache),
983
1052
  ...options.queryFn ?? callbacks?.getJoomlaMenu ? {
984
1053
  queryFn: options.queryFn ?? (() => callbacks.getJoomlaMenu(options.filters))
@@ -993,12 +1062,12 @@ function useJoomlaMenu(options = {}) {
993
1062
  }
994
1063
 
995
1064
  // src/hooks/use-joomla-menu-doc.ts
996
- import { useQuery as useQuery16 } from "@tanstack/react-query";
1065
+ import { useQuery as useQuery17 } from "@tanstack/react-query";
997
1066
  function useJoomlaMenuDoc(menuId, options = {}) {
998
1067
  const api = useAugurApiOptional();
999
1068
  const callbacks = useAugurCallbacks();
1000
1069
  const cache = useAugurCache();
1001
- const { data, isLoading, error } = useQuery16({
1070
+ const { data, isLoading, error } = useQuery17({
1002
1071
  ...menuId ? getJoomlaMenuDocOptions(api, menuId, cache) : {
1003
1072
  queryKey: getJoomlaMenuDocKey(""),
1004
1073
  /* v8 ignore next */
@@ -1015,19 +1084,24 @@ function useJoomlaMenuDoc(menuId, options = {}) {
1015
1084
  }
1016
1085
 
1017
1086
  // src/hooks/use-customer-orders.ts
1018
- import { useQuery as useQuery17 } from "@tanstack/react-query";
1087
+ import { useQuery as useQuery18 } from "@tanstack/react-query";
1088
+ var EMPTY_LIST = { data: [], total: 0 };
1019
1089
  function useCustomerOrders(customerId, params, options = {}) {
1020
1090
  const callbacks = useAugurCallbacks();
1021
1091
  const auth = useAugurAuth();
1022
- const effectiveCustomerId = customerId ?? auth?.customerId;
1023
- const { data, isLoading, error } = useQuery17({
1092
+ const site = useAugurSite();
1093
+ const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
1094
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerOrders ? () => callbacks.getCustomerOrders(effectiveCustomerId, params) : void 0);
1095
+ const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!resolvedQueryFn;
1096
+ const { data, isLoading, error } = useQuery18({
1024
1097
  queryKey: getCustomerOrdersKey(effectiveCustomerId, params),
1025
- queryFn: options.queryFn ?? (() => callbacks.getCustomerOrders(effectiveCustomerId, params)),
1026
- enabled: (options.enabled ?? true) && !!effectiveCustomerId && !!(options.queryFn ?? callbacks?.getCustomerOrders)
1098
+ queryFn: resolvedQueryFn,
1099
+ enabled
1027
1100
  });
1101
+ const result = data || EMPTY_LIST;
1028
1102
  return {
1029
- orders: data?.data ?? [],
1030
- total: data?.total ?? 0,
1103
+ orders: result.data,
1104
+ total: result.total,
1031
1105
  isLoading,
1032
1106
  error
1033
1107
  };
@@ -1035,33 +1109,41 @@ function useCustomerOrders(customerId, params, options = {}) {
1035
1109
  function useOrderDetail(customerId, orderId, options = {}) {
1036
1110
  const callbacks = useAugurCallbacks();
1037
1111
  const auth = useAugurAuth();
1038
- const effectiveCustomerId = customerId ?? auth?.customerId;
1039
- const { data, isLoading, error } = useQuery17({
1112
+ const site = useAugurSite();
1113
+ const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
1114
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerOrderDetail ? () => callbacks.getCustomerOrderDetail(effectiveCustomerId, orderId) : void 0);
1115
+ const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!orderId && !!resolvedQueryFn;
1116
+ const { data, isLoading, error } = useQuery18({
1040
1117
  queryKey: getCustomerOrderDetailKey(effectiveCustomerId, orderId),
1041
- queryFn: options.queryFn ?? (() => callbacks.getCustomerOrderDetail(effectiveCustomerId, orderId)),
1042
- enabled: (options.enabled ?? true) && !!effectiveCustomerId && !!orderId && !!(options.queryFn ?? callbacks?.getCustomerOrderDetail)
1118
+ queryFn: resolvedQueryFn,
1119
+ enabled
1043
1120
  });
1044
1121
  return {
1045
- order: data ?? null,
1122
+ order: data || null,
1046
1123
  isLoading,
1047
1124
  error
1048
1125
  };
1049
1126
  }
1050
1127
 
1051
1128
  // src/hooks/use-customer-invoices.ts
1052
- import { useQuery as useQuery18 } from "@tanstack/react-query";
1129
+ import { useQuery as useQuery19 } from "@tanstack/react-query";
1130
+ var EMPTY_LIST2 = { data: [], total: 0 };
1053
1131
  function useCustomerInvoices(customerId, params, options = {}) {
1054
1132
  const callbacks = useAugurCallbacks();
1055
1133
  const auth = useAugurAuth();
1056
- const effectiveCustomerId = customerId ?? auth?.customerId;
1057
- const { data, isLoading, error } = useQuery18({
1134
+ const site = useAugurSite();
1135
+ const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
1136
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerInvoices ? () => callbacks.getCustomerInvoices(effectiveCustomerId, params) : void 0);
1137
+ const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!resolvedQueryFn;
1138
+ const { data, isLoading, error } = useQuery19({
1058
1139
  queryKey: getCustomerInvoicesKey(effectiveCustomerId, params),
1059
- queryFn: options.queryFn ?? (() => callbacks.getCustomerInvoices(effectiveCustomerId, params)),
1060
- enabled: (options.enabled ?? true) && !!effectiveCustomerId && !!(options.queryFn ?? callbacks?.getCustomerInvoices)
1140
+ queryFn: resolvedQueryFn,
1141
+ enabled
1061
1142
  });
1143
+ const result = data || EMPTY_LIST2;
1062
1144
  return {
1063
- invoices: data?.data ?? [],
1064
- total: data?.total ?? 0,
1145
+ invoices: result.data,
1146
+ total: result.total,
1065
1147
  isLoading,
1066
1148
  error
1067
1149
  };
@@ -1069,36 +1151,41 @@ function useCustomerInvoices(customerId, params, options = {}) {
1069
1151
  function useInvoiceDetail(customerId, invoiceNo, options = {}) {
1070
1152
  const callbacks = useAugurCallbacks();
1071
1153
  const auth = useAugurAuth();
1072
- const effectiveCustomerId = customerId ?? auth?.customerId;
1073
- const { data, isLoading, error } = useQuery18({
1154
+ const site = useAugurSite();
1155
+ const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
1156
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerInvoiceDetail ? () => callbacks.getCustomerInvoiceDetail(effectiveCustomerId, invoiceNo) : void 0);
1157
+ const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!invoiceNo && !!resolvedQueryFn;
1158
+ const { data, isLoading, error } = useQuery19({
1074
1159
  queryKey: getCustomerInvoiceDetailKey(effectiveCustomerId, invoiceNo),
1075
- queryFn: options.queryFn ?? (() => callbacks.getCustomerInvoiceDetail(
1076
- effectiveCustomerId,
1077
- invoiceNo
1078
- )),
1079
- enabled: (options.enabled ?? true) && !!effectiveCustomerId && !!invoiceNo && !!(options.queryFn ?? callbacks?.getCustomerInvoiceDetail)
1160
+ queryFn: resolvedQueryFn,
1161
+ enabled
1080
1162
  });
1081
1163
  return {
1082
- invoice: data ?? null,
1164
+ invoice: data || null,
1083
1165
  isLoading,
1084
1166
  error
1085
1167
  };
1086
1168
  }
1087
1169
 
1088
1170
  // src/hooks/use-customer-quotes.ts
1089
- import { useQuery as useQuery19 } from "@tanstack/react-query";
1171
+ import { useQuery as useQuery20 } from "@tanstack/react-query";
1172
+ var EMPTY_LIST3 = { data: [], total: 0 };
1090
1173
  function useCustomerQuotes(customerId, params, options = {}) {
1091
1174
  const callbacks = useAugurCallbacks();
1092
1175
  const auth = useAugurAuth();
1093
- const effectiveCustomerId = customerId ?? auth?.customerId;
1094
- const { data, isLoading, error } = useQuery19({
1176
+ const site = useAugurSite();
1177
+ const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
1178
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerQuotes ? () => callbacks.getCustomerQuotes(effectiveCustomerId, params) : void 0);
1179
+ const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!resolvedQueryFn;
1180
+ const { data, isLoading, error } = useQuery20({
1095
1181
  queryKey: getCustomerQuotesKey(effectiveCustomerId, params),
1096
- queryFn: options.queryFn ?? (() => callbacks.getCustomerQuotes(effectiveCustomerId, params)),
1097
- enabled: (options.enabled ?? true) && !!effectiveCustomerId && !!(options.queryFn ?? callbacks?.getCustomerQuotes)
1182
+ queryFn: resolvedQueryFn,
1183
+ enabled
1098
1184
  });
1185
+ const result = data || EMPTY_LIST3;
1099
1186
  return {
1100
- quotes: data?.data ?? [],
1101
- total: data?.total ?? 0,
1187
+ quotes: result.data,
1188
+ total: result.total,
1102
1189
  isLoading,
1103
1190
  error
1104
1191
  };
@@ -1106,14 +1193,17 @@ function useCustomerQuotes(customerId, params, options = {}) {
1106
1193
  function useQuoteDetail(customerId, quoteNo, options = {}) {
1107
1194
  const callbacks = useAugurCallbacks();
1108
1195
  const auth = useAugurAuth();
1109
- const effectiveCustomerId = customerId ?? auth?.customerId;
1110
- const { data, isLoading, error } = useQuery19({
1196
+ const site = useAugurSite();
1197
+ const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
1198
+ const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerQuoteDetail ? () => callbacks.getCustomerQuoteDetail(effectiveCustomerId, quoteNo) : void 0);
1199
+ const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!quoteNo && !!resolvedQueryFn;
1200
+ const { data, isLoading, error } = useQuery20({
1111
1201
  queryKey: getCustomerQuoteDetailKey(effectiveCustomerId, quoteNo),
1112
- queryFn: options.queryFn ?? (() => callbacks.getCustomerQuoteDetail(effectiveCustomerId, quoteNo)),
1113
- enabled: (options.enabled ?? true) && !!effectiveCustomerId && !!quoteNo && !!(options.queryFn ?? callbacks?.getCustomerQuoteDetail)
1202
+ queryFn: resolvedQueryFn,
1203
+ enabled
1114
1204
  });
1115
1205
  return {
1116
- quote: data ?? null,
1206
+ quote: data || null,
1117
1207
  isLoading,
1118
1208
  error
1119
1209
  };
@@ -1126,7 +1216,7 @@ function createSiteHooks(config = {}) {
1126
1216
  function Provider({ api, auth, children }) {
1127
1217
  const mergedAuth = {
1128
1218
  status: auth?.status ?? "unauthenticated",
1129
- customerId: auth?.customerId ?? defaultCustomerId,
1219
+ customerId: auth?.customerId,
1130
1220
  userId: auth?.userId,
1131
1221
  cartHdrUid: auth?.cartHdrUid
1132
1222
  };
@@ -1135,6 +1225,7 @@ function createSiteHooks(config = {}) {
1135
1225
  callbacks,
1136
1226
  auth: mergedAuth,
1137
1227
  cache,
1228
+ site: defaultCustomerId ? { name: "", defaults: { customerId: defaultCustomerId } } : void 0,
1138
1229
  children
1139
1230
  });
1140
1231
  }
@@ -1192,7 +1283,7 @@ function createSiteHooks(config = {}) {
1192
1283
  }
1193
1284
 
1194
1285
  // src/persistence/use-persistence.ts
1195
- import { useState as useState2, useEffect as useEffect4, useMemo as useMemo5 } from "react";
1286
+ import { useState as useState2, useEffect as useEffect4, useMemo as useMemo6 } from "react";
1196
1287
 
1197
1288
  // src/persistence/serializer.ts
1198
1289
  function serialize(data) {
@@ -1337,7 +1428,7 @@ function useAugurPersistence(config) {
1337
1428
  useStorageMonitor(config);
1338
1429
  const isDev = typeof process !== "undefined" && process.env?.NODE_ENV === "development";
1339
1430
  const { persistableKeys } = config;
1340
- const dehydrateOptions = useMemo5(() => ({
1431
+ const dehydrateOptions = useMemo6(() => ({
1341
1432
  shouldDehydrateQuery: (query) => {
1342
1433
  const key = query.queryKey;
1343
1434
  if (!Array.isArray(key) || key.length === 0) return false;
@@ -1397,12 +1488,15 @@ export {
1397
1488
  getProductSearchOptions,
1398
1489
  getSearchSuggestionsKey,
1399
1490
  getSearchSuggestionsOptions,
1491
+ getStockKey,
1492
+ getStockOptions,
1400
1493
  useAugurApi,
1401
1494
  useAugurApiOptional,
1402
1495
  useAugurAuth,
1403
1496
  useAugurCache,
1404
1497
  useAugurOptions,
1405
1498
  useAugurPersistence,
1499
+ useAugurSite,
1406
1500
  useBatchInvMastDoc,
1407
1501
  useCartActions,
1408
1502
  useCartHdrUid,
@@ -1440,6 +1534,7 @@ export {
1440
1534
  useQuoteDetail,
1441
1535
  useSearchSuggestions,
1442
1536
  useSetCartHdrUid,
1443
- useSetCartLines
1537
+ useSetCartLines,
1538
+ useStock
1444
1539
  };
1445
1540
  //# sourceMappingURL=index.js.map