@simpleapps-com/augur-hooks 2.3.1 → 2026.11.1

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.
Files changed (99) hide show
  1. package/EXPORTS.md +25 -65
  2. package/README.md +21 -246
  3. package/dist/checkout/create-checkout-provider.d.ts +25 -0
  4. package/dist/checkout/create-checkout-provider.d.ts.map +1 -0
  5. package/dist/checkout/index.cjs +123 -106
  6. package/dist/checkout/index.cjs.map +1 -1
  7. package/dist/checkout/index.d.ts +5 -293
  8. package/dist/checkout/index.d.ts.map +1 -0
  9. package/dist/checkout/index.js +99 -82
  10. package/dist/checkout/index.js.map +1 -1
  11. package/dist/checkout/{index.d.cts → types.d.ts} +18 -40
  12. package/dist/checkout/types.d.ts.map +1 -0
  13. package/dist/chunk-6Z6JGK2C.cjs.map +1 -1
  14. package/dist/chunk-QB7VB5FZ.cjs +523 -0
  15. package/dist/chunk-QB7VB5FZ.cjs.map +1 -0
  16. package/dist/{chunk-NRWH2BMN.js → chunk-UTDAFIQP.js} +237 -91
  17. package/dist/chunk-UTDAFIQP.js.map +1 -0
  18. package/dist/hooks/use-cart-actions.d.ts +68 -0
  19. package/dist/hooks/use-cart-actions.d.ts.map +1 -0
  20. package/dist/hooks/use-cart-initialization.d.ts +60 -0
  21. package/dist/hooks/use-cart-initialization.d.ts.map +1 -0
  22. package/dist/hooks/use-cart-pricing.d.ts +41 -0
  23. package/dist/hooks/use-cart-pricing.d.ts.map +1 -0
  24. package/dist/hooks/use-checkout-persistence.d.ts +40 -0
  25. package/dist/hooks/use-checkout-persistence.d.ts.map +1 -0
  26. package/dist/hooks/use-debounce.d.ts +6 -0
  27. package/dist/hooks/use-debounce.d.ts.map +1 -0
  28. package/dist/hooks/use-format-price.d.ts +29 -0
  29. package/dist/hooks/use-format-price.d.ts.map +1 -0
  30. package/dist/hooks/use-latest.d.ts +8 -0
  31. package/dist/hooks/use-latest.d.ts.map +1 -0
  32. package/dist/hooks/use-modal-lifecycle.d.ts +11 -0
  33. package/dist/hooks/use-modal-lifecycle.d.ts.map +1 -0
  34. package/dist/hooks/use-order-readiness.d.ts +47 -0
  35. package/dist/hooks/use-order-readiness.d.ts.map +1 -0
  36. package/dist/hooks/use-pagination-prefetch.d.ts +26 -0
  37. package/dist/hooks/use-pagination-prefetch.d.ts.map +1 -0
  38. package/dist/{use-order-readiness-DZTIfRzw.d.ts → hooks/use-payment-flow.d.ts} +23 -67
  39. package/dist/hooks/use-payment-flow.d.ts.map +1 -0
  40. package/dist/hooks/use-stock.d.ts +32 -0
  41. package/dist/hooks/use-stock.d.ts.map +1 -0
  42. package/dist/index.cjs +251 -192
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.d.ts +32 -456
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +230 -171
  47. package/dist/index.js.map +1 -1
  48. package/dist/persistence/apply-limits.d.ts +8 -0
  49. package/dist/persistence/apply-limits.d.ts.map +1 -0
  50. package/dist/persistence/create-persister.d.ts +10 -0
  51. package/dist/persistence/create-persister.d.ts.map +1 -0
  52. package/dist/persistence/serializer.d.ts +11 -0
  53. package/dist/persistence/serializer.d.ts.map +1 -0
  54. package/dist/persistence/use-persistence.d.ts +59 -0
  55. package/dist/persistence/use-persistence.d.ts.map +1 -0
  56. package/dist/persistence/use-storage-monitor.d.ts +11 -0
  57. package/dist/persistence/use-storage-monitor.d.ts.map +1 -0
  58. package/dist/provider.d.ts +89 -0
  59. package/dist/provider.d.ts.map +1 -0
  60. package/dist/queries/batch-query.d.ts +23 -0
  61. package/dist/queries/batch-query.d.ts.map +1 -0
  62. package/dist/queries/cache-helper.d.ts +16 -0
  63. package/dist/queries/cache-helper.d.ts.map +1 -0
  64. package/dist/queries/index.d.ts +3 -0
  65. package/dist/queries/index.d.ts.map +1 -0
  66. package/dist/query-action-registry.d.ts +19 -0
  67. package/dist/query-action-registry.d.ts.map +1 -0
  68. package/dist/rules.d.ts +130 -0
  69. package/dist/rules.d.ts.map +1 -0
  70. package/dist/server.cjs.map +1 -1
  71. package/dist/server.d.ts +10 -12
  72. package/dist/server.d.ts.map +1 -0
  73. package/dist/stores/cart-store.d.ts +51 -0
  74. package/dist/stores/cart-store.d.ts.map +1 -0
  75. package/dist/stores/items-filters-store.d.ts +30 -0
  76. package/dist/stores/items-filters-store.d.ts.map +1 -0
  77. package/dist/types.d.ts +48 -0
  78. package/dist/types.d.ts.map +1 -0
  79. package/dist/web/use-image-with-fallback.d.ts +16 -0
  80. package/dist/web/use-image-with-fallback.d.ts.map +1 -0
  81. package/dist/web/use-mobile-detection.d.ts +28 -0
  82. package/dist/web/use-mobile-detection.d.ts.map +1 -0
  83. package/dist/web/use-mobile-optimized-intersection.d.ts +17 -0
  84. package/dist/web/use-mobile-optimized-intersection.d.ts.map +1 -0
  85. package/dist/web.cjs.map +1 -1
  86. package/dist/web.d.ts +4 -60
  87. package/dist/web.d.ts.map +1 -0
  88. package/dist/web.js.map +1 -1
  89. package/llms.txt +76 -54
  90. package/package.json +25 -14
  91. package/dist/batch-query-CTlvxSmL.d.cts +0 -165
  92. package/dist/batch-query-CTlvxSmL.d.ts +0 -165
  93. package/dist/chunk-I4A5L2I6.cjs +0 -377
  94. package/dist/chunk-I4A5L2I6.cjs.map +0 -1
  95. package/dist/chunk-NRWH2BMN.js.map +0 -1
  96. package/dist/index.d.cts +0 -456
  97. package/dist/server.d.cts +0 -44
  98. package/dist/use-order-readiness-DZTIfRzw.d.cts +0 -137
  99. package/dist/web.d.cts +0 -60
@@ -1,6 +1,98 @@
1
1
  // src/stores/cart-store.ts
2
2
  import { create } from "zustand";
3
3
  import { devtools } from "zustand/middleware";
4
+
5
+ // ../utils/src/strings.ts
6
+ function codeAt(s, i) {
7
+ return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
8
+ }
9
+ function indexOfCode(s, code, from) {
10
+ const c = codeAt(s, from);
11
+ if (c === code) return from;
12
+ if (c === -1) return -1;
13
+ return indexOfCode(s, code, from + 1);
14
+ }
15
+
16
+ // src/rules.ts
17
+ function quantityTotalFrom(quantities, i, acc) {
18
+ if (i === quantities.length) return acc;
19
+ return quantityTotalFrom(quantities, i + 1, acc + quantities[i]);
20
+ }
21
+ function qtyOrZero(q) {
22
+ if (q === null) return 0;
23
+ return q;
24
+ }
25
+ function indexOfUidFrom(uids, uid, i) {
26
+ if (i === uids.length) return -1;
27
+ if (uids[i] === uid) return i;
28
+ return indexOfUidFrom(uids, uid, i + 1);
29
+ }
30
+ function keepsAfterReverse(current, q) {
31
+ return qtyOrZero(current) - q > 0;
32
+ }
33
+ function requiredCartUid(uid) {
34
+ if (uid === void 0) return null;
35
+ if (uid === 0) return null;
36
+ return uid;
37
+ }
38
+ function checkoutCartUid(uid) {
39
+ if (uid === void 0) return 0;
40
+ return uid;
41
+ }
42
+ function defaultPaymentMethodOf(fromHook, hasCallbacks) {
43
+ if (fromHook !== void 0 && fromHook !== "") return fromHook;
44
+ return hasCallbacks ? "credit-card" : "invoice";
45
+ }
46
+ function defaultReady(r) {
47
+ return nothingBusy(r) && detailsComplete(r) && paymentSettled(r);
48
+ }
49
+ function nothingBusy(r) {
50
+ return !r.editShippingInfo && !r.editShippingMethods && !r.editBillingInfo && !r.editCc && !r.processing;
51
+ }
52
+ function detailsComplete(r) {
53
+ return r.cartUidSet && r.hasShippingAddress && r.hasBillingAddress && r.methodSaved && r.showBillingSummary;
54
+ }
55
+ function paymentSettled(r) {
56
+ return (!r.isCreditCard || r.hasAccountId && r.hasUnifiedBilling) && (r.isFreeShipping || r.hasShippingFee);
57
+ }
58
+ function orderReadyOf(custom, ready) {
59
+ if (custom !== void 0) return custom;
60
+ return ready;
61
+ }
62
+ function preSubmitOutcome(validateError, beforeSubmitFalse, hasShippingAddress) {
63
+ if (validateError !== void 0 && validateError !== "") {
64
+ return { kind: "refused", message: validateError };
65
+ }
66
+ if (beforeSubmitFalse) return { kind: "cancelled" };
67
+ if (!hasShippingAddress) return { kind: "refused", message: "Shipping address is required." };
68
+ return { kind: "ok" };
69
+ }
70
+ function secondEqualsField(s) {
71
+ const k = indexOfCode(s, 61, 0);
72
+ if (k < 0) return "";
73
+ const j = indexOfCode(s, 61, k + 1);
74
+ if (j < 0) return s.slice(k + 1);
75
+ return s.slice(k + 1, j);
76
+ }
77
+ function isExpired(now, savedAt, ttl) {
78
+ return now - savedAt > ttl;
79
+ }
80
+ function shouldPersistOf(hasHead, succeeded, listed) {
81
+ return hasHead && succeeded && listed;
82
+ }
83
+ function pow2(n) {
84
+ if (n === 0) return 1;
85
+ return 2 * pow2(n - 1);
86
+ }
87
+ function stockRetryDelay(attemptIndex) {
88
+ if (attemptIndex >= 4) return 1e4;
89
+ return 1e3 * pow2(attemptIndex);
90
+ }
91
+ function stockEnabled(enabled, uidSet) {
92
+ return (enabled === void 0 || enabled === true) && uidSet;
93
+ }
94
+
95
+ // src/stores/cart-store.ts
4
96
  var useCartStore = create()(
5
97
  devtools(
6
98
  (set) => ({
@@ -10,7 +102,8 @@ var useCartStore = create()(
10
102
  cartLineCount: 0,
11
103
  setCartHdrUid: (cartHdrUid) => set({ cartHdrUid }, false, "setCartHdrUid"),
12
104
  setCartLines: (cartLines) => {
13
- const cartQuantityTotal = cartLines.reduce((sum, line) => sum + (line.quantity || 0), 0);
105
+ const quantities = cartLines.map((line) => line.quantity || 0);
106
+ const cartQuantityTotal = quantityTotalFrom(quantities, 0, 0);
14
107
  const cartLineCount = cartLines.length;
15
108
  set({ cartLines, cartQuantityTotal, cartLineCount }, false, "setCartLines");
16
109
  },
@@ -46,7 +139,7 @@ function loadFromSession(key, ttl = DEFAULT_TTL, validate) {
46
139
  const raw = sessionStorage.getItem(key);
47
140
  if (!raw) return null;
48
141
  const entry = JSON.parse(raw);
49
- if (Date.now() - entry.savedAt > ttl) {
142
+ if (isExpired(Date.now(), entry.savedAt, ttl)) {
50
143
  sessionStorage.removeItem(key);
51
144
  return null;
52
145
  }
@@ -78,7 +171,7 @@ function useCheckoutPersistence(fields) {
78
171
  }, []);
79
172
  const serialized = JSON.stringify(fields.map((f) => [f.key, f.value]));
80
173
  useEffect(() => {
81
- for (const field of fields) {
174
+ for (const field of fieldsRef.current) {
82
175
  if (field.value !== void 0 && field.value !== null) {
83
176
  saveToSession(field.key, field.value);
84
177
  }
@@ -94,6 +187,23 @@ function clearCheckoutPersistence(keys) {
94
187
  // src/hooks/use-payment-flow.ts
95
188
  import { useCallback, useEffect as useEffect2, useRef as useRef2, useState } from "react";
96
189
  var PAYMENT_STORAGE_KEY = "checkout:payment";
190
+ function toastError(callbacks, message) {
191
+ callbacks.toast?.error?.(message);
192
+ }
193
+ function withCapturedBin(account, capturedBin) {
194
+ return capturedBin && !account.Bin ? { ...account, Bin: capturedBin } : account;
195
+ }
196
+ function paymentToPersist(transactionSetupId, uiEndpoint, account, persistPayment) {
197
+ if (!persistPayment || !account.PaymentAccountID) return null;
198
+ return {
199
+ transactionSetupId,
200
+ uiEndpoint,
201
+ paymentAccountId: account.PaymentAccountID
202
+ };
203
+ }
204
+ function isRestorable(saved) {
205
+ return Boolean(saved?.transactionSetupId && saved.uiEndpoint && saved.paymentAccountId);
206
+ }
97
207
  function usePaymentFlow({
98
208
  callbacks,
99
209
  customerId,
@@ -115,6 +225,7 @@ function usePaymentFlow({
115
225
  }, []);
116
226
  const customerIdRef = useRef2(customerId);
117
227
  customerIdRef.current = customerId;
228
+ const hasVerifiedRef = useRef2(null);
118
229
  const postUnified = useCallback(async () => {
119
230
  if (!customerIdRef.current) return;
120
231
  try {
@@ -122,47 +233,50 @@ function usePaymentFlow({
122
233
  customerId: String(customerIdRef.current)
123
234
  });
124
235
  if (!result) {
125
- callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
236
+ toastError(callbacks, "Unable to initialize payment. Please try again.");
126
237
  return;
127
238
  }
128
239
  setUnified(result);
129
240
  } catch (error) {
130
241
  console.error("transactionSetup failed:", error);
131
- callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
242
+ toastError(callbacks, "Unable to initialize payment. Please try again.");
132
243
  }
133
244
  }, [callbacks]);
134
- const getCardInfo = useCallback(async () => {
135
- if (!unified?.transactionSetupId) return;
136
- try {
137
- const result = await callbacks.cardInfo({ transactionSetupId: unified.transactionSetupId });
138
- if (!result) {
139
- callbacks.toast?.error?.("Unable to verify card details. Please try again.");
140
- return;
245
+ const getCardInfo = useCallback(
246
+ async (transactionSetupId) => {
247
+ try {
248
+ const result = await callbacks.cardInfo({ transactionSetupId });
249
+ if (!result) {
250
+ toastError(callbacks, "Unable to verify card details. Please try again.");
251
+ return;
252
+ }
253
+ setUnifiedCc(result);
254
+ } catch (error) {
255
+ console.error("cardInfo failed:", error);
256
+ toastError(callbacks, "Unable to verify card details. Please try again.");
141
257
  }
142
- setUnifiedCc(result);
143
- } catch (error) {
144
- console.error("cardInfo failed:", error);
145
- callbacks.toast?.error?.("Unable to verify card details. Please try again.");
146
- }
147
- }, [unified, callbacks]);
258
+ },
259
+ [callbacks]
260
+ );
148
261
  const verifyUnified = useCallback(async () => {
149
- if (!unified?.transactionSetupId || !customerIdRef.current) return;
262
+ const transactionSetupId = unified?.transactionSetupId;
263
+ if (!transactionSetupId || !customerIdRef.current) return;
150
264
  try {
151
265
  const result = await callbacks.validatePayment({
152
- transactionSetupId: unified.transactionSetupId,
266
+ transactionSetupId,
153
267
  customerId: String(customerIdRef.current)
154
268
  });
155
- if (!result) {
156
- callbacks.toast?.error?.("Payment verification failed. Please try again.");
269
+ if (result === void 0) {
270
+ toastError(callbacks, "Payment verification failed. Please try again.");
157
271
  return;
158
272
  }
159
- setUnifiedResponse(result.valid);
160
- if (result.valid) {
161
- await getCardInfo();
273
+ setUnifiedResponse(result);
274
+ if (result) {
275
+ await getCardInfo(transactionSetupId);
162
276
  }
163
277
  } catch (error) {
164
278
  console.error("validatePayment failed:", error);
165
- callbacks.toast?.error?.("Payment verification failed. Please try again.");
279
+ toastError(callbacks, "Payment verification failed. Please try again.");
166
280
  }
167
281
  }, [unified, getCardInfo, callbacks]);
168
282
  const getUnifiedPayment = useCallback(async () => {
@@ -173,44 +287,46 @@ function usePaymentFlow({
173
287
  customerId: String(customerIdRef.current)
174
288
  });
175
289
  if (!result) {
176
- callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
290
+ toastError(callbacks, "Unable to retrieve payment account. Please try again.");
177
291
  return;
178
292
  }
179
- const payment = capturedBin && !result.Bin ? { ...result, Bin: capturedBin } : result;
180
- setUnifiedPayment(payment);
181
- if (persistPayment && result.PaymentAccountID) {
182
- saveToSession(PAYMENT_STORAGE_KEY, {
183
- transactionSetupId: unified.transactionSetupId,
184
- paymentAccountId: result.PaymentAccountID
185
- });
186
- }
293
+ setUnifiedPayment(withCapturedBin(result, capturedBin));
294
+ const toPersist = paymentToPersist(
295
+ unified.transactionSetupId,
296
+ unified.uiEndpoint,
297
+ result,
298
+ persistPayment
299
+ );
300
+ if (toPersist) saveToSession(PAYMENT_STORAGE_KEY, toPersist);
187
301
  } catch (error) {
188
302
  console.error("accountQuery failed:", error);
189
- callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
303
+ toastError(callbacks, "Unable to retrieve payment account. Please try again.");
190
304
  }
191
305
  }, [unified, capturedBin, callbacks, persistPayment]);
192
- const updateUnifiedBilling = useCallback(async () => {
193
- if (!unified?.transactionSetupId || !billingAddress) return;
194
- try {
195
- const result = await callbacks.billingUpdate({
196
- transactionSetupId: unified.transactionSetupId,
197
- address1: billingAddress.address1,
198
- address2: billingAddress.address2,
199
- city: billingAddress.city,
200
- state: billingAddress.state,
201
- zip: billingAddress.postalCode
202
- });
203
- if (!result) {
204
- callbacks.toast?.error?.("Billing update failed. Please try again.");
205
- return;
306
+ const updateUnifiedBilling = useCallback(
307
+ async (transactionSetupId, address) => {
308
+ try {
309
+ const result = await callbacks.billingUpdate({
310
+ transactionSetupId,
311
+ address1: address.address1,
312
+ address2: address.address2,
313
+ city: address.city,
314
+ state: address.state,
315
+ zip: address.postalCode
316
+ });
317
+ if (!result) {
318
+ toastError(callbacks, "Billing update failed. Please try again.");
319
+ return;
320
+ }
321
+ setUnifiedBilling(true);
322
+ void getUnifiedPayment();
323
+ } catch (error) {
324
+ console.error("billingUpdate failed:", error);
325
+ toastError(callbacks, "Billing update failed. Please try again.");
206
326
  }
207
- setUnifiedBilling(true);
208
- void getUnifiedPayment();
209
- } catch (error) {
210
- console.error("billingUpdate failed:", error);
211
- callbacks.toast?.error?.("Billing update failed. Please try again.");
212
- }
213
- }, [unified, billingAddress, getUnifiedPayment, callbacks]);
327
+ },
328
+ [getUnifiedPayment, callbacks]
329
+ );
214
330
  useEffect2(() => {
215
331
  if (isOpen && (!shippingAccepted || paymentMethod !== "credit-card")) {
216
332
  setIsOpen(false);
@@ -222,20 +338,25 @@ function usePaymentFlow({
222
338
  }
223
339
  }, [isOpen, shippingAccepted, paymentMethod, unified, postUnified]);
224
340
  useEffect2(() => {
225
- if (!isOpen && unified !== null && shippingAccepted && paymentMethod === "credit-card") {
341
+ const setupId2 = unified?.transactionSetupId;
342
+ if (!isOpen && setupId2 && shippingAccepted && paymentMethod === "credit-card") {
343
+ if (hasVerifiedRef.current === setupId2) return;
344
+ hasVerifiedRef.current = setupId2;
226
345
  void verifyUnified();
227
346
  }
228
347
  }, [isOpen, unified, shippingAccepted, paymentMethod, verifyUnified]);
348
+ const setupId = unified?.transactionSetupId;
229
349
  useEffect2(() => {
230
- if (unifiedResponse && billingAddress !== void 0 && unifiedCc?.transactionSetupId && paymentMethod === "credit-card") {
231
- void updateUnifiedBilling();
350
+ if (unifiedResponse && billingAddress !== void 0 && unifiedCc?.transactionSetupId && paymentMethod === "credit-card" && setupId) {
351
+ void updateUnifiedBilling(setupId, billingAddress);
232
352
  }
233
353
  }, [
234
354
  unifiedResponse,
235
355
  billingAddress,
236
356
  unifiedCc?.transactionSetupId,
237
357
  updateUnifiedBilling,
238
- paymentMethod
358
+ paymentMethod,
359
+ setupId
239
360
  ]);
240
361
  useEffect2(() => {
241
362
  if (editCc) {
@@ -246,6 +367,7 @@ function usePaymentFlow({
246
367
  setUnifiedBilling(false);
247
368
  setUnifiedResponse(false);
248
369
  setCapturedBin(null);
370
+ hasVerifiedRef.current = null;
249
371
  if (persistPayment) {
250
372
  clearFromSession(PAYMENT_STORAGE_KEY);
251
373
  }
@@ -254,8 +376,8 @@ function usePaymentFlow({
254
376
  const restorePayment = useCallback(async () => {
255
377
  if (!customerIdRef.current) return;
256
378
  const saved = loadFromSession(PAYMENT_STORAGE_KEY);
257
- if (!saved?.transactionSetupId || !saved?.paymentAccountId) return;
258
- const { transactionSetupId } = saved;
379
+ if (!isRestorable(saved)) return;
380
+ const { transactionSetupId, uiEndpoint } = saved;
259
381
  try {
260
382
  const account = await callbacks.accountQuery({
261
383
  transactionSetupId,
@@ -265,7 +387,8 @@ function usePaymentFlow({
265
387
  clearFromSession(PAYMENT_STORAGE_KEY);
266
388
  return;
267
389
  }
268
- setUnified({ transactionSetupId });
390
+ hasVerifiedRef.current = transactionSetupId;
391
+ setUnified({ transactionSetupId, uiEndpoint });
269
392
  setUnifiedPayment(account);
270
393
  setUnifiedResponse(true);
271
394
  setUnifiedBilling(true);
@@ -275,9 +398,11 @@ function usePaymentFlow({
275
398
  clearFromSession(PAYMENT_STORAGE_KEY);
276
399
  }
277
400
  }, [callbacks]);
401
+ const restorePaymentRef = useRef2(restorePayment);
402
+ restorePaymentRef.current = restorePayment;
278
403
  useEffect2(() => {
279
404
  if (persistPayment) {
280
- void restorePayment();
405
+ void restorePaymentRef.current();
281
406
  }
282
407
  }, [persistPayment]);
283
408
  return {
@@ -297,44 +422,53 @@ function usePaymentFlow({
297
422
 
298
423
  // src/hooks/use-order-readiness.ts
299
424
  import { useEffect as useEffect3, useState as useState2 } from "react";
425
+
426
+ // src/hooks/use-latest.ts
427
+ import { useRef as useRef3 } from "react";
428
+ function useLatest(value) {
429
+ const ref = useRef3(value);
430
+ ref.current = value;
431
+ return ref;
432
+ }
433
+
434
+ // src/hooks/use-order-readiness.ts
300
435
  function determineOrderReadiness(params) {
301
- if (params.customReadinessCheck) {
302
- const override = params.customReadinessCheck(params);
303
- if (override !== void 0) return override;
304
- }
305
- if (!params.cartHdrUid) return false;
306
- const blockers = [
307
- params.isEditShippingInfo,
308
- params.isEditShippingMethods,
309
- params.isEditBillingInfo,
310
- params.editCc,
311
- params.shippingAddress === void 0,
312
- params.billingAddress === void 0,
313
- !params.shippingMethodSaved,
314
- !params.showBillingInfoSummary,
315
- params.processingOrder
316
- ];
317
- if (blockers.some(Boolean)) return false;
318
- if (params.paymentMethod === "credit-card" && (!params.unifiedPaymentAccountId || !params.unifiedBilling)) {
319
- return false;
320
- }
321
- if (!params.isFreeShipping && params.shippingFee === void 0) {
322
- return false;
323
- }
324
- return true;
436
+ return orderReadyOf(params.customReadinessCheck?.(params), defaultReady(readinessFlags(params)));
437
+ }
438
+ function readinessFlags(params) {
439
+ return {
440
+ cartUidSet: !!params.cartHdrUid,
441
+ editShippingInfo: params.isEditShippingInfo,
442
+ editShippingMethods: params.isEditShippingMethods,
443
+ editBillingInfo: params.isEditBillingInfo,
444
+ editCc: params.editCc,
445
+ hasShippingAddress: params.shippingAddress !== void 0,
446
+ hasBillingAddress: params.billingAddress !== void 0,
447
+ methodSaved: params.shippingMethodSaved,
448
+ showBillingSummary: params.showBillingInfoSummary,
449
+ processing: params.processingOrder,
450
+ isCreditCard: params.paymentMethod === "credit-card",
451
+ hasAccountId: !!params.unifiedPaymentAccountId,
452
+ hasUnifiedBilling: params.unifiedBilling,
453
+ isFreeShipping: params.isFreeShipping,
454
+ hasShippingFee: params.shippingFee !== void 0
455
+ };
325
456
  }
326
457
  function useOrderReadiness(params) {
327
458
  const [enableProcessOrderBtn, setEnableProcessOrderBtn] = useState2(false);
328
459
  const [processingValidation, setProcessingValidation] = useState2(false);
460
+ const paramsRef = useLatest(params);
329
461
  useEffect3(() => {
330
462
  setProcessingValidation(true);
463
+ const current = paramsRef.current;
331
464
  const timeoutId = setTimeout(() => {
332
- const ready = determineOrderReadiness(params);
465
+ const ready = determineOrderReadiness(current);
333
466
  setEnableProcessOrderBtn(ready);
334
467
  setProcessingValidation(false);
335
468
  }, 300);
336
469
  return () => clearTimeout(timeoutId);
337
470
  }, [
471
+ paramsRef,
338
472
  params.billingAddress,
339
473
  params.shippingAddress,
340
474
  params.isEditShippingInfo,
@@ -356,6 +490,18 @@ function useOrderReadiness(params) {
356
490
  }
357
491
 
358
492
  export {
493
+ useLatest,
494
+ qtyOrZero,
495
+ indexOfUidFrom,
496
+ keepsAfterReverse,
497
+ requiredCartUid,
498
+ checkoutCartUid,
499
+ defaultPaymentMethodOf,
500
+ preSubmitOutcome,
501
+ secondEqualsField,
502
+ shouldPersistOf,
503
+ stockRetryDelay,
504
+ stockEnabled,
359
505
  useCartStore,
360
506
  useCartHdrUid,
361
507
  useCartLines,
@@ -374,4 +520,4 @@ export {
374
520
  determineOrderReadiness,
375
521
  useOrderReadiness
376
522
  };
377
- //# sourceMappingURL=chunk-NRWH2BMN.js.map
523
+ //# sourceMappingURL=chunk-UTDAFIQP.js.map