@simpleapps-com/augur-hooks 0.1.8 → 0.2.0

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.
@@ -1,5 +1,5 @@
1
1
  import * as _simpleapps_com_augur_utils from '@simpleapps-com/augur-utils';
2
- import { TPriceData, TItemDetails, TInvMastDoc, TCategory, TAttribute, TItemsFilters, TProductItem, TProductCategory } from '@simpleapps-com/augur-utils';
2
+ import { TPriceData, TItemDetails, TInvMastDoc, TCategory, TAttribute, TItemsFilters, TProductItem, TJoomlaContent, TJoomlaContentFilters, TProductCategory } from '@simpleapps-com/augur-utils';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
5
 
@@ -44,6 +44,32 @@ type SearchSuggestionsResponse = {
44
44
  total: number;
45
45
  totalResults: number;
46
46
  };
47
+ /** Cache provider for Redis-compatible storage. */
48
+ interface CacheProvider {
49
+ prefix: string;
50
+ get: (key: string) => Promise<string | null>;
51
+ set: (key: string, value: string, ttlSeconds: number) => Promise<void>;
52
+ }
53
+ /** Cache settings for a single tier. */
54
+ interface CacheTierConfig {
55
+ /** CDN edge cache. Passed directly to SDK as edgeCache. Valid values: 1–8 (hours) or '30s', '1m', '5m'. */
56
+ edgeCache?: number | string;
57
+ /** Redis cache TTL in seconds. Requires provider. */
58
+ redis?: number;
59
+ /** React Query staleTime in ms. Overrides the built-in default. */
60
+ staleTime?: number;
61
+ /** React Query gcTime (garbage collection) in ms. Overrides the built-in default. */
62
+ gcTime?: number;
63
+ }
64
+ /** Cache configuration. All fields optional, all off by default. */
65
+ interface CacheConfig {
66
+ /** Redis-compatible cache. Required for redis caching. */
67
+ provider?: CacheProvider;
68
+ /** TTLs for long-lived data (categories, item details, docs). */
69
+ static?: CacheTierConfig;
70
+ /** TTLs for frequently-changing data (prices, stock, search). */
71
+ semiStatic?: CacheTierConfig;
72
+ }
47
73
  /** API options for item category queries. */
48
74
  interface GetItemCategoryApiOptions {
49
75
  childrenFilter?: string;
@@ -160,6 +186,10 @@ interface AugurCallbacks {
160
186
  itemCategoryUid?: number | string;
161
187
  pageParam: number;
162
188
  }) => Promise<InfiniteScrollPage>;
189
+ /** Override Joomla content fetching. */
190
+ getJoomlaContent?: (articleId: number | string) => Promise<TJoomlaContent>;
191
+ /** Override Joomla content list fetching. */
192
+ getJoomlaContentList?: (categoryId: number | string, filters?: Partial<TJoomlaContentFilters>) => Promise<TJoomlaContent[]>;
163
193
  }
164
194
 
165
195
  /**
@@ -174,6 +204,8 @@ interface AugurHooksProviderProps {
174
204
  callbacks?: AugurCallbacks;
175
205
  /** Optional auth context — hooks fall back to these values when not passed directly. */
176
206
  auth?: AugurAuthContext;
207
+ /** Optional cache configuration — controls edge and Redis caching per tier. */
208
+ cache?: CacheConfig;
177
209
  children: ReactNode;
178
210
  }
179
211
  /**
@@ -199,7 +231,7 @@ interface AugurHooksProviderProps {
199
231
  * </AugurHooksProvider>
200
232
  * ```
201
233
  */
202
- declare function AugurHooksProvider({ api, callbacks, auth, children, }: AugurHooksProviderProps): react_jsx_runtime.JSX.Element;
234
+ declare function AugurHooksProvider({ api, callbacks, auth, cache, children, }: AugurHooksProviderProps): react_jsx_runtime.JSX.Element;
203
235
  /**
204
236
  * Returns the augur-api SDK instance from context.
205
237
  * Throws if called outside of `<AugurHooksProvider>`.
@@ -211,16 +243,12 @@ declare function useAugurApi(): AugurApiClient;
211
243
  * auth fields are not passed directly as hook parameters.
212
244
  */
213
245
  declare function useAugurAuth(): AugurAuthContext | undefined;
246
+ /**
247
+ * Returns the provider-level cache configuration, if any.
248
+ * Used internally by hooks to enable edge/Redis caching.
249
+ */
250
+ declare function useAugurCache(): CacheConfig | undefined;
214
251
 
215
- declare const PRICE_CACHE_OPTIONS: {
216
- readonly refetchOnReconnect: true;
217
- readonly refetchOnWindowFocus: false;
218
- readonly meta: {
219
- readonly persist: true;
220
- };
221
- readonly staleTime: number;
222
- readonly gcTime: number;
223
- };
224
252
  /**
225
253
  * Generates a consistent query key for item price queries.
226
254
  * Usable in both client hooks and server-side prefetch.
@@ -230,22 +258,18 @@ declare const getItemPriceKey: (itemId: string | undefined, customerId: string |
230
258
  * Query options for item price. Accepts the SDK instance so it works
231
259
  * in both client (via provider) and server (via direct construction).
232
260
  */
233
- declare const getItemPriceOptions: (api: AugurApiClient, itemId: string | undefined, customerId: string | number | undefined, quantity?: number) => {
234
- refetchOnReconnect: true;
235
- refetchOnWindowFocus: false;
236
- meta: {
237
- readonly persist: true;
238
- };
239
- staleTime: number;
240
- gcTime: number;
261
+ declare const getItemPriceOptions: (api: AugurApiClient, itemId: string | undefined, customerId: string | number | undefined, quantity?: number, cache?: CacheConfig) => {
241
262
  queryKey: readonly ["price", string, string | number | undefined, number];
242
263
  queryFn: () => Promise<TPriceData>;
264
+ staleTime: number | undefined;
265
+ gcTime: number | undefined;
266
+ refetchOnReconnect: boolean;
267
+ refetchOnWindowFocus: boolean;
268
+ meta: {
269
+ persist: boolean;
270
+ };
243
271
  };
244
272
 
245
- declare const INV_MAST_DOC_CACHE_OPTIONS: {
246
- readonly staleTime: number;
247
- readonly gcTime: number;
248
- };
249
273
  /**
250
274
  * Generates a consistent query key for inv mast doc queries.
251
275
  * Usable in both client hooks and server-side prefetch.
@@ -255,17 +279,13 @@ declare const getInvMastDocKey: (invMastUid: number, itemId: string, includePric
255
279
  * Query options for inv mast doc. Accepts the SDK instance so it works
256
280
  * in both client (via provider) and server (via direct construction).
257
281
  */
258
- declare const getInvMastDocOptions: (api: AugurApiClient, invMastUid: number, itemId: string, includePricing: "Y" | "N") => {
259
- staleTime: number;
260
- gcTime: number;
282
+ declare const getInvMastDocOptions: (api: AugurApiClient, invMastUid: number, itemId: string, includePricing: "Y" | "N", cache?: CacheConfig) => {
261
283
  queryKey: readonly ["invMastDoc", number, string, "Y" | "N"];
262
284
  queryFn: () => Promise<TInvMastDoc>;
285
+ staleTime: number | undefined;
286
+ gcTime: number | undefined;
263
287
  };
264
288
 
265
- declare const CATEGORY_CACHE_OPTIONS: {
266
- readonly staleTime: number;
267
- readonly gcTime: number;
268
- };
269
289
  type ItemCategoryQueryKey = readonly [
270
290
  "itemCategory",
271
291
  number,
@@ -280,31 +300,27 @@ declare const getItemCategoryKey: (itemCategoryUid: number, apiOptions?: GetItem
280
300
  * Query options for item category. Accepts the SDK instance so it works
281
301
  * in both client (via provider) and server (via direct construction).
282
302
  */
283
- declare const getItemCategoryOptions: (api: AugurApiClient, itemCategoryUid: number, apiOptions?: GetItemCategoryApiOptions) => {
284
- staleTime: number;
285
- gcTime: number;
303
+ declare const getItemCategoryOptions: (api: AugurApiClient, itemCategoryUid: number, apiOptions?: GetItemCategoryApiOptions, cache?: CacheConfig) => {
286
304
  queryKey: ItemCategoryQueryKey;
287
305
  queryFn: () => Promise<TCategory>;
306
+ staleTime: number | undefined;
307
+ gcTime: number | undefined;
288
308
  };
289
309
 
290
- declare const INV_MAST_CACHE_OPTIONS: {
291
- readonly staleTime: number;
292
- readonly gcTime: number;
293
- };
294
310
  declare const getInvMastKey: (invMastUid: number, itemId: string) => readonly ["invMast", number, string];
295
- declare const getInvMastOptions: (api: AugurApiClient, invMastUid: number, itemId: string) => {
296
- staleTime: number;
297
- gcTime: number;
311
+ declare const getInvMastOptions: (api: AugurApiClient, invMastUid: number, itemId: string, cache?: CacheConfig) => {
298
312
  queryKey: readonly ["invMast", number, string];
299
313
  queryFn: () => Promise<TItemDetails>;
314
+ staleTime: number | undefined;
315
+ gcTime: number | undefined;
300
316
  };
301
317
 
302
318
  declare const getInvMastStockKey: (invMastUid: number | string) => readonly ["invMastStock", string | number];
303
- declare const getInvMastStockOptions: (api: AugurApiClient, invMastUid: number | string) => {
304
- staleTime: number;
305
- gcTime: number;
319
+ declare const getInvMastStockOptions: (api: AugurApiClient, invMastUid: number | string, cache?: CacheConfig) => {
306
320
  queryKey: readonly ["invMastStock", string | number];
307
321
  queryFn: () => Promise<number>;
322
+ staleTime: number | undefined;
323
+ gcTime: number | undefined;
308
324
  };
309
325
 
310
326
  type ProductCategoryResponse = {
@@ -314,27 +330,27 @@ type ProductCategoryResponse = {
314
330
  categoryImage: string | null;
315
331
  };
316
332
  declare const getProductCategoryKey: (itemCategoryUid: number | string | null) => readonly ["productCategory", string | number | null];
317
- declare const getProductCategoryOptions: (api: AugurApiClient, itemCategoryUid: number | string) => {
318
- staleTime: number;
319
- gcTime: number;
333
+ declare const getProductCategoryOptions: (api: AugurApiClient, itemCategoryUid: number | string, cache?: CacheConfig) => {
320
334
  queryKey: readonly ["productCategory", string | number | null];
321
335
  queryFn: () => Promise<ProductCategoryResponse>;
336
+ staleTime: number | undefined;
337
+ gcTime: number | undefined;
322
338
  };
323
339
 
324
340
  declare const getItemDetailsKey: (itemId: number | string) => readonly ["itemDetails", string | number];
325
- declare const getItemDetailsOptions: (api: AugurApiClient, itemId: number | string) => {
326
- staleTime: number;
327
- gcTime: number;
341
+ declare const getItemDetailsOptions: (api: AugurApiClient, itemId: number | string, cache?: CacheConfig) => {
328
342
  queryKey: readonly ["itemDetails", string | number];
329
343
  queryFn: () => Promise<TItemDetails>;
344
+ staleTime: number | undefined;
345
+ gcTime: number | undefined;
330
346
  };
331
347
 
332
348
  declare const getItemAttributesKey: (itemCategoryUid: number | string | null) => readonly ["itemAttributes", string | number | null];
333
- declare const getItemAttributesOptions: (api: AugurApiClient, itemCategoryUid: number | string) => {
334
- staleTime: number;
335
- gcTime: number;
349
+ declare const getItemAttributesOptions: (api: AugurApiClient, itemCategoryUid: number | string, cache?: CacheConfig) => {
336
350
  queryKey: readonly ["itemAttributes", string | number | null];
337
351
  queryFn: () => Promise<any>;
352
+ staleTime: number | undefined;
353
+ gcTime: number | undefined;
338
354
  };
339
355
 
340
356
  type ProductSearchResponse = {
@@ -349,17 +365,13 @@ declare const getProductSearchKey: (pageData: PageData) => readonly ["productSea
349
365
  * Query options for product search. Accepts the SDK instance so it works
350
366
  * in both client (via provider) and server (via direct construction).
351
367
  */
352
- declare const getProductSearchOptions: (api: AugurApiClient, pageData: PageData) => {
353
- staleTime: number;
354
- gcTime: number;
368
+ declare const getProductSearchOptions: (api: AugurApiClient, pageData: PageData, cache?: CacheConfig) => {
355
369
  queryKey: readonly ["productSearch", string, number, number, string, number | undefined];
356
370
  queryFn: () => Promise<ProductSearchResponse>;
371
+ staleTime: number | undefined;
372
+ gcTime: number | undefined;
357
373
  };
358
374
 
359
- declare const SEARCH_SUGGESTIONS_CACHE_OPTIONS: {
360
- readonly staleTime: number;
361
- readonly gcTime: number;
362
- };
363
375
  /**
364
376
  * Generates a consistent query key for search suggestion queries.
365
377
  */
@@ -368,11 +380,11 @@ declare const getSearchSuggestionsKey: (query: string, limit: number, offset: nu
368
380
  * Query options for search suggestions. Accepts the SDK instance so it works
369
381
  * in both client (via provider) and server (via direct construction).
370
382
  */
371
- declare const getSearchSuggestionsOptions: (api: AugurApiClient, query: string, limit?: number, offset?: number) => {
372
- staleTime: number;
373
- gcTime: number;
383
+ declare const getSearchSuggestionsOptions: (api: AugurApiClient, query: string, limit?: number, offset?: number, cache?: CacheConfig) => {
374
384
  queryKey: readonly ["searchSuggestions", string, number, number];
375
385
  queryFn: () => Promise<SearchSuggestionsResponse>;
386
+ staleTime: number | undefined;
387
+ gcTime: number | undefined;
376
388
  };
377
389
 
378
390
  /**
@@ -381,17 +393,17 @@ declare const getSearchSuggestionsOptions: (api: AugurApiClient, query: string,
381
393
  declare function getCartPricingQueryOptions(api: AugurApiClient, cartLines: Array<{
382
394
  itemId: string;
383
395
  quantity: number;
384
- }>, customerId: string | number | undefined): {
396
+ }>, customerId: string | number | undefined, cache?: CacheConfig): {
385
397
  enabled: boolean;
386
- refetchOnReconnect: true;
387
- refetchOnWindowFocus: false;
388
- meta: {
389
- readonly persist: true;
390
- };
391
- staleTime: number;
392
- gcTime: number;
393
398
  queryKey: readonly ["price", string, string | number | undefined, number];
394
399
  queryFn: () => Promise<_simpleapps_com_augur_utils.TPriceData>;
400
+ staleTime: number | undefined;
401
+ gcTime: number | undefined;
402
+ refetchOnReconnect: boolean;
403
+ refetchOnWindowFocus: boolean;
404
+ meta: {
405
+ persist: boolean;
406
+ };
395
407
  }[];
396
408
 
397
409
  declare const getCategoryItemsInfiniteKey: (itemCategoryUid: number, itemsFilters: TItemsFilters) => readonly ["categoryItemsInfinite", number, string];
@@ -399,15 +411,15 @@ declare const getCategoryItemsInfiniteKey: (itemCategoryUid: number, itemsFilter
399
411
  * Full infinite query options for category items.
400
412
  * Usable for server-side prefetch with `queryClient.prefetchInfiniteQuery()`.
401
413
  */
402
- declare const getCategoryItemsInfiniteOptions: (api: AugurApiClient, itemCategoryUid: number, itemsFilters: TItemsFilters) => {
403
- staleTime: number;
404
- gcTime: number;
414
+ declare const getCategoryItemsInfiniteOptions: (api: AugurApiClient, itemCategoryUid: number, itemsFilters: TItemsFilters, cache?: CacheConfig) => {
405
415
  queryKey: readonly ["categoryItemsInfinite", number, string];
406
416
  queryFn: ({ pageParam, }: {
407
417
  pageParam?: unknown;
408
418
  }) => Promise<InfiniteScrollPage>;
409
419
  initialPageParam: number;
410
420
  getNextPageParam: (lastPage: InfiniteScrollPage) => number | undefined;
421
+ staleTime: number | undefined;
422
+ gcTime: number | undefined;
411
423
  };
412
424
 
413
425
  declare const getItemSearchInfiniteKey: (itemsFilters: TItemsFilters, itemCategoryUid?: number | string) => readonly ["itemSearchInfinite", string, string | number | undefined];
@@ -415,18 +427,34 @@ declare const getItemSearchInfiniteKey: (itemsFilters: TItemsFilters, itemCatego
415
427
  * Full infinite query options for item search.
416
428
  * Usable for server-side prefetch with `queryClient.prefetchInfiniteQuery()`.
417
429
  */
418
- declare const getItemSearchInfiniteOptions: (api: AugurApiClient, itemsFilters: TItemsFilters, itemCategoryUid?: number | string) => {
419
- meta: {
420
- persist: boolean;
421
- };
422
- staleTime: number;
423
- gcTime: number;
430
+ declare const getItemSearchInfiniteOptions: (api: AugurApiClient, itemsFilters: TItemsFilters, itemCategoryUid?: number | string, cache?: CacheConfig) => {
424
431
  queryKey: readonly ["itemSearchInfinite", string, string | number | undefined];
425
432
  queryFn: ({ pageParam, }: {
426
433
  pageParam?: unknown;
427
434
  }) => Promise<InfiniteScrollPage>;
428
435
  initialPageParam: number;
429
436
  getNextPageParam: (lastPage: InfiniteScrollPage) => number | undefined;
437
+ staleTime: number | undefined;
438
+ gcTime: number | undefined;
439
+ meta: {
440
+ persist: boolean;
441
+ };
442
+ };
443
+
444
+ declare const getJoomlaContentKey: (articleId: number | string) => readonly ["joomlaContent", string | number];
445
+ declare const getJoomlaContentOptions: (api: AugurApiClient, articleId: number | string, cache?: CacheConfig) => {
446
+ queryKey: readonly ["joomlaContent", string | number];
447
+ queryFn: () => Promise<TJoomlaContent>;
448
+ staleTime: number | undefined;
449
+ gcTime: number | undefined;
450
+ };
451
+
452
+ declare const getJoomlaContentListKey: (categoryId: number | string, filters?: Partial<TJoomlaContentFilters>) => readonly ["joomlaContentList", string | number, Partial<TJoomlaContentFilters> | undefined];
453
+ declare const getJoomlaContentListOptions: (api: AugurApiClient, categoryId: number | string, filters?: Partial<TJoomlaContentFilters>, cache?: CacheConfig) => {
454
+ queryKey: readonly ["joomlaContentList", string | number, Partial<TJoomlaContentFilters> | undefined];
455
+ queryFn: () => Promise<TJoomlaContent[]>;
456
+ staleTime: number | undefined;
457
+ gcTime: number | undefined;
430
458
  };
431
459
 
432
- export { type AugurApiClient as A, getItemSearchInfiniteOptions as B, CATEGORY_CACHE_OPTIONS as C, getProductCategoryKey as D, getProductCategoryOptions as E, getProductSearchKey as F, type GetItemCategoryApiOptions as G, getProductSearchOptions as H, type InfiniteScrollPage as I, getSearchSuggestionsKey as J, getSearchSuggestionsOptions as K, useAugurApi as L, useAugurAuth as M, type PageData as P, type SearchSuggestionsResponse as S, type SearchSuggestion as a, type AugurAuthContext as b, type AugurCallbacks as c, AugurHooksProvider as d, INV_MAST_CACHE_OPTIONS as e, INV_MAST_DOC_CACHE_OPTIONS as f, PRICE_CACHE_OPTIONS as g, SEARCH_SUGGESTIONS_CACHE_OPTIONS as h, getCartPricingQueryOptions as i, getCategoryItemsInfiniteKey as j, getCategoryItemsInfiniteOptions as k, getInvMastDocKey as l, getInvMastDocOptions as m, getInvMastKey as n, getInvMastOptions as o, getInvMastStockKey as p, getInvMastStockOptions as q, getItemAttributesKey as r, getItemAttributesOptions as s, getItemCategoryKey as t, getItemCategoryOptions as u, getItemDetailsKey as v, getItemDetailsOptions as w, getItemPriceKey as x, getItemPriceOptions as y, getItemSearchInfiniteKey as z };
460
+ export { type AugurCallbacks as A, getJoomlaContentListKey as B, type CacheConfig as C, getJoomlaContentListOptions as D, getJoomlaContentOptions as E, getProductCategoryKey as F, type GetItemCategoryApiOptions as G, getProductCategoryOptions as H, type InfiniteScrollPage as I, getProductSearchKey as J, getProductSearchOptions as K, getSearchSuggestionsKey as L, getSearchSuggestionsOptions as M, useAugurApi as N, useAugurAuth as O, type PageData as P, useAugurCache as Q, type SearchSuggestionsResponse as S, type SearchSuggestion as a, type AugurApiClient as b, type AugurAuthContext as c, AugurHooksProvider as d, type CacheProvider as e, type CacheTierConfig as f, getCartPricingQueryOptions as g, getCategoryItemsInfiniteKey as h, getCategoryItemsInfiniteOptions as i, getInvMastDocKey as j, getInvMastDocOptions as k, getInvMastKey as l, getInvMastOptions as m, getInvMastStockKey as n, getInvMastStockOptions as o, getItemAttributesKey as p, getItemAttributesOptions as q, getItemCategoryKey as r, getItemCategoryOptions as s, getItemDetailsKey as t, getItemDetailsOptions as u, getItemPriceKey as v, getItemPriceOptions as w, getItemSearchInfiniteKey as x, getItemSearchInfiniteOptions as y, getJoomlaContentKey as z };