@simpleapps-com/augur-hooks 1.0.5 → 1.0.7

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.cjs CHANGED
@@ -199,7 +199,9 @@ function useFormatPrice(locale = "en-US", currency = "USD") {
199
199
  }
200
200
 
201
201
  // src/hooks/use-item-price.ts
202
+
202
203
  var _reactquery = require('@tanstack/react-query');
204
+ var _augurutils = require('@simpleapps-com/augur-utils');
203
205
  function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
204
206
  const api = useAugurApiOptional();
205
207
  const callbacks = useAugurCallbacks();
@@ -208,12 +210,17 @@ function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
208
210
  const effectiveCustomerId = _nullishCoalesce(customerId, () => ( _optionalChain([auth, 'optionalAccess', _ => _.customerId])));
209
211
  const defaultOptions = _chunkC7JC34SMcjs.getItemPriceOptions.call(void 0, api, itemId, effectiveCustomerId, quantity, cache);
210
212
  const resolvedQueryFn = _nullishCoalesce(options.queryFn, () => ( (_optionalChain([callbacks, 'optionalAccess', _2 => _2.getItemPrice]) ? () => callbacks.getItemPrice(itemId, effectiveCustomerId, quantity) : void 0)));
211
- return _reactquery.useQuery.call(void 0, {
213
+ const query = _reactquery.useQuery.call(void 0, {
212
214
  ...defaultOptions,
213
215
  ...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
214
216
  enabled: _nullishCoalesce(options.enabled, () => ( (Boolean(itemId) && Boolean(effectiveCustomerId)))),
215
217
  retry: 3
216
218
  });
219
+ const derived = _react.useMemo.call(void 0,
220
+ () => _augurutils.derivePrice.call(void 0, { priceData: query.data, quantity }),
221
+ [query.data, quantity]
222
+ );
223
+ return { ...query, derived };
217
224
  }
218
225
 
219
226
  // src/hooks/use-inv-mast-doc.ts
@@ -754,6 +761,7 @@ function useCartInitialization(session, callbacks) {
754
761
  // src/hooks/use-cart-pricing.ts
755
762
 
756
763
 
764
+
757
765
  function useCartPricing(options = {}) {
758
766
  const api = useAugurApiOptional();
759
767
  const callbacks = useAugurCallbacks();
@@ -782,8 +790,9 @@ function useCartPricing(options = {}) {
782
790
  cartLines.forEach((line, index) => {
783
791
  const queryResult = priceQueries[index];
784
792
  if (_optionalChain([queryResult, 'optionalAccess', _45 => _45.data])) {
793
+ const derived = _augurutils.derivePrice.call(void 0, { priceData: queryResult.data, quantity: line.quantity });
785
794
  map[line.itemId.toUpperCase()] = {
786
- unitPrice: _nullishCoalesce(queryResult.data.unitPrice, () => ( 0)),
795
+ unitPrice: derived.unitPrice,
787
796
  priceData: queryResult.data
788
797
  };
789
798
  }