@simpleapps-com/augur-hooks 0.1.3 → 0.1.5

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,3 +1,34 @@
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
+ getInvMastDocKey,
10
+ getInvMastDocOptions,
11
+ getInvMastKey,
12
+ getInvMastOptions,
13
+ getInvMastStockKey,
14
+ getInvMastStockOptions,
15
+ getItemAttributesKey,
16
+ getItemAttributesOptions,
17
+ getItemCategoryKey,
18
+ getItemCategoryOptions,
19
+ getItemDetailsKey,
20
+ getItemDetailsOptions,
21
+ getItemPriceKey,
22
+ getItemPriceOptions,
23
+ getItemSearchInfiniteKey,
24
+ getProductCategoryKey,
25
+ getProductCategoryOptions,
26
+ getProductSearchKey,
27
+ getProductSearchOptions,
28
+ getSearchSuggestionsKey,
29
+ getSearchSuggestionsOptions
30
+ } from "./chunk-V3RMLU3V.js";
31
+
1
32
  // src/provider.tsx
2
33
  import { createContext, useContext } from "react";
3
34
  import { jsx } from "react/jsx-runtime";
@@ -102,28 +133,6 @@ function useFormatPrice(locale = "en-US", currency = "USD") {
102
133
 
103
134
  // src/hooks/use-item-price.ts
104
135
  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
136
  function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
128
137
  const api = useAugurApi();
129
138
  const defaultOptions = getItemPriceOptions(api, itemId, customerId, quantity);
@@ -137,27 +146,6 @@ function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
137
146
 
138
147
  // src/hooks/use-inv-mast-doc.ts
139
148
  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
149
  function useInvMastDoc(invMastUid, itemId, options = {}) {
162
150
  const api = useAugurApi();
163
151
  const queryOpts = getInvMastDocOptions(
@@ -177,23 +165,6 @@ function useInvMastDoc(invMastUid, itemId, options = {}) {
177
165
 
178
166
  // src/hooks/use-item-category.ts
179
167
  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
168
  function useItemCategory(itemCategoryUid, options = {}) {
198
169
  const api = useAugurApi();
199
170
  const queryOpts = getItemCategoryOptions(
@@ -211,20 +182,6 @@ function useItemCategory(itemCategoryUid, options = {}) {
211
182
 
212
183
  // src/hooks/use-inv-mast.ts
213
184
  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
185
  function useInvMast(invMastUid, itemId, options = {}) {
229
186
  const api = useAugurApi();
230
187
  const queryOpts = getInvMastOptions(api, invMastUid, itemId);
@@ -238,22 +195,6 @@ function useInvMast(invMastUid, itemId, options = {}) {
238
195
 
239
196
  // src/hooks/use-inv-mast-stock.ts
240
197
  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
198
  function useInvMastStock(invMastUid, options = {}) {
258
199
  const api = useAugurApi();
259
200
  const queryOpts = getInvMastStockOptions(api, invMastUid);
@@ -275,20 +216,6 @@ function useInvMastStock(invMastUid, options = {}) {
275
216
 
276
217
  // src/hooks/use-product-category.ts
277
218
  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
- });
292
219
  function useProductCategory(itemCategoryUid, options = {}) {
293
220
  const api = useAugurApi();
294
221
  const { data, isLoading, error } = useQuery6({
@@ -316,19 +243,6 @@ function useProductCategory(itemCategoryUid, options = {}) {
316
243
 
317
244
  // src/hooks/use-item-details.ts
318
245
  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
246
  function useItemDetails(itemId, options = {}) {
333
247
  const api = useAugurApi();
334
248
  const { data, isLoading, error } = useQuery7({
@@ -355,22 +269,6 @@ function useItemDetails(itemId, options = {}) {
355
269
 
356
270
  // src/hooks/use-item-attributes.ts
357
271
  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
272
  function useItemAttributes(itemCategoryUid, options = {}) {
375
273
  const api = useAugurApi();
376
274
  const { data, isLoading, error } = useQuery8({
@@ -395,32 +293,6 @@ function useItemAttributes(itemCategoryUid, options = {}) {
395
293
 
396
294
  // src/hooks/use-product-search.ts
397
295
  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
296
  function useProductSearch(pageData, options = {}) {
425
297
  const api = useAugurApi();
426
298
  const defaultOptions = getProductSearchOptions(api, pageData);
@@ -442,21 +314,6 @@ function useProductSearch(pageData, options = {}) {
442
314
 
443
315
  // src/hooks/use-search-suggestions.ts
444
316
  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
317
  function useSearchSuggestions(query, options = {}) {
461
318
  const api = useAugurApi();
462
319
  const limit = options.limit ?? 10;
@@ -662,7 +519,7 @@ function useCartActions(callbacks) {
662
519
  // src/hooks/use-cart-initialization.ts
663
520
  import { useEffect as useEffect2, useRef } from "react";
664
521
  import { useQuery as useQuery11, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
665
- import { CACHE_CONFIG as CACHE_CONFIG11 } from "@simpleapps-com/augur-utils";
522
+ import { CACHE_CONFIG } from "@simpleapps-com/augur-utils";
666
523
  var MAX_RETRY_ATTEMPTS = 7;
667
524
  var RETRY_DELAY_MS = 1e3;
668
525
  function useCartInitialization(session, callbacks) {
@@ -739,7 +596,7 @@ function useCartInitialization(session, callbacks) {
739
596
  queryKey: ["cartLines", cartHdrUid],
740
597
  queryFn: () => callbacks.getCartLines(Number(cartHdrUid)),
741
598
  enabled: !!cartHdrUid,
742
- ...CACHE_CONFIG11.CART
599
+ ...CACHE_CONFIG.CART
743
600
  });
744
601
  useEffect2(() => {
745
602
  if (cartLinesData) {
@@ -808,12 +665,6 @@ function useCartPricing(options = {}) {
808
665
  isError
809
666
  };
810
667
  }
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
668
 
818
669
  // src/hooks/use-pagination-prefetch.ts
819
670
  import { useQueryClient as useQueryClient3 } from "@tanstack/react-query";
@@ -860,15 +711,8 @@ var usePaginationPrefetch = ({
860
711
  // src/hooks/use-category-items-infinite.ts
861
712
  import { useInfiniteQuery } from "@tanstack/react-query";
862
713
  import {
863
- CACHE_CONFIG as CACHE_CONFIG12
714
+ CACHE_CONFIG as CACHE_CONFIG2
864
715
  } from "@simpleapps-com/augur-utils";
865
- var getCategoryItemsInfiniteKey = (itemCategoryUid, itemsFilters) => {
866
- return [
867
- "categoryItemsInfinite",
868
- itemCategoryUid,
869
- JSON.stringify(itemsFilters)
870
- ];
871
- };
872
716
  function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
873
717
  const api = useAugurApi();
874
718
  const { enabled = true } = options;
@@ -894,7 +738,7 @@ function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
894
738
  },
895
739
  initialPageParam: 0,
896
740
  getNextPageParam: (lastPage) => lastPage.nextCursor,
897
- ...CACHE_CONFIG12.SEMI_STATIC,
741
+ ...CACHE_CONFIG2.SEMI_STATIC,
898
742
  enabled: enabled && !!itemCategoryUid
899
743
  });
900
744
  }
@@ -902,15 +746,8 @@ function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
902
746
  // src/hooks/use-item-search-infinite.ts
903
747
  import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
904
748
  import {
905
- CACHE_CONFIG as CACHE_CONFIG13
749
+ CACHE_CONFIG as CACHE_CONFIG3
906
750
  } from "@simpleapps-com/augur-utils";
907
- var getItemSearchInfiniteKey = (itemsFilters, itemCategoryUid) => {
908
- return [
909
- "itemSearchInfinite",
910
- JSON.stringify(itemsFilters),
911
- itemCategoryUid
912
- ];
913
- };
914
751
  function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
915
752
  const api = useAugurApi();
916
753
  const { enabled = true } = options;
@@ -936,7 +773,7 @@ function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
936
773
  },
937
774
  initialPageParam: 0,
938
775
  getNextPageParam: (lastPage) => lastPage.nextCursor,
939
- ...CACHE_CONFIG13.SEMI_STATIC,
776
+ ...CACHE_CONFIG3.SEMI_STATIC,
940
777
  enabled: enabled && !!itemsFilters.q,
941
778
  meta: { persist: true }
942
779
  });
@@ -947,6 +784,7 @@ export {
947
784
  INV_MAST_CACHE_OPTIONS,
948
785
  INV_MAST_DOC_CACHE_OPTIONS,
949
786
  PRICE_CACHE_OPTIONS,
787
+ SEARCH_SUGGESTIONS_CACHE_OPTIONS,
950
788
  getCartPricingQueryOptions,
951
789
  getCategoryItemsInfiniteKey,
952
790
  getInvMastDocKey,