@simpleapps-com/augur-hooks 0.1.9 → 0.2.1
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/chunk-4CNSPZ7Q.cjs +575 -0
- package/dist/chunk-4CNSPZ7Q.cjs.map +1 -0
- package/dist/chunk-D3APHDL4.js +575 -0
- package/dist/chunk-D3APHDL4.js.map +1 -0
- package/dist/index.cjs +58 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +48 -36
- package/dist/index.js.map +1 -1
- package/dist/{joomla-content-list-MMF5wDQy.d.ts → joomla-content-list-CDF5-OJ3.d.cts} +93 -93
- package/dist/{joomla-content-list-MMF5wDQy.d.cts → joomla-content-list-CDF5-OJ3.d.ts} +93 -93
- package/dist/server.cjs +2 -16
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -15
- package/package.json +2 -2
- package/dist/chunk-ENELW5AU.cjs +0 -374
- package/dist/chunk-ENELW5AU.cjs.map +0 -1
- package/dist/chunk-TUNAYTS6.js +0 -374
- package/dist/chunk-TUNAYTS6.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CATEGORY_CACHE_OPTIONS,
|
|
3
|
-
INV_MAST_CACHE_OPTIONS,
|
|
4
|
-
INV_MAST_DOC_CACHE_OPTIONS,
|
|
5
|
-
JOOMLA_CONTENT_CACHE_OPTIONS,
|
|
6
|
-
JOOMLA_CONTENT_LIST_CACHE_OPTIONS,
|
|
7
|
-
PRICE_CACHE_OPTIONS,
|
|
8
|
-
SEARCH_SUGGESTIONS_CACHE_OPTIONS,
|
|
9
2
|
getCartPricingQueryOptions,
|
|
10
3
|
getCategoryItemsInfiniteKey,
|
|
11
4
|
getCategoryItemsInfiniteOptions,
|
|
@@ -35,7 +28,7 @@ import {
|
|
|
35
28
|
getProductSearchOptions,
|
|
36
29
|
getSearchSuggestionsKey,
|
|
37
30
|
getSearchSuggestionsOptions
|
|
38
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-D3APHDL4.js";
|
|
39
32
|
|
|
40
33
|
// src/provider.tsx
|
|
41
34
|
import { createContext, useContext } from "react";
|
|
@@ -47,13 +40,15 @@ var AugurCallbacksContext = createContext(
|
|
|
47
40
|
var AugurAuthReactContext = createContext(
|
|
48
41
|
void 0
|
|
49
42
|
);
|
|
43
|
+
var AugurCacheContext = createContext(void 0);
|
|
50
44
|
function AugurHooksProvider({
|
|
51
45
|
api,
|
|
52
46
|
callbacks,
|
|
53
47
|
auth,
|
|
48
|
+
cache,
|
|
54
49
|
children
|
|
55
50
|
}) {
|
|
56
|
-
return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api, children: /* @__PURE__ */ jsx(AugurCallbacksContext.Provider, { value: callbacks, children: /* @__PURE__ */ jsx(AugurAuthReactContext.Provider, { value: auth, children }) }) });
|
|
51
|
+
return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api, children: /* @__PURE__ */ jsx(AugurCallbacksContext.Provider, { value: callbacks, children: /* @__PURE__ */ jsx(AugurAuthReactContext.Provider, { value: auth, children: /* @__PURE__ */ jsx(AugurCacheContext.Provider, { value: cache, children }) }) }) });
|
|
57
52
|
}
|
|
58
53
|
function useAugurApi() {
|
|
59
54
|
const api = useContext(AugurApiContext);
|
|
@@ -70,6 +65,9 @@ function useAugurCallbacks() {
|
|
|
70
65
|
function useAugurAuth() {
|
|
71
66
|
return useContext(AugurAuthReactContext);
|
|
72
67
|
}
|
|
68
|
+
function useAugurCache() {
|
|
69
|
+
return useContext(AugurCacheContext);
|
|
70
|
+
}
|
|
73
71
|
|
|
74
72
|
// src/stores/cart-store.ts
|
|
75
73
|
import { create } from "zustand";
|
|
@@ -162,8 +160,9 @@ function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
|
|
|
162
160
|
const api = useAugurApi();
|
|
163
161
|
const callbacks = useAugurCallbacks();
|
|
164
162
|
const auth = useAugurAuth();
|
|
163
|
+
const cache = useAugurCache();
|
|
165
164
|
const effectiveCustomerId = customerId ?? auth?.customerId;
|
|
166
|
-
const defaultOptions = getItemPriceOptions(api, itemId, effectiveCustomerId, quantity);
|
|
165
|
+
const defaultOptions = getItemPriceOptions(api, itemId, effectiveCustomerId, quantity, cache);
|
|
167
166
|
const resolvedQueryFn = options.queryFn ?? (callbacks?.getItemPrice ? () => callbacks.getItemPrice(itemId, effectiveCustomerId, quantity) : void 0);
|
|
168
167
|
return useQuery({
|
|
169
168
|
...defaultOptions,
|
|
@@ -178,11 +177,13 @@ import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
|
178
177
|
function useInvMastDoc(invMastUid, itemId, options = {}) {
|
|
179
178
|
const api = useAugurApi();
|
|
180
179
|
const callbacks = useAugurCallbacks();
|
|
180
|
+
const cache = useAugurCache();
|
|
181
181
|
const queryOpts = getInvMastDocOptions(
|
|
182
182
|
api,
|
|
183
183
|
invMastUid,
|
|
184
184
|
itemId,
|
|
185
|
-
options.includePricing ?? "N"
|
|
185
|
+
options.includePricing ?? "N",
|
|
186
|
+
cache
|
|
186
187
|
);
|
|
187
188
|
const { data, isLoading, error } = useQuery2({
|
|
188
189
|
...queryOpts,
|
|
@@ -198,10 +199,12 @@ import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
|
198
199
|
function useItemCategory(itemCategoryUid, options = {}) {
|
|
199
200
|
const api = useAugurApi();
|
|
200
201
|
const callbacks = useAugurCallbacks();
|
|
202
|
+
const cache = useAugurCache();
|
|
201
203
|
const queryOpts = getItemCategoryOptions(
|
|
202
204
|
api,
|
|
203
205
|
itemCategoryUid,
|
|
204
|
-
options.apiOptions
|
|
206
|
+
options.apiOptions,
|
|
207
|
+
cache
|
|
205
208
|
);
|
|
206
209
|
const { data, isLoading, error } = useQuery3({
|
|
207
210
|
...queryOpts,
|
|
@@ -216,7 +219,8 @@ import { useQuery as useQuery4 } from "@tanstack/react-query";
|
|
|
216
219
|
function useInvMast(invMastUid, itemId, options = {}) {
|
|
217
220
|
const api = useAugurApi();
|
|
218
221
|
const callbacks = useAugurCallbacks();
|
|
219
|
-
const
|
|
222
|
+
const cache = useAugurCache();
|
|
223
|
+
const queryOpts = getInvMastOptions(api, invMastUid, itemId, cache);
|
|
220
224
|
const { data, isLoading, error } = useQuery4({
|
|
221
225
|
...queryOpts,
|
|
222
226
|
...options.queryFn ?? callbacks?.getInvMast ? { queryFn: options.queryFn ?? (() => callbacks.getInvMast(invMastUid, itemId)) } : {},
|
|
@@ -230,7 +234,8 @@ import { useQuery as useQuery5 } from "@tanstack/react-query";
|
|
|
230
234
|
function useInvMastStock(invMastUid, options = {}) {
|
|
231
235
|
const api = useAugurApi();
|
|
232
236
|
const callbacks = useAugurCallbacks();
|
|
233
|
-
const
|
|
237
|
+
const cache = useAugurCache();
|
|
238
|
+
const queryOpts = getInvMastStockOptions(api, invMastUid, cache);
|
|
234
239
|
const { data, isLoading, error } = useQuery5({
|
|
235
240
|
...queryOpts,
|
|
236
241
|
...options.queryFn ?? callbacks?.getInvMastStock ? { queryFn: options.queryFn ?? (() => callbacks.getInvMastStock(invMastUid)) } : {},
|
|
@@ -260,7 +265,8 @@ function resolveData(data) {
|
|
|
260
265
|
function useProductCategory(itemCategoryUid, options = {}) {
|
|
261
266
|
const api = useAugurApi();
|
|
262
267
|
const callbacks = useAugurCallbacks();
|
|
263
|
-
const
|
|
268
|
+
const cache = useAugurCache();
|
|
269
|
+
const baseOptions = itemCategoryUid ? getProductCategoryOptions(api, itemCategoryUid, cache) : {
|
|
264
270
|
queryKey: getProductCategoryKey(null),
|
|
265
271
|
/* v8 ignore next */
|
|
266
272
|
queryFn: () => Promise.reject()
|
|
@@ -287,8 +293,9 @@ import { useQuery as useQuery7 } from "@tanstack/react-query";
|
|
|
287
293
|
function useItemDetails(itemId, options = {}) {
|
|
288
294
|
const api = useAugurApi();
|
|
289
295
|
const callbacks = useAugurCallbacks();
|
|
296
|
+
const cache = useAugurCache();
|
|
290
297
|
const { data, isLoading, error } = useQuery7({
|
|
291
|
-
...itemId ? getItemDetailsOptions(api, itemId) : {
|
|
298
|
+
...itemId ? getItemDetailsOptions(api, itemId, cache) : {
|
|
292
299
|
queryKey: getItemDetailsKey(""),
|
|
293
300
|
/* v8 ignore next */
|
|
294
301
|
queryFn: () => Promise.reject()
|
|
@@ -314,8 +321,9 @@ import { useQuery as useQuery8 } from "@tanstack/react-query";
|
|
|
314
321
|
function useItemAttributes(itemCategoryUid, options = {}) {
|
|
315
322
|
const api = useAugurApi();
|
|
316
323
|
const callbacks = useAugurCallbacks();
|
|
324
|
+
const cache = useAugurCache();
|
|
317
325
|
const { data, isLoading, error } = useQuery8({
|
|
318
|
-
...itemCategoryUid ? getItemAttributesOptions(api, itemCategoryUid) : {
|
|
326
|
+
...itemCategoryUid ? getItemAttributesOptions(api, itemCategoryUid, cache) : {
|
|
319
327
|
queryKey: getItemAttributesKey(null),
|
|
320
328
|
/* v8 ignore next */
|
|
321
329
|
queryFn: () => Promise.reject()
|
|
@@ -339,7 +347,8 @@ import { useQuery as useQuery9 } from "@tanstack/react-query";
|
|
|
339
347
|
function useProductSearch(pageData, options = {}) {
|
|
340
348
|
const api = useAugurApi();
|
|
341
349
|
const callbacks = useAugurCallbacks();
|
|
342
|
-
const
|
|
350
|
+
const cache = useAugurCache();
|
|
351
|
+
const defaultOptions = getProductSearchOptions(api, pageData, cache);
|
|
343
352
|
const { data, isLoading, error } = useQuery9({
|
|
344
353
|
...defaultOptions,
|
|
345
354
|
...options.queryFn ?? callbacks?.getProductSearch ? { queryFn: options.queryFn ?? (() => callbacks.getProductSearch(pageData)) } : {},
|
|
@@ -361,10 +370,11 @@ import { useQuery as useQuery10 } from "@tanstack/react-query";
|
|
|
361
370
|
function useSearchSuggestions(query, options = {}) {
|
|
362
371
|
const api = useAugurApi();
|
|
363
372
|
const callbacks = useAugurCallbacks();
|
|
373
|
+
const cache = useAugurCache();
|
|
364
374
|
const limit = options.limit ?? 10;
|
|
365
375
|
const offset = options.offset ?? 0;
|
|
366
376
|
const enabled = (options.enabled ?? true) && query.trim().length > 0;
|
|
367
|
-
const defaultOptions = getSearchSuggestionsOptions(api, query, limit, offset);
|
|
377
|
+
const defaultOptions = getSearchSuggestionsOptions(api, query, limit, offset, cache);
|
|
368
378
|
const { data, isLoading, error } = useQuery10({
|
|
369
379
|
...defaultOptions,
|
|
370
380
|
...options.queryFn ?? callbacks?.getSearchSuggestions ? { queryFn: options.queryFn ?? (() => callbacks.getSearchSuggestions(query, limit, offset)) } : {},
|
|
@@ -564,7 +574,6 @@ function useCartActions(callbacks) {
|
|
|
564
574
|
// src/hooks/use-cart-initialization.ts
|
|
565
575
|
import { useEffect as useEffect2, useMemo, useRef } from "react";
|
|
566
576
|
import { useQuery as useQuery11, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
567
|
-
import { CACHE_CONFIG } from "@simpleapps-com/augur-utils";
|
|
568
577
|
var MAX_RETRY_ATTEMPTS = 7;
|
|
569
578
|
var RETRY_DELAY_MS = 1e3;
|
|
570
579
|
function useCartInitialization(session, callbacks) {
|
|
@@ -648,8 +657,7 @@ function useCartInitialization(session, callbacks) {
|
|
|
648
657
|
const { data: cartLinesData } = useQuery11({
|
|
649
658
|
queryKey: ["cartLines", cartHdrUid],
|
|
650
659
|
queryFn: async () => await callbacks.getCartLines(Number(cartHdrUid)) ?? [],
|
|
651
|
-
enabled: !!cartHdrUid
|
|
652
|
-
...CACHE_CONFIG.CART
|
|
660
|
+
enabled: !!cartHdrUid
|
|
653
661
|
});
|
|
654
662
|
useEffect2(() => {
|
|
655
663
|
if (cartLinesData) {
|
|
@@ -670,6 +678,7 @@ function useCartPricing(options = {}) {
|
|
|
670
678
|
const api = useAugurApi();
|
|
671
679
|
const callbacks = useAugurCallbacks();
|
|
672
680
|
const auth = useAugurAuth();
|
|
681
|
+
const cache = useAugurCache();
|
|
673
682
|
const cartLines = useCartLines();
|
|
674
683
|
const customerId = options.customerId ?? auth?.customerId;
|
|
675
684
|
const priceFn = options.queryFn ?? callbacks?.getItemPrice;
|
|
@@ -678,8 +687,10 @@ function useCartPricing(options = {}) {
|
|
|
678
687
|
const base = priceFn ? {
|
|
679
688
|
queryKey: getItemPriceKey(line.itemId, customerId, line.quantity),
|
|
680
689
|
queryFn: () => priceFn(line.itemId, customerId, line.quantity),
|
|
681
|
-
|
|
682
|
-
|
|
690
|
+
refetchOnReconnect: true,
|
|
691
|
+
refetchOnWindowFocus: false,
|
|
692
|
+
meta: { persist: true }
|
|
693
|
+
} : getItemPriceOptions(api, line.itemId, customerId, line.quantity, cache);
|
|
683
694
|
return {
|
|
684
695
|
...base,
|
|
685
696
|
enabled: !!customerId && !!line.itemId
|
|
@@ -777,11 +788,13 @@ import { useInfiniteQuery } from "@tanstack/react-query";
|
|
|
777
788
|
function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
|
|
778
789
|
const api = useAugurApi();
|
|
779
790
|
const callbacks = useAugurCallbacks();
|
|
791
|
+
const cache = useAugurCache();
|
|
780
792
|
const { enabled = true } = options;
|
|
781
793
|
const defaultOptions = getCategoryItemsInfiniteOptions(
|
|
782
794
|
api,
|
|
783
795
|
itemCategoryUid,
|
|
784
|
-
itemsFilters
|
|
796
|
+
itemsFilters,
|
|
797
|
+
cache
|
|
785
798
|
);
|
|
786
799
|
const cb = callbacks?.getCategoryItemsInfinite;
|
|
787
800
|
const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
|
|
@@ -802,11 +815,13 @@ import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
|
|
|
802
815
|
function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
|
|
803
816
|
const api = useAugurApi();
|
|
804
817
|
const callbacks = useAugurCallbacks();
|
|
818
|
+
const cache = useAugurCache();
|
|
805
819
|
const { enabled = true } = options;
|
|
806
820
|
const defaultOptions = getItemSearchInfiniteOptions(
|
|
807
821
|
api,
|
|
808
822
|
itemsFilters,
|
|
809
|
-
itemCategoryUid
|
|
823
|
+
itemCategoryUid,
|
|
824
|
+
cache
|
|
810
825
|
);
|
|
811
826
|
const cb = callbacks?.getItemSearchInfinite;
|
|
812
827
|
const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
|
|
@@ -827,8 +842,9 @@ import { useQuery as useQuery12 } from "@tanstack/react-query";
|
|
|
827
842
|
function useJoomlaContent(articleId, options = {}) {
|
|
828
843
|
const api = useAugurApi();
|
|
829
844
|
const callbacks = useAugurCallbacks();
|
|
845
|
+
const cache = useAugurCache();
|
|
830
846
|
const { data, isLoading, error } = useQuery12({
|
|
831
|
-
...articleId ? getJoomlaContentOptions(api, articleId) : {
|
|
847
|
+
...articleId ? getJoomlaContentOptions(api, articleId, cache) : {
|
|
832
848
|
queryKey: getJoomlaContentKey(""),
|
|
833
849
|
/* v8 ignore next */
|
|
834
850
|
queryFn: () => Promise.reject()
|
|
@@ -848,8 +864,9 @@ import { useQuery as useQuery13 } from "@tanstack/react-query";
|
|
|
848
864
|
function useJoomlaContentList(categoryId, options = {}) {
|
|
849
865
|
const api = useAugurApi();
|
|
850
866
|
const callbacks = useAugurCallbacks();
|
|
867
|
+
const cache = useAugurCache();
|
|
851
868
|
const { data, isLoading, error } = useQuery13({
|
|
852
|
-
...categoryId ? getJoomlaContentListOptions(api, categoryId, options.filters) : {
|
|
869
|
+
...categoryId ? getJoomlaContentListOptions(api, categoryId, options.filters, cache) : {
|
|
853
870
|
queryKey: getJoomlaContentListKey(""),
|
|
854
871
|
/* v8 ignore next */
|
|
855
872
|
queryFn: () => Promise.reject()
|
|
@@ -869,7 +886,7 @@ function useJoomlaContentList(categoryId, options = {}) {
|
|
|
869
886
|
// src/create-site-hooks.ts
|
|
870
887
|
import { createElement } from "react";
|
|
871
888
|
function createSiteHooks(config = {}) {
|
|
872
|
-
const { callbacks, defaultCustomerId } = config;
|
|
889
|
+
const { callbacks, defaultCustomerId, cache } = config;
|
|
873
890
|
function Provider({ api, auth, children }) {
|
|
874
891
|
const mergedAuth = {
|
|
875
892
|
status: auth?.status ?? "unauthenticated",
|
|
@@ -881,6 +898,7 @@ function createSiteHooks(config = {}) {
|
|
|
881
898
|
api,
|
|
882
899
|
callbacks,
|
|
883
900
|
auth: mergedAuth,
|
|
901
|
+
cache,
|
|
884
902
|
children
|
|
885
903
|
});
|
|
886
904
|
}
|
|
@@ -919,13 +937,6 @@ function createSiteHooks(config = {}) {
|
|
|
919
937
|
}
|
|
920
938
|
export {
|
|
921
939
|
AugurHooksProvider,
|
|
922
|
-
CATEGORY_CACHE_OPTIONS,
|
|
923
|
-
INV_MAST_CACHE_OPTIONS,
|
|
924
|
-
INV_MAST_DOC_CACHE_OPTIONS,
|
|
925
|
-
JOOMLA_CONTENT_CACHE_OPTIONS,
|
|
926
|
-
JOOMLA_CONTENT_LIST_CACHE_OPTIONS,
|
|
927
|
-
PRICE_CACHE_OPTIONS,
|
|
928
|
-
SEARCH_SUGGESTIONS_CACHE_OPTIONS,
|
|
929
940
|
createSiteHooks,
|
|
930
941
|
getCartPricingQueryOptions,
|
|
931
942
|
getCategoryItemsInfiniteKey,
|
|
@@ -958,6 +969,7 @@ export {
|
|
|
958
969
|
getSearchSuggestionsOptions,
|
|
959
970
|
useAugurApi,
|
|
960
971
|
useAugurAuth,
|
|
972
|
+
useAugurCache,
|
|
961
973
|
useCartActions,
|
|
962
974
|
useCartHdrUid,
|
|
963
975
|
useCartInitialization,
|