@simpleapps-com/augur-hooks 0.1.7 → 0.1.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.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { G as GetItemCategoryApiOptions, P as PageData, S as SearchSuggestionsResponse, a as SearchSuggestion, I as InfiniteScrollPage } from './server-CF43MUMf.js';
2
- export { A as AugurApiClient, b as AugurAuthContext, c as AugurCallbacks, d as AugurHooksProvider, C as CATEGORY_CACHE_OPTIONS, e as INV_MAST_CACHE_OPTIONS, f as INV_MAST_DOC_CACHE_OPTIONS, g as PRICE_CACHE_OPTIONS, h as SEARCH_SUGGESTIONS_CACHE_OPTIONS, i as getCartPricingQueryOptions, j as getCategoryItemsInfiniteKey, k as getCategoryItemsInfiniteOptions, l as getInvMastDocKey, m as getInvMastDocOptions, n as getInvMastKey, o as getInvMastOptions, p as getInvMastStockKey, q as getInvMastStockOptions, r as getItemAttributesKey, s as getItemAttributesOptions, t as getItemCategoryKey, u as getItemCategoryOptions, v as getItemDetailsKey, w as getItemDetailsOptions, x as getItemPriceKey, y as getItemPriceOptions, z as getItemSearchInfiniteKey, B as getItemSearchInfiniteOptions, D as getProductCategoryKey, E as getProductCategoryOptions, F as getProductSearchKey, H as getProductSearchOptions, J as getSearchSuggestionsKey, K as getSearchSuggestionsOptions, L as useAugurApi, M as useAugurAuth } from './server-CF43MUMf.js';
1
+ import { G as GetItemCategoryApiOptions, P as PageData, S as SearchSuggestionsResponse, a as SearchSuggestion, I as InfiniteScrollPage, A as AugurCallbacks, b as AugurApiClient, c as AugurAuthContext } from './joomla-content-list-MMF5wDQy.js';
2
+ export { d as AugurHooksProvider, C as CATEGORY_CACHE_OPTIONS, e as INV_MAST_CACHE_OPTIONS, f as INV_MAST_DOC_CACHE_OPTIONS, J as JOOMLA_CONTENT_CACHE_OPTIONS, g as JOOMLA_CONTENT_LIST_CACHE_OPTIONS, h as PRICE_CACHE_OPTIONS, i as SEARCH_SUGGESTIONS_CACHE_OPTIONS, j as getCartPricingQueryOptions, k as getCategoryItemsInfiniteKey, l as getCategoryItemsInfiniteOptions, m as getInvMastDocKey, n as getInvMastDocOptions, o as getInvMastKey, p as getInvMastOptions, q as getInvMastStockKey, r as getInvMastStockOptions, s as getItemAttributesKey, t as getItemAttributesOptions, u as getItemCategoryKey, v as getItemCategoryOptions, w as getItemDetailsKey, x as getItemDetailsOptions, y as getItemPriceKey, z as getItemPriceOptions, B as getItemSearchInfiniteKey, D as getItemSearchInfiniteOptions, E as getJoomlaContentKey, F as getJoomlaContentListKey, H as getJoomlaContentListOptions, K as getJoomlaContentOptions, L as getProductCategoryKey, M as getProductCategoryOptions, N as getProductSearchKey, O as getProductSearchOptions, Q as getSearchSuggestionsKey, R as getSearchSuggestionsOptions, T as useAugurApi, U as useAugurAuth } from './joomla-content-list-MMF5wDQy.js';
3
3
  import * as zustand from 'zustand';
4
- import { TCartLine, TItemsFilters, TPriceData, TInvMastDoc, TCategory, TItemDetails, TAttribute } from '@simpleapps-com/augur-utils';
4
+ import { TCartLine, TItemsFilters, TPriceData, TInvMastDoc, TCategory, TItemDetails, TAttribute, TJoomlaContent, TJoomlaContentFilters } from '@simpleapps-com/augur-utils';
5
5
  import * as _tanstack_react_query from '@tanstack/react-query';
6
6
  import { QueryKey } from '@tanstack/react-query';
7
+ import { ReactNode, createElement } from 'react';
7
8
  import 'react/jsx-runtime';
8
- import 'react';
9
9
 
10
10
  interface CartState {
11
11
  cartHdrUid: number | string | undefined;
@@ -391,6 +391,8 @@ interface UsePaginationPrefetchOptions {
391
391
  queryFn: (offset: number) => Promise<unknown>;
392
392
  /** Number of items per page */
393
393
  pageSize: number;
394
+ /** Custom query key builder. Receives the base key and offset, returns the full key. Default: [...queryKey, offset]. */
395
+ queryKeyFn?: (baseKey: QueryKey, offset: number) => QueryKey;
394
396
  /** Stale time in ms (defaults to 10 minutes) */
395
397
  staleTime?: number;
396
398
  /** GC time in ms (defaults to 30 minutes) */
@@ -401,7 +403,7 @@ interface UsePaginationPrefetchOptions {
401
403
  * Prefetch adjacent pages on hover for instant pagination.
402
404
  * Accepts a generic queryFn so it works with any paginated resource.
403
405
  */
404
- declare const usePaginationPrefetch: ({ queryKey, queryFn, pageSize, staleTime, gcTime, enabled, }: UsePaginationPrefetchOptions) => {
406
+ declare const usePaginationPrefetch: ({ queryKey, queryFn, pageSize, queryKeyFn, staleTime, gcTime, enabled, }: UsePaginationPrefetchOptions) => {
405
407
  prefetchPage: (page: number) => Promise<void>;
406
408
  handlePaginationHover: (page: number) => () => void;
407
409
  };
@@ -432,4 +434,94 @@ interface UseItemSearchInfiniteOptions {
432
434
  */
433
435
  declare function useItemSearchInfinite(itemsFilters: TItemsFilters, itemCategoryUid?: number | string, options?: UseItemSearchInfiniteOptions): _tanstack_react_query.UseInfiniteQueryResult<_tanstack_react_query.InfiniteData<InfiniteScrollPage, unknown>, Error>;
434
436
 
435
- export { type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, GetItemCategoryApiOptions, InfiniteScrollPage, PageData, SearchSuggestion, SearchSuggestionsResponse, useCartActions, useCartHdrUid, useCartInitialization, useCartItemCount, useCartLines, useCartPricing, useCartStore, useCategoryItemsInfinite, useClearCart, useDebounce, useFormatPrice, useInvMast, useInvMastDoc, useInvMastStock, useItemAttributes, useItemCategory, useItemDetails, useItemFiltersStore, useItemPrice, useItemSearchInfinite, usePaginationPrefetch, useProductCategory, useProductSearch, useSearchSuggestions, useSetCartHdrUid, useSetCartLines };
437
+ interface UseJoomlaContentOptions {
438
+ enabled?: boolean;
439
+ queryFn?: () => Promise<TJoomlaContent>;
440
+ }
441
+ declare function useJoomlaContent(articleId: number | string | undefined, options?: UseJoomlaContentOptions): {
442
+ article: TJoomlaContent | null;
443
+ isLoading: boolean;
444
+ error: Error | null;
445
+ };
446
+
447
+ interface UseJoomlaContentListOptions {
448
+ enabled?: boolean;
449
+ queryFn?: () => Promise<TJoomlaContent[]>;
450
+ filters?: Partial<TJoomlaContentFilters>;
451
+ }
452
+ declare function useJoomlaContentList(categoryId: number | string | undefined, options?: UseJoomlaContentListOptions): {
453
+ articles: TJoomlaContent[];
454
+ isLoading: boolean;
455
+ error: Error | null;
456
+ };
457
+
458
+ /**
459
+ * Factory function that creates a pre-configured provider + hook bundle,
460
+ * eliminating per-hook wrapper boilerplate in consumer sites.
461
+ *
462
+ * @example
463
+ * ```ts
464
+ * // lib/augur.ts
465
+ * import { createSiteHooks } from "@simpleapps-com/augur-hooks";
466
+ * import { getItemPrice, getItemCategory } from "@/lib/actions/pricing";
467
+ *
468
+ * export const augur = createSiteHooks({
469
+ * callbacks: { getItemPrice, getItemCategory },
470
+ * defaultCustomerId: process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_ID,
471
+ * });
472
+ *
473
+ * // app/layout.tsx
474
+ * <augur.Provider api={api} auth={{ status, customerId, userId }}>
475
+ * {children}
476
+ * </augur.Provider>
477
+ *
478
+ * // components/price.tsx
479
+ * const { data } = augur.useItemPrice(itemId);
480
+ * ```
481
+ */
482
+
483
+ interface CreateSiteHooksConfig {
484
+ /** Callback registry for routing SDK calls through server actions. */
485
+ callbacks?: Partial<AugurCallbacks>;
486
+ /** Default customer ID used when auth.customerId is not provided. */
487
+ defaultCustomerId?: string | number;
488
+ }
489
+ interface SiteHooksProviderProps {
490
+ /** The augur-api SDK instance. */
491
+ api: AugurApiClient;
492
+ /** Auth context (partial -- missing fields are filled from config defaults). */
493
+ auth?: Partial<AugurAuthContext>;
494
+ children: ReactNode;
495
+ }
496
+ interface SiteHooks {
497
+ Provider: (props: SiteHooksProviderProps) => ReturnType<typeof createElement>;
498
+ useItemPrice: typeof useItemPrice;
499
+ useCartPricing: typeof useCartPricing;
500
+ useInvMast: typeof useInvMast;
501
+ useInvMastDoc: typeof useInvMastDoc;
502
+ useInvMastStock: typeof useInvMastStock;
503
+ useItemCategory: typeof useItemCategory;
504
+ useProductCategory: typeof useProductCategory;
505
+ useItemDetails: typeof useItemDetails;
506
+ useItemAttributes: typeof useItemAttributes;
507
+ useProductSearch: typeof useProductSearch;
508
+ useSearchSuggestions: typeof useSearchSuggestions;
509
+ useCartActions: typeof useCartActions;
510
+ useCartInitialization: typeof useCartInitialization;
511
+ usePaginationPrefetch: typeof usePaginationPrefetch;
512
+ useCategoryItemsInfinite: typeof useCategoryItemsInfinite;
513
+ useItemSearchInfinite: typeof useItemSearchInfinite;
514
+ useJoomlaContent: typeof useJoomlaContent;
515
+ useJoomlaContentList: typeof useJoomlaContentList;
516
+ useDebounce: typeof useDebounce;
517
+ useFormatPrice: typeof useFormatPrice;
518
+ }
519
+ /**
520
+ * Creates a pre-configured provider component and re-exports all hooks.
521
+ *
522
+ * The returned `Provider` merges `config.defaultCustomerId` into the auth
523
+ * context; an explicit `auth.customerId` prop takes priority.
524
+ */
525
+ declare function createSiteHooks(config?: CreateSiteHooksConfig): SiteHooks;
526
+
527
+ export { AugurApiClient, AugurAuthContext, AugurCallbacks, type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type CreateSiteHooksConfig, GetItemCategoryApiOptions, InfiniteScrollPage, PageData, SearchSuggestion, SearchSuggestionsResponse, createSiteHooks, useCartActions, useCartHdrUid, useCartInitialization, useCartItemCount, useCartLines, useCartPricing, useCartStore, useCategoryItemsInfinite, useClearCart, useDebounce, useFormatPrice, useInvMast, useInvMastDoc, useInvMastStock, useItemAttributes, useItemCategory, useItemDetails, useItemFiltersStore, useItemPrice, useItemSearchInfinite, useJoomlaContent, useJoomlaContentList, usePaginationPrefetch, useProductCategory, useProductSearch, useSearchSuggestions, useSetCartHdrUid, useSetCartLines };
package/dist/index.js CHANGED
@@ -2,6 +2,8 @@ import {
2
2
  CATEGORY_CACHE_OPTIONS,
3
3
  INV_MAST_CACHE_OPTIONS,
4
4
  INV_MAST_DOC_CACHE_OPTIONS,
5
+ JOOMLA_CONTENT_CACHE_OPTIONS,
6
+ JOOMLA_CONTENT_LIST_CACHE_OPTIONS,
5
7
  PRICE_CACHE_OPTIONS,
6
8
  SEARCH_SUGGESTIONS_CACHE_OPTIONS,
7
9
  getCartPricingQueryOptions,
@@ -23,13 +25,17 @@ import {
23
25
  getItemPriceOptions,
24
26
  getItemSearchInfiniteKey,
25
27
  getItemSearchInfiniteOptions,
28
+ getJoomlaContentKey,
29
+ getJoomlaContentListKey,
30
+ getJoomlaContentListOptions,
31
+ getJoomlaContentOptions,
26
32
  getProductCategoryKey,
27
33
  getProductCategoryOptions,
28
34
  getProductSearchKey,
29
35
  getProductSearchOptions,
30
36
  getSearchSuggestionsKey,
31
37
  getSearchSuggestionsOptions
32
- } from "./chunk-DS2ECDHJ.js";
38
+ } from "./chunk-TUNAYTS6.js";
33
39
 
34
40
  // src/provider.tsx
35
41
  import { createContext, useContext } from "react";
@@ -730,6 +736,7 @@ var usePaginationPrefetch = ({
730
736
  queryKey,
731
737
  queryFn,
732
738
  pageSize,
739
+ queryKeyFn,
733
740
  staleTime = 10 * 60 * 1e3,
734
741
  gcTime = 30 * 60 * 1e3,
735
742
  enabled = true
@@ -741,7 +748,7 @@ var usePaginationPrefetch = ({
741
748
  const offset = (page - 1) * pageSize;
742
749
  try {
743
750
  await queryClient.prefetchQuery({
744
- queryKey: [...queryKey, offset],
751
+ queryKey: queryKeyFn ? queryKeyFn(queryKey, offset) : [...queryKey, offset],
745
752
  queryFn: () => queryFn(offset),
746
753
  staleTime,
747
754
  gcTime
@@ -750,7 +757,7 @@ var usePaginationPrefetch = ({
750
757
  console.warn(`Error prefetching page ${page}:`, error);
751
758
  }
752
759
  },
753
- [queryKey, queryFn, pageSize, staleTime, gcTime, queryClient, enabled]
760
+ [queryKey, queryFn, pageSize, queryKeyFn, staleTime, gcTime, queryClient, enabled]
754
761
  );
755
762
  const handlePaginationHover = useCallback2(
756
763
  (page) => {
@@ -814,13 +821,112 @@ function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
814
821
  enabled: enabled && !!itemsFilters.q
815
822
  });
816
823
  }
824
+
825
+ // src/hooks/use-joomla-content.ts
826
+ import { useQuery as useQuery12 } from "@tanstack/react-query";
827
+ function useJoomlaContent(articleId, options = {}) {
828
+ const api = useAugurApi();
829
+ const callbacks = useAugurCallbacks();
830
+ const { data, isLoading, error } = useQuery12({
831
+ ...articleId ? getJoomlaContentOptions(api, articleId) : {
832
+ queryKey: getJoomlaContentKey(""),
833
+ /* v8 ignore next */
834
+ queryFn: () => Promise.reject()
835
+ },
836
+ ...options.queryFn ?? callbacks?.getJoomlaContent ? { queryFn: options.queryFn ?? (() => callbacks.getJoomlaContent(articleId)) } : {},
837
+ enabled: (options.enabled ?? true) && !!articleId
838
+ });
839
+ return {
840
+ article: data ?? null,
841
+ isLoading,
842
+ error
843
+ };
844
+ }
845
+
846
+ // src/hooks/use-joomla-content-list.ts
847
+ import { useQuery as useQuery13 } from "@tanstack/react-query";
848
+ function useJoomlaContentList(categoryId, options = {}) {
849
+ const api = useAugurApi();
850
+ const callbacks = useAugurCallbacks();
851
+ const { data, isLoading, error } = useQuery13({
852
+ ...categoryId ? getJoomlaContentListOptions(api, categoryId, options.filters) : {
853
+ queryKey: getJoomlaContentListKey(""),
854
+ /* v8 ignore next */
855
+ queryFn: () => Promise.reject()
856
+ },
857
+ ...options.queryFn ?? callbacks?.getJoomlaContentList ? {
858
+ queryFn: options.queryFn ?? (() => callbacks.getJoomlaContentList(categoryId, options.filters))
859
+ } : {},
860
+ enabled: (options.enabled ?? true) && !!categoryId
861
+ });
862
+ return {
863
+ articles: data ?? [],
864
+ isLoading,
865
+ error
866
+ };
867
+ }
868
+
869
+ // src/create-site-hooks.ts
870
+ import { createElement } from "react";
871
+ function createSiteHooks(config = {}) {
872
+ const { callbacks, defaultCustomerId } = config;
873
+ function Provider({ api, auth, children }) {
874
+ const mergedAuth = {
875
+ status: auth?.status ?? "unauthenticated",
876
+ customerId: auth?.customerId ?? defaultCustomerId,
877
+ userId: auth?.userId,
878
+ cartHdrUid: auth?.cartHdrUid
879
+ };
880
+ return createElement(AugurHooksProvider, {
881
+ api,
882
+ callbacks,
883
+ auth: mergedAuth,
884
+ children
885
+ });
886
+ }
887
+ Provider.displayName = "AugurSiteProvider";
888
+ return {
889
+ Provider,
890
+ // Hooks -- pricing
891
+ useItemPrice,
892
+ useCartPricing,
893
+ // Hooks -- inventory
894
+ useInvMast,
895
+ useInvMastDoc,
896
+ useInvMastStock,
897
+ // Hooks -- items & categories
898
+ useItemCategory,
899
+ useProductCategory,
900
+ useItemDetails,
901
+ useItemAttributes,
902
+ // Hooks -- search
903
+ useProductSearch,
904
+ useSearchSuggestions,
905
+ // Hooks -- cart
906
+ useCartActions,
907
+ useCartInitialization,
908
+ // Hooks -- pagination & infinite scroll
909
+ usePaginationPrefetch,
910
+ useCategoryItemsInfinite,
911
+ useItemSearchInfinite,
912
+ // Hooks -- Joomla
913
+ useJoomlaContent,
914
+ useJoomlaContentList,
915
+ // Hooks -- utilities
916
+ useDebounce,
917
+ useFormatPrice
918
+ };
919
+ }
817
920
  export {
818
921
  AugurHooksProvider,
819
922
  CATEGORY_CACHE_OPTIONS,
820
923
  INV_MAST_CACHE_OPTIONS,
821
924
  INV_MAST_DOC_CACHE_OPTIONS,
925
+ JOOMLA_CONTENT_CACHE_OPTIONS,
926
+ JOOMLA_CONTENT_LIST_CACHE_OPTIONS,
822
927
  PRICE_CACHE_OPTIONS,
823
928
  SEARCH_SUGGESTIONS_CACHE_OPTIONS,
929
+ createSiteHooks,
824
930
  getCartPricingQueryOptions,
825
931
  getCategoryItemsInfiniteKey,
826
932
  getCategoryItemsInfiniteOptions,
@@ -840,6 +946,10 @@ export {
840
946
  getItemPriceOptions,
841
947
  getItemSearchInfiniteKey,
842
948
  getItemSearchInfiniteOptions,
949
+ getJoomlaContentKey,
950
+ getJoomlaContentListKey,
951
+ getJoomlaContentListOptions,
952
+ getJoomlaContentOptions,
843
953
  getProductCategoryKey,
844
954
  getProductCategoryOptions,
845
955
  getProductSearchKey,
@@ -868,6 +978,8 @@ export {
868
978
  useItemFiltersStore,
869
979
  useItemPrice,
870
980
  useItemSearchInfinite,
981
+ useJoomlaContent,
982
+ useJoomlaContentList,
871
983
  usePaginationPrefetch,
872
984
  useProductCategory,
873
985
  useProductSearch,