@simpleapps-com/augur-hooks 2.4.0 → 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-JNOHB4OP.js → chunk-UTDAFIQP.js} +234 -94
  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 +215 -178
  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 +193 -156
  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-F5DUFW57.cjs +0 -383
  94. package/dist/chunk-F5DUFW57.cjs.map +0 -1
  95. package/dist/chunk-JNOHB4OP.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,
@@ -123,47 +233,50 @@ function usePaymentFlow({
123
233
  customerId: String(customerIdRef.current)
124
234
  });
125
235
  if (!result) {
126
- callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
236
+ toastError(callbacks, "Unable to initialize payment. Please try again.");
127
237
  return;
128
238
  }
129
239
  setUnified(result);
130
240
  } catch (error) {
131
241
  console.error("transactionSetup failed:", error);
132
- callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
242
+ toastError(callbacks, "Unable to initialize payment. Please try again.");
133
243
  }
134
244
  }, [callbacks]);
135
- const getCardInfo = useCallback(async () => {
136
- if (!unified?.transactionSetupId) return;
137
- try {
138
- const result = await callbacks.cardInfo({ transactionSetupId: unified.transactionSetupId });
139
- if (!result) {
140
- callbacks.toast?.error?.("Unable to verify card details. Please try again.");
141
- 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.");
142
257
  }
143
- setUnifiedCc(result);
144
- } catch (error) {
145
- console.error("cardInfo failed:", error);
146
- callbacks.toast?.error?.("Unable to verify card details. Please try again.");
147
- }
148
- }, [unified, callbacks]);
258
+ },
259
+ [callbacks]
260
+ );
149
261
  const verifyUnified = useCallback(async () => {
150
- if (!unified?.transactionSetupId || !customerIdRef.current) return;
262
+ const transactionSetupId = unified?.transactionSetupId;
263
+ if (!transactionSetupId || !customerIdRef.current) return;
151
264
  try {
152
265
  const result = await callbacks.validatePayment({
153
- transactionSetupId: unified.transactionSetupId,
266
+ transactionSetupId,
154
267
  customerId: String(customerIdRef.current)
155
268
  });
156
- if (!result) {
157
- callbacks.toast?.error?.("Payment verification failed. Please try again.");
269
+ if (result === void 0) {
270
+ toastError(callbacks, "Payment verification failed. Please try again.");
158
271
  return;
159
272
  }
160
- setUnifiedResponse(result.valid);
161
- if (result.valid) {
162
- await getCardInfo();
273
+ setUnifiedResponse(result);
274
+ if (result) {
275
+ await getCardInfo(transactionSetupId);
163
276
  }
164
277
  } catch (error) {
165
278
  console.error("validatePayment failed:", error);
166
- callbacks.toast?.error?.("Payment verification failed. Please try again.");
279
+ toastError(callbacks, "Payment verification failed. Please try again.");
167
280
  }
168
281
  }, [unified, getCardInfo, callbacks]);
169
282
  const getUnifiedPayment = useCallback(async () => {
@@ -174,44 +287,46 @@ function usePaymentFlow({
174
287
  customerId: String(customerIdRef.current)
175
288
  });
176
289
  if (!result) {
177
- callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
290
+ toastError(callbacks, "Unable to retrieve payment account. Please try again.");
178
291
  return;
179
292
  }
180
- const payment = capturedBin && !result.Bin ? { ...result, Bin: capturedBin } : result;
181
- setUnifiedPayment(payment);
182
- if (persistPayment && result.PaymentAccountID) {
183
- saveToSession(PAYMENT_STORAGE_KEY, {
184
- transactionSetupId: unified.transactionSetupId,
185
- paymentAccountId: result.PaymentAccountID
186
- });
187
- }
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);
188
301
  } catch (error) {
189
302
  console.error("accountQuery failed:", error);
190
- callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
303
+ toastError(callbacks, "Unable to retrieve payment account. Please try again.");
191
304
  }
192
305
  }, [unified, capturedBin, callbacks, persistPayment]);
193
- const updateUnifiedBilling = useCallback(async () => {
194
- if (!unified?.transactionSetupId || !billingAddress) return;
195
- try {
196
- const result = await callbacks.billingUpdate({
197
- transactionSetupId: unified.transactionSetupId,
198
- address1: billingAddress.address1,
199
- address2: billingAddress.address2,
200
- city: billingAddress.city,
201
- state: billingAddress.state,
202
- zip: billingAddress.postalCode
203
- });
204
- if (!result) {
205
- callbacks.toast?.error?.("Billing update failed. Please try again.");
206
- 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.");
207
326
  }
208
- setUnifiedBilling(true);
209
- void getUnifiedPayment();
210
- } catch (error) {
211
- console.error("billingUpdate failed:", error);
212
- callbacks.toast?.error?.("Billing update failed. Please try again.");
213
- }
214
- }, [unified, billingAddress, getUnifiedPayment, callbacks]);
327
+ },
328
+ [getUnifiedPayment, callbacks]
329
+ );
215
330
  useEffect2(() => {
216
331
  if (isOpen && (!shippingAccepted || paymentMethod !== "credit-card")) {
217
332
  setIsOpen(false);
@@ -223,23 +338,25 @@ function usePaymentFlow({
223
338
  }
224
339
  }, [isOpen, shippingAccepted, paymentMethod, unified, postUnified]);
225
340
  useEffect2(() => {
226
- const setupId = unified?.transactionSetupId;
227
- if (!isOpen && setupId && shippingAccepted && paymentMethod === "credit-card") {
228
- if (hasVerifiedRef.current === setupId) return;
229
- hasVerifiedRef.current = setupId;
341
+ const setupId2 = unified?.transactionSetupId;
342
+ if (!isOpen && setupId2 && shippingAccepted && paymentMethod === "credit-card") {
343
+ if (hasVerifiedRef.current === setupId2) return;
344
+ hasVerifiedRef.current = setupId2;
230
345
  void verifyUnified();
231
346
  }
232
347
  }, [isOpen, unified, shippingAccepted, paymentMethod, verifyUnified]);
348
+ const setupId = unified?.transactionSetupId;
233
349
  useEffect2(() => {
234
- if (unifiedResponse && billingAddress !== void 0 && unifiedCc?.transactionSetupId && paymentMethod === "credit-card") {
235
- void updateUnifiedBilling();
350
+ if (unifiedResponse && billingAddress !== void 0 && unifiedCc?.transactionSetupId && paymentMethod === "credit-card" && setupId) {
351
+ void updateUnifiedBilling(setupId, billingAddress);
236
352
  }
237
353
  }, [
238
354
  unifiedResponse,
239
355
  billingAddress,
240
356
  unifiedCc?.transactionSetupId,
241
357
  updateUnifiedBilling,
242
- paymentMethod
358
+ paymentMethod,
359
+ setupId
243
360
  ]);
244
361
  useEffect2(() => {
245
362
  if (editCc) {
@@ -259,8 +376,8 @@ function usePaymentFlow({
259
376
  const restorePayment = useCallback(async () => {
260
377
  if (!customerIdRef.current) return;
261
378
  const saved = loadFromSession(PAYMENT_STORAGE_KEY);
262
- if (!saved?.transactionSetupId || !saved?.paymentAccountId) return;
263
- const { transactionSetupId } = saved;
379
+ if (!isRestorable(saved)) return;
380
+ const { transactionSetupId, uiEndpoint } = saved;
264
381
  try {
265
382
  const account = await callbacks.accountQuery({
266
383
  transactionSetupId,
@@ -271,7 +388,7 @@ function usePaymentFlow({
271
388
  return;
272
389
  }
273
390
  hasVerifiedRef.current = transactionSetupId;
274
- setUnified({ transactionSetupId });
391
+ setUnified({ transactionSetupId, uiEndpoint });
275
392
  setUnifiedPayment(account);
276
393
  setUnifiedResponse(true);
277
394
  setUnifiedBilling(true);
@@ -281,9 +398,11 @@ function usePaymentFlow({
281
398
  clearFromSession(PAYMENT_STORAGE_KEY);
282
399
  }
283
400
  }, [callbacks]);
401
+ const restorePaymentRef = useRef2(restorePayment);
402
+ restorePaymentRef.current = restorePayment;
284
403
  useEffect2(() => {
285
404
  if (persistPayment) {
286
- void restorePayment();
405
+ void restorePaymentRef.current();
287
406
  }
288
407
  }, [persistPayment]);
289
408
  return {
@@ -303,44 +422,53 @@ function usePaymentFlow({
303
422
 
304
423
  // src/hooks/use-order-readiness.ts
305
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
306
435
  function determineOrderReadiness(params) {
307
- if (params.customReadinessCheck) {
308
- const override = params.customReadinessCheck(params);
309
- if (override !== void 0) return override;
310
- }
311
- if (!params.cartHdrUid) return false;
312
- const blockers = [
313
- params.isEditShippingInfo,
314
- params.isEditShippingMethods,
315
- params.isEditBillingInfo,
316
- params.editCc,
317
- params.shippingAddress === void 0,
318
- params.billingAddress === void 0,
319
- !params.shippingMethodSaved,
320
- !params.showBillingInfoSummary,
321
- params.processingOrder
322
- ];
323
- if (blockers.some(Boolean)) return false;
324
- if (params.paymentMethod === "credit-card" && (!params.unifiedPaymentAccountId || !params.unifiedBilling)) {
325
- return false;
326
- }
327
- if (!params.isFreeShipping && params.shippingFee === void 0) {
328
- return false;
329
- }
330
- 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
+ };
331
456
  }
332
457
  function useOrderReadiness(params) {
333
458
  const [enableProcessOrderBtn, setEnableProcessOrderBtn] = useState2(false);
334
459
  const [processingValidation, setProcessingValidation] = useState2(false);
460
+ const paramsRef = useLatest(params);
335
461
  useEffect3(() => {
336
462
  setProcessingValidation(true);
463
+ const current = paramsRef.current;
337
464
  const timeoutId = setTimeout(() => {
338
- const ready = determineOrderReadiness(params);
465
+ const ready = determineOrderReadiness(current);
339
466
  setEnableProcessOrderBtn(ready);
340
467
  setProcessingValidation(false);
341
468
  }, 300);
342
469
  return () => clearTimeout(timeoutId);
343
470
  }, [
471
+ paramsRef,
344
472
  params.billingAddress,
345
473
  params.shippingAddress,
346
474
  params.isEditShippingInfo,
@@ -362,6 +490,18 @@ function useOrderReadiness(params) {
362
490
  }
363
491
 
364
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,
365
505
  useCartStore,
366
506
  useCartHdrUid,
367
507
  useCartLines,
@@ -380,4 +520,4 @@ export {
380
520
  determineOrderReadiness,
381
521
  useOrderReadiness
382
522
  };
383
- //# sourceMappingURL=chunk-JNOHB4OP.js.map
523
+ //# sourceMappingURL=chunk-UTDAFIQP.js.map