@simpleapps-com/augur-hooks 2.2.4 → 2.2.6

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/EXPORTS.md CHANGED
@@ -33,8 +33,10 @@ Version: 2.0.21
33
33
  | `SearchSuggestionsResponse` | value | |
34
34
  | `executeBatchQuery` | function | |
35
35
  | `getCartPricingQueryOptions` | function | |
36
+ | `getRegisteredQueryAction` | function | Returns the registered query action function or null |
36
37
  | `getStockKey` | value | |
37
38
  | `getStockOptions` | value | |
39
+ | `registerQueryAction` | function | Registers a query action function for auto-detection by the provider and hooks |
38
40
  | `useAugurApi` | function | |
39
41
  | `useAugurApiOptional` | value | |
40
42
  | `useAugurAuth` | value | |
@@ -141,6 +141,7 @@ interface GetItemCategoryApiOptions {
141
141
  }
142
142
 
143
143
  declare const getStockKey: (invMastUid: number | string) => readonly ["stock", string | number];
144
+ /** @deprecated Use createServerQueryProxy() from augur-server/hooks instead. */
144
145
  declare const getStockOptions: (api: AugurApiClient, invMastUid: number | string, cache?: CacheConfig) => {
145
146
  queryKey: readonly ["stock", string | number];
146
147
  queryFn: () => Promise<TStock>;
@@ -172,6 +173,8 @@ declare function executeBatchQuery<TParam, TData>(config: BatchQueryConfig<TPara
172
173
 
173
174
  /**
174
175
  * Get cart pricing query options for prefetching or parent components.
176
+ *
177
+ * @deprecated Use createServerQueryProxy() from augur-server/hooks instead.
175
178
  */
176
179
  declare function getCartPricingQueryOptions(api: AugurApiClient, cartLines: Array<{
177
180
  itemId: string;
@@ -141,6 +141,7 @@ interface GetItemCategoryApiOptions {
141
141
  }
142
142
 
143
143
  declare const getStockKey: (invMastUid: number | string) => readonly ["stock", string | number];
144
+ /** @deprecated Use createServerQueryProxy() from augur-server/hooks instead. */
144
145
  declare const getStockOptions: (api: AugurApiClient, invMastUid: number | string, cache?: CacheConfig) => {
145
146
  queryKey: readonly ["stock", string | number];
146
147
  queryFn: () => Promise<TStock>;
@@ -172,6 +173,8 @@ declare function executeBatchQuery<TParam, TData>(config: BatchQueryConfig<TPara
172
173
 
173
174
  /**
174
175
  * Get cart pricing query options for prefetching or parent components.
176
+ *
177
+ * @deprecated Use createServerQueryProxy() from augur-server/hooks instead.
175
178
  */
176
179
  declare function getCartPricingQueryOptions(api: AugurApiClient, cartLines: Array<{
177
180
  itemId: string;
@@ -129,7 +129,5 @@ function getCartPricingQueryOptions(api, cartLines, customerId, cache) {
129
129
 
130
130
 
131
131
 
132
-
133
-
134
- exports.getStockKey = getStockKey; exports.getStockOptions = getStockOptions; exports.executeBatchQuery = executeBatchQuery; exports.getItemPriceKey = getItemPriceKey; exports.getItemPriceOptions = getItemPriceOptions; exports.getCartPricingQueryOptions = getCartPricingQueryOptions;
135
- //# sourceMappingURL=chunk-UMCLTMAJ.cjs.map
132
+ exports.getStockKey = getStockKey; exports.getStockOptions = getStockOptions; exports.executeBatchQuery = executeBatchQuery; exports.getCartPricingQueryOptions = getCartPricingQueryOptions;
133
+ //# sourceMappingURL=chunk-A3AWGAIZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/chunk-A3AWGAIZ.cjs","../src/queries/cache-helper.ts","../src/queries/stock.ts","../src/queries/batch-query.ts","../src/queries/cart-pricing.ts"],"names":[],"mappings":"AAAA;ACCA,uDAAgC;AAKhC,SAAS,KAAA,CAAM,GAAA,EAAqB;AAClC,EAAA,IAAI,EAAA,EAAI,UAAA;AACR,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAA,EAAK;AACnC,IAAA,EAAA,GAAK,GAAA,CAAI,UAAA,CAAW,CAAC,CAAA;AACrB,IAAA,EAAA,EAAI,IAAA,CAAK,IAAA,CAAK,CAAA,EAAG,QAAU,CAAA;AAAA,EAC7B;AACA,EAAA,OAAA,CAAQ,EAAA,IAAM,CAAA,CAAA,CAAG,QA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,YAAA;AACA,YAAA;AACI,YAAA;AACL,UAAA;AACD,UAAA;AACF,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACW,IAAA;AACH,IAAA;AACR,IAAA;AACA,IAAA;AACQ,IAAA;AACV,EAAA;AACF;AAOgB;AAMP,EAAA;AACF,IAAA;AACQ,IAAA;AACX,EAAA;AACJ;AJgDe;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/chunk-A3AWGAIZ.cjs","sourcesContent":[null,"import type { CacheProvider, CacheTierConfig } from \"../types\";\nimport { stableStringify } from \"@simpleapps-com/augur-core\";\n\n/**\n * FNV-1a 32-bit hash. Fast, cross-platform (no Node crypto needed).\n */\nfunction fnv1a(str: string): string {\n let h = 0x811c9dc5;\n for (let i = 0; i < str.length; i++) {\n h ^= str.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0).toString(16).padStart(8, \"0\");\n}\n\n/**\n * Wraps an async function with optional Redis caching.\n *\n * - When `provider` and `tier.redis` are both set, checks Redis before\n * calling `fn`, then caches the result on miss.\n * - When either is missing, calls `fn` directly (no-op passthrough).\n *\n * @param provider Redis-compatible get/set + prefix. Undefined = skip Redis.\n * @param tier Cache tier config. Undefined or missing `redis` = skip Redis.\n * @param methodPath Dot-separated SDK method path (used as cache key segment).\n * @param fn The async function to cache (typically the SDK call).\n * @param keyArgs Values to hash for the cache key (e.g. query params).\n */\nexport async function withCache<T>(\n provider: CacheProvider | undefined,\n tier: CacheTierConfig | undefined,\n methodPath: string,\n fn: () => Promise<T>,\n ...keyArgs: unknown[]\n): Promise<T> {\n const redisTtl = tier?.redis;\n if (!provider || !redisTtl) return fn();\n\n const key = `${provider.prefix}sdk:${methodPath}:${fnv1a(stableStringify(keyArgs))}`;\n\n try {\n const cached = await provider.get(key);\n if (cached != null) return JSON.parse(cached) as T;\n } catch {\n /* Redis read error — fall through to SDK call */\n }\n\n const result = await fn();\n\n try {\n provider.set(key, JSON.stringify(result), redisTtl).catch(() => {});\n } catch {\n /* Non-serializable or write error — skip caching */\n }\n\n return result;\n}\n","import type { TStock } from \"@simpleapps-com/augur-utils\";\nimport type { AugurApiClient } from \"../provider\";\nimport type { CacheConfig } from \"../types\";\nimport { withCache } from \"./cache-helper\";\n\nexport const getStockKey = (invMastUid: number | string) => {\n return [\"stock\", invMastUid] as const;\n};\n\n/** @deprecated Use createServerQueryProxy() from augur-server/hooks instead. */\nexport const getStockOptions = (\n api: AugurApiClient,\n invMastUid: number | string,\n cache?: CacheConfig,\n) => {\n const tier = cache?.semiStatic;\n return {\n queryKey: getStockKey(invMastUid),\n queryFn: async (): Promise<TStock> => {\n const edgeCache = tier?.edgeCache;\n return withCache(\n cache?.provider,\n tier,\n \"items.invMast.stock.get\",\n async () => {\n const response = await api.items.invMast.stock.get(Number(invMastUid), {\n ...(edgeCache != null ? { edgeCache } : {}),\n });\n const stockData = response.data?.stockData ?? [];\n const companySummary = response.data?.companySummary ?? {};\n return { stockData, companySummary } as TStock;\n },\n invMastUid,\n );\n },\n staleTime: tier?.staleTime,\n gcTime: tier?.gcTime,\n };\n};\n","import type { QueryClient } from \"@tanstack/react-query\";\n\nexport interface BatchQueryConfig<TParam, TData> {\n params: TParam[];\n queryClient: QueryClient;\n /** Build individual cache key for a single param. */\n getItemKey: (param: TParam) => readonly unknown[];\n /** Build the string key for the result Record from a param. */\n getResultKey: (param: TParam) => string;\n /** Fetch only uncached items, return keyed Record. */\n fetchItems: (uncached: TParam[]) => Promise<Record<string, TData>>;\n /** Extract individual cache key from a fetched result entry (for seeding). */\n getSeedKey: (resultKey: string, data: TData) => readonly unknown[];\n}\n\n/**\n * Generic batch query executor.\n *\n * 1. Checks queryClient cache for each param\n * 2. Fetches only uncached items in a single batch call\n * 3. Seeds individual cache entries from the response\n * 4. Returns merged cached + fetched record\n */\nexport async function executeBatchQuery<TParam, TData>(\n config: BatchQueryConfig<TParam, TData>,\n): Promise<Record<string, TData>> {\n const { params, queryClient, getItemKey, getResultKey, fetchItems, getSeedKey } = config;\n\n if (params.length === 0) {\n return {};\n }\n\n const cached: Record<string, TData> = {};\n const uncached: TParam[] = [];\n\n for (const param of params) {\n const existing = queryClient.getQueryData<TData>(getItemKey(param));\n if (existing !== undefined) {\n cached[getResultKey(param)] = existing;\n } else {\n uncached.push(param);\n }\n }\n\n if (uncached.length === 0) {\n return cached;\n }\n\n const fetched = await fetchItems(uncached);\n\n for (const [key, data] of Object.entries(fetched)) {\n queryClient.setQueryData(getSeedKey(key, data as TData), data);\n }\n\n return { ...cached, ...fetched };\n}\n","import type { TPriceData } from \"@simpleapps-com/augur-utils\";\nimport type { AugurApiClient } from \"../provider\";\nimport type { CacheConfig } from \"../types\";\nimport { withCache } from \"./cache-helper\";\n\n/**\n * Generates a consistent query key for item price queries.\n * Used internally by useCartPricing and getCartPricingQueryOptions.\n */\nexport const getItemPriceKey = (\n itemId: string | undefined,\n customerId: string | number | undefined,\n quantity: number = 1,\n) => {\n return [\"price\", itemId?.toUpperCase() || \"\", customerId, quantity] as const;\n};\n\n/**\n * Query options for item price. Accepts the SDK instance so it works\n * in both client (via provider) and server (via direct construction).\n * Used internally by useCartPricing and getCartPricingQueryOptions.\n *\n * @deprecated Use createServerQueryProxy() from augur-server/hooks instead.\n */\nexport const getItemPriceOptions = (\n api: AugurApiClient,\n itemId: string | undefined,\n customerId: string | number | undefined,\n quantity: number = 1,\n cache?: CacheConfig,\n) => {\n const tier = cache?.semiStatic;\n return {\n queryKey: getItemPriceKey(itemId, customerId, quantity),\n queryFn: async (): Promise<TPriceData> => {\n const edgeCache = tier?.edgeCache;\n return withCache(\n cache?.provider,\n tier,\n \"pricing.priceEngine.get\",\n async () => {\n const response = await api.pricing.priceEngine.get({\n itemId: itemId?.toUpperCase() || \"\",\n customerId: Number(customerId),\n quantity,\n ...(edgeCache != null ? { edgeCache } : {}),\n });\n return response.data;\n },\n itemId,\n customerId,\n quantity,\n );\n },\n staleTime: tier?.staleTime,\n gcTime: tier?.gcTime,\n refetchOnReconnect: true,\n refetchOnWindowFocus: false,\n meta: { persist: true },\n };\n};\n\n/**\n * Get cart pricing query options for prefetching or parent components.\n *\n * @deprecated Use createServerQueryProxy() from augur-server/hooks instead.\n */\nexport function getCartPricingQueryOptions(\n api: AugurApiClient,\n cartLines: Array<{ itemId: string; quantity: number }>,\n customerId: string | number | undefined,\n cache?: CacheConfig,\n) {\n return cartLines.map((line) => ({\n ...getItemPriceOptions(api, line.itemId, customerId, line.quantity, cache),\n enabled: !!customerId && !!line.itemId,\n }));\n}\n"]}
@@ -128,8 +128,6 @@ export {
128
128
  getStockKey,
129
129
  getStockOptions,
130
130
  executeBatchQuery,
131
- getItemPriceKey,
132
- getItemPriceOptions,
133
131
  getCartPricingQueryOptions
134
132
  };
135
- //# sourceMappingURL=chunk-V2CAXA4X.js.map
133
+ //# sourceMappingURL=chunk-LDM4GLWN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/queries/cache-helper.ts","../src/queries/stock.ts","../src/queries/batch-query.ts","../src/queries/cart-pricing.ts"],"sourcesContent":["import type { CacheProvider, CacheTierConfig } from \"../types\";\nimport { stableStringify } from \"@simpleapps-com/augur-core\";\n\n/**\n * FNV-1a 32-bit hash. Fast, cross-platform (no Node crypto needed).\n */\nfunction fnv1a(str: string): string {\n let h = 0x811c9dc5;\n for (let i = 0; i < str.length; i++) {\n h ^= str.charCodeAt(i);\n h = Math.imul(h, 0x01000193);\n }\n return (h >>> 0).toString(16).padStart(8, \"0\");\n}\n\n/**\n * Wraps an async function with optional Redis caching.\n *\n * - When `provider` and `tier.redis` are both set, checks Redis before\n * calling `fn`, then caches the result on miss.\n * - When either is missing, calls `fn` directly (no-op passthrough).\n *\n * @param provider Redis-compatible get/set + prefix. Undefined = skip Redis.\n * @param tier Cache tier config. Undefined or missing `redis` = skip Redis.\n * @param methodPath Dot-separated SDK method path (used as cache key segment).\n * @param fn The async function to cache (typically the SDK call).\n * @param keyArgs Values to hash for the cache key (e.g. query params).\n */\nexport async function withCache<T>(\n provider: CacheProvider | undefined,\n tier: CacheTierConfig | undefined,\n methodPath: string,\n fn: () => Promise<T>,\n ...keyArgs: unknown[]\n): Promise<T> {\n const redisTtl = tier?.redis;\n if (!provider || !redisTtl) return fn();\n\n const key = `${provider.prefix}sdk:${methodPath}:${fnv1a(stableStringify(keyArgs))}`;\n\n try {\n const cached = await provider.get(key);\n if (cached != null) return JSON.parse(cached) as T;\n } catch {\n /* Redis read error — fall through to SDK call */\n }\n\n const result = await fn();\n\n try {\n provider.set(key, JSON.stringify(result), redisTtl).catch(() => {});\n } catch {\n /* Non-serializable or write error — skip caching */\n }\n\n return result;\n}\n","import type { TStock } from \"@simpleapps-com/augur-utils\";\nimport type { AugurApiClient } from \"../provider\";\nimport type { CacheConfig } from \"../types\";\nimport { withCache } from \"./cache-helper\";\n\nexport const getStockKey = (invMastUid: number | string) => {\n return [\"stock\", invMastUid] as const;\n};\n\n/** @deprecated Use createServerQueryProxy() from augur-server/hooks instead. */\nexport const getStockOptions = (\n api: AugurApiClient,\n invMastUid: number | string,\n cache?: CacheConfig,\n) => {\n const tier = cache?.semiStatic;\n return {\n queryKey: getStockKey(invMastUid),\n queryFn: async (): Promise<TStock> => {\n const edgeCache = tier?.edgeCache;\n return withCache(\n cache?.provider,\n tier,\n \"items.invMast.stock.get\",\n async () => {\n const response = await api.items.invMast.stock.get(Number(invMastUid), {\n ...(edgeCache != null ? { edgeCache } : {}),\n });\n const stockData = response.data?.stockData ?? [];\n const companySummary = response.data?.companySummary ?? {};\n return { stockData, companySummary } as TStock;\n },\n invMastUid,\n );\n },\n staleTime: tier?.staleTime,\n gcTime: tier?.gcTime,\n };\n};\n","import type { QueryClient } from \"@tanstack/react-query\";\n\nexport interface BatchQueryConfig<TParam, TData> {\n params: TParam[];\n queryClient: QueryClient;\n /** Build individual cache key for a single param. */\n getItemKey: (param: TParam) => readonly unknown[];\n /** Build the string key for the result Record from a param. */\n getResultKey: (param: TParam) => string;\n /** Fetch only uncached items, return keyed Record. */\n fetchItems: (uncached: TParam[]) => Promise<Record<string, TData>>;\n /** Extract individual cache key from a fetched result entry (for seeding). */\n getSeedKey: (resultKey: string, data: TData) => readonly unknown[];\n}\n\n/**\n * Generic batch query executor.\n *\n * 1. Checks queryClient cache for each param\n * 2. Fetches only uncached items in a single batch call\n * 3. Seeds individual cache entries from the response\n * 4. Returns merged cached + fetched record\n */\nexport async function executeBatchQuery<TParam, TData>(\n config: BatchQueryConfig<TParam, TData>,\n): Promise<Record<string, TData>> {\n const { params, queryClient, getItemKey, getResultKey, fetchItems, getSeedKey } = config;\n\n if (params.length === 0) {\n return {};\n }\n\n const cached: Record<string, TData> = {};\n const uncached: TParam[] = [];\n\n for (const param of params) {\n const existing = queryClient.getQueryData<TData>(getItemKey(param));\n if (existing !== undefined) {\n cached[getResultKey(param)] = existing;\n } else {\n uncached.push(param);\n }\n }\n\n if (uncached.length === 0) {\n return cached;\n }\n\n const fetched = await fetchItems(uncached);\n\n for (const [key, data] of Object.entries(fetched)) {\n queryClient.setQueryData(getSeedKey(key, data as TData), data);\n }\n\n return { ...cached, ...fetched };\n}\n","import type { TPriceData } from \"@simpleapps-com/augur-utils\";\nimport type { AugurApiClient } from \"../provider\";\nimport type { CacheConfig } from \"../types\";\nimport { withCache } from \"./cache-helper\";\n\n/**\n * Generates a consistent query key for item price queries.\n * Used internally by useCartPricing and getCartPricingQueryOptions.\n */\nexport const getItemPriceKey = (\n itemId: string | undefined,\n customerId: string | number | undefined,\n quantity: number = 1,\n) => {\n return [\"price\", itemId?.toUpperCase() || \"\", customerId, quantity] as const;\n};\n\n/**\n * Query options for item price. Accepts the SDK instance so it works\n * in both client (via provider) and server (via direct construction).\n * Used internally by useCartPricing and getCartPricingQueryOptions.\n *\n * @deprecated Use createServerQueryProxy() from augur-server/hooks instead.\n */\nexport const getItemPriceOptions = (\n api: AugurApiClient,\n itemId: string | undefined,\n customerId: string | number | undefined,\n quantity: number = 1,\n cache?: CacheConfig,\n) => {\n const tier = cache?.semiStatic;\n return {\n queryKey: getItemPriceKey(itemId, customerId, quantity),\n queryFn: async (): Promise<TPriceData> => {\n const edgeCache = tier?.edgeCache;\n return withCache(\n cache?.provider,\n tier,\n \"pricing.priceEngine.get\",\n async () => {\n const response = await api.pricing.priceEngine.get({\n itemId: itemId?.toUpperCase() || \"\",\n customerId: Number(customerId),\n quantity,\n ...(edgeCache != null ? { edgeCache } : {}),\n });\n return response.data;\n },\n itemId,\n customerId,\n quantity,\n );\n },\n staleTime: tier?.staleTime,\n gcTime: tier?.gcTime,\n refetchOnReconnect: true,\n refetchOnWindowFocus: false,\n meta: { persist: true },\n };\n};\n\n/**\n * Get cart pricing query options for prefetching or parent components.\n *\n * @deprecated Use createServerQueryProxy() from augur-server/hooks instead.\n */\nexport function getCartPricingQueryOptions(\n api: AugurApiClient,\n cartLines: Array<{ itemId: string; quantity: number }>,\n customerId: string | number | undefined,\n cache?: CacheConfig,\n) {\n return cartLines.map((line) => ({\n ...getItemPriceOptions(api, line.itemId, customerId, line.quantity, cache),\n enabled: !!customerId && !!line.itemId,\n }));\n}\n"],"mappings":";AACA,SAAS,uBAAuB;AAKhC,SAAS,MAAM,KAAqB;AAClC,MAAI,IAAI;AACR,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,SAAK,IAAI,WAAW,CAAC;AACrB,QAAI,KAAK,KAAK,GAAG,QAAU;AAAA,EAC7B;AACA,UAAQ,MAAM,GAAG,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAC/C;AAeA,eAAsB,UACpB,UACA,MACA,YACA,OACG,SACS;AACZ,QAAM,WAAW,MAAM;AACvB,MAAI,CAAC,YAAY,CAAC,SAAU,QAAO,GAAG;AAEtC,QAAM,MAAM,GAAG,SAAS,MAAM,OAAO,UAAU,IAAI,MAAM,gBAAgB,OAAO,CAAC,CAAC;AAElF,MAAI;AACF,UAAM,SAAS,MAAM,SAAS,I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,UAAU,IAAI,CAAC,UAAU;AAAA,IAC9B,GAAG,oBAAoB,KAAK,KAAK,QAAQ,YAAY,KAAK,UAAU,KAAK;AAAA,IACzE,SAAS,CAAC,CAAC,cAAc,CAAC,CAAC,KAAK;AAAA,EAClC,EAAE;AACJ;","names":[]}
package/dist/index.cjs CHANGED
@@ -3,13 +3,26 @@
3
3
 
4
4
 
5
5
 
6
-
7
-
8
- var _chunkUMCLTMAJcjs = require('./chunk-UMCLTMAJ.cjs');
6
+ var _chunkA3AWGAIZcjs = require('./chunk-A3AWGAIZ.cjs');
9
7
 
10
8
  // src/provider.tsx
11
9
  var _react = require('react');
10
+
11
+
12
+
13
+
12
14
  var _augurcore = require('@simpleapps-com/augur-core');
15
+
16
+ // src/query-action-registry.ts
17
+ var _queryAction = null;
18
+ function registerQueryAction(fn) {
19
+ _queryAction = fn;
20
+ }
21
+ function getRegisteredQueryAction() {
22
+ return _queryAction;
23
+ }
24
+
25
+ // src/provider.tsx
13
26
  var _jsxruntime = require('react/jsx-runtime');
14
27
  var AugurApiContext = _react.createContext.call(void 0, null);
15
28
  var AugurAuthReactContext = _react.createContext.call(void 0, void 0);
@@ -18,12 +31,12 @@ var AugurOptionsContext = _react.createContext.call(void 0, null);
18
31
  var AugurSiteContext = _react.createContext.call(void 0, void 0);
19
32
  function AugurHooksProvider({ api, auth, cache, site, children }) {
20
33
  const proxyConfig = cache ? { cache: { static: cache.static, semiStatic: cache.semiStatic } } : void 0;
21
- const options = _react.useMemo.call(void 0,
22
- // eslint-disable-next-line @typescript-eslint/no-deprecated -- backward compat for sites not yet using createServerQueryProxy
23
- () => api ? _augurcore.createOptionsProxy.call(void 0, api, proxyConfig) : _augurcore.createKeysOnlyProxy.call(void 0, proxyConfig),
24
- // eslint-disable-next-line react-hooks/exhaustive-deps
25
- [api]
26
- );
34
+ const options = _react.useMemo.call(void 0, () => {
35
+ if (api) return _augurcore.createOptionsProxy.call(void 0, api, proxyConfig);
36
+ const registeredAction = getRegisteredQueryAction();
37
+ if (registeredAction) return _augurcore.createQueryActionProxy.call(void 0, registeredAction, proxyConfig);
38
+ return _augurcore.createKeysOnlyProxy.call(void 0, proxyConfig);
39
+ }, [api]);
27
40
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AugurApiContext.Provider, { value: _nullishCoalesce(api, () => ( null)), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AugurAuthReactContext.Provider, { value: auth, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AugurCacheContext.Provider, { value: cache, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AugurSiteContext.Provider, { value: site, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AugurOptionsContext.Provider, { value: options, children }) }) }) }) });
28
41
  }
29
42
  function useAugurOptions() {
@@ -175,12 +188,11 @@ function useFormatPrice(optionsOrLocale, legacyCurrency) {
175
188
  var _reactquery = require('@tanstack/react-query');
176
189
  var _augurutils = require('@simpleapps-com/augur-utils');
177
190
  function useStock(invMastUid, options = {}) {
178
- const api = useAugurApiOptional();
179
- const cache = useAugurCache();
180
- const queryOpts = _chunkUMCLTMAJcjs.getStockOptions.call(void 0, api, invMastUid, cache);
191
+ const proxy = useAugurOptions();
181
192
  const resolvedQueryFn = options.queryFn;
193
+ const proxyOpts = proxy.items.invMast.stock.get(Number(invMastUid));
182
194
  const query = _reactquery.useQuery.call(void 0, {
183
- ...queryOpts,
195
+ ...proxyOpts,
184
196
  ...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
185
197
  enabled: (_nullishCoalesce(options.enabled, () => ( true))) && !!invMastUid,
186
198
  retry: 3,
@@ -188,24 +200,28 @@ function useStock(invMastUid, options = {}) {
188
200
  retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
189
201
  /* v8 ignore stop */
190
202
  });
203
+ const stockData = _react.useMemo.call(void 0, () => {
204
+ const rawData = query.data;
205
+ if (!rawData) return null;
206
+ const inner = _nullishCoalesce(rawData.data, () => ( rawData));
207
+ const stock = inner;
208
+ return {
209
+ stockData: _nullishCoalesce(stock.stockData, () => ( [])),
210
+ companySummary: _nullishCoalesce(stock.companySummary, () => ( {}))
211
+ };
212
+ }, [query.data]);
191
213
  const resolved = _react.useMemo.call(void 0,
192
214
  () => _augurutils.resolveStock.call(void 0, {
193
- stock: _nullishCoalesce(query.data, () => ( null)),
215
+ stock: stockData,
194
216
  companyKey: options.companyKey,
195
217
  round: options.round,
196
218
  lowStockThreshold: options.lowStockThreshold,
197
219
  showQuantity: options.showQuantity
198
220
  }),
199
- [
200
- query.data,
201
- options.companyKey,
202
- options.round,
203
- options.lowStockThreshold,
204
- options.showQuantity
205
- ]
221
+ [stockData, options.companyKey, options.round, options.lowStockThreshold, options.showQuantity]
206
222
  );
207
223
  return {
208
- stock: _nullishCoalesce(query.data, () => ( null)),
224
+ stock: stockData,
209
225
  resolved,
210
226
  loading: query.isLoading,
211
227
  error: query.error
@@ -664,25 +680,35 @@ function useCartInitialization(session, callbacks) {
664
680
 
665
681
 
666
682
  function useCartPricing(options = {}) {
667
- const api = useAugurApiOptional();
683
+ const proxy = useAugurOptions();
668
684
  const auth = useAugurAuth();
669
- const cache = useAugurCache();
670
685
  const site = useAugurSite();
671
686
  const cartLines = useCartLines();
672
687
  const customerId = _nullishCoalesce(_nullishCoalesce(options.customerId, () => ( _optionalChain([auth, 'optionalAccess', _64 => _64.customerId]))), () => ( _optionalChain([site, 'optionalAccess', _65 => _65.defaults, 'optionalAccess', _66 => _66.customerId])));
673
688
  const priceFn = options.queryFn;
674
689
  const priceQueries = _reactquery.useQueries.call(void 0, {
675
690
  queries: cartLines.map((line) => {
676
- const base = priceFn ? {
677
- queryKey: _chunkUMCLTMAJcjs.getItemPriceKey.call(void 0, line.itemId, customerId, line.quantity),
678
- queryFn: () => priceFn(line.itemId, customerId, line.quantity),
691
+ if (priceFn) {
692
+ return {
693
+ queryKey: ["price", _optionalChain([line, 'access', _67 => _67.itemId, 'optionalAccess', _68 => _68.toUpperCase, 'call', _69 => _69()]) || "", customerId, line.quantity],
694
+ queryFn: () => priceFn(line.itemId, customerId, line.quantity),
695
+ refetchOnReconnect: true,
696
+ refetchOnWindowFocus: false,
697
+ meta: { persist: true },
698
+ enabled: !!customerId && !!line.itemId
699
+ };
700
+ }
701
+ const proxyOpts = proxy.pricing.priceEngine.get({
702
+ itemId: _optionalChain([line, 'access', _70 => _70.itemId, 'optionalAccess', _71 => _71.toUpperCase, 'call', _72 => _72()]) || "",
703
+ customerId: Number(customerId),
704
+ quantity: line.quantity
705
+ });
706
+ return {
707
+ ...proxyOpts,
708
+ enabled: !!customerId && !!line.itemId,
679
709
  refetchOnReconnect: true,
680
710
  refetchOnWindowFocus: false,
681
711
  meta: { persist: true }
682
- } : _chunkUMCLTMAJcjs.getItemPriceOptions.call(void 0, api, line.itemId, customerId, line.quantity, cache);
683
- return {
684
- ...base,
685
- enabled: !!customerId && !!line.itemId
686
712
  };
687
713
  })
688
714
  });
@@ -690,11 +716,16 @@ function useCartPricing(options = {}) {
690
716
  const map = {};
691
717
  cartLines.forEach((line, index) => {
692
718
  const queryResult = priceQueries[index];
693
- if (_optionalChain([queryResult, 'optionalAccess', _67 => _67.data])) {
694
- const derived = _augurutils.derivePrice.call(void 0, { priceData: queryResult.data, quantity: line.quantity });
719
+ const rawData = _optionalChain([queryResult, 'optionalAccess', _73 => _73.data]);
720
+ if (rawData) {
721
+ const priceData = _nullishCoalesce(rawData.data, () => ( rawData));
722
+ const derived = _augurutils.derivePrice.call(void 0, {
723
+ priceData,
724
+ quantity: line.quantity
725
+ });
695
726
  map[line.itemId.toUpperCase()] = {
696
727
  unitPrice: derived.unitPrice,
697
- priceData: queryResult.data
728
+ priceData
698
729
  };
699
730
  }
700
731
  });
@@ -702,7 +733,7 @@ function useCartPricing(options = {}) {
702
733
  }, [cartLines, priceQueries]);
703
734
  const getUnitPrice = _react.useMemo.call(void 0, () => {
704
735
  return (itemId) => {
705
- return _nullishCoalesce(_optionalChain([prices, 'access', _68 => _68[_optionalChain([itemId, 'optionalAccess', _69 => _69.toUpperCase, 'call', _70 => _70()])], 'optionalAccess', _71 => _71.unitPrice]), () => ( 0));
736
+ return _nullishCoalesce(_optionalChain([prices, 'access', _74 => _74[_optionalChain([itemId, 'optionalAccess', _75 => _75.toUpperCase, 'call', _76 => _76()])], 'optionalAccess', _77 => _77.unitPrice]), () => ( 0));
706
737
  };
707
738
  }, [prices]);
708
739
  const getItemTotal = _react.useMemo.call(void 0, () => {
@@ -712,7 +743,7 @@ function useCartPricing(options = {}) {
712
743
  }, [getUnitPrice]);
713
744
  const subtotal = _react.useMemo.call(void 0, () => {
714
745
  return cartLines.reduce((sum, line) => {
715
- const unitPrice = _nullishCoalesce(_optionalChain([prices, 'access', _72 => _72[line.itemId.toUpperCase()], 'optionalAccess', _73 => _73.unitPrice]), () => ( 0));
746
+ const unitPrice = _nullishCoalesce(_optionalChain([prices, 'access', _78 => _78[line.itemId.toUpperCase()], 'optionalAccess', _79 => _79.unitPrice]), () => ( 0));
716
747
  return sum + unitPrice * line.quantity;
717
748
  }, 0);
718
749
  }, [cartLines, prices]);
@@ -789,7 +820,7 @@ function deserialize(data) {
789
820
 
790
821
  // src/persistence/apply-limits.ts
791
822
  function applyLimits(data, limits) {
792
- const queries = _optionalChain([data, 'access', _74 => _74.clientState, 'optionalAccess', _75 => _75.queries]);
823
+ const queries = _optionalChain([data, 'access', _80 => _80.clientState, 'optionalAccess', _81 => _81.queries]);
793
824
  if (!queries || Object.keys(limits).length === 0) return data;
794
825
  const entries = queries;
795
826
  const unlimited = [];
@@ -890,7 +921,7 @@ function useStorageMonitor(config) {
890
921
  const raw = storage.getItem(key);
891
922
  if (!raw) return;
892
923
  const parsed = JSON.parse(raw);
893
- if (!_optionalChain([parsed, 'access', _76 => _76.clientState, 'optionalAccess', _77 => _77.queries])) return;
924
+ if (!_optionalChain([parsed, 'access', _82 => _82.clientState, 'optionalAccess', _83 => _83.queries])) return;
894
925
  parsed.clientState.queries = parsed.clientState.queries.filter(
895
926
  (q) => {
896
927
  if (!Array.isArray(q.queryKey)) return true;
@@ -917,7 +948,7 @@ function useAugurPersistence(config) {
917
948
  setIsMounted(true);
918
949
  }, []);
919
950
  useStorageMonitor(config);
920
- const isDev = typeof process !== "undefined" && _optionalChain([process, 'access', _78 => _78.env, 'optionalAccess', _79 => _79["NODE_ENV"]]) === "development";
951
+ const isDev = typeof process !== "undefined" && _optionalChain([process, 'access', _84 => _84.env, 'optionalAccess', _85 => _85["NODE_ENV"]]) === "development";
921
952
  const { persistableKeys } = config;
922
953
  const dehydrateOptions = _react.useMemo.call(void 0,
923
954
  () => ({
@@ -967,5 +998,7 @@ function useAugurPersistence(config) {
967
998
 
968
999
 
969
1000
 
970
- exports.AugurHooksProvider = AugurHooksProvider; exports.executeBatchQuery = _chunkUMCLTMAJcjs.executeBatchQuery; exports.getCartPricingQueryOptions = _chunkUMCLTMAJcjs.getCartPricingQueryOptions; exports.getStockKey = _chunkUMCLTMAJcjs.getStockKey; exports.getStockOptions = _chunkUMCLTMAJcjs.getStockOptions; exports.useAugurApi = useAugurApi; exports.useAugurApiOptional = useAugurApiOptional; exports.useAugurAuth = useAugurAuth; exports.useAugurCache = useAugurCache; exports.useAugurOptions = useAugurOptions; exports.useAugurPersistence = useAugurPersistence; exports.useAugurSite = useAugurSite; exports.useCartActions = useCartActions; exports.useCartHdrUid = useCartHdrUid; exports.useCartInitialization = useCartInitialization; exports.useCartLineCount = useCartLineCount; exports.useCartLines = useCartLines; exports.useCartPricing = useCartPricing; exports.useCartQuantityTotal = useCartQuantityTotal; exports.useCartStore = useCartStore; exports.useClearCart = useClearCart; exports.useDebounce = useDebounce; exports.useFormatPrice = useFormatPrice; exports.useItemFiltersStore = useItemFiltersStore; exports.usePaginationPrefetch = usePaginationPrefetch; exports.usePaymentFlow = usePaymentFlow; exports.useSetCartHdrUid = useSetCartHdrUid; exports.useSetCartLines = useSetCartLines; exports.useStock = useStock;
1001
+
1002
+
1003
+ exports.AugurHooksProvider = AugurHooksProvider; exports.executeBatchQuery = _chunkA3AWGAIZcjs.executeBatchQuery; exports.getCartPricingQueryOptions = _chunkA3AWGAIZcjs.getCartPricingQueryOptions; exports.getRegisteredQueryAction = getRegisteredQueryAction; exports.getStockKey = _chunkA3AWGAIZcjs.getStockKey; exports.getStockOptions = _chunkA3AWGAIZcjs.getStockOptions; exports.registerQueryAction = registerQueryAction; exports.useAugurApi = useAugurApi; exports.useAugurApiOptional = useAugurApiOptional; exports.useAugurAuth = useAugurAuth; exports.useAugurCache = useAugurCache; exports.useAugurOptions = useAugurOptions; exports.useAugurPersistence = useAugurPersistence; exports.useAugurSite = useAugurSite; exports.useCartActions = useCartActions; exports.useCartHdrUid = useCartHdrUid; exports.useCartInitialization = useCartInitialization; exports.useCartLineCount = useCartLineCount; exports.useCartLines = useCartLines; exports.useCartPricing = useCartPricing; exports.useCartQuantityTotal = useCartQuantityTotal; exports.useCartStore = useCartStore; exports.useClearCart = useClearCart; exports.useDebounce = useDebounce; exports.useFormatPrice = useFormatPrice; exports.useItemFiltersStore = useItemFiltersStore; exports.usePaginationPrefetch = usePaginationPrefetch; exports.usePaymentFlow = usePaymentFlow; exports.useSetCartHdrUid = useSetCartHdrUid; exports.useSetCartLines = useSetCartLines; exports.useStock = useStock;
971
1004
  //# sourceMappingURL=index.cjs.map