@simpleapps-com/augur-hooks 2.2.16 → 2.2.18

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,38 @@
1
+ // src/stores/cart-store.ts
2
+ import { create } from "zustand";
3
+ import { devtools } from "zustand/middleware";
4
+ var useCartStore = create()(
5
+ devtools(
6
+ (set) => ({
7
+ cartHdrUid: void 0,
8
+ cartLines: [],
9
+ cartQuantityTotal: 0,
10
+ cartLineCount: 0,
11
+ setCartHdrUid: (cartHdrUid) => set({ cartHdrUid }, false, "setCartHdrUid"),
12
+ setCartLines: (cartLines) => {
13
+ const cartQuantityTotal = cartLines.reduce((sum, line) => sum + (line.quantity || 0), 0);
14
+ const cartLineCount = cartLines.length;
15
+ set({ cartLines, cartQuantityTotal, cartLineCount }, false, "setCartLines");
16
+ },
17
+ clearCart: () => set(
18
+ { cartHdrUid: void 0, cartLines: [], cartQuantityTotal: 0, cartLineCount: 0 },
19
+ false,
20
+ "clearCart"
21
+ )
22
+ }),
23
+ { name: "CartStore", enabled: process.env["NODE_ENV"] === "development" }
24
+ )
25
+ );
26
+ var useCartHdrUid = () => useCartStore((s) => s.cartHdrUid);
27
+ var useCartLines = () => useCartStore((s) => s.cartLines);
28
+ var useCartQuantityTotal = () => useCartStore((s) => s.cartQuantityTotal);
29
+ var useCartLineCount = () => useCartStore((s) => s.cartLineCount);
30
+ var useSetCartHdrUid = () => useCartStore((s) => s.setCartHdrUid);
31
+ var useSetCartLines = () => useCartStore((s) => s.setCartLines);
32
+ var useClearCart = () => useCartStore((s) => s.clearCart);
33
+
1
34
  // src/hooks/use-payment-flow.ts
2
- import { useCallback, useEffect, useState } from "react";
35
+ import { useCallback, useEffect, useRef, useState } from "react";
3
36
  function usePaymentFlow({
4
37
  callbacks,
5
38
  customerId,
@@ -18,10 +51,14 @@ function usePaymentFlow({
18
51
  const handleBinCapture = useCallback((bin) => {
19
52
  setCapturedBin(bin);
20
53
  }, []);
54
+ const customerIdRef = useRef(customerId);
55
+ customerIdRef.current = customerId;
21
56
  const postUnified = useCallback(async () => {
22
- if (!customerId) return;
57
+ if (!customerIdRef.current) return;
23
58
  try {
24
- const result = await callbacks.transactionSetup({ customerId: String(customerId) });
59
+ const result = await callbacks.transactionSetup({
60
+ customerId: String(customerIdRef.current)
61
+ });
25
62
  if (!result) {
26
63
  callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
27
64
  return;
@@ -31,7 +68,7 @@ function usePaymentFlow({
31
68
  console.error("transactionSetup failed:", error);
32
69
  callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
33
70
  }
34
- }, [customerId, callbacks]);
71
+ }, [callbacks]);
35
72
  const getCardInfo = useCallback(async () => {
36
73
  if (!unified?.transactionSetupId) return;
37
74
  try {
@@ -47,11 +84,11 @@ function usePaymentFlow({
47
84
  }
48
85
  }, [unified, callbacks]);
49
86
  const verifyUnified = useCallback(async () => {
50
- if (!unified?.transactionSetupId || !customerId) return;
87
+ if (!unified?.transactionSetupId || !customerIdRef.current) return;
51
88
  try {
52
89
  const result = await callbacks.validatePayment({
53
90
  transactionSetupId: unified.transactionSetupId,
54
- customerId: String(customerId)
91
+ customerId: String(customerIdRef.current)
55
92
  });
56
93
  if (!result) {
57
94
  callbacks.toast?.error?.("Payment verification failed. Please try again.");
@@ -65,13 +102,13 @@ function usePaymentFlow({
65
102
  console.error("validatePayment failed:", error);
66
103
  callbacks.toast?.error?.("Payment verification failed. Please try again.");
67
104
  }
68
- }, [unified, customerId, getCardInfo, callbacks]);
105
+ }, [unified, getCardInfo, callbacks]);
69
106
  const getUnifiedPayment = useCallback(async () => {
70
- if (!unified?.transactionSetupId || !customerId) return;
107
+ if (!unified?.transactionSetupId || !customerIdRef.current) return;
71
108
  try {
72
109
  const result = await callbacks.accountQuery({
73
110
  transactionSetupId: unified.transactionSetupId,
74
- customerId: String(customerId)
111
+ customerId: String(customerIdRef.current)
75
112
  });
76
113
  if (!result) {
77
114
  callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
@@ -83,7 +120,7 @@ function usePaymentFlow({
83
120
  console.error("accountQuery failed:", error);
84
121
  callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
85
122
  }
86
- }, [unified, customerId, capturedBin, callbacks]);
123
+ }, [unified, capturedBin, callbacks]);
87
124
  const updateUnifiedBilling = useCallback(async () => {
88
125
  if (!unified?.transactionSetupId || !billingAddress) return;
89
126
  try {
@@ -218,8 +255,16 @@ function useOrderReadiness(params) {
218
255
  }
219
256
 
220
257
  export {
258
+ useCartStore,
259
+ useCartHdrUid,
260
+ useCartLines,
261
+ useCartQuantityTotal,
262
+ useCartLineCount,
263
+ useSetCartHdrUid,
264
+ useSetCartLines,
265
+ useClearCart,
221
266
  usePaymentFlow,
222
267
  determineOrderReadiness,
223
268
  useOrderReadiness
224
269
  };
225
- //# sourceMappingURL=chunk-AJ2TD5BG.js.map
270
+ //# sourceMappingURL=chunk-ONB6O35U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/stores/cart-store.ts","../src/hooks/use-payment-flow.ts","../src/hooks/use-order-readiness.ts"],"sourcesContent":["import { create } from \"zustand\";\nimport { devtools } from \"zustand/middleware\";\nimport type { TCartLine } from \"@simpleapps-com/augur-utils\";\n\n/** Internal state shape for the cart Zustand store. */\ninterface CartState {\n /** P21 cart header UID; `undefined` when no cart exists. */\n cartHdrUid: number | string | undefined;\n /** Current line items in the cart. */\n cartLines: TCartLine[];\n /** Sum of `quantity` across all cart lines (auto-computed by `setCartLines`). */\n cartQuantityTotal: number;\n /** Number of distinct line items (auto-computed by `setCartLines`). */\n cartLineCount: number;\n setCartHdrUid: (cartHdrUid: number | string | undefined) => void;\n /** Replace all cart lines. Auto-recomputes `cartQuantityTotal` and `cartLineCount`. */\n setCartLines: (cartLines: TCartLine[]) => void;\n /** Reset the cart to its empty initial state. */\n clearCart: () => void;\n}\n\n/** Zustand store for cart state. Prefer the individual selector hooks below for optimal re-renders. */\nexport const useCartStore = create<CartState>()(\n devtools(\n (set) => ({\n cartHdrUid: undefined,\n cartLines: [],\n cartQuantityTotal: 0,\n cartLineCount: 0,\n\n setCartHdrUid: (cartHdrUid) => set({ cartHdrUid }, false, \"setCartHdrUid\"),\n\n setCartLines: (cartLines) => {\n const cartQuantityTotal = cartLines.reduce((sum, line) => sum + (line.quantity || 0), 0);\n const cartLineCount = cartLines.length;\n set({ cartLines, cartQuantityTotal, cartLineCount }, false, \"setCartLines\");\n },\n\n clearCart: () =>\n set(\n { cartHdrUid: undefined, cartLines: [], cartQuantityTotal: 0, cartLineCount: 0 },\n false,\n \"clearCart\",\n ),\n }),\n { name: \"CartStore\", enabled: process.env[\"NODE_ENV\"] === \"development\" },\n ),\n);\n\n// Selector hooks -- only re-render when specific state changes\n\n/** Select the current cart header UID. */\nexport const useCartHdrUid = () => useCartStore((s) => s.cartHdrUid);\n/** Select the current cart line items array. */\nexport const useCartLines = () => useCartStore((s) => s.cartLines);\n/** Select the total quantity summed across all cart lines. */\nexport const useCartQuantityTotal = () => useCartStore((s) => s.cartQuantityTotal);\n/** Select the number of distinct line items in the cart. */\nexport const useCartLineCount = () => useCartStore((s) => s.cartLineCount);\n/** Get the `setCartHdrUid` action (stable reference). */\nexport const useSetCartHdrUid = () => useCartStore((s) => s.setCartHdrUid);\n/** Get the `setCartLines` action (stable reference). Also recomputes totals. */\nexport const useSetCartLines = () => useCartStore((s) => s.setCartLines);\n/** Get the `clearCart` action (stable reference). */\nexport const useClearCart = () => useCartStore((s) => s.clearCart);\n","import { useCallback, useEffect, useRef, useState } from \"react\";\nimport type {\n TTransactionSetup,\n TCardInfo,\n TPaymentValidation,\n TAccountQuery,\n TBillingUpdate,\n} from \"@simpleapps-com/augur-utils\";\n\n/** Site-specific payment action callbacks injected into usePaymentFlow. */\nexport interface PaymentFlowCallbacks {\n /** Initialize a payment session. Returns transaction setup or undefined on failure. */\n transactionSetup: (params: { customerId: string }) => Promise<TTransactionSetup | undefined>;\n /** Retrieve card details after iframe entry. */\n cardInfo: (params: { transactionSetupId: string }) => Promise<TCardInfo | undefined>;\n /** Verify card is valid. */\n validatePayment: (params: {\n transactionSetupId: string;\n customerId: string;\n }) => Promise<TPaymentValidation | undefined>;\n /** Get payment account ID. */\n accountQuery: (params: {\n transactionSetupId: string;\n customerId: string;\n }) => Promise<TAccountQuery | undefined>;\n /** Send billing address to payment processor. */\n billingUpdate: (params: {\n transactionSetupId: string;\n address1: string;\n address2?: string;\n city: string;\n state: string;\n zip: string;\n }) => Promise<TBillingUpdate | undefined>;\n /** Optional toast notification callback. */\n toast?: {\n error?: (message: string) => void;\n };\n}\n\n/** Billing address shape accepted by the payment flow. */\nexport interface PaymentBillingAddress {\n address1: string;\n address2?: string;\n city: string;\n state: string;\n postalCode: string;\n}\n\ninterface UsePaymentFlowParams {\n callbacks: PaymentFlowCallbacks;\n customerId: string | number | undefined;\n billingAddress: PaymentBillingAddress | undefined;\n paymentMethod: string;\n shippingAccepted: boolean;\n}\n\n/**\n * Manages the full Element/Unified payment lifecycle:\n * transactionSetup -> cardInfo -> validatePayment -> accountQuery -> billingUpdate\n *\n * Accepts site-specific server action callbacks so the hook has no dependency\n * on any particular server action implementation.\n *\n * @example\n * ```tsx\n * import { usePaymentFlow } from \"@simpleapps-com/augur-hooks\";\n * import { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } from \"@/lib/actions/payments\";\n *\n * const payment = usePaymentFlow({\n * callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate },\n * customerId,\n * billingAddress,\n * paymentMethod: \"credit-card\",\n * shippingAccepted: true,\n * });\n * ```\n */\nexport function usePaymentFlow({\n callbacks,\n customerId,\n billingAddress,\n paymentMethod,\n shippingAccepted,\n}: UsePaymentFlowParams) {\n const [isOpen, setIsOpen] = useState(false);\n const [unified, setUnified] = useState<TTransactionSetup | null>(null);\n const [unifiedCc, setUnifiedCc] = useState<TCardInfo | null>(null);\n const [unifiedResponse, setUnifiedResponse] = useState(false);\n const [unifiedBilling, setUnifiedBilling] = useState(false);\n const [unifiedPayment, setUnifiedPayment] = useState<TAccountQuery | null>(null);\n const [capturedBin, setCapturedBin] = useState<string | null>(null);\n const [editCc, setEditCc] = useState(false);\n\n const handleBinCapture = useCallback((bin: string) => {\n setCapturedBin(bin);\n }, []);\n\n // Ref ensures callbacks always read the latest customerId, avoiding stale\n // closures when React batches state updates (e.g., modal close + verify).\n const customerIdRef = useRef(customerId);\n customerIdRef.current = customerId;\n\n // Step 1: Initialize payment session\n const postUnified = useCallback(async () => {\n if (!customerIdRef.current) return;\n try {\n const result = await callbacks.transactionSetup({\n customerId: String(customerIdRef.current),\n });\n if (!result) {\n callbacks.toast?.error?.(\"Unable to initialize payment. Please try again.\");\n return;\n }\n setUnified(result);\n } catch (error) {\n console.error(\"transactionSetup failed:\", error);\n callbacks.toast?.error?.(\"Unable to initialize payment. Please try again.\");\n }\n }, [callbacks]);\n\n // Step 2: Get card info after iframe entry\n const getCardInfo = useCallback(async () => {\n /* v8 ignore next -- defensive: caller (verifyUnified) already guards */\n if (!unified?.transactionSetupId) return;\n try {\n const result = await callbacks.cardInfo({ transactionSetupId: unified.transactionSetupId });\n if (!result) {\n callbacks.toast?.error?.(\"Unable to verify card details. Please try again.\");\n return;\n }\n setUnifiedCc(result);\n } catch (error) {\n console.error(\"cardInfo failed:\", error);\n callbacks.toast?.error?.(\"Unable to verify card details. Please try again.\");\n }\n }, [unified, callbacks]);\n\n // Step 3: Validate payment\n const verifyUnified = useCallback(async () => {\n if (!unified?.transactionSetupId || !customerIdRef.current) return;\n try {\n const result = await callbacks.validatePayment({\n transactionSetupId: unified.transactionSetupId,\n customerId: String(customerIdRef.current),\n });\n if (!result) {\n callbacks.toast?.error?.(\"Payment verification failed. Please try again.\");\n return;\n }\n setUnifiedResponse(result.valid);\n if (result.valid) {\n await getCardInfo();\n }\n } catch (error) {\n console.error(\"validatePayment failed:\", error);\n callbacks.toast?.error?.(\"Payment verification failed. Please try again.\");\n }\n }, [unified, getCardInfo, callbacks]);\n\n // Step 4: Get payment account info\n const getUnifiedPayment = useCallback(async () => {\n if (!unified?.transactionSetupId || !customerIdRef.current) return;\n try {\n const result = await callbacks.accountQuery({\n transactionSetupId: unified.transactionSetupId,\n customerId: String(customerIdRef.current),\n });\n if (!result) {\n callbacks.toast?.error?.(\"Unable to retrieve payment account. Please try again.\");\n return;\n }\n const payment = capturedBin && !result.Bin ? { ...result, Bin: capturedBin } : result;\n setUnifiedPayment(payment);\n } catch (error) {\n console.error(\"accountQuery failed:\", error);\n callbacks.toast?.error?.(\"Unable to retrieve payment account. Please try again.\");\n }\n }, [unified, capturedBin, callbacks]);\n\n // Step 5: Update billing info\n const updateUnifiedBilling = useCallback(async () => {\n /* v8 ignore next -- defensive: effect already guards billingAddress/unified */\n if (!unified?.transactionSetupId || !billingAddress) return;\n try {\n const result = await callbacks.billingUpdate({\n transactionSetupId: unified.transactionSetupId,\n address1: billingAddress.address1,\n address2: billingAddress.address2,\n city: billingAddress.city,\n state: billingAddress.state,\n zip: billingAddress.postalCode,\n });\n if (!result) {\n callbacks.toast?.error?.(\"Billing update failed. Please try again.\");\n return;\n }\n setUnifiedBilling(true);\n void getUnifiedPayment();\n } catch (error) {\n console.error(\"billingUpdate failed:\", error);\n callbacks.toast?.error?.(\"Billing update failed. Please try again.\");\n }\n }, [unified, billingAddress, getUnifiedPayment, callbacks]);\n\n // Close payment modal if preconditions are lost\n useEffect(() => {\n if (isOpen && (!shippingAccepted || paymentMethod !== \"credit-card\")) {\n setIsOpen(false);\n }\n }, [isOpen, shippingAccepted, paymentMethod]);\n\n // Initialize payment setup when modal opens with no transaction\n useEffect(() => {\n if (isOpen && shippingAccepted && paymentMethod === \"credit-card\" && unified === null) {\n void postUnified();\n }\n }, [isOpen, shippingAccepted, paymentMethod, unified, postUnified]);\n\n // Verify payment after modal closes\n useEffect(() => {\n if (!isOpen && unified !== null && shippingAccepted && paymentMethod === \"credit-card\") {\n void verifyUnified();\n }\n }, [isOpen, unified, shippingAccepted, paymentMethod, verifyUnified]);\n\n // Trigger billing update when card verified + billing address ready\n useEffect(() => {\n if (\n unifiedResponse &&\n billingAddress !== undefined &&\n unifiedCc?.transactionSetupId &&\n paymentMethod === \"credit-card\"\n ) {\n void updateUnifiedBilling();\n }\n }, [\n unifiedResponse,\n billingAddress,\n unifiedCc?.transactionSetupId,\n updateUnifiedBilling,\n paymentMethod,\n ]);\n\n // Reset all payment state when editing CC\n useEffect(() => {\n if (editCc) {\n setIsOpen(true);\n setUnified(null);\n setUnifiedCc(null);\n setUnifiedPayment(null);\n setUnifiedBilling(false);\n setUnifiedResponse(false);\n setCapturedBin(null);\n }\n }, [editCc]);\n\n return {\n isOpen,\n setIsOpen,\n editCc,\n setEditCc,\n unified,\n unifiedCc,\n unifiedResponse,\n unifiedBilling,\n unifiedPayment,\n capturedBin,\n handleBinCapture,\n };\n}\n","\"use client\";\n\nimport { useEffect, useState } from \"react\";\n\n/** Parameters for order readiness validation. */\nexport interface OrderReadinessParams {\n cartHdrUid: string | number | undefined;\n shippingAddress: unknown;\n billingAddress: unknown;\n shippingMethodSaved: boolean;\n showBillingInfoSummary: boolean;\n processingOrder: boolean;\n paymentMethod: string;\n unifiedPaymentAccountId: string | undefined;\n unifiedBilling: boolean;\n isFreeShipping: boolean;\n carrierId: string;\n shippingFee: number | undefined;\n isEditShippingInfo: boolean;\n isEditShippingMethods: boolean;\n isEditBillingInfo: boolean;\n editCc: boolean;\n /** Site-provided function to check if the order is ready. Overrides default logic when provided. */\n customReadinessCheck?: (params: OrderReadinessParams) => boolean;\n}\n\n/**\n * Pure function that determines if an order is ready to submit.\n *\n * Checks all gates: cart exists, addresses present, shipping method saved,\n * billing shown, payment complete (for credit card), shipping fee present\n * (for non-free, non-pickup orders), and no sections being edited.\n */\nexport function determineOrderReadiness(params: OrderReadinessParams): boolean {\n if (params.customReadinessCheck) {\n return params.customReadinessCheck(params);\n }\n\n if (!params.cartHdrUid) return false;\n\n // Block if any section is being edited or addresses are missing\n const blockers = [\n params.isEditShippingInfo,\n params.isEditShippingMethods,\n params.isEditBillingInfo,\n params.editCc,\n params.shippingAddress === undefined,\n params.billingAddress === undefined,\n !params.shippingMethodSaved,\n !params.showBillingInfoSummary,\n params.processingOrder,\n ];\n if (blockers.some(Boolean)) return false;\n\n // Credit card requires completed payment flow\n if (\n params.paymentMethod === \"credit-card\" &&\n (!params.unifiedPaymentAccountId || !params.unifiedBilling)\n ) {\n return false;\n }\n\n // Non-free shipping requires a fee (unless carrier is pickup/freight)\n if (!params.isFreeShipping && params.shippingFee === undefined) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Debounced order readiness hook.\n *\n * Recomputes readiness 300ms after any dependency changes to avoid\n * excessive re-renders during rapid state transitions (e.g., typing\n * in address fields).\n */\nexport function useOrderReadiness(params: OrderReadinessParams) {\n const [enableProcessOrderBtn, setEnableProcessOrderBtn] = useState(false);\n const [processingValidation, setProcessingValidation] = useState(false);\n\n useEffect(() => {\n setProcessingValidation(true);\n\n const timeoutId = setTimeout(() => {\n const ready = determineOrderReadiness(params);\n setEnableProcessOrderBtn(ready);\n setProcessingValidation(false);\n }, 300);\n\n return () => clearTimeout(timeoutId);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n params.billingAddress,\n params.shippingAddress,\n params.isEditShippingInfo,\n params.isEditShippingMethods,\n params.isEditBillingInfo,\n params.editCc,\n params.isFreeShipping,\n params.unifiedPaymentAccountId,\n params.unifiedBilling,\n params.paymentMethod,\n params.processingOrder,\n params.carrierId,\n params.shippingFee,\n params.shippingMethodSaved,\n params.showBillingInfoSummary,\n params.cartHdrUid,\n ]);\n\n return { enableProcessOrderBtn, processingValidation };\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB;AAqBlB,IAAM,eAAe,OAAkB;AAAA,EAC5C;AAAA,IACE,CAAC,SAAS;AAAA,MACR,YAAY;AAAA,MACZ,WAAW,CAAC;AAAA,MACZ,mBAAmB;AAAA,MACnB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AAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,EACT,CAAC;AAED,SAAO,EAAE,uBAAuB,qBAAqB;AACvD;","names":["useEffect","useState"]}
package/dist/index.cjs CHANGED
@@ -10,7 +10,15 @@ var _chunkXJJ6DZDKcjs = require('./chunk-XJJ6DZDK.cjs');
10
10
 
11
11
 
12
12
 
13
- var _chunkSSOW6W53cjs = require('./chunk-SSOW6W53.cjs');
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+ var _chunkEOHLFKJNcjs = require('./chunk-EOHLFKJN.cjs');
14
22
 
15
23
  // src/provider.tsx
16
24
  var _react = require('react');
@@ -66,42 +74,9 @@ function useAugurSite() {
66
74
  return _react.useContext.call(void 0, AugurSiteContext);
67
75
  }
68
76
 
69
- // src/stores/cart-store.ts
77
+ // src/stores/items-filters-store.ts
70
78
  var _zustand = require('zustand');
71
79
  var _middleware = require('zustand/middleware');
72
- var useCartStore = _zustand.create.call(void 0, )(
73
- _middleware.devtools.call(void 0,
74
- (set) => ({
75
- cartHdrUid: void 0,
76
- cartLines: [],
77
- cartQuantityTotal: 0,
78
- cartLineCount: 0,
79
- setCartHdrUid: (cartHdrUid) => set({ cartHdrUid }, false, "setCartHdrUid"),
80
- setCartLines: (cartLines) => {
81
- const cartQuantityTotal = cartLines.reduce((sum, line) => sum + (line.quantity || 0), 0);
82
- const cartLineCount = cartLines.length;
83
- set({ cartLines, cartQuantityTotal, cartLineCount }, false, "setCartLines");
84
- },
85
- clearCart: () => set(
86
- { cartHdrUid: void 0, cartLines: [], cartQuantityTotal: 0, cartLineCount: 0 },
87
- false,
88
- "clearCart"
89
- )
90
- }),
91
- { name: "CartStore", enabled: process.env["NODE_ENV"] === "development" }
92
- )
93
- );
94
- var useCartHdrUid = () => useCartStore((s) => s.cartHdrUid);
95
- var useCartLines = () => useCartStore((s) => s.cartLines);
96
- var useCartQuantityTotal = () => useCartStore((s) => s.cartQuantityTotal);
97
- var useCartLineCount = () => useCartStore((s) => s.cartLineCount);
98
- var useSetCartHdrUid = () => useCartStore((s) => s.setCartHdrUid);
99
- var useSetCartLines = () => useCartStore((s) => s.setCartLines);
100
- var useClearCart = () => useCartStore((s) => s.clearCart);
101
-
102
- // src/stores/items-filters-store.ts
103
-
104
-
105
80
  var DEFAULT_FILTER_STATE = {
106
81
  filters: [],
107
82
  limit: 12,
@@ -256,9 +231,9 @@ function buildOptimisticAdd(cartLines, item, cartHdrUid, itemId) {
256
231
  }
257
232
  function useCartActions(callbacks) {
258
233
  const queryClient = _reactquery.useQueryClient.call(void 0, );
259
- const cartHdrUid = useCartHdrUid();
260
- const cartLines = useCartLines();
261
- const setCartLines = useSetCartLines();
234
+ const cartHdrUid = _chunkEOHLFKJNcjs.useCartHdrUid.call(void 0, );
235
+ const cartLines = _chunkEOHLFKJNcjs.useCartLines.call(void 0, );
236
+ const setCartLines = _chunkEOHLFKJNcjs.useSetCartLines.call(void 0, );
262
237
  const notify = callbacks.toast;
263
238
  const invalidateCartCache = _react.useCallback.call(void 0, () => {
264
239
  void queryClient.invalidateQueries({ queryKey: ["cartLines", cartHdrUid] });
@@ -501,10 +476,10 @@ function useCartInitialization(session, callbacks) {
501
476
  const saveCartToken = _nullishCoalesce(callbacks.saveCartToken, () => ( defaultSaveCartToken));
502
477
  const generateCartToken = _nullishCoalesce(callbacks.generateCartToken, () => ( defaultGenerateCartToken));
503
478
  const auth = useAugurAuth();
504
- const cartHdrUid = useCartHdrUid();
505
- const setCartHdrUid = useSetCartHdrUid();
506
- const setCartLines = useSetCartLines();
507
- const clearCart = useClearCart();
479
+ const cartHdrUid = _chunkEOHLFKJNcjs.useCartHdrUid.call(void 0, );
480
+ const setCartHdrUid = _chunkEOHLFKJNcjs.useSetCartHdrUid.call(void 0, );
481
+ const setCartLines = _chunkEOHLFKJNcjs.useSetCartLines.call(void 0, );
482
+ const clearCart = _chunkEOHLFKJNcjs.useClearCart.call(void 0, );
508
483
  const queryClient = _reactquery.useQueryClient.call(void 0, );
509
484
  const effectiveStatus = session.status;
510
485
  const effectiveUserId = _nullishCoalesce(session.userId, () => ( _optionalChain([auth, 'optionalAccess', _26 => _26.userId])));
@@ -602,7 +577,7 @@ function useCartPricing(options = {}) {
602
577
  const proxy = useAugurOptions();
603
578
  const auth = useAugurAuth();
604
579
  const site = useAugurSite();
605
- const cartLines = useCartLines();
580
+ const cartLines = _chunkEOHLFKJNcjs.useCartLines.call(void 0, );
606
581
  const customerId = _nullishCoalesce(_nullishCoalesce(options.customerId, () => ( _optionalChain([auth, 'optionalAccess', _28 => _28.customerId]))), () => ( _optionalChain([site, 'optionalAccess', _29 => _29.defaults, 'optionalAccess', _30 => _30.customerId])));
607
582
  const priceFn = options.queryFn;
608
583
  const priceQueries = _reactquery.useQueries.call(void 0, {
@@ -927,5 +902,5 @@ function useAugurPersistence(config) {
927
902
 
928
903
 
929
904
 
930
- exports.AugurHooksProvider = AugurHooksProvider; exports.clearCheckoutPersistence = clearCheckoutPersistence; exports.clearFromSession = clearFromSession; exports.determineOrderReadiness = _chunkSSOW6W53cjs.determineOrderReadiness; exports.executeBatchQuery = _chunkXJJ6DZDKcjs.executeBatchQuery; exports.getCartPricingQueryOptions = _chunkXJJ6DZDKcjs.getCartPricingQueryOptions; exports.getRegisteredQueryAction = _chunkXJJ6DZDKcjs.getRegisteredQueryAction; exports.getStockKey = _chunkXJJ6DZDKcjs.getStockKey; exports.getStockOptions = _chunkXJJ6DZDKcjs.getStockOptions; exports.loadFromSession = loadFromSession; exports.registerQueryAction = _chunkXJJ6DZDKcjs.registerQueryAction; exports.saveToSession = saveToSession; 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.useCheckoutPersistence = useCheckoutPersistence; exports.useClearCart = useClearCart; exports.useDebounce = useDebounce; exports.useFormatPrice = useFormatPrice; exports.useItemFiltersStore = useItemFiltersStore; exports.useModalLifecycle = useModalLifecycle; exports.useOrderReadiness = _chunkSSOW6W53cjs.useOrderReadiness; exports.usePaginationPrefetch = usePaginationPrefetch; exports.usePaymentFlow = _chunkSSOW6W53cjs.usePaymentFlow; exports.useSetCartHdrUid = useSetCartHdrUid; exports.useSetCartLines = useSetCartLines; exports.useStock = useStock;
905
+ exports.AugurHooksProvider = AugurHooksProvider; exports.clearCheckoutPersistence = clearCheckoutPersistence; exports.clearFromSession = clearFromSession; exports.determineOrderReadiness = _chunkEOHLFKJNcjs.determineOrderReadiness; exports.executeBatchQuery = _chunkXJJ6DZDKcjs.executeBatchQuery; exports.getCartPricingQueryOptions = _chunkXJJ6DZDKcjs.getCartPricingQueryOptions; exports.getRegisteredQueryAction = _chunkXJJ6DZDKcjs.getRegisteredQueryAction; exports.getStockKey = _chunkXJJ6DZDKcjs.getStockKey; exports.getStockOptions = _chunkXJJ6DZDKcjs.getStockOptions; exports.loadFromSession = loadFromSession; exports.registerQueryAction = _chunkXJJ6DZDKcjs.registerQueryAction; exports.saveToSession = saveToSession; 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 = _chunkEOHLFKJNcjs.useCartHdrUid; exports.useCartInitialization = useCartInitialization; exports.useCartLineCount = _chunkEOHLFKJNcjs.useCartLineCount; exports.useCartLines = _chunkEOHLFKJNcjs.useCartLines; exports.useCartPricing = useCartPricing; exports.useCartQuantityTotal = _chunkEOHLFKJNcjs.useCartQuantityTotal; exports.useCartStore = _chunkEOHLFKJNcjs.useCartStore; exports.useCheckoutPersistence = useCheckoutPersistence; exports.useClearCart = _chunkEOHLFKJNcjs.useClearCart; exports.useDebounce = useDebounce; exports.useFormatPrice = useFormatPrice; exports.useItemFiltersStore = useItemFiltersStore; exports.useModalLifecycle = useModalLifecycle; exports.useOrderReadiness = _chunkEOHLFKJNcjs.useOrderReadiness; exports.usePaginationPrefetch = usePaginationPrefetch; exports.usePaymentFlow = _chunkEOHLFKJNcjs.usePaymentFlow; exports.useSetCartHdrUid = _chunkEOHLFKJNcjs.useSetCartHdrUid; exports.useSetCartLines = _chunkEOHLFKJNcjs.useSetCartLines; exports.useStock = useStock;
931
906
  //# sourceMappingURL=index.cjs.map