@simpleapps-com/augur-hooks 2.0.3 → 2.0.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
@@ -43,7 +43,7 @@ import {
43
43
  getSearchSuggestionsOptions,
44
44
  getStockKey,
45
45
  getStockOptions
46
- } from "./chunk-4RSFZ6WY.js";
46
+ } from "./chunk-QFZHOGID.js";
47
47
  import {
48
48
  useImageWithFallback
49
49
  } from "./chunk-LTBEP4MC.js";
@@ -53,12 +53,8 @@ import { createContext, useContext, useMemo } from "react";
53
53
  import { createOptionsProxy } from "@simpleapps-com/augur-core";
54
54
  import { jsx } from "react/jsx-runtime";
55
55
  var AugurApiContext = createContext(null);
56
- var AugurCallbacksContext = createContext(
57
- void 0
58
- );
59
- var AugurAuthReactContext = createContext(
60
- void 0
61
- );
56
+ var AugurCallbacksContext = createContext(void 0);
57
+ var AugurAuthReactContext = createContext(void 0);
62
58
  var AugurCacheContext = createContext(void 0);
63
59
  var AugurOptionsContext = createContext(null);
64
60
  var AugurSiteContext = createContext(void 0);
@@ -70,7 +66,7 @@ function AugurHooksProvider({
70
66
  site,
71
67
  children
72
68
  }) {
73
- if (process.env.NODE_ENV === "development" && !api && !callbacks) {
69
+ if (process.env["NODE_ENV"] === "development" && !api && !callbacks) {
74
70
  console.warn(
75
71
  "AugurHooksProvider: neither `api` nor `callbacks` provided. Hooks will fail at runtime unless every hook receives a queryFn override."
76
72
  );
@@ -129,10 +125,7 @@ var useCartStore = create()(
129
125
  cartLineCount: 0,
130
126
  setCartHdrUid: (cartHdrUid) => set({ cartHdrUid }, false, "setCartHdrUid"),
131
127
  setCartLines: (cartLines) => {
132
- const cartQuantityTotal = cartLines.reduce(
133
- (sum, line) => sum + (line.quantity || 0),
134
- 0
135
- );
128
+ const cartQuantityTotal = cartLines.reduce((sum, line) => sum + (line.quantity || 0), 0);
136
129
  const cartLineCount = cartLines.length;
137
130
  set({ cartLines, cartQuantityTotal, cartLineCount }, false, "setCartLines");
138
131
  },
@@ -142,7 +135,7 @@ var useCartStore = create()(
142
135
  "clearCart"
143
136
  )
144
137
  }),
145
- { name: "CartStore", enabled: process.env.NODE_ENV === "development" }
138
+ { name: "CartStore", enabled: process.env["NODE_ENV"] === "development" }
146
139
  )
147
140
  );
148
141
  var useCartHdrUid = () => useCartStore((s) => s.cartHdrUid);
@@ -173,7 +166,7 @@ var useItemFiltersStore = create2()(
173
166
  }),
174
167
  {
175
168
  name: "ItemsFiltersStore",
176
- enabled: process.env.NODE_ENV === "development"
169
+ enabled: process.env["NODE_ENV"] === "development"
177
170
  }
178
171
  )
179
172
  );
@@ -211,7 +204,12 @@ function resolveFormatting(opts, siteFormatting) {
211
204
  function useFormatPrice(optionsOrLocale, legacyCurrency) {
212
205
  const site = useAugurSite();
213
206
  const opts = normaliseOptions(optionsOrLocale, legacyCurrency);
214
- const { locale, currency, precision: basePrecision, zeroLabel } = resolveFormatting(opts, site?.formatting);
207
+ const {
208
+ locale,
209
+ currency,
210
+ precision: basePrecision,
211
+ zeroLabel
212
+ } = resolveFormatting(opts, site?.formatting);
215
213
  const formatPrice = (price, callOptions) => {
216
214
  const effectiveValue = price * (callOptions?.quantity ?? 1);
217
215
  if (effectiveValue === 0 && zeroLabel !== void 0) {
@@ -269,7 +267,9 @@ function useInvMastDoc(invMastUid, itemId, options = {}) {
269
267
  );
270
268
  const { data, isLoading, error } = useQuery2({
271
269
  ...queryOpts,
272
- ...options.queryFn ?? callbacks?.getInvMastDoc ? { queryFn: options.queryFn ?? (() => callbacks.getInvMastDoc(invMastUid, itemId, options.includePricing ?? "N")) } : {},
270
+ ...options.queryFn ?? callbacks?.getInvMastDoc ? {
271
+ queryFn: options.queryFn ?? (() => callbacks.getInvMastDoc(invMastUid, itemId, options.includePricing ?? "N"))
272
+ } : {},
273
273
  enabled: options.enabled ?? true,
274
274
  initialData: options.initialData
275
275
  });
@@ -282,15 +282,12 @@ function useItemCategory(itemCategoryUid, options = {}) {
282
282
  const api = useAugurApiOptional();
283
283
  const callbacks = useAugurCallbacks();
284
284
  const cache = useAugurCache();
285
- const queryOpts = getItemCategoryOptions(
286
- api,
287
- itemCategoryUid,
288
- options.apiOptions,
289
- cache
290
- );
285
+ const queryOpts = getItemCategoryOptions(api, itemCategoryUid, options.apiOptions, cache);
291
286
  const { data, isLoading, error } = useQuery3({
292
287
  ...queryOpts,
293
- ...options.queryFn ?? callbacks?.getItemCategory ? { queryFn: options.queryFn ?? (() => callbacks.getItemCategory(itemCategoryUid, options.apiOptions)) } : {},
288
+ ...options.queryFn ?? callbacks?.getItemCategory ? {
289
+ queryFn: options.queryFn ?? (() => callbacks.getItemCategory(itemCategoryUid, options.apiOptions))
290
+ } : {},
294
291
  enabled: options.enabled ?? true
295
292
  });
296
293
  return { category: data, isLoading, error };
@@ -361,7 +358,13 @@ function useStock(invMastUid, options = {}) {
361
358
  lowStockThreshold: options.lowStockThreshold,
362
359
  showQuantity: options.showQuantity
363
360
  }),
364
- [query.data, options.companyKey, options.round, options.lowStockThreshold, options.showQuantity]
361
+ [
362
+ query.data,
363
+ options.companyKey,
364
+ options.round,
365
+ options.lowStockThreshold,
366
+ options.showQuantity
367
+ ]
365
368
  );
366
369
  return {
367
370
  stock: query.data ?? null,
@@ -515,6 +518,7 @@ function useProductSearch(pageData, options = {}) {
515
518
  return {
516
519
  productItems: data?.items ?? null,
517
520
  total: data?.totalResults ?? 0,
521
+ result: data,
518
522
  loading: isLoading,
519
523
  error
520
524
  };
@@ -532,12 +536,19 @@ function useSearchSuggestions(query, options = {}) {
532
536
  const defaultOptions = getSearchSuggestionsOptions(api, query, limit, offset, cache);
533
537
  const { data, isLoading, error } = useQuery12({
534
538
  ...defaultOptions,
535
- ...options.queryFn ?? callbacks?.getSearchSuggestions ? { queryFn: options.queryFn ?? (() => callbacks.getSearchSuggestions(query, limit, offset)) } : {},
539
+ ...options.queryFn ?? callbacks?.getSearchSuggestions ? {
540
+ queryFn: options.queryFn ?? (() => callbacks.getSearchSuggestions(query, limit, offset))
541
+ } : {},
536
542
  enabled
537
543
  });
538
544
  return {
539
545
  suggestions: data?.data ?? [],
540
546
  total: data?.total ?? 0,
547
+ count: data?.count,
548
+ totalResults: data?.totalResults,
549
+ message: data?.message,
550
+ status: data?.status,
551
+ result: data,
541
552
  isLoading,
542
553
  error
543
554
  };
@@ -552,9 +563,7 @@ function requireCartUid(cartHdrUid) {
552
563
  return num;
553
564
  }
554
565
  function buildOptimisticAdd(cartLines, item, cartHdrUid, itemId) {
555
- const existingIndex = cartLines.findIndex(
556
- (line) => line.invMastUid === item.invMastUid
557
- );
566
+ const existingIndex = cartLines.findIndex((line) => line.invMastUid === item.invMastUid);
558
567
  if (existingIndex >= 0) {
559
568
  return cartLines.map(
560
569
  (line, index) => index === existingIndex ? { ...line, quantity: line.quantity + item.quantity } : line
@@ -582,8 +591,8 @@ function useCartActions(callbacks) {
582
591
  const setCartLines = useSetCartLines();
583
592
  const notify = callbacks.toast;
584
593
  const invalidateCartCache = useCallback(() => {
585
- queryClient.invalidateQueries({ queryKey: ["cartLines", cartHdrUid] });
586
- queryClient.invalidateQueries({
594
+ void queryClient.invalidateQueries({ queryKey: ["cartLines", cartHdrUid] });
595
+ void queryClient.invalidateQueries({
587
596
  queryKey: ["cart-also-bought", cartHdrUid]
588
597
  });
589
598
  }, [queryClient, cartHdrUid]);
@@ -780,10 +789,7 @@ function useCartInitialization(session, callbacks) {
780
789
  }
781
790
  retryCountRef.current++;
782
791
  if (retryCountRef.current < MAX_RETRY_ATTEMPTS) {
783
- const delay = Math.min(
784
- RETRY_DELAY_MS * Math.pow(1.5, retryCountRef.current),
785
- 1e4
786
- );
792
+ const delay = Math.min(RETRY_DELAY_MS * Math.pow(1.5, retryCountRef.current), 1e4);
787
793
  await new Promise((resolve) => setTimeout(resolve, delay));
788
794
  }
789
795
  } catch (error) {
@@ -793,20 +799,15 @@ function useCartInitialization(session, callbacks) {
793
799
  );
794
800
  retryCountRef.current++;
795
801
  if (retryCountRef.current < MAX_RETRY_ATTEMPTS) {
796
- const delay = Math.min(
797
- RETRY_DELAY_MS * Math.pow(1.5, retryCountRef.current),
798
- 1e4
799
- );
802
+ const delay = Math.min(RETRY_DELAY_MS * Math.pow(1.5, retryCountRef.current), 1e4);
800
803
  await new Promise((resolve) => setTimeout(resolve, delay));
801
804
  }
802
805
  }
803
806
  }
804
- console.error(
805
- `Cart initialization failed after ${MAX_RETRY_ATTEMPTS} attempts`
806
- );
807
+ console.error(`Cart initialization failed after ${MAX_RETRY_ATTEMPTS} attempts`);
807
808
  isInitializingRef.current = false;
808
809
  };
809
- initializeGuestCart();
810
+ void initializeGuestCart();
810
811
  }
811
812
  }, [effectiveSession, cartHdrUid, setCartHdrUid, callbacks]);
812
813
  const { data: cartLinesData } = useQuery13({
@@ -948,12 +949,7 @@ function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
948
949
  const callbacks = useAugurCallbacks();
949
950
  const cache = useAugurCache();
950
951
  const { enabled = true } = options;
951
- const defaultOptions = getCategoryItemsInfiniteOptions(
952
- api,
953
- itemCategoryUid,
954
- itemsFilters,
955
- cache
956
- );
952
+ const defaultOptions = getCategoryItemsInfiniteOptions(api, itemCategoryUid, itemsFilters, cache);
957
953
  const cb = callbacks?.getCategoryItemsInfinite;
958
954
  const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
959
955
  itemCategoryUid,
@@ -975,12 +971,7 @@ function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
975
971
  const callbacks = useAugurCallbacks();
976
972
  const cache = useAugurCache();
977
973
  const { enabled = true } = options;
978
- const defaultOptions = getItemSearchInfiniteOptions(
979
- api,
980
- itemsFilters,
981
- itemCategoryUid,
982
- cache
983
- );
974
+ const defaultOptions = getItemSearchInfiniteOptions(api, itemsFilters, itemCategoryUid, cache);
984
975
  const cb = callbacks?.getItemSearchInfinite;
985
976
  const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
986
977
  itemsFilters,
@@ -1019,6 +1010,7 @@ function useJoomlaContent(articleId, options = {}) {
1019
1010
 
1020
1011
  // src/hooks/use-joomla-content-list.ts
1021
1012
  import { useQuery as useQuery15 } from "@tanstack/react-query";
1013
+ var EMPTY_LIST = { data: [], total: 0 };
1022
1014
  function useJoomlaContentList(categoryId, options = {}) {
1023
1015
  const api = useAugurApiOptional();
1024
1016
  const callbacks = useAugurCallbacks();
@@ -1033,9 +1025,17 @@ function useJoomlaContentList(categoryId, options = {}) {
1033
1025
  queryFn: options.queryFn ?? (() => callbacks.getJoomlaContentList(categoryId, options.filters))
1034
1026
  } : {},
1035
1027
  enabled: (options.enabled ?? true) && !!categoryId
1028
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1036
1029
  });
1030
+ const result = data || EMPTY_LIST;
1037
1031
  return {
1038
- articles: data ?? [],
1032
+ articles: result.data,
1033
+ total: result.total,
1034
+ count: result.count,
1035
+ totalResults: result.totalResults,
1036
+ message: result.message,
1037
+ status: result.status,
1038
+ result,
1039
1039
  isLoading,
1040
1040
  error
1041
1041
  };
@@ -1043,6 +1043,7 @@ function useJoomlaContentList(categoryId, options = {}) {
1043
1043
 
1044
1044
  // src/hooks/use-joomla-menu.ts
1045
1045
  import { useQuery as useQuery16 } from "@tanstack/react-query";
1046
+ var EMPTY_LIST2 = { data: [], total: 0 };
1046
1047
  function useJoomlaMenu(options = {}) {
1047
1048
  const api = useAugurApiOptional();
1048
1049
  const callbacks = useAugurCallbacks();
@@ -1053,9 +1054,17 @@ function useJoomlaMenu(options = {}) {
1053
1054
  queryFn: options.queryFn ?? (() => callbacks.getJoomlaMenu(options.filters))
1054
1055
  } : {},
1055
1056
  enabled: options.enabled ?? true
1057
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1056
1058
  });
1059
+ const result = data || EMPTY_LIST2;
1057
1060
  return {
1058
- menuItems: data ?? [],
1061
+ menuItems: result.data,
1062
+ total: result.total,
1063
+ count: result.count,
1064
+ totalResults: result.totalResults,
1065
+ message: result.message,
1066
+ status: result.status,
1067
+ result,
1059
1068
  isLoading,
1060
1069
  error
1061
1070
  };
@@ -1085,7 +1094,7 @@ function useJoomlaMenuDoc(menuId, options = {}) {
1085
1094
 
1086
1095
  // src/hooks/use-customer-orders.ts
1087
1096
  import { useQuery as useQuery18 } from "@tanstack/react-query";
1088
- var EMPTY_LIST = { data: [], total: 0 };
1097
+ var EMPTY_LIST3 = { data: [], total: 0 };
1089
1098
  function useCustomerOrders(customerId, params, options = {}) {
1090
1099
  const callbacks = useAugurCallbacks();
1091
1100
  const auth = useAugurAuth();
@@ -1098,10 +1107,15 @@ function useCustomerOrders(customerId, params, options = {}) {
1098
1107
  queryFn: resolvedQueryFn,
1099
1108
  enabled
1100
1109
  });
1101
- const result = data || EMPTY_LIST;
1110
+ const result = data || EMPTY_LIST3;
1102
1111
  return {
1103
1112
  orders: result.data,
1104
1113
  total: result.total,
1114
+ count: result.count,
1115
+ totalResults: result.totalResults,
1116
+ message: result.message,
1117
+ status: result.status,
1118
+ result,
1105
1119
  isLoading,
1106
1120
  error
1107
1121
  };
@@ -1127,7 +1141,7 @@ function useOrderDetail(customerId, orderId, options = {}) {
1127
1141
 
1128
1142
  // src/hooks/use-customer-invoices.ts
1129
1143
  import { useQuery as useQuery19 } from "@tanstack/react-query";
1130
- var EMPTY_LIST2 = { data: [], total: 0 };
1144
+ var EMPTY_LIST4 = { data: [], total: 0 };
1131
1145
  function useCustomerInvoices(customerId, params, options = {}) {
1132
1146
  const callbacks = useAugurCallbacks();
1133
1147
  const auth = useAugurAuth();
@@ -1140,10 +1154,15 @@ function useCustomerInvoices(customerId, params, options = {}) {
1140
1154
  queryFn: resolvedQueryFn,
1141
1155
  enabled
1142
1156
  });
1143
- const result = data || EMPTY_LIST2;
1157
+ const result = data || EMPTY_LIST4;
1144
1158
  return {
1145
1159
  invoices: result.data,
1146
1160
  total: result.total,
1161
+ count: result.count,
1162
+ totalResults: result.totalResults,
1163
+ message: result.message,
1164
+ status: result.status,
1165
+ result,
1147
1166
  isLoading,
1148
1167
  error
1149
1168
  };
@@ -1169,7 +1188,7 @@ function useInvoiceDetail(customerId, invoiceNo, options = {}) {
1169
1188
 
1170
1189
  // src/hooks/use-customer-quotes.ts
1171
1190
  import { useQuery as useQuery20 } from "@tanstack/react-query";
1172
- var EMPTY_LIST3 = { data: [], total: 0 };
1191
+ var EMPTY_LIST5 = { data: [], total: 0 };
1173
1192
  function useCustomerQuotes(customerId, params, options = {}) {
1174
1193
  const callbacks = useAugurCallbacks();
1175
1194
  const auth = useAugurAuth();
@@ -1182,10 +1201,15 @@ function useCustomerQuotes(customerId, params, options = {}) {
1182
1201
  queryFn: resolvedQueryFn,
1183
1202
  enabled
1184
1203
  });
1185
- const result = data || EMPTY_LIST3;
1204
+ const result = data || EMPTY_LIST5;
1186
1205
  return {
1187
1206
  quotes: result.data,
1188
1207
  total: result.total,
1208
+ count: result.count,
1209
+ totalResults: result.totalResults,
1210
+ message: result.message,
1211
+ status: result.status,
1212
+ result,
1189
1213
  isLoading,
1190
1214
  error
1191
1215
  };
@@ -1273,9 +1297,7 @@ function createSiteHooks(config = {}) {
1273
1297
  // Hooks -- images
1274
1298
  useImageWithFallback: (imagePath, options) => {
1275
1299
  if (!imageConfig) {
1276
- throw new Error(
1277
- "useImageWithFallback requires imageConfig in createSiteHooks config"
1278
- );
1300
+ throw new Error("useImageWithFallback requires imageConfig in createSiteHooks config");
1279
1301
  }
1280
1302
  return useImageWithFallback(imageConfig, imagePath, options);
1281
1303
  }
@@ -1426,16 +1448,19 @@ function useAugurPersistence(config) {
1426
1448
  setIsMounted(true);
1427
1449
  }, []);
1428
1450
  useStorageMonitor(config);
1429
- const isDev = typeof process !== "undefined" && process.env?.NODE_ENV === "development";
1451
+ const isDev = typeof process !== "undefined" && process.env?.["NODE_ENV"] === "development";
1430
1452
  const { persistableKeys } = config;
1431
- const dehydrateOptions = useMemo6(() => ({
1432
- shouldDehydrateQuery: (query) => {
1433
- const key = query.queryKey;
1434
- if (!Array.isArray(key) || key.length === 0) return false;
1435
- if (query.state.status !== "success") return false;
1436
- return persistableKeys.includes(key[0]);
1437
- }
1438
- }), [persistableKeys]);
1453
+ const dehydrateOptions = useMemo6(
1454
+ () => ({
1455
+ shouldDehydrateQuery: (query) => {
1456
+ const key = query.queryKey;
1457
+ if (!Array.isArray(key) || key.length === 0) return false;
1458
+ if (query.state.status !== "success") return false;
1459
+ return persistableKeys.includes(key[0]);
1460
+ }
1461
+ }),
1462
+ [persistableKeys]
1463
+ );
1439
1464
  return {
1440
1465
  persister,
1441
1466
  maxAge: isMounted ? config.maxAge ?? 24 * 60 * 60 * 1e3 : 0,