@simpleapps-com/augur-hooks 2.2.13 → 2.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cart-pricing-DGlwKSqt.d.cts → cart-pricing-CTMlA3nE.d.cts} +1 -0
- package/dist/{cart-pricing-DGlwKSqt.d.ts → cart-pricing-CTMlA3nE.d.ts} +1 -0
- package/dist/checkout/index.cjs +311 -0
- package/dist/checkout/index.cjs.map +1 -0
- package/dist/checkout/index.d.cts +231 -0
- package/dist/checkout/index.d.ts +231 -0
- package/dist/checkout/index.js +311 -0
- package/dist/checkout/index.js.map +1 -0
- package/dist/chunk-AJ2TD5BG.js +225 -0
- package/dist/chunk-AJ2TD5BG.js.map +1 -0
- package/dist/{chunk-Q7OENJHD.js → chunk-GHON6UMJ.js} +1 -1
- package/dist/chunk-GHON6UMJ.js.map +1 -0
- package/dist/chunk-SSOW6W53.cjs +225 -0
- package/dist/chunk-SSOW6W53.cjs.map +1 -0
- package/dist/{chunk-PBKAAR53.cjs → chunk-XJJ6DZDK.cjs} +1 -1
- package/dist/chunk-XJJ6DZDK.cjs.map +1 -0
- package/dist/index.cjs +102 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -81
- package/dist/index.d.ts +90 -81
- package/dist/index.js +102 -166
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +3 -3
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/use-payment-flow-DF8OEQiq.d.cts +88 -0
- package/dist/use-payment-flow-DF8OEQiq.d.ts +88 -0
- package/package.json +8 -3
- package/dist/chunk-PBKAAR53.cjs.map +0 -1
- package/dist/chunk-Q7OENJHD.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { P as PersistenceConfig } from './cart-pricing-
|
|
2
|
-
export { A as AugurApiClient, a as AugurHooksProvider, B as BatchQueryConfig, G as GetItemCategoryApiOptions, b as PageData, e as executeBatchQuery, g as getCartPricingQueryOptions, c as getStockKey, d as getStockOptions, u as useAugurApi, f as useAugurApiOptional, h as useAugurAuth, i as useAugurCache, j as useAugurOptions, k as useAugurSite } from './cart-pricing-
|
|
1
|
+
import { P as PersistenceConfig } from './cart-pricing-CTMlA3nE.js';
|
|
2
|
+
export { A as AugurApiClient, a as AugurHooksProvider, B as BatchQueryConfig, G as GetItemCategoryApiOptions, b as PageData, e as executeBatchQuery, g as getCartPricingQueryOptions, c as getStockKey, d as getStockOptions, u as useAugurApi, f as useAugurApiOptional, h as useAugurAuth, i as useAugurCache, j as useAugurOptions, k as useAugurSite } from './cart-pricing-CTMlA3nE.js';
|
|
3
3
|
export { AugurAuthContext, AugurSiteConfig, AugurSiteDefaults, AugurSiteFormatting, CacheConfig, CacheProvider, CacheTierConfig, DeepQueryOptions, EdgeCacheValue, InfiniteScrollPage, ProxyMutationOptions, ProxyQueryOptions } from '@simpleapps-com/augur-core';
|
|
4
4
|
import * as zustand from 'zustand';
|
|
5
5
|
import * as _simpleapps_com_augur_utils from '@simpleapps-com/augur-utils';
|
|
6
|
-
import { TCartLine, TItemsFilters, TStock,
|
|
6
|
+
import { TCartLine, TItemsFilters, TStock, TPriceData } from '@simpleapps-com/augur-utils';
|
|
7
7
|
export { DerivePriceInput, DerivedPrice, ResolveStockInput, ResolvedStock, TSearchSuggestion as SearchSuggestion, TSearchSuggestionsResponse as SearchSuggestionsResponse } from '@simpleapps-com/augur-utils';
|
|
8
|
-
|
|
8
|
+
export { P as PaymentBillingAddress, a as PaymentFlowCallbacks, u as usePaymentFlow } from './use-payment-flow-DF8OEQiq.js';
|
|
9
9
|
import { QueryKey } from '@tanstack/react-query';
|
|
10
10
|
import * as _tanstack_react_query_persist_client from '@tanstack/react-query-persist-client';
|
|
11
11
|
import 'react/jsx-runtime';
|
|
12
|
+
import 'react';
|
|
12
13
|
import '@simpleapps-com/augur-api';
|
|
13
14
|
|
|
14
15
|
/** Internal state shape for the cart Zustand store. */
|
|
@@ -212,90 +213,98 @@ declare function useCartActions(callbacks: CartActionCallbacks): {
|
|
|
212
213
|
invalidateCartCache: () => void;
|
|
213
214
|
};
|
|
214
215
|
|
|
215
|
-
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}) => Promise<TAccountQuery | undefined>;
|
|
235
|
-
/** Send billing address to payment processor. */
|
|
236
|
-
billingUpdate: (params: {
|
|
237
|
-
transactionSetupId: string;
|
|
238
|
-
address1: string;
|
|
239
|
-
address2?: string;
|
|
240
|
-
city: string;
|
|
241
|
-
state: string;
|
|
242
|
-
zip: string;
|
|
243
|
-
}) => Promise<TBillingUpdate | undefined>;
|
|
244
|
-
/** Optional toast notification callback. */
|
|
245
|
-
toast?: {
|
|
246
|
-
error?: (message: string) => void;
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
/** Billing address shape accepted by the payment flow. */
|
|
250
|
-
interface PaymentBillingAddress {
|
|
251
|
-
address1: string;
|
|
252
|
-
address2?: string;
|
|
253
|
-
city: string;
|
|
254
|
-
state: string;
|
|
255
|
-
postalCode: string;
|
|
256
|
-
}
|
|
257
|
-
interface UsePaymentFlowParams {
|
|
258
|
-
callbacks: PaymentFlowCallbacks;
|
|
259
|
-
customerId: string | number | undefined;
|
|
260
|
-
billingAddress: PaymentBillingAddress | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Shared modal lifecycle hook -- scroll lock, Escape key, client-side hydration gate.
|
|
218
|
+
*
|
|
219
|
+
* Locks body scroll when the modal is open and restores it on close.
|
|
220
|
+
* Listens for Escape key to trigger onClose. Returns isClient for
|
|
221
|
+
* hydration-safe conditional rendering.
|
|
222
|
+
*/
|
|
223
|
+
declare function useModalLifecycle(isOpen: boolean, onClose: () => void): {
|
|
224
|
+
isClient: boolean;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/** Parameters for order readiness validation. */
|
|
228
|
+
interface OrderReadinessParams {
|
|
229
|
+
cartHdrUid: string | number | undefined;
|
|
230
|
+
shippingAddress: unknown;
|
|
231
|
+
billingAddress: unknown;
|
|
232
|
+
shippingMethodSaved: boolean;
|
|
233
|
+
showBillingInfoSummary: boolean;
|
|
234
|
+
processingOrder: boolean;
|
|
261
235
|
paymentMethod: string;
|
|
262
|
-
|
|
236
|
+
unifiedPaymentAccountId: string | undefined;
|
|
237
|
+
unifiedBilling: boolean;
|
|
238
|
+
isFreeShipping: boolean;
|
|
239
|
+
carrierId: string;
|
|
240
|
+
shippingFee: number | undefined;
|
|
241
|
+
isEditShippingInfo: boolean;
|
|
242
|
+
isEditShippingMethods: boolean;
|
|
243
|
+
isEditBillingInfo: boolean;
|
|
244
|
+
editCc: boolean;
|
|
245
|
+
/** Site-provided function to check if the order is ready. Overrides default logic when provided. */
|
|
246
|
+
customReadinessCheck?: (params: OrderReadinessParams) => boolean;
|
|
263
247
|
}
|
|
264
248
|
/**
|
|
265
|
-
*
|
|
266
|
-
* transactionSetup -> cardInfo -> validatePayment -> accountQuery -> billingUpdate
|
|
267
|
-
*
|
|
268
|
-
* Accepts site-specific server action callbacks so the hook has no dependency
|
|
269
|
-
* on any particular server action implementation.
|
|
249
|
+
* Pure function that determines if an order is ready to submit.
|
|
270
250
|
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
|
|
251
|
+
* Checks all gates: cart exists, addresses present, shipping method saved,
|
|
252
|
+
* billing shown, payment complete (for credit card), shipping fee present
|
|
253
|
+
* (for non-free, non-pickup orders), and no sections being edited.
|
|
254
|
+
*/
|
|
255
|
+
declare function determineOrderReadiness(params: OrderReadinessParams): boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Debounced order readiness hook.
|
|
275
258
|
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* billingAddress,
|
|
280
|
-
* paymentMethod: "credit-card",
|
|
281
|
-
* shippingAccepted: true,
|
|
282
|
-
* });
|
|
283
|
-
* ```
|
|
259
|
+
* Recomputes readiness 300ms after any dependency changes to avoid
|
|
260
|
+
* excessive re-renders during rapid state transitions (e.g., typing
|
|
261
|
+
* in address fields).
|
|
284
262
|
*/
|
|
285
|
-
declare function
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
editCc: boolean;
|
|
289
|
-
setEditCc: react.Dispatch<react.SetStateAction<boolean>>;
|
|
290
|
-
unified: TTransactionSetup | null;
|
|
291
|
-
unifiedCc: TCardInfo | null;
|
|
292
|
-
unifiedResponse: boolean;
|
|
293
|
-
unifiedBilling: boolean;
|
|
294
|
-
unifiedPayment: TAccountQuery | null;
|
|
295
|
-
capturedBin: string | null;
|
|
296
|
-
handleBinCapture: (bin: string) => void;
|
|
263
|
+
declare function useOrderReadiness(params: OrderReadinessParams): {
|
|
264
|
+
enableProcessOrderBtn: boolean;
|
|
265
|
+
processingValidation: boolean;
|
|
297
266
|
};
|
|
298
267
|
|
|
268
|
+
/** A single persisted field with its storage key and optional TTL. */
|
|
269
|
+
interface CheckoutPersistField<T> {
|
|
270
|
+
key: string;
|
|
271
|
+
value: T;
|
|
272
|
+
set: (value: T) => void;
|
|
273
|
+
/** Valibot or custom validator. Return the parsed value or throw to reject. */
|
|
274
|
+
validate?: (raw: unknown) => T;
|
|
275
|
+
/** TTL in milliseconds. Default: 30 minutes. */
|
|
276
|
+
ttl?: number;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Saves a value to sessionStorage with a timestamp for TTL expiration.
|
|
280
|
+
*
|
|
281
|
+
* Fails silently on storage errors (private browsing, quota exceeded).
|
|
282
|
+
*/
|
|
283
|
+
declare function saveToSession(key: string, value: unknown): void;
|
|
284
|
+
/**
|
|
285
|
+
* Loads a value from sessionStorage, checking TTL and optionally validating.
|
|
286
|
+
*
|
|
287
|
+
* Returns null if missing, expired, invalid, or storage is unavailable.
|
|
288
|
+
* Cleans up expired entries automatically.
|
|
289
|
+
*/
|
|
290
|
+
declare function loadFromSession<T>(key: string, ttl?: number, validate?: (raw: unknown) => T): T | null;
|
|
291
|
+
/** Removes a checkout persistence key from sessionStorage. */
|
|
292
|
+
declare function clearFromSession(key: string): void;
|
|
293
|
+
/**
|
|
294
|
+
* Hook that persists checkout state fields to sessionStorage and restores on mount.
|
|
295
|
+
*
|
|
296
|
+
* Each field is saved when its value changes and restored once on initial mount.
|
|
297
|
+
* Validates restored values against an optional schema to guard against
|
|
298
|
+
* corrupted or stale storage. Expired entries (past TTL) are discarded.
|
|
299
|
+
*/
|
|
300
|
+
declare function useCheckoutPersistence(fields: CheckoutPersistField<unknown>[]): void;
|
|
301
|
+
/**
|
|
302
|
+
* Clears all checkout persistence keys from sessionStorage.
|
|
303
|
+
*
|
|
304
|
+
* Call after successful order submission to prevent stale data on next checkout.
|
|
305
|
+
*/
|
|
306
|
+
declare function clearCheckoutPersistence(keys: string[]): void;
|
|
307
|
+
|
|
299
308
|
/** Session info passed from the consumer's auth system. */
|
|
300
309
|
interface CartSessionInfo {
|
|
301
310
|
/** Auth status: "loading" | "authenticated" | "unauthenticated" */
|
|
@@ -485,4 +494,4 @@ declare function registerQueryAction(fn: QueryActionFn): void;
|
|
|
485
494
|
/** Returns the registered query action, or null if none registered. */
|
|
486
495
|
declare function getRegisteredQueryAction(): QueryActionFn | null;
|
|
487
496
|
|
|
488
|
-
export { type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type
|
|
497
|
+
export { type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type CheckoutPersistField, type FormatPriceCallOptions, type OrderReadinessParams, PersistenceConfig, type UseFormatPriceOptions, type UseStockOptions, clearCheckoutPersistence, clearFromSession, determineOrderReadiness, getRegisteredQueryAction, loadFromSession, registerQueryAction, saveToSession, useAugurPersistence, useCartActions, useCartHdrUid, useCartInitialization, useCartLineCount, useCartLines, useCartPricing, useCartQuantityTotal, useCartStore, useCheckoutPersistence, useClearCart, useDebounce, useFormatPrice, useItemFiltersStore, useModalLifecycle, useOrderReadiness, usePaginationPrefetch, useSetCartHdrUid, useSetCartLines, useStock };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,12 @@ import {
|
|
|
5
5
|
getStockKey,
|
|
6
6
|
getStockOptions,
|
|
7
7
|
registerQueryAction
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GHON6UMJ.js";
|
|
9
|
+
import {
|
|
10
|
+
determineOrderReadiness,
|
|
11
|
+
useOrderReadiness,
|
|
12
|
+
usePaymentFlow
|
|
13
|
+
} from "./chunk-AJ2TD5BG.js";
|
|
9
14
|
|
|
10
15
|
// src/provider.tsx
|
|
11
16
|
import { createContext, useContext, useMemo } from "react";
|
|
@@ -400,168 +405,91 @@ function useCartActions(callbacks) {
|
|
|
400
405
|
};
|
|
401
406
|
}
|
|
402
407
|
|
|
403
|
-
// src/hooks/use-
|
|
404
|
-
import {
|
|
405
|
-
function
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
paymentMethod,
|
|
410
|
-
shippingAccepted
|
|
411
|
-
}) {
|
|
412
|
-
const [isOpen, setIsOpen] = useState2(false);
|
|
413
|
-
const [unified, setUnified] = useState2(null);
|
|
414
|
-
const [unifiedCc, setUnifiedCc] = useState2(null);
|
|
415
|
-
const [unifiedResponse, setUnifiedResponse] = useState2(false);
|
|
416
|
-
const [unifiedBilling, setUnifiedBilling] = useState2(false);
|
|
417
|
-
const [unifiedPayment, setUnifiedPayment] = useState2(null);
|
|
418
|
-
const [capturedBin, setCapturedBin] = useState2(null);
|
|
419
|
-
const [editCc, setEditCc] = useState2(false);
|
|
420
|
-
const handleBinCapture = useCallback2((bin) => {
|
|
421
|
-
setCapturedBin(bin);
|
|
408
|
+
// src/hooks/use-modal-lifecycle.ts
|
|
409
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
410
|
+
function useModalLifecycle(isOpen, onClose) {
|
|
411
|
+
const [isClient, setIsClient] = useState2(false);
|
|
412
|
+
useEffect2(() => {
|
|
413
|
+
setIsClient(true);
|
|
422
414
|
}, []);
|
|
423
|
-
const postUnified = useCallback2(async () => {
|
|
424
|
-
if (!customerId) return;
|
|
425
|
-
try {
|
|
426
|
-
const result = await callbacks.transactionSetup({ customerId: String(customerId) });
|
|
427
|
-
if (!result) {
|
|
428
|
-
callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
setUnified(result);
|
|
432
|
-
} catch (error) {
|
|
433
|
-
console.error("transactionSetup failed:", error);
|
|
434
|
-
callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
|
|
435
|
-
}
|
|
436
|
-
}, [customerId, callbacks]);
|
|
437
|
-
const getCardInfo = useCallback2(async () => {
|
|
438
|
-
if (!unified?.transactionSetupId) return;
|
|
439
|
-
try {
|
|
440
|
-
const result = await callbacks.cardInfo({ transactionSetupId: unified.transactionSetupId });
|
|
441
|
-
if (!result) {
|
|
442
|
-
callbacks.toast?.error?.("Unable to verify card details. Please try again.");
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
setUnifiedCc(result);
|
|
446
|
-
} catch (error) {
|
|
447
|
-
console.error("cardInfo failed:", error);
|
|
448
|
-
callbacks.toast?.error?.("Unable to verify card details. Please try again.");
|
|
449
|
-
}
|
|
450
|
-
}, [unified, callbacks]);
|
|
451
|
-
const verifyUnified = useCallback2(async () => {
|
|
452
|
-
if (!unified?.transactionSetupId || !customerId) return;
|
|
453
|
-
try {
|
|
454
|
-
const result = await callbacks.validatePayment({
|
|
455
|
-
transactionSetupId: unified.transactionSetupId,
|
|
456
|
-
customerId: String(customerId)
|
|
457
|
-
});
|
|
458
|
-
if (!result) {
|
|
459
|
-
callbacks.toast?.error?.("Payment verification failed. Please try again.");
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
setUnifiedResponse(result.valid);
|
|
463
|
-
if (result.valid) {
|
|
464
|
-
await getCardInfo();
|
|
465
|
-
}
|
|
466
|
-
} catch (error) {
|
|
467
|
-
console.error("validatePayment failed:", error);
|
|
468
|
-
callbacks.toast?.error?.("Payment verification failed. Please try again.");
|
|
469
|
-
}
|
|
470
|
-
}, [unified, customerId, getCardInfo, callbacks]);
|
|
471
|
-
const getUnifiedPayment = useCallback2(async () => {
|
|
472
|
-
if (!unified?.transactionSetupId || !customerId) return;
|
|
473
|
-
try {
|
|
474
|
-
const result = await callbacks.accountQuery({
|
|
475
|
-
transactionSetupId: unified.transactionSetupId,
|
|
476
|
-
customerId: String(customerId)
|
|
477
|
-
});
|
|
478
|
-
if (!result) {
|
|
479
|
-
callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
const payment = capturedBin && !result.Bin ? { ...result, Bin: capturedBin } : result;
|
|
483
|
-
setUnifiedPayment(payment);
|
|
484
|
-
} catch (error) {
|
|
485
|
-
console.error("accountQuery failed:", error);
|
|
486
|
-
callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
|
|
487
|
-
}
|
|
488
|
-
}, [unified, customerId, capturedBin, callbacks]);
|
|
489
|
-
const updateUnifiedBilling = useCallback2(async () => {
|
|
490
|
-
if (!unified?.transactionSetupId || !billingAddress) return;
|
|
491
|
-
try {
|
|
492
|
-
const result = await callbacks.billingUpdate({
|
|
493
|
-
transactionSetupId: unified.transactionSetupId,
|
|
494
|
-
address1: billingAddress.address1,
|
|
495
|
-
address2: billingAddress.address2,
|
|
496
|
-
city: billingAddress.city,
|
|
497
|
-
state: billingAddress.state,
|
|
498
|
-
zip: billingAddress.postalCode
|
|
499
|
-
});
|
|
500
|
-
if (!result) {
|
|
501
|
-
callbacks.toast?.error?.("Billing update failed. Please try again.");
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
setUnifiedBilling(true);
|
|
505
|
-
void getUnifiedPayment();
|
|
506
|
-
} catch (error) {
|
|
507
|
-
console.error("billingUpdate failed:", error);
|
|
508
|
-
callbacks.toast?.error?.("Billing update failed. Please try again.");
|
|
509
|
-
}
|
|
510
|
-
}, [unified, billingAddress, getUnifiedPayment, callbacks]);
|
|
511
415
|
useEffect2(() => {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
416
|
+
document.body.style.overflow = isOpen ? "hidden" : "auto";
|
|
417
|
+
return () => {
|
|
418
|
+
document.body.style.overflow = "auto";
|
|
419
|
+
};
|
|
420
|
+
}, [isOpen]);
|
|
516
421
|
useEffect2(() => {
|
|
517
|
-
|
|
518
|
-
|
|
422
|
+
const handleEscape = (e) => {
|
|
423
|
+
if (e.key === "Escape" && isOpen) onClose();
|
|
424
|
+
};
|
|
425
|
+
document.addEventListener("keydown", handleEscape);
|
|
426
|
+
return () => document.removeEventListener("keydown", handleEscape);
|
|
427
|
+
}, [isOpen, onClose]);
|
|
428
|
+
return { isClient };
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/hooks/use-checkout-persistence.ts
|
|
432
|
+
import { useEffect as useEffect3, useRef } from "react";
|
|
433
|
+
var DEFAULT_TTL = 30 * 60 * 1e3;
|
|
434
|
+
function saveToSession(key, value) {
|
|
435
|
+
try {
|
|
436
|
+
const entry = { value, savedAt: Date.now() };
|
|
437
|
+
sessionStorage.setItem(key, JSON.stringify(entry));
|
|
438
|
+
} catch {
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
function loadFromSession(key, ttl = DEFAULT_TTL, validate) {
|
|
442
|
+
try {
|
|
443
|
+
const raw = sessionStorage.getItem(key);
|
|
444
|
+
if (!raw) return null;
|
|
445
|
+
const entry = JSON.parse(raw);
|
|
446
|
+
if (Date.now() - entry.savedAt > ttl) {
|
|
447
|
+
sessionStorage.removeItem(key);
|
|
448
|
+
return null;
|
|
519
449
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
if (!isOpen && unified !== null && shippingAccepted && paymentMethod === "credit-card") {
|
|
523
|
-
void verifyUnified();
|
|
450
|
+
if (validate) {
|
|
451
|
+
return validate(entry.value);
|
|
524
452
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
453
|
+
return entry.value;
|
|
454
|
+
} catch {
|
|
455
|
+
sessionStorage.removeItem(key);
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function clearFromSession(key) {
|
|
460
|
+
try {
|
|
461
|
+
sessionStorage.removeItem(key);
|
|
462
|
+
} catch {
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function useCheckoutPersistence(fields) {
|
|
466
|
+
const fieldsRef = useRef(fields);
|
|
467
|
+
fieldsRef.current = fields;
|
|
468
|
+
useEffect3(() => {
|
|
469
|
+
for (const field of fieldsRef.current) {
|
|
470
|
+
const restored = loadFromSession(field.key, field.ttl ?? DEFAULT_TTL, field.validate);
|
|
471
|
+
if (restored !== null) {
|
|
472
|
+
field.set(restored);
|
|
473
|
+
}
|
|
529
474
|
}
|
|
530
|
-
}, [
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
useEffect2(() => {
|
|
538
|
-
if (editCc) {
|
|
539
|
-
setIsOpen(true);
|
|
540
|
-
setUnified(null);
|
|
541
|
-
setUnifiedCc(null);
|
|
542
|
-
setUnifiedPayment(null);
|
|
543
|
-
setUnifiedBilling(false);
|
|
544
|
-
setUnifiedResponse(false);
|
|
545
|
-
setCapturedBin(null);
|
|
475
|
+
}, []);
|
|
476
|
+
const serialized = JSON.stringify(fields.map((f) => [f.key, f.value]));
|
|
477
|
+
useEffect3(() => {
|
|
478
|
+
for (const field of fields) {
|
|
479
|
+
if (field.value !== void 0 && field.value !== null) {
|
|
480
|
+
saveToSession(field.key, field.value);
|
|
481
|
+
}
|
|
546
482
|
}
|
|
547
|
-
}, [
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
unified,
|
|
554
|
-
unifiedCc,
|
|
555
|
-
unifiedResponse,
|
|
556
|
-
unifiedBilling,
|
|
557
|
-
unifiedPayment,
|
|
558
|
-
capturedBin,
|
|
559
|
-
handleBinCapture
|
|
560
|
-
};
|
|
483
|
+
}, [serialized]);
|
|
484
|
+
}
|
|
485
|
+
function clearCheckoutPersistence(keys) {
|
|
486
|
+
for (const key of keys) {
|
|
487
|
+
clearFromSession(key);
|
|
488
|
+
}
|
|
561
489
|
}
|
|
562
490
|
|
|
563
491
|
// src/hooks/use-cart-initialization.ts
|
|
564
|
-
import { useEffect as
|
|
492
|
+
import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef2 } from "react";
|
|
565
493
|
import { useQuery as useQuery2, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
566
494
|
var MAX_RETRY_ATTEMPTS = 7;
|
|
567
495
|
var RETRY_DELAY_MS = 1e3;
|
|
@@ -585,10 +513,10 @@ function useCartInitialization(session, callbacks) {
|
|
|
585
513
|
() => ({ status: effectiveStatus, userId: effectiveUserId, cartHdrUid: effectiveCartHdrUid }),
|
|
586
514
|
[effectiveStatus, effectiveUserId, effectiveCartHdrUid]
|
|
587
515
|
);
|
|
588
|
-
const retryCountRef =
|
|
589
|
-
const isInitializingRef =
|
|
590
|
-
const prevStatusRef =
|
|
591
|
-
|
|
516
|
+
const retryCountRef = useRef2(0);
|
|
517
|
+
const isInitializingRef = useRef2(false);
|
|
518
|
+
const prevStatusRef = useRef2(effectiveSession.status);
|
|
519
|
+
useEffect4(() => {
|
|
592
520
|
const prevStatus = prevStatusRef.current;
|
|
593
521
|
prevStatusRef.current = effectiveSession.status;
|
|
594
522
|
if (prevStatus === "authenticated" && effectiveSession.status === "unauthenticated") {
|
|
@@ -597,7 +525,7 @@ function useCartInitialization(session, callbacks) {
|
|
|
597
525
|
queryClient.removeQueries({ queryKey: ["cart-also-bought"] });
|
|
598
526
|
}
|
|
599
527
|
}, [effectiveSession.status, clearCart, queryClient]);
|
|
600
|
-
|
|
528
|
+
useEffect4(() => {
|
|
601
529
|
if (cartHdrUid || effectiveSession.status === "loading") return;
|
|
602
530
|
if (effectiveSession.cartHdrUid && effectiveSession.status === "authenticated") {
|
|
603
531
|
setCartHdrUid(effectiveSession.cartHdrUid);
|
|
@@ -654,7 +582,7 @@ function useCartInitialization(session, callbacks) {
|
|
|
654
582
|
queryFn: async () => await callbacks.getCartLines(Number(cartHdrUid)) ?? [],
|
|
655
583
|
enabled: !!cartHdrUid
|
|
656
584
|
});
|
|
657
|
-
|
|
585
|
+
useEffect4(() => {
|
|
658
586
|
if (cartLinesData) {
|
|
659
587
|
setCartLines(cartLinesData);
|
|
660
588
|
}
|
|
@@ -754,7 +682,7 @@ function useCartPricing(options = {}) {
|
|
|
754
682
|
|
|
755
683
|
// src/hooks/use-pagination-prefetch.ts
|
|
756
684
|
import { useQueryClient as useQueryClient3 } from "@tanstack/react-query";
|
|
757
|
-
import { useCallback as
|
|
685
|
+
import { useCallback as useCallback2 } from "react";
|
|
758
686
|
var usePaginationPrefetch = ({
|
|
759
687
|
queryKey,
|
|
760
688
|
queryFn,
|
|
@@ -765,7 +693,7 @@ var usePaginationPrefetch = ({
|
|
|
765
693
|
enabled = true
|
|
766
694
|
}) => {
|
|
767
695
|
const queryClient = useQueryClient3();
|
|
768
|
-
const prefetchPage =
|
|
696
|
+
const prefetchPage = useCallback2(
|
|
769
697
|
async (page) => {
|
|
770
698
|
if (!enabled) return;
|
|
771
699
|
const offset = (page - 1) * pageSize;
|
|
@@ -782,7 +710,7 @@ var usePaginationPrefetch = ({
|
|
|
782
710
|
},
|
|
783
711
|
[queryKey, queryFn, pageSize, queryKeyFn, staleTime, gcTime, queryClient, enabled]
|
|
784
712
|
);
|
|
785
|
-
const handlePaginationHover =
|
|
713
|
+
const handlePaginationHover = useCallback2(
|
|
786
714
|
(page) => {
|
|
787
715
|
const timeoutId = setTimeout(() => prefetchPage(page), 150);
|
|
788
716
|
return () => clearTimeout(timeoutId);
|
|
@@ -796,7 +724,7 @@ var usePaginationPrefetch = ({
|
|
|
796
724
|
};
|
|
797
725
|
|
|
798
726
|
// src/persistence/use-persistence.ts
|
|
799
|
-
import { useState as useState3, useEffect as
|
|
727
|
+
import { useState as useState3, useEffect as useEffect6, useMemo as useMemo5 } from "react";
|
|
800
728
|
|
|
801
729
|
// src/persistence/serializer.ts
|
|
802
730
|
function serialize(data) {
|
|
@@ -892,12 +820,12 @@ function createPersister(config) {
|
|
|
892
820
|
}
|
|
893
821
|
|
|
894
822
|
// src/persistence/use-storage-monitor.ts
|
|
895
|
-
import { useEffect as
|
|
823
|
+
import { useEffect as useEffect5 } from "react";
|
|
896
824
|
var CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
897
825
|
function useStorageMonitor(config) {
|
|
898
826
|
const { key, limits = {}, maxStorageMB = 3 } = config;
|
|
899
827
|
const limitKeys = Object.keys(limits);
|
|
900
|
-
|
|
828
|
+
useEffect5(() => {
|
|
901
829
|
if (typeof window === "undefined" || limitKeys.length === 0) return;
|
|
902
830
|
function evict() {
|
|
903
831
|
const storage = window.localStorage;
|
|
@@ -935,7 +863,7 @@ function useStorageMonitor(config) {
|
|
|
935
863
|
function useAugurPersistence(config) {
|
|
936
864
|
const [persister] = useState3(() => createPersister(config));
|
|
937
865
|
const [isMounted, setIsMounted] = useState3(false);
|
|
938
|
-
|
|
866
|
+
useEffect6(() => {
|
|
939
867
|
setIsMounted(true);
|
|
940
868
|
}, []);
|
|
941
869
|
useStorageMonitor(config);
|
|
@@ -961,12 +889,17 @@ function useAugurPersistence(config) {
|
|
|
961
889
|
}
|
|
962
890
|
export {
|
|
963
891
|
AugurHooksProvider,
|
|
892
|
+
clearCheckoutPersistence,
|
|
893
|
+
clearFromSession,
|
|
894
|
+
determineOrderReadiness,
|
|
964
895
|
executeBatchQuery,
|
|
965
896
|
getCartPricingQueryOptions,
|
|
966
897
|
getRegisteredQueryAction,
|
|
967
898
|
getStockKey,
|
|
968
899
|
getStockOptions,
|
|
900
|
+
loadFromSession,
|
|
969
901
|
registerQueryAction,
|
|
902
|
+
saveToSession,
|
|
970
903
|
useAugurApi,
|
|
971
904
|
useAugurApiOptional,
|
|
972
905
|
useAugurAuth,
|
|
@@ -982,10 +915,13 @@ export {
|
|
|
982
915
|
useCartPricing,
|
|
983
916
|
useCartQuantityTotal,
|
|
984
917
|
useCartStore,
|
|
918
|
+
useCheckoutPersistence,
|
|
985
919
|
useClearCart,
|
|
986
920
|
useDebounce,
|
|
987
921
|
useFormatPrice,
|
|
988
922
|
useItemFiltersStore,
|
|
923
|
+
useModalLifecycle,
|
|
924
|
+
useOrderReadiness,
|
|
989
925
|
usePaginationPrefetch,
|
|
990
926
|
usePaymentFlow,
|
|
991
927
|
useSetCartHdrUid,
|