@simpleapps-com/augur-hooks 0.1.9 → 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.
@@ -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;
@@ -178,6 +204,8 @@ interface AugurHooksProviderProps {
178
204
  callbacks?: AugurCallbacks;
179
205
  /** Optional auth context — hooks fall back to these values when not passed directly. */
180
206
  auth?: AugurAuthContext;
207
+ /** Optional cache configuration — controls edge and Redis caching per tier. */
208
+ cache?: CacheConfig;
181
209
  children: ReactNode;
182
210
  }
183
211
  /**
@@ -203,7 +231,7 @@ interface AugurHooksProviderProps {
203
231
  * </AugurHooksProvider>
204
232
  * ```
205
233
  */
206
- 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;
207
235
  /**
208
236
  * Returns the augur-api SDK instance from context.
209
237
  * Throws if called outside of `<AugurHooksProvider>`.
@@ -215,16 +243,12 @@ declare function useAugurApi(): AugurApiClient;
215
243
  * auth fields are not passed directly as hook parameters.
216
244
  */
217
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;
218
251
 
219
- declare const PRICE_CACHE_OPTIONS: {
220
- readonly refetchOnReconnect: true;
221
- readonly refetchOnWindowFocus: false;
222
- readonly meta: {
223
- readonly persist: true;
224
- };
225
- readonly staleTime: number;
226
- readonly gcTime: number;
227
- };
228
252
  /**
229
253
  * Generates a consistent query key for item price queries.
230
254
  * Usable in both client hooks and server-side prefetch.
@@ -234,22 +258,18 @@ declare const getItemPriceKey: (itemId: string | undefined, customerId: string |
234
258
  * Query options for item price. Accepts the SDK instance so it works
235
259
  * in both client (via provider) and server (via direct construction).
236
260
  */
237
- declare const getItemPriceOptions: (api: AugurApiClient, itemId: string | undefined, customerId: string | number | undefined, quantity?: number) => {
238
- refetchOnReconnect: true;
239
- refetchOnWindowFocus: false;
240
- meta: {
241
- readonly persist: true;
242
- };
243
- staleTime: number;
244
- gcTime: number;
261
+ declare const getItemPriceOptions: (api: AugurApiClient, itemId: string | undefined, customerId: string | number | undefined, quantity?: number, cache?: CacheConfig) => {
245
262
  queryKey: readonly ["price", string, string | number | undefined, number];
246
263
  queryFn: () => Promise<TPriceData>;
264
+ staleTime: number | undefined;
265
+ gcTime: number | undefined;
266
+ refetchOnReconnect: boolean;
267
+ refetchOnWindowFocus: boolean;
268
+ meta: {
269
+ persist: boolean;
270
+ };
247
271
  };
248
272
 
249
- declare const INV_MAST_DOC_CACHE_OPTIONS: {
250
- readonly staleTime: number;
251
- readonly gcTime: number;
252
- };
253
273
  /**
254
274
  * Generates a consistent query key for inv mast doc queries.
255
275
  * Usable in both client hooks and server-side prefetch.
@@ -259,17 +279,13 @@ declare const getInvMastDocKey: (invMastUid: number, itemId: string, includePric
259
279
  * Query options for inv mast doc. Accepts the SDK instance so it works
260
280
  * in both client (via provider) and server (via direct construction).
261
281
  */
262
- declare const getInvMastDocOptions: (api: AugurApiClient, invMastUid: number, itemId: string, includePricing: "Y" | "N") => {
263
- staleTime: number;
264
- gcTime: number;
282
+ declare const getInvMastDocOptions: (api: AugurApiClient, invMastUid: number, itemId: string, includePricing: "Y" | "N", cache?: CacheConfig) => {
265
283
  queryKey: readonly ["invMastDoc", number, string, "Y" | "N"];
266
284
  queryFn: () => Promise<TInvMastDoc>;
285
+ staleTime: number | undefined;
286
+ gcTime: number | undefined;
267
287
  };
268
288
 
269
- declare const CATEGORY_CACHE_OPTIONS: {
270
- readonly staleTime: number;
271
- readonly gcTime: number;
272
- };
273
289
  type ItemCategoryQueryKey = readonly [
274
290
  "itemCategory",
275
291
  number,
@@ -284,31 +300,27 @@ declare const getItemCategoryKey: (itemCategoryUid: number, apiOptions?: GetItem
284
300
  * Query options for item category. Accepts the SDK instance so it works
285
301
  * in both client (via provider) and server (via direct construction).
286
302
  */
287
- declare const getItemCategoryOptions: (api: AugurApiClient, itemCategoryUid: number, apiOptions?: GetItemCategoryApiOptions) => {
288
- staleTime: number;
289
- gcTime: number;
303
+ declare const getItemCategoryOptions: (api: AugurApiClient, itemCategoryUid: number, apiOptions?: GetItemCategoryApiOptions, cache?: CacheConfig) => {
290
304
  queryKey: ItemCategoryQueryKey;
291
305
  queryFn: () => Promise<TCategory>;
306
+ staleTime: number | undefined;
307
+ gcTime: number | undefined;
292
308
  };
293
309
 
294
- declare const INV_MAST_CACHE_OPTIONS: {
295
- readonly staleTime: number;
296
- readonly gcTime: number;
297
- };
298
310
  declare const getInvMastKey: (invMastUid: number, itemId: string) => readonly ["invMast", number, string];
299
- declare const getInvMastOptions: (api: AugurApiClient, invMastUid: number, itemId: string) => {
300
- staleTime: number;
301
- gcTime: number;
311
+ declare const getInvMastOptions: (api: AugurApiClient, invMastUid: number, itemId: string, cache?: CacheConfig) => {
302
312
  queryKey: readonly ["invMast", number, string];
303
313
  queryFn: () => Promise<TItemDetails>;
314
+ staleTime: number | undefined;
315
+ gcTime: number | undefined;
304
316
  };
305
317
 
306
318
  declare const getInvMastStockKey: (invMastUid: number | string) => readonly ["invMastStock", string | number];
307
- declare const getInvMastStockOptions: (api: AugurApiClient, invMastUid: number | string) => {
308
- staleTime: number;
309
- gcTime: number;
319
+ declare const getInvMastStockOptions: (api: AugurApiClient, invMastUid: number | string, cache?: CacheConfig) => {
310
320
  queryKey: readonly ["invMastStock", string | number];
311
321
  queryFn: () => Promise<number>;
322
+ staleTime: number | undefined;
323
+ gcTime: number | undefined;
312
324
  };
313
325
 
314
326
  type ProductCategoryResponse = {
@@ -318,27 +330,27 @@ type ProductCategoryResponse = {
318
330
  categoryImage: string | null;
319
331
  };
320
332
  declare const getProductCategoryKey: (itemCategoryUid: number | string | null) => readonly ["productCategory", string | number | null];
321
- declare const getProductCategoryOptions: (api: AugurApiClient, itemCategoryUid: number | string) => {
322
- staleTime: number;
323
- gcTime: number;
333
+ declare const getProductCategoryOptions: (api: AugurApiClient, itemCategoryUid: number | string, cache?: CacheConfig) => {
324
334
  queryKey: readonly ["productCategory", string | number | null];
325
335
  queryFn: () => Promise<ProductCategoryResponse>;
336
+ staleTime: number | undefined;
337
+ gcTime: number | undefined;
326
338
  };
327
339
 
328
340
  declare const getItemDetailsKey: (itemId: number | string) => readonly ["itemDetails", string | number];
329
- declare const getItemDetailsOptions: (api: AugurApiClient, itemId: number | string) => {
330
- staleTime: number;
331
- gcTime: number;
341
+ declare const getItemDetailsOptions: (api: AugurApiClient, itemId: number | string, cache?: CacheConfig) => {
332
342
  queryKey: readonly ["itemDetails", string | number];
333
343
  queryFn: () => Promise<TItemDetails>;
344
+ staleTime: number | undefined;
345
+ gcTime: number | undefined;
334
346
  };
335
347
 
336
348
  declare const getItemAttributesKey: (itemCategoryUid: number | string | null) => readonly ["itemAttributes", string | number | null];
337
- declare const getItemAttributesOptions: (api: AugurApiClient, itemCategoryUid: number | string) => {
338
- staleTime: number;
339
- gcTime: number;
349
+ declare const getItemAttributesOptions: (api: AugurApiClient, itemCategoryUid: number | string, cache?: CacheConfig) => {
340
350
  queryKey: readonly ["itemAttributes", string | number | null];
341
351
  queryFn: () => Promise<any>;
352
+ staleTime: number | undefined;
353
+ gcTime: number | undefined;
342
354
  };
343
355
 
344
356
  type ProductSearchResponse = {
@@ -353,17 +365,13 @@ declare const getProductSearchKey: (pageData: PageData) => readonly ["productSea
353
365
  * Query options for product search. Accepts the SDK instance so it works
354
366
  * in both client (via provider) and server (via direct construction).
355
367
  */
356
- declare const getProductSearchOptions: (api: AugurApiClient, pageData: PageData) => {
357
- staleTime: number;
358
- gcTime: number;
368
+ declare const getProductSearchOptions: (api: AugurApiClient, pageData: PageData, cache?: CacheConfig) => {
359
369
  queryKey: readonly ["productSearch", string, number, number, string, number | undefined];
360
370
  queryFn: () => Promise<ProductSearchResponse>;
371
+ staleTime: number | undefined;
372
+ gcTime: number | undefined;
361
373
  };
362
374
 
363
- declare const SEARCH_SUGGESTIONS_CACHE_OPTIONS: {
364
- readonly staleTime: number;
365
- readonly gcTime: number;
366
- };
367
375
  /**
368
376
  * Generates a consistent query key for search suggestion queries.
369
377
  */
@@ -372,11 +380,11 @@ declare const getSearchSuggestionsKey: (query: string, limit: number, offset: nu
372
380
  * Query options for search suggestions. Accepts the SDK instance so it works
373
381
  * in both client (via provider) and server (via direct construction).
374
382
  */
375
- declare const getSearchSuggestionsOptions: (api: AugurApiClient, query: string, limit?: number, offset?: number) => {
376
- staleTime: number;
377
- gcTime: number;
383
+ declare const getSearchSuggestionsOptions: (api: AugurApiClient, query: string, limit?: number, offset?: number, cache?: CacheConfig) => {
378
384
  queryKey: readonly ["searchSuggestions", string, number, number];
379
385
  queryFn: () => Promise<SearchSuggestionsResponse>;
386
+ staleTime: number | undefined;
387
+ gcTime: number | undefined;
380
388
  };
381
389
 
382
390
  /**
@@ -385,17 +393,17 @@ declare const getSearchSuggestionsOptions: (api: AugurApiClient, query: string,
385
393
  declare function getCartPricingQueryOptions(api: AugurApiClient, cartLines: Array<{
386
394
  itemId: string;
387
395
  quantity: number;
388
- }>, customerId: string | number | undefined): {
396
+ }>, customerId: string | number | undefined, cache?: CacheConfig): {
389
397
  enabled: boolean;
390
- refetchOnReconnect: true;
391
- refetchOnWindowFocus: false;
392
- meta: {
393
- readonly persist: true;
394
- };
395
- staleTime: number;
396
- gcTime: number;
397
398
  queryKey: readonly ["price", string, string | number | undefined, number];
398
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
+ };
399
407
  }[];
400
408
 
401
409
  declare const getCategoryItemsInfiniteKey: (itemCategoryUid: number, itemsFilters: TItemsFilters) => readonly ["categoryItemsInfinite", number, string];
@@ -403,15 +411,15 @@ declare const getCategoryItemsInfiniteKey: (itemCategoryUid: number, itemsFilter
403
411
  * Full infinite query options for category items.
404
412
  * Usable for server-side prefetch with `queryClient.prefetchInfiniteQuery()`.
405
413
  */
406
- declare const getCategoryItemsInfiniteOptions: (api: AugurApiClient, itemCategoryUid: number, itemsFilters: TItemsFilters) => {
407
- staleTime: number;
408
- gcTime: number;
414
+ declare const getCategoryItemsInfiniteOptions: (api: AugurApiClient, itemCategoryUid: number, itemsFilters: TItemsFilters, cache?: CacheConfig) => {
409
415
  queryKey: readonly ["categoryItemsInfinite", number, string];
410
416
  queryFn: ({ pageParam, }: {
411
417
  pageParam?: unknown;
412
418
  }) => Promise<InfiniteScrollPage>;
413
419
  initialPageParam: number;
414
420
  getNextPageParam: (lastPage: InfiniteScrollPage) => number | undefined;
421
+ staleTime: number | undefined;
422
+ gcTime: number | undefined;
415
423
  };
416
424
 
417
425
  declare const getItemSearchInfiniteKey: (itemsFilters: TItemsFilters, itemCategoryUid?: number | string) => readonly ["itemSearchInfinite", string, string | number | undefined];
@@ -419,42 +427,34 @@ declare const getItemSearchInfiniteKey: (itemsFilters: TItemsFilters, itemCatego
419
427
  * Full infinite query options for item search.
420
428
  * Usable for server-side prefetch with `queryClient.prefetchInfiniteQuery()`.
421
429
  */
422
- declare const getItemSearchInfiniteOptions: (api: AugurApiClient, itemsFilters: TItemsFilters, itemCategoryUid?: number | string) => {
423
- meta: {
424
- persist: boolean;
425
- };
426
- staleTime: number;
427
- gcTime: number;
430
+ declare const getItemSearchInfiniteOptions: (api: AugurApiClient, itemsFilters: TItemsFilters, itemCategoryUid?: number | string, cache?: CacheConfig) => {
428
431
  queryKey: readonly ["itemSearchInfinite", string, string | number | undefined];
429
432
  queryFn: ({ pageParam, }: {
430
433
  pageParam?: unknown;
431
434
  }) => Promise<InfiniteScrollPage>;
432
435
  initialPageParam: number;
433
436
  getNextPageParam: (lastPage: InfiniteScrollPage) => number | undefined;
437
+ staleTime: number | undefined;
438
+ gcTime: number | undefined;
439
+ meta: {
440
+ persist: boolean;
441
+ };
434
442
  };
435
443
 
436
- declare const JOOMLA_CONTENT_CACHE_OPTIONS: {
437
- readonly staleTime: number;
438
- readonly gcTime: number;
439
- };
440
444
  declare const getJoomlaContentKey: (articleId: number | string) => readonly ["joomlaContent", string | number];
441
- declare const getJoomlaContentOptions: (api: AugurApiClient, articleId: number | string) => {
442
- staleTime: number;
443
- gcTime: number;
445
+ declare const getJoomlaContentOptions: (api: AugurApiClient, articleId: number | string, cache?: CacheConfig) => {
444
446
  queryKey: readonly ["joomlaContent", string | number];
445
447
  queryFn: () => Promise<TJoomlaContent>;
448
+ staleTime: number | undefined;
449
+ gcTime: number | undefined;
446
450
  };
447
451
 
448
- declare const JOOMLA_CONTENT_LIST_CACHE_OPTIONS: {
449
- readonly staleTime: number;
450
- readonly gcTime: number;
451
- };
452
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>) => {
454
- staleTime: number;
455
- gcTime: number;
453
+ declare const getJoomlaContentListOptions: (api: AugurApiClient, categoryId: number | string, filters?: Partial<TJoomlaContentFilters>, cache?: CacheConfig) => {
456
454
  queryKey: readonly ["joomlaContentList", string | number, Partial<TJoomlaContentFilters> | undefined];
457
455
  queryFn: () => Promise<TJoomlaContent[]>;
456
+ staleTime: number | undefined;
457
+ gcTime: number | undefined;
458
458
  };
459
459
 
460
- export { type AugurCallbacks as A, getItemSearchInfiniteKey as B, CATEGORY_CACHE_OPTIONS as C, getItemSearchInfiniteOptions as D, getJoomlaContentKey as E, getJoomlaContentListKey as F, type GetItemCategoryApiOptions as G, getJoomlaContentListOptions as H, type InfiniteScrollPage as I, JOOMLA_CONTENT_CACHE_OPTIONS as J, getJoomlaContentOptions as K, getProductCategoryKey as L, getProductCategoryOptions as M, getProductSearchKey as N, getProductSearchOptions as O, type PageData as P, getSearchSuggestionsKey as Q, getSearchSuggestionsOptions as R, type SearchSuggestionsResponse as S, useAugurApi as T, useAugurAuth as U, type SearchSuggestion as a, type AugurApiClient as b, type AugurAuthContext as c, AugurHooksProvider as d, INV_MAST_CACHE_OPTIONS as e, INV_MAST_DOC_CACHE_OPTIONS as f, JOOMLA_CONTENT_LIST_CACHE_OPTIONS as g, PRICE_CACHE_OPTIONS as h, SEARCH_SUGGESTIONS_CACHE_OPTIONS as i, getCartPricingQueryOptions as j, getCategoryItemsInfiniteKey as k, getCategoryItemsInfiniteOptions as l, getInvMastDocKey as m, getInvMastDocOptions as n, getInvMastKey as o, getInvMastOptions as p, getInvMastStockKey as q, getInvMastStockOptions as r, getItemAttributesKey as s, getItemAttributesOptions as t, getItemCategoryKey as u, getItemCategoryOptions as v, getItemDetailsKey as w, getItemDetailsOptions as x, getItemPriceKey as y, getItemPriceOptions 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 };