@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
@@ -0,0 +1,523 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/stores/cart-store.ts
2
+ var _zustand = require('zustand');
3
+ var _middleware = require('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
96
+ var useCartStore = _zustand.create.call(void 0, )(
97
+ _middleware.devtools.call(void 0,
98
+ (set) => ({
99
+ cartHdrUid: void 0,
100
+ cartLines: [],
101
+ cartQuantityTotal: 0,
102
+ cartLineCount: 0,
103
+ setCartHdrUid: (cartHdrUid) => set({ cartHdrUid }, false, "setCartHdrUid"),
104
+ setCartLines: (cartLines) => {
105
+ const quantities = cartLines.map((line) => line.quantity || 0);
106
+ const cartQuantityTotal = quantityTotalFrom(quantities, 0, 0);
107
+ const cartLineCount = cartLines.length;
108
+ set({ cartLines, cartQuantityTotal, cartLineCount }, false, "setCartLines");
109
+ },
110
+ clearCart: () => set(
111
+ { cartHdrUid: void 0, cartLines: [], cartQuantityTotal: 0, cartLineCount: 0 },
112
+ false,
113
+ "clearCart"
114
+ )
115
+ }),
116
+ { name: "CartStore", enabled: process.env["NODE_ENV"] === "development" }
117
+ )
118
+ );
119
+ var useCartHdrUid = () => useCartStore((s) => s.cartHdrUid);
120
+ var useCartLines = () => useCartStore((s) => s.cartLines);
121
+ var useCartQuantityTotal = () => useCartStore((s) => s.cartQuantityTotal);
122
+ var useCartLineCount = () => useCartStore((s) => s.cartLineCount);
123
+ var useSetCartHdrUid = () => useCartStore((s) => s.setCartHdrUid);
124
+ var useSetCartLines = () => useCartStore((s) => s.setCartLines);
125
+ var useClearCart = () => useCartStore((s) => s.clearCart);
126
+
127
+ // src/hooks/use-checkout-persistence.ts
128
+ var _react = require('react');
129
+ var DEFAULT_TTL = 30 * 60 * 1e3;
130
+ function saveToSession(key, value) {
131
+ try {
132
+ const entry = { value, savedAt: Date.now() };
133
+ sessionStorage.setItem(key, JSON.stringify(entry));
134
+ } catch (e) {
135
+ }
136
+ }
137
+ function loadFromSession(key, ttl = DEFAULT_TTL, validate) {
138
+ try {
139
+ const raw = sessionStorage.getItem(key);
140
+ if (!raw) return null;
141
+ const entry = JSON.parse(raw);
142
+ if (isExpired(Date.now(), entry.savedAt, ttl)) {
143
+ sessionStorage.removeItem(key);
144
+ return null;
145
+ }
146
+ if (validate) {
147
+ return validate(entry.value);
148
+ }
149
+ return entry.value;
150
+ } catch (e2) {
151
+ sessionStorage.removeItem(key);
152
+ return null;
153
+ }
154
+ }
155
+ function clearFromSession(key) {
156
+ try {
157
+ sessionStorage.removeItem(key);
158
+ } catch (e3) {
159
+ }
160
+ }
161
+ function useCheckoutPersistence(fields) {
162
+ const fieldsRef = _react.useRef.call(void 0, fields);
163
+ fieldsRef.current = fields;
164
+ _react.useEffect.call(void 0, () => {
165
+ for (const field of fieldsRef.current) {
166
+ const restored = loadFromSession(field.key, _nullishCoalesce(field.ttl, () => ( DEFAULT_TTL)), field.validate);
167
+ if (restored !== null) {
168
+ field.set(restored);
169
+ }
170
+ }
171
+ }, []);
172
+ const serialized = JSON.stringify(fields.map((f) => [f.key, f.value]));
173
+ _react.useEffect.call(void 0, () => {
174
+ for (const field of fieldsRef.current) {
175
+ if (field.value !== void 0 && field.value !== null) {
176
+ saveToSession(field.key, field.value);
177
+ }
178
+ }
179
+ }, [serialized]);
180
+ }
181
+ function clearCheckoutPersistence(keys) {
182
+ for (const key of keys) {
183
+ clearFromSession(key);
184
+ }
185
+ }
186
+
187
+ // src/hooks/use-payment-flow.ts
188
+
189
+ var PAYMENT_STORAGE_KEY = "checkout:payment";
190
+ function toastError(callbacks, message) {
191
+ _optionalChain([callbacks, 'access', _ => _.toast, 'optionalAccess', _2 => _2.error, 'optionalCall', _3 => _3(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(_optionalChain([saved, 'optionalAccess', _4 => _4.transactionSetupId]) && saved.uiEndpoint && saved.paymentAccountId);
206
+ }
207
+ function usePaymentFlow({
208
+ callbacks,
209
+ customerId,
210
+ billingAddress,
211
+ paymentMethod,
212
+ shippingAccepted,
213
+ persistPayment
214
+ }) {
215
+ const [isOpen, setIsOpen] = _react.useState.call(void 0, false);
216
+ const [unified, setUnified] = _react.useState.call(void 0, null);
217
+ const [unifiedCc, setUnifiedCc] = _react.useState.call(void 0, null);
218
+ const [unifiedResponse, setUnifiedResponse] = _react.useState.call(void 0, false);
219
+ const [unifiedBilling, setUnifiedBilling] = _react.useState.call(void 0, false);
220
+ const [unifiedPayment, setUnifiedPayment] = _react.useState.call(void 0, null);
221
+ const [capturedBin, setCapturedBin] = _react.useState.call(void 0, null);
222
+ const [editCc, setEditCc] = _react.useState.call(void 0, false);
223
+ const handleBinCapture = _react.useCallback.call(void 0, (bin) => {
224
+ setCapturedBin(bin);
225
+ }, []);
226
+ const customerIdRef = _react.useRef.call(void 0, customerId);
227
+ customerIdRef.current = customerId;
228
+ const hasVerifiedRef = _react.useRef.call(void 0, null);
229
+ const postUnified = _react.useCallback.call(void 0, async () => {
230
+ if (!customerIdRef.current) return;
231
+ try {
232
+ const result = await callbacks.transactionSetup({
233
+ customerId: String(customerIdRef.current)
234
+ });
235
+ if (!result) {
236
+ toastError(callbacks, "Unable to initialize payment. Please try again.");
237
+ return;
238
+ }
239
+ setUnified(result);
240
+ } catch (error) {
241
+ console.error("transactionSetup failed:", error);
242
+ toastError(callbacks, "Unable to initialize payment. Please try again.");
243
+ }
244
+ }, [callbacks]);
245
+ const getCardInfo = _react.useCallback.call(void 0,
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.");
257
+ }
258
+ },
259
+ [callbacks]
260
+ );
261
+ const verifyUnified = _react.useCallback.call(void 0, async () => {
262
+ const transactionSetupId = _optionalChain([unified, 'optionalAccess', _5 => _5.transactionSetupId]);
263
+ if (!transactionSetupId || !customerIdRef.current) return;
264
+ try {
265
+ const result = await callbacks.validatePayment({
266
+ transactionSetupId,
267
+ customerId: String(customerIdRef.current)
268
+ });
269
+ if (result === void 0) {
270
+ toastError(callbacks, "Payment verification failed. Please try again.");
271
+ return;
272
+ }
273
+ setUnifiedResponse(result);
274
+ if (result) {
275
+ await getCardInfo(transactionSetupId);
276
+ }
277
+ } catch (error) {
278
+ console.error("validatePayment failed:", error);
279
+ toastError(callbacks, "Payment verification failed. Please try again.");
280
+ }
281
+ }, [unified, getCardInfo, callbacks]);
282
+ const getUnifiedPayment = _react.useCallback.call(void 0, async () => {
283
+ if (!_optionalChain([unified, 'optionalAccess', _6 => _6.transactionSetupId]) || !customerIdRef.current) return;
284
+ try {
285
+ const result = await callbacks.accountQuery({
286
+ transactionSetupId: unified.transactionSetupId,
287
+ customerId: String(customerIdRef.current)
288
+ });
289
+ if (!result) {
290
+ toastError(callbacks, "Unable to retrieve payment account. Please try again.");
291
+ return;
292
+ }
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);
301
+ } catch (error) {
302
+ console.error("accountQuery failed:", error);
303
+ toastError(callbacks, "Unable to retrieve payment account. Please try again.");
304
+ }
305
+ }, [unified, capturedBin, callbacks, persistPayment]);
306
+ const updateUnifiedBilling = _react.useCallback.call(void 0,
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.");
326
+ }
327
+ },
328
+ [getUnifiedPayment, callbacks]
329
+ );
330
+ _react.useEffect.call(void 0, () => {
331
+ if (isOpen && (!shippingAccepted || paymentMethod !== "credit-card")) {
332
+ setIsOpen(false);
333
+ }
334
+ }, [isOpen, shippingAccepted, paymentMethod]);
335
+ _react.useEffect.call(void 0, () => {
336
+ if (isOpen && shippingAccepted && paymentMethod === "credit-card" && unified === null) {
337
+ void postUnified();
338
+ }
339
+ }, [isOpen, shippingAccepted, paymentMethod, unified, postUnified]);
340
+ _react.useEffect.call(void 0, () => {
341
+ const setupId2 = _optionalChain([unified, 'optionalAccess', _7 => _7.transactionSetupId]);
342
+ if (!isOpen && setupId2 && shippingAccepted && paymentMethod === "credit-card") {
343
+ if (hasVerifiedRef.current === setupId2) return;
344
+ hasVerifiedRef.current = setupId2;
345
+ void verifyUnified();
346
+ }
347
+ }, [isOpen, unified, shippingAccepted, paymentMethod, verifyUnified]);
348
+ const setupId = _optionalChain([unified, 'optionalAccess', _8 => _8.transactionSetupId]);
349
+ _react.useEffect.call(void 0, () => {
350
+ if (unifiedResponse && billingAddress !== void 0 && _optionalChain([unifiedCc, 'optionalAccess', _9 => _9.transactionSetupId]) && paymentMethod === "credit-card" && setupId) {
351
+ void updateUnifiedBilling(setupId, billingAddress);
352
+ }
353
+ }, [
354
+ unifiedResponse,
355
+ billingAddress,
356
+ _optionalChain([unifiedCc, 'optionalAccess', _10 => _10.transactionSetupId]),
357
+ updateUnifiedBilling,
358
+ paymentMethod,
359
+ setupId
360
+ ]);
361
+ _react.useEffect.call(void 0, () => {
362
+ if (editCc) {
363
+ setIsOpen(true);
364
+ setUnified(null);
365
+ setUnifiedCc(null);
366
+ setUnifiedPayment(null);
367
+ setUnifiedBilling(false);
368
+ setUnifiedResponse(false);
369
+ setCapturedBin(null);
370
+ hasVerifiedRef.current = null;
371
+ if (persistPayment) {
372
+ clearFromSession(PAYMENT_STORAGE_KEY);
373
+ }
374
+ }
375
+ }, [editCc, persistPayment]);
376
+ const restorePayment = _react.useCallback.call(void 0, async () => {
377
+ if (!customerIdRef.current) return;
378
+ const saved = loadFromSession(PAYMENT_STORAGE_KEY);
379
+ if (!isRestorable(saved)) return;
380
+ const { transactionSetupId, uiEndpoint } = saved;
381
+ try {
382
+ const account = await callbacks.accountQuery({
383
+ transactionSetupId,
384
+ customerId: String(customerIdRef.current)
385
+ });
386
+ if (!_optionalChain([account, 'optionalAccess', _11 => _11.PaymentAccountID])) {
387
+ clearFromSession(PAYMENT_STORAGE_KEY);
388
+ return;
389
+ }
390
+ hasVerifiedRef.current = transactionSetupId;
391
+ setUnified({ transactionSetupId, uiEndpoint });
392
+ setUnifiedPayment(account);
393
+ setUnifiedResponse(true);
394
+ setUnifiedBilling(true);
395
+ const card = await callbacks.cardInfo({ transactionSetupId });
396
+ if (card) setUnifiedCc(card);
397
+ } catch (e4) {
398
+ clearFromSession(PAYMENT_STORAGE_KEY);
399
+ }
400
+ }, [callbacks]);
401
+ const restorePaymentRef = _react.useRef.call(void 0, restorePayment);
402
+ restorePaymentRef.current = restorePayment;
403
+ _react.useEffect.call(void 0, () => {
404
+ if (persistPayment) {
405
+ void restorePaymentRef.current();
406
+ }
407
+ }, [persistPayment]);
408
+ return {
409
+ isOpen,
410
+ setIsOpen,
411
+ editCc,
412
+ setEditCc,
413
+ unified,
414
+ unifiedCc,
415
+ unifiedResponse,
416
+ unifiedBilling,
417
+ unifiedPayment,
418
+ capturedBin,
419
+ handleBinCapture
420
+ };
421
+ }
422
+
423
+ // src/hooks/use-order-readiness.ts
424
+
425
+
426
+ // src/hooks/use-latest.ts
427
+
428
+ function useLatest(value) {
429
+ const ref = _react.useRef.call(void 0, value);
430
+ ref.current = value;
431
+ return ref;
432
+ }
433
+
434
+ // src/hooks/use-order-readiness.ts
435
+ function determineOrderReadiness(params) {
436
+ return orderReadyOf(_optionalChain([params, 'access', _12 => _12.customReadinessCheck, 'optionalCall', _13 => _13(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
+ };
456
+ }
457
+ function useOrderReadiness(params) {
458
+ const [enableProcessOrderBtn, setEnableProcessOrderBtn] = _react.useState.call(void 0, false);
459
+ const [processingValidation, setProcessingValidation] = _react.useState.call(void 0, false);
460
+ const paramsRef = useLatest(params);
461
+ _react.useEffect.call(void 0, () => {
462
+ setProcessingValidation(true);
463
+ const current = paramsRef.current;
464
+ const timeoutId = setTimeout(() => {
465
+ const ready = determineOrderReadiness(current);
466
+ setEnableProcessOrderBtn(ready);
467
+ setProcessingValidation(false);
468
+ }, 300);
469
+ return () => clearTimeout(timeoutId);
470
+ }, [
471
+ paramsRef,
472
+ params.billingAddress,
473
+ params.shippingAddress,
474
+ params.isEditShippingInfo,
475
+ params.isEditShippingMethods,
476
+ params.isEditBillingInfo,
477
+ params.editCc,
478
+ params.isFreeShipping,
479
+ params.unifiedPaymentAccountId,
480
+ params.unifiedBilling,
481
+ params.paymentMethod,
482
+ params.processingOrder,
483
+ params.carrierId,
484
+ params.shippingFee,
485
+ params.shippingMethodSaved,
486
+ params.showBillingInfoSummary,
487
+ params.cartHdrUid
488
+ ]);
489
+ return { enableProcessOrderBtn, processingValidation };
490
+ }
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+ exports.useLatest = useLatest; exports.qtyOrZero = qtyOrZero; exports.indexOfUidFrom = indexOfUidFrom; exports.keepsAfterReverse = keepsAfterReverse; exports.requiredCartUid = requiredCartUid; exports.checkoutCartUid = checkoutCartUid; exports.defaultPaymentMethodOf = defaultPaymentMethodOf; exports.preSubmitOutcome = preSubmitOutcome; exports.secondEqualsField = secondEqualsField; exports.shouldPersistOf = shouldPersistOf; exports.stockRetryDelay = stockRetryDelay; exports.stockEnabled = stockEnabled; exports.useCartStore = useCartStore; exports.useCartHdrUid = useCartHdrUid; exports.useCartLines = useCartLines; exports.useCartQuantityTotal = useCartQuantityTotal; exports.useCartLineCount = useCartLineCount; exports.useSetCartHdrUid = useSetCartHdrUid; exports.useSetCartLines = useSetCartLines; exports.useClearCart = useClearCart; exports.saveToSession = saveToSession; exports.loadFromSession = loadFromSession; exports.clearFromSession = clearFromSession; exports.useCheckoutPersistence = useCheckoutPersistence; exports.clearCheckoutPersistence = clearCheckoutPersistence; exports.PAYMENT_STORAGE_KEY = PAYMENT_STORAGE_KEY; exports.usePaymentFlow = usePaymentFlow; exports.determineOrderReadiness = determineOrderReadiness; exports.useOrderReadiness = useOrderReadiness;
523
+ //# sourceMappingURL=chunk-QB7VB5FZ.cjs.map