@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,137 +0,0 @@
1
- import * as react from 'react';
2
- import { TTransactionSetup, TCardInfo, TPaymentValidation, TAccountQuery, TBillingUpdate } from '@simpleapps-com/augur-utils';
3
-
4
- /** Site-specific payment action callbacks injected into usePaymentFlow. */
5
- interface PaymentFlowCallbacks {
6
- /** Initialize a payment session. Returns transaction setup or undefined on failure. */
7
- transactionSetup: (params: {
8
- customerId: string;
9
- }) => Promise<TTransactionSetup | undefined>;
10
- /** Retrieve card details after iframe entry. */
11
- cardInfo: (params: {
12
- transactionSetupId: string;
13
- }) => Promise<TCardInfo | undefined>;
14
- /** Verify card is valid. */
15
- validatePayment: (params: {
16
- transactionSetupId: string;
17
- customerId: string;
18
- }) => Promise<TPaymentValidation | undefined>;
19
- /** Get payment account ID. */
20
- accountQuery: (params: {
21
- transactionSetupId: string;
22
- customerId: string;
23
- }) => Promise<TAccountQuery | undefined>;
24
- /** Send billing address to payment processor. */
25
- billingUpdate: (params: {
26
- transactionSetupId: string;
27
- address1: string;
28
- address2?: string;
29
- city: string;
30
- state: string;
31
- zip: string;
32
- }) => Promise<TBillingUpdate | undefined>;
33
- /** Optional toast notification callback. */
34
- toast?: {
35
- error?: (message: string) => void;
36
- };
37
- }
38
- /** Billing address shape accepted by the payment flow. */
39
- interface PaymentBillingAddress {
40
- address1: string;
41
- address2?: string;
42
- city: string;
43
- state: string;
44
- postalCode: string;
45
- }
46
- interface UsePaymentFlowParams {
47
- callbacks: PaymentFlowCallbacks;
48
- customerId: string | number | undefined;
49
- billingAddress: PaymentBillingAddress | undefined;
50
- paymentMethod: string;
51
- shippingAccepted: boolean;
52
- /** Persist payment tokens to sessionStorage for cross-navigation recovery. */
53
- persistPayment?: boolean;
54
- }
55
- /**
56
- * Manages the full Element/Unified payment lifecycle:
57
- * transactionSetup -> cardInfo -> validatePayment -> accountQuery -> billingUpdate
58
- *
59
- * Accepts site-specific server action callbacks so the hook has no dependency
60
- * on any particular server action implementation.
61
- *
62
- * @example
63
- * ```tsx
64
- * import { usePaymentFlow } from "@simpleapps-com/augur-hooks";
65
- * import { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } from "@/lib/actions/payments";
66
- *
67
- * const payment = usePaymentFlow({
68
- * callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate },
69
- * customerId,
70
- * billingAddress,
71
- * paymentMethod: "credit-card",
72
- * shippingAccepted: true,
73
- * });
74
- * ```
75
- */
76
- declare function usePaymentFlow({ callbacks, customerId, billingAddress, paymentMethod, shippingAccepted, persistPayment, }: UsePaymentFlowParams): {
77
- isOpen: boolean;
78
- setIsOpen: react.Dispatch<react.SetStateAction<boolean>>;
79
- editCc: boolean;
80
- setEditCc: react.Dispatch<react.SetStateAction<boolean>>;
81
- unified: TTransactionSetup | null;
82
- unifiedCc: TCardInfo | null;
83
- unifiedResponse: boolean;
84
- unifiedBilling: boolean;
85
- unifiedPayment: TAccountQuery | null;
86
- capturedBin: string | null;
87
- handleBinCapture: (bin: string) => void;
88
- };
89
-
90
- /** Parameters for order readiness validation. */
91
- interface OrderReadinessParams {
92
- cartHdrUid: string | number | undefined;
93
- shippingAddress: unknown;
94
- billingAddress: unknown;
95
- shippingMethodSaved: boolean;
96
- showBillingInfoSummary: boolean;
97
- processingOrder: boolean;
98
- paymentMethod: string;
99
- unifiedPaymentAccountId: string | undefined;
100
- unifiedBilling: boolean;
101
- isFreeShipping: boolean;
102
- carrierId: string;
103
- shippingFee: number | undefined;
104
- isEditShippingInfo: boolean;
105
- isEditShippingMethods: boolean;
106
- isEditBillingInfo: boolean;
107
- editCc: boolean;
108
- /**
109
- * Site-provided function to check if the order is ready.
110
- *
111
- * Return `true` or `false` to override the default gates. Return
112
- * `undefined` to defer to the default logic (useful when the override
113
- * only applies to specific order flows — e.g. sample-only or pickup).
114
- */
115
- customReadinessCheck?: (params: OrderReadinessParams) => boolean | undefined;
116
- }
117
- /**
118
- * Pure function that determines if an order is ready to submit.
119
- *
120
- * Checks all gates: cart exists, addresses present, shipping method saved,
121
- * billing shown, payment complete (for credit card), shipping fee present
122
- * (for non-free, non-pickup orders), and no sections being edited.
123
- */
124
- declare function determineOrderReadiness(params: OrderReadinessParams): boolean;
125
- /**
126
- * Debounced order readiness hook.
127
- *
128
- * Recomputes readiness 300ms after any dependency changes to avoid
129
- * excessive re-renders during rapid state transitions (e.g., typing
130
- * in address fields).
131
- */
132
- declare function useOrderReadiness(params: OrderReadinessParams): {
133
- enableProcessOrderBtn: boolean;
134
- processingValidation: boolean;
135
- };
136
-
137
- export { type OrderReadinessParams as O, type PaymentBillingAddress as P, type PaymentFlowCallbacks as a, usePaymentFlow as b, determineOrderReadiness as d, useOrderReadiness as u };
package/dist/web.d.cts DELETED
@@ -1,60 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as react from 'react';
3
- import { ReactNode } from 'react';
4
- import { ImageConfig, ImageUrlOptions } from '@simpleapps-com/augur-utils';
5
-
6
- /**
7
- * Returns whether the screen is mobile-sized.
8
- * Uses `useSyncExternalStore` for proper SSR support.
9
- *
10
- * - SSR-safe: returns false on server, updates on client after hydration
11
- * - Single listener: one resize listener regardless of component count
12
- * - Throttled: resize events throttled to prevent excessive re-renders
13
- */
14
- declare function useIsMobile(): boolean;
15
- interface MobileProviderProps {
16
- children: ReactNode;
17
- }
18
- /**
19
- * Optional provider that tracks hydration state.
20
- * Wrap your app with this if you need to conditionally render
21
- * mobile-only content after hydration.
22
- */
23
- declare function MobileProvider({ children }: MobileProviderProps): react_jsx_runtime.JSX.Element;
24
- /**
25
- * Returns true only after the client has hydrated.
26
- * Prevents hydration mismatches with conditional rendering.
27
- */
28
- declare function useIsHydrated(): boolean;
29
-
30
- interface UseMobileOptimizedIntersectionOptions {
31
- rootMarginMobile?: string;
32
- rootMarginDesktop?: string;
33
- threshold?: number;
34
- enabled?: boolean;
35
- mobileBreakpoint?: number;
36
- }
37
- /**
38
- * IntersectionObserver hook with mobile-optimized root margins.
39
- * Uses larger margins on mobile for more aggressive prefetching/lazy loading.
40
- */
41
- declare const useMobileOptimizedIntersection: ({ rootMarginMobile, rootMarginDesktop, threshold, enabled, mobileBreakpoint, }?: UseMobileOptimizedIntersectionOptions) => {
42
- ref: react.RefObject<HTMLDivElement | null>;
43
- isIntersecting: boolean;
44
- };
45
-
46
- interface UseImageWithFallbackResult {
47
- src: string;
48
- isLoading: boolean;
49
- hasError: boolean;
50
- }
51
- /**
52
- * Preloads an agr.media image and shows a fallback while loading.
53
- *
54
- * 1. Returns the default image immediately.
55
- * 2. Preloads the real image via `new Image()`.
56
- * 3. Swaps to the real URL on success; keeps the fallback on error.
57
- */
58
- declare function useImageWithFallback(config: ImageConfig, imagePath: string | undefined, options?: ImageUrlOptions): UseImageWithFallbackResult;
59
-
60
- export { MobileProvider, useImageWithFallback, useIsHydrated, useIsMobile, useMobileOptimizedIntersection };