@simpleapps-com/augur-hooks 2.4.0 → 2026.11.2
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/EXPORTS.md +25 -65
- package/README.md +21 -246
- package/dist/checkout/create-checkout-provider.d.ts +25 -0
- package/dist/checkout/create-checkout-provider.d.ts.map +1 -0
- package/dist/checkout/index.cjs +123 -106
- package/dist/checkout/index.cjs.map +1 -1
- package/dist/checkout/index.d.ts +5 -293
- package/dist/checkout/index.d.ts.map +1 -0
- package/dist/checkout/index.js +99 -82
- package/dist/checkout/index.js.map +1 -1
- package/dist/checkout/{index.d.cts → types.d.ts} +18 -40
- package/dist/checkout/types.d.ts.map +1 -0
- package/dist/chunk-6Z6JGK2C.cjs.map +1 -1
- package/dist/chunk-JJX23M5N.js +532 -0
- package/dist/chunk-JJX23M5N.js.map +1 -0
- package/dist/chunk-UZAFXUAO.cjs +532 -0
- package/dist/chunk-UZAFXUAO.cjs.map +1 -0
- package/dist/duration.d.ts +16 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/hooks/use-cart-actions.d.ts +68 -0
- package/dist/hooks/use-cart-actions.d.ts.map +1 -0
- package/dist/hooks/use-cart-initialization.d.ts +60 -0
- package/dist/hooks/use-cart-initialization.d.ts.map +1 -0
- package/dist/hooks/use-cart-pricing.d.ts +41 -0
- package/dist/hooks/use-cart-pricing.d.ts.map +1 -0
- package/dist/hooks/use-checkout-persistence.d.ts +41 -0
- package/dist/hooks/use-checkout-persistence.d.ts.map +1 -0
- package/dist/hooks/use-debounce.d.ts +6 -0
- package/dist/hooks/use-debounce.d.ts.map +1 -0
- package/dist/hooks/use-format-price.d.ts +29 -0
- package/dist/hooks/use-format-price.d.ts.map +1 -0
- package/dist/hooks/use-latest.d.ts +8 -0
- package/dist/hooks/use-latest.d.ts.map +1 -0
- package/dist/hooks/use-modal-lifecycle.d.ts +11 -0
- package/dist/hooks/use-modal-lifecycle.d.ts.map +1 -0
- package/dist/hooks/use-order-readiness.d.ts +47 -0
- package/dist/hooks/use-order-readiness.d.ts.map +1 -0
- package/dist/hooks/use-pagination-prefetch.d.ts +27 -0
- package/dist/hooks/use-pagination-prefetch.d.ts.map +1 -0
- package/dist/{use-order-readiness-DZTIfRzw.d.ts → hooks/use-payment-flow.d.ts} +23 -67
- package/dist/hooks/use-payment-flow.d.ts.map +1 -0
- package/dist/hooks/use-stock.d.ts +32 -0
- package/dist/hooks/use-stock.d.ts.map +1 -0
- package/dist/index.cjs +227 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -456
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +205 -162
- package/dist/index.js.map +1 -1
- package/dist/persistence/apply-limits.d.ts +8 -0
- package/dist/persistence/apply-limits.d.ts.map +1 -0
- package/dist/persistence/create-persister.d.ts +10 -0
- package/dist/persistence/create-persister.d.ts.map +1 -0
- package/dist/persistence/serializer.d.ts +11 -0
- package/dist/persistence/serializer.d.ts.map +1 -0
- package/dist/persistence/use-persistence.d.ts +59 -0
- package/dist/persistence/use-persistence.d.ts.map +1 -0
- package/dist/persistence/use-storage-monitor.d.ts +11 -0
- package/dist/persistence/use-storage-monitor.d.ts.map +1 -0
- package/dist/provider.d.ts +89 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/queries/batch-query.d.ts +23 -0
- package/dist/queries/batch-query.d.ts.map +1 -0
- package/dist/queries/index.d.ts +3 -0
- package/dist/queries/index.d.ts.map +1 -0
- package/dist/query-action-registry.d.ts +19 -0
- package/dist/query-action-registry.d.ts.map +1 -0
- package/dist/rules.d.ts +133 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/server.cjs +2 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +10 -12
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/stores/cart-store.d.ts +51 -0
- package/dist/stores/cart-store.d.ts.map +1 -0
- package/dist/stores/items-filters-store.d.ts +30 -0
- package/dist/stores/items-filters-store.d.ts.map +1 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/web/use-image-with-fallback.d.ts +16 -0
- package/dist/web/use-image-with-fallback.d.ts.map +1 -0
- package/dist/web/use-mobile-detection.d.ts +28 -0
- package/dist/web/use-mobile-detection.d.ts.map +1 -0
- package/dist/web/use-mobile-optimized-intersection.d.ts +17 -0
- package/dist/web/use-mobile-optimized-intersection.d.ts.map +1 -0
- package/dist/web.cjs.map +1 -1
- package/dist/web.d.ts +4 -60
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js.map +1 -1
- package/llms.txt +76 -54
- package/package.json +26 -14
- package/dist/batch-query-CTlvxSmL.d.cts +0 -165
- package/dist/batch-query-CTlvxSmL.d.ts +0 -165
- package/dist/chunk-F5DUFW57.cjs +0 -383
- package/dist/chunk-F5DUFW57.cjs.map +0 -1
- package/dist/chunk-JNOHB4OP.js +0 -383
- package/dist/chunk-JNOHB4OP.js.map +0 -1
- package/dist/index.d.cts +0 -456
- package/dist/server.d.cts +0 -44
- package/dist/use-order-readiness-DZTIfRzw.d.cts +0 -137
- package/dist/web.d.cts +0 -60
package/dist/index.d.cts
DELETED
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
import { P as PersistenceConfig } from './batch-query-CTlvxSmL.cjs';
|
|
2
|
-
export { A as AugurApiClient, a as AugurHooksProvider, B as BatchQueryConfig, G as GetItemCategoryApiOptions, b as PageData, e as executeBatchQuery, u as useAugurApi, c as useAugurApiOptional, d as useAugurAuth, f as useAugurCache, g as useAugurOptions, h as useAugurSite } from './batch-query-CTlvxSmL.cjs';
|
|
3
|
-
export { AugurAuthContext, AugurSiteConfig, AugurSiteDefaults, AugurSiteFormatting, CacheConfig, CacheProvider, CacheTierConfig, DeepQueryOptions, EdgeCacheValue, InfiniteScrollPage, ProxyMutationOptions, ProxyQueryOptions } from '@simpleapps-com/augur-core';
|
|
4
|
-
import * as zustand from 'zustand';
|
|
5
|
-
import * as _simpleapps_com_augur_utils from '@simpleapps-com/augur-utils';
|
|
6
|
-
import { TCartLine, TItemsFilters, TStock, TPriceData } from '@simpleapps-com/augur-utils';
|
|
7
|
-
export { DerivePriceInput, DerivedPrice, ResolveStockInput, ResolvedStock, TSearchSuggestion as SearchSuggestion, TSearchSuggestionsResponse as SearchSuggestionsResponse } from '@simpleapps-com/augur-utils';
|
|
8
|
-
export { O as OrderReadinessParams, P as PaymentBillingAddress, a as PaymentFlowCallbacks, d as determineOrderReadiness, u as useOrderReadiness, b as usePaymentFlow } from './use-order-readiness-DZTIfRzw.cjs';
|
|
9
|
-
import { QueryKey } from '@tanstack/react-query';
|
|
10
|
-
import * as _tanstack_react_query_persist_client from '@tanstack/react-query-persist-client';
|
|
11
|
-
import 'react/jsx-runtime';
|
|
12
|
-
import 'react';
|
|
13
|
-
import '@simpleapps-com/augur-api';
|
|
14
|
-
|
|
15
|
-
/** Internal state shape for the cart Zustand store. */
|
|
16
|
-
interface CartState {
|
|
17
|
-
/** P21 cart header UID; `undefined` when no cart exists. */
|
|
18
|
-
cartHdrUid: number | string | undefined;
|
|
19
|
-
/** Current line items in the cart. */
|
|
20
|
-
cartLines: TCartLine[];
|
|
21
|
-
/** Sum of `quantity` across all cart lines (auto-computed by `setCartLines`). */
|
|
22
|
-
cartQuantityTotal: number;
|
|
23
|
-
/** Number of distinct line items (auto-computed by `setCartLines`). */
|
|
24
|
-
cartLineCount: number;
|
|
25
|
-
setCartHdrUid: (cartHdrUid: number | string | undefined) => void;
|
|
26
|
-
/** Replace all cart lines. Auto-recomputes `cartQuantityTotal` and `cartLineCount`. */
|
|
27
|
-
setCartLines: (cartLines: TCartLine[]) => void;
|
|
28
|
-
/** Reset the cart to its empty initial state. */
|
|
29
|
-
clearCart: () => void;
|
|
30
|
-
}
|
|
31
|
-
/** Zustand store for cart state. Prefer the individual selector hooks below for optimal re-renders. */
|
|
32
|
-
declare const useCartStore: zustand.UseBoundStore<Omit<zustand.StoreApi<CartState>, "setState" | "devtools"> & {
|
|
33
|
-
setState(partial: CartState | Partial<CartState> | ((state: CartState) => CartState | Partial<CartState>), replace?: false | undefined, action?: (string | {
|
|
34
|
-
[x: string]: unknown;
|
|
35
|
-
[x: number]: unknown;
|
|
36
|
-
[x: symbol]: unknown;
|
|
37
|
-
type: string;
|
|
38
|
-
}) | undefined): void;
|
|
39
|
-
setState(state: CartState | ((state: CartState) => CartState), replace: true, action?: (string | {
|
|
40
|
-
[x: string]: unknown;
|
|
41
|
-
[x: number]: unknown;
|
|
42
|
-
[x: symbol]: unknown;
|
|
43
|
-
type: string;
|
|
44
|
-
}) | undefined): void;
|
|
45
|
-
devtools: {
|
|
46
|
-
cleanup: () => void;
|
|
47
|
-
};
|
|
48
|
-
}>;
|
|
49
|
-
/** Select the current cart header UID. */
|
|
50
|
-
declare const useCartHdrUid: () => string | number | undefined;
|
|
51
|
-
/** Select the current cart line items array. */
|
|
52
|
-
declare const useCartLines: () => TCartLine[];
|
|
53
|
-
/** Select the total quantity summed across all cart lines. */
|
|
54
|
-
declare const useCartQuantityTotal: () => number;
|
|
55
|
-
/** Select the number of distinct line items in the cart. */
|
|
56
|
-
declare const useCartLineCount: () => number;
|
|
57
|
-
/** Get the `setCartHdrUid` action (stable reference). */
|
|
58
|
-
declare const useSetCartHdrUid: () => (cartHdrUid: number | string | undefined) => void;
|
|
59
|
-
/** Get the `setCartLines` action (stable reference). Also recomputes totals. */
|
|
60
|
-
declare const useSetCartLines: () => (cartLines: TCartLine[]) => void;
|
|
61
|
-
/** Get the `clearCart` action (stable reference). */
|
|
62
|
-
declare const useClearCart: () => () => void;
|
|
63
|
-
|
|
64
|
-
/** Zustand state shape for item list filtering, sorting, and pagination. */
|
|
65
|
-
interface ItemsFiltersState {
|
|
66
|
-
/** Snapshot of the initial defaults; useful for "reset filters" UIs. */
|
|
67
|
-
initialFiltersState: TItemsFilters;
|
|
68
|
-
/** Current active filter/sort/pagination state. */
|
|
69
|
-
itemsFilters: TItemsFilters;
|
|
70
|
-
/** Replace the entire filter state. */
|
|
71
|
-
setItemsFilters: (itemFilters: TItemsFilters) => void;
|
|
72
|
-
}
|
|
73
|
-
/** Zustand store for item list filters, sorting, and pagination state. */
|
|
74
|
-
declare const useItemFiltersStore: zustand.UseBoundStore<Omit<zustand.StoreApi<ItemsFiltersState>, "setState" | "devtools"> & {
|
|
75
|
-
setState(partial: ItemsFiltersState | Partial<ItemsFiltersState> | ((state: ItemsFiltersState) => ItemsFiltersState | Partial<ItemsFiltersState>), replace?: false | undefined, action?: (string | {
|
|
76
|
-
[x: string]: unknown;
|
|
77
|
-
[x: number]: unknown;
|
|
78
|
-
[x: symbol]: unknown;
|
|
79
|
-
type: string;
|
|
80
|
-
}) | undefined): void;
|
|
81
|
-
setState(state: ItemsFiltersState | ((state: ItemsFiltersState) => ItemsFiltersState), replace: true, action?: (string | {
|
|
82
|
-
[x: string]: unknown;
|
|
83
|
-
[x: number]: unknown;
|
|
84
|
-
[x: symbol]: unknown;
|
|
85
|
-
type: string;
|
|
86
|
-
}) | undefined): void;
|
|
87
|
-
devtools: {
|
|
88
|
-
cleanup: () => void;
|
|
89
|
-
};
|
|
90
|
-
}>;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Debounces a rapidly-changing value.
|
|
94
|
-
* Returns the latest value only after `delay` ms of inactivity.
|
|
95
|
-
*/
|
|
96
|
-
declare function useDebounce<T>(value: T, delay?: number): T;
|
|
97
|
-
|
|
98
|
-
/** Options for configuring the useFormatPrice hook. */
|
|
99
|
-
interface UseFormatPriceOptions {
|
|
100
|
-
/** BCP 47 locale tag. Overrides site.formatting.locale. */
|
|
101
|
-
locale?: string;
|
|
102
|
-
/** ISO 4217 currency code. Overrides site.formatting.currency. */
|
|
103
|
-
currency?: string;
|
|
104
|
-
/** Decimal digits. Overrides site.formatting.precision. */
|
|
105
|
-
precision?: number;
|
|
106
|
-
/** Label returned when the effective value is 0 (e.g. "Call for Price"). */
|
|
107
|
-
zeroLabel?: string;
|
|
108
|
-
}
|
|
109
|
-
/** Per-call options passed to the returned formatPrice function. */
|
|
110
|
-
interface FormatPriceCallOptions {
|
|
111
|
-
/** Override decimal digits for this call only. */
|
|
112
|
-
precision?: number;
|
|
113
|
-
/** Multiply the value by this quantity before formatting. */
|
|
114
|
-
quantity?: number;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Hook that returns a price formatter.
|
|
118
|
-
* Reads defaults from site config when params are omitted.
|
|
119
|
-
*
|
|
120
|
-
* Supports both the new options-object signature and the legacy positional
|
|
121
|
-
* `(locale?, currency?)` signature for backwards compatibility.
|
|
122
|
-
*/
|
|
123
|
-
declare function useFormatPrice(optionsOrLocale?: UseFormatPriceOptions | string, legacyCurrency?: string): {
|
|
124
|
-
formatPrice: (price: number, callOptions?: FormatPriceCallOptions) => string;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
interface UseStockOptions {
|
|
128
|
-
enabled?: boolean;
|
|
129
|
-
/** Override the default queryFn (e.g. with a custom server action). */
|
|
130
|
-
queryFn?: () => Promise<TStock>;
|
|
131
|
-
/** Company key to extract stock for a specific company. */
|
|
132
|
-
companyKey?: string;
|
|
133
|
-
/** Whether to round the quantity. */
|
|
134
|
-
round?: boolean;
|
|
135
|
-
/** Threshold below which stock is considered "low". */
|
|
136
|
-
lowStockThreshold?: number;
|
|
137
|
-
/** Whether to include the quantity in the resolved output. */
|
|
138
|
-
showQuantity?: boolean;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Fetches full TStock data and resolves it into a normalized stock object.
|
|
142
|
-
*
|
|
143
|
-
* Uses the proxy from AugurHooksProvider context. Works with:
|
|
144
|
-
* - Direct SDK (api prop on provider)
|
|
145
|
-
* - Server actions (auto-detected via queryAction registration)
|
|
146
|
-
* - Custom queryFn override
|
|
147
|
-
*/
|
|
148
|
-
declare function useStock(invMastUid: number | string, options?: UseStockOptions): {
|
|
149
|
-
stock: TStock | null;
|
|
150
|
-
resolved: _simpleapps_com_augur_utils.ResolvedStock | null;
|
|
151
|
-
loading: false;
|
|
152
|
-
error: Error | null;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
type CartLineInput = Pick<TCartLine, "invMastUid" | "quantity" | "unitOfMeasure"> & {
|
|
156
|
-
cartHdrUid?: number | string | undefined;
|
|
157
|
-
};
|
|
158
|
-
/** Site-specific callbacks injected into useCartActions. */
|
|
159
|
-
interface CartActionCallbacks {
|
|
160
|
-
/** Add items to cart via API. Truthy = success, falsy = failure. */
|
|
161
|
-
addToCart: (cartHdrUid: number, items: Array<{
|
|
162
|
-
cartHdrUid: number;
|
|
163
|
-
invMastUid: number;
|
|
164
|
-
quantity: number;
|
|
165
|
-
unitOfMeasure: string;
|
|
166
|
-
}>) => Promise<boolean | undefined | void>;
|
|
167
|
-
/** Update cart lines via API. Truthy = success, falsy = failure. */
|
|
168
|
-
updateCartLines: (cartHdrUid: number, lines: TCartLine[]) => Promise<boolean | undefined | void>;
|
|
169
|
-
/** Delete all items from cart via API. Truthy = success, falsy = failure. */
|
|
170
|
-
deleteItemsFromCart: (cartHdrUid: number) => Promise<boolean | undefined | void>;
|
|
171
|
-
/** Optional toast notification callback. */
|
|
172
|
-
toast?: {
|
|
173
|
-
info?: (message: string) => void;
|
|
174
|
-
error?: (message: string) => void;
|
|
175
|
-
success?: (message: string) => void;
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
interface CartActionOptions {
|
|
179
|
-
showToast?: boolean;
|
|
180
|
-
itemId?: string;
|
|
181
|
-
onSuccess?: () => void;
|
|
182
|
-
onError?: (error: Error) => void;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Optimistic cart actions hook with automatic rollback on failure.
|
|
186
|
-
*
|
|
187
|
-
* Accepts site-specific server action callbacks so the hook itself
|
|
188
|
-
* has no dependency on any particular server action implementation.
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```tsx
|
|
192
|
-
* import { useCartActions } from "@simpleapps-com/augur-hooks";
|
|
193
|
-
* import { addToCart, updateCartLines, deleteItemsFromCart } from "@/lib/actions/commerce";
|
|
194
|
-
* import { toast } from "react-toastify";
|
|
195
|
-
*
|
|
196
|
-
* const cart = useCartActions({
|
|
197
|
-
* addToCart, updateCartLines, deleteItemsFromCart,
|
|
198
|
-
* toast: { info: toast.info, error: toast.error },
|
|
199
|
-
* });
|
|
200
|
-
*
|
|
201
|
-
* await cart.addToCart({ invMastUid: 123, quantity: 1, unitOfMeasure: "EA" });
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
declare function useCartActions(callbacks: CartActionCallbacks): {
|
|
205
|
-
addToCart: (item: CartLineInput, options?: CartActionOptions) => Promise<boolean>;
|
|
206
|
-
updateQuantity: (invMastUid: number, newQuantity: number, options?: CartActionOptions) => Promise<boolean>;
|
|
207
|
-
removeFromCart: (invMastUid: number, options?: CartActionOptions) => Promise<boolean>;
|
|
208
|
-
clearCart: (options?: Omit<CartActionOptions, "itemId">) => Promise<boolean>;
|
|
209
|
-
isInCart: (invMastUid: number) => boolean;
|
|
210
|
-
getItemQuantity: (invMastUid: number) => number;
|
|
211
|
-
cartHdrUid: string | number | undefined;
|
|
212
|
-
cartLines: TCartLine[];
|
|
213
|
-
invalidateCartCache: () => void;
|
|
214
|
-
};
|
|
215
|
-
|
|
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
|
-
/** A single persisted field with its storage key and optional TTL. */
|
|
228
|
-
interface CheckoutPersistField<T> {
|
|
229
|
-
key: string;
|
|
230
|
-
value: T;
|
|
231
|
-
set: (value: T) => void;
|
|
232
|
-
/** Valibot or custom validator. Return the parsed value or throw to reject. */
|
|
233
|
-
validate?: (raw: unknown) => T;
|
|
234
|
-
/** TTL in milliseconds. Default: 30 minutes. */
|
|
235
|
-
ttl?: number;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Saves a value to sessionStorage with a timestamp for TTL expiration.
|
|
239
|
-
*
|
|
240
|
-
* Fails silently on storage errors (private browsing, quota exceeded).
|
|
241
|
-
*/
|
|
242
|
-
declare function saveToSession(key: string, value: unknown): void;
|
|
243
|
-
/**
|
|
244
|
-
* Loads a value from sessionStorage, checking TTL and optionally validating.
|
|
245
|
-
*
|
|
246
|
-
* Returns null if missing, expired, invalid, or storage is unavailable.
|
|
247
|
-
* Cleans up expired entries automatically.
|
|
248
|
-
*/
|
|
249
|
-
declare function loadFromSession<T>(key: string, ttl?: number, validate?: (raw: unknown) => T): T | null;
|
|
250
|
-
/** Removes a checkout persistence key from sessionStorage. */
|
|
251
|
-
declare function clearFromSession(key: string): void;
|
|
252
|
-
/**
|
|
253
|
-
* Hook that persists checkout state fields to sessionStorage and restores on mount.
|
|
254
|
-
*
|
|
255
|
-
* Each field is saved when its value changes and restored once on initial mount.
|
|
256
|
-
* Validates restored values against an optional schema to guard against
|
|
257
|
-
* corrupted or stale storage. Expired entries (past TTL) are discarded.
|
|
258
|
-
*/
|
|
259
|
-
declare function useCheckoutPersistence(fields: CheckoutPersistField<unknown>[]): void;
|
|
260
|
-
/**
|
|
261
|
-
* Clears all checkout persistence keys from sessionStorage.
|
|
262
|
-
*
|
|
263
|
-
* Call after successful order submission to prevent stale data on next checkout.
|
|
264
|
-
*/
|
|
265
|
-
declare function clearCheckoutPersistence(keys: string[]): void;
|
|
266
|
-
|
|
267
|
-
/** Session info passed from the consumer's auth system. */
|
|
268
|
-
interface CartSessionInfo {
|
|
269
|
-
/** Auth status: "loading" | "authenticated" | "unauthenticated" */
|
|
270
|
-
status: "loading" | "authenticated" | "unauthenticated";
|
|
271
|
-
/** User's ID (e.g., Joomla user ID). Undefined if not authenticated. */
|
|
272
|
-
userId?: string | number;
|
|
273
|
-
/** Cart header UID from the auth session, if available. */
|
|
274
|
-
cartHdrUid?: number | string;
|
|
275
|
-
}
|
|
276
|
-
/** Site-specific callbacks injected into useCartInitialization. */
|
|
277
|
-
interface CartInitCallbacks {
|
|
278
|
-
/** Look up or create a cart header. Returns { cartHdrUid, cartToken? }. */
|
|
279
|
-
cartHdrLookup: (userId: string | number, cartToken: string) => Promise<{
|
|
280
|
-
cartHdrUid: number;
|
|
281
|
-
cartToken?: string | null;
|
|
282
|
-
} | null | undefined>;
|
|
283
|
-
/** Fetch cart line items for a given cart header UID. */
|
|
284
|
-
getCartLines: (cartHdrUid: number) => Promise<TCartLine[] | undefined>;
|
|
285
|
-
/** Get the current cart token. Defaults to localStorage.getItem("cartToken"). */
|
|
286
|
-
getCartToken?: () => string | null;
|
|
287
|
-
/** Save cart token. Defaults to localStorage.setItem("cartToken", token). */
|
|
288
|
-
saveCartToken?: (token: string) => void;
|
|
289
|
-
/** Generate a new unique cart token. Defaults to crypto.randomUUID(). */
|
|
290
|
-
generateCartToken?: () => string;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Initialize cart state from session (authenticated) or cookie (guest).
|
|
294
|
-
* Call once in the root layout.
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```tsx
|
|
298
|
-
* import { useCartInitialization } from "@simpleapps-com/augur-hooks";
|
|
299
|
-
* import { useSession } from "next-auth/react";
|
|
300
|
-
* import { cartHdrLookup, getCartLines } from "@/lib/actions/commerce";
|
|
301
|
-
*
|
|
302
|
-
* function CartInitializer() {
|
|
303
|
-
* const { data: session, status } = useSession();
|
|
304
|
-
*
|
|
305
|
-
* // Minimal setup — token storage defaults to localStorage,
|
|
306
|
-
* // token generation defaults to crypto.randomUUID().
|
|
307
|
-
* useCartInitialization(
|
|
308
|
-
* {
|
|
309
|
-
* status,
|
|
310
|
-
* userId: session?.user?.id,
|
|
311
|
-
* cartHdrUid: session?.user?.cartHdrUid,
|
|
312
|
-
* },
|
|
313
|
-
* { cartHdrLookup, getCartLines },
|
|
314
|
-
* );
|
|
315
|
-
*
|
|
316
|
-
* return null;
|
|
317
|
-
* }
|
|
318
|
-
* ```
|
|
319
|
-
*/
|
|
320
|
-
declare function useCartInitialization(session: CartSessionInfo, callbacks: CartInitCallbacks): {
|
|
321
|
-
cartHdrUid: string | number | undefined;
|
|
322
|
-
isInitializing: boolean;
|
|
323
|
-
retryCount: number;
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
interface CartPriceData {
|
|
327
|
-
unitPrice: number;
|
|
328
|
-
priceData: Record<string, unknown> | null;
|
|
329
|
-
}
|
|
330
|
-
interface CartPricingResult {
|
|
331
|
-
/** Map of itemId -> price data (with quantity-specific pricing) */
|
|
332
|
-
prices: Record<string, CartPriceData>;
|
|
333
|
-
/** Get unit price for an item (returns 0 if not found) */
|
|
334
|
-
getUnitPrice: (itemId: string) => number;
|
|
335
|
-
/** Get total price for an item (unitPrice * quantity) */
|
|
336
|
-
getItemTotal: (itemId: string, quantity: number) => number;
|
|
337
|
-
/** Cart subtotal (sum of all item totals) */
|
|
338
|
-
subtotal: number;
|
|
339
|
-
/** True if any price is still loading */
|
|
340
|
-
isLoading: boolean;
|
|
341
|
-
/** True if all prices loaded successfully */
|
|
342
|
-
isSuccess: boolean;
|
|
343
|
-
/** True if any price failed to load */
|
|
344
|
-
isError: boolean;
|
|
345
|
-
}
|
|
346
|
-
interface UseCartPricingOptions {
|
|
347
|
-
customerId?: string | number;
|
|
348
|
-
/** Override per-item price fetching (e.g. with a custom server action). */
|
|
349
|
-
queryFn?: (itemId: string, customerId: string | number, quantity: number) => Promise<TPriceData>;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Centralized hook for cart/checkout pricing.
|
|
353
|
-
*
|
|
354
|
-
* Fetches prices for ALL cart items with their actual quantities
|
|
355
|
-
* to support quantity-based price breaks. React Query dedupes
|
|
356
|
-
* identical calls across components.
|
|
357
|
-
*
|
|
358
|
-
* Uses the proxy from AugurHooksProvider context. Works with:
|
|
359
|
-
* - Direct SDK (api prop on provider)
|
|
360
|
-
* - Server actions (auto-detected via queryAction registration)
|
|
361
|
-
* - Custom queryFn override
|
|
362
|
-
*/
|
|
363
|
-
declare function useCartPricing(options?: UseCartPricingOptions): CartPricingResult;
|
|
364
|
-
|
|
365
|
-
interface UsePaginationPrefetchOptions {
|
|
366
|
-
/** Query key for the paginated data */
|
|
367
|
-
queryKey: QueryKey;
|
|
368
|
-
/** Function to fetch a page of data */
|
|
369
|
-
queryFn: (offset: number) => Promise<unknown>;
|
|
370
|
-
/** Number of items per page */
|
|
371
|
-
pageSize: number;
|
|
372
|
-
/** Custom query key builder. Receives the base key and offset, returns the full key. Default: [...queryKey, offset]. */
|
|
373
|
-
queryKeyFn?: (baseKey: QueryKey, offset: number) => QueryKey;
|
|
374
|
-
/** Stale time in ms (defaults to 10 minutes) */
|
|
375
|
-
staleTime?: number;
|
|
376
|
-
/** GC time in ms (defaults to 30 minutes) */
|
|
377
|
-
gcTime?: number;
|
|
378
|
-
enabled?: boolean;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Prefetch adjacent pages on hover for instant pagination.
|
|
382
|
-
* Accepts a generic queryFn so it works with any paginated resource.
|
|
383
|
-
*/
|
|
384
|
-
declare const usePaginationPrefetch: ({ queryKey, queryFn, pageSize, queryKeyFn, staleTime, gcTime, enabled, }: UsePaginationPrefetchOptions) => {
|
|
385
|
-
prefetchPage: (page: number) => Promise<void>;
|
|
386
|
-
handlePaginationHover: (page: number) => () => void;
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Returns a fully configured `persistOptions` object for use with
|
|
391
|
-
* `PersistQueryClientProvider` from `@tanstack/react-query-persist-client`.
|
|
392
|
-
*
|
|
393
|
-
* Handles:
|
|
394
|
-
* - SSR-safe persister creation (no-op on server)
|
|
395
|
-
* - Map → Record serialization for localStorage compatibility
|
|
396
|
-
* - Selective persistence (only successful queries matching persistableKeys)
|
|
397
|
-
* - Per-key-prefix LRU eviction (via `limits`)
|
|
398
|
-
* - Throttled writes to localStorage
|
|
399
|
-
* - Hydration safety (maxAge: 0 until client mount)
|
|
400
|
-
* - Storage monitoring with automatic eviction when over threshold
|
|
401
|
-
* - Dev mode auto-buster (invalidates cache on each restart)
|
|
402
|
-
*
|
|
403
|
-
* @example
|
|
404
|
-
* ```tsx
|
|
405
|
-
* import { useAugurPersistence } from "@simpleapps-com/augur-hooks";
|
|
406
|
-
*
|
|
407
|
-
* function Providers({ children }) {
|
|
408
|
-
* const [queryClient] = useState(() => new QueryClient({ ... }));
|
|
409
|
-
* const persistOptions = useAugurPersistence({
|
|
410
|
-
* key: "my-site-cache",
|
|
411
|
-
* buster: "1.0.0",
|
|
412
|
-
* persistableKeys: ["price", "categories", "invMast"],
|
|
413
|
-
* limits: { invMast: 100 },
|
|
414
|
-
* });
|
|
415
|
-
*
|
|
416
|
-
* return (
|
|
417
|
-
* <PersistQueryClientProvider client={queryClient} persistOptions={persistOptions}>
|
|
418
|
-
* <augur.Provider api={api} auth={auth}>
|
|
419
|
-
* {children}
|
|
420
|
-
* </augur.Provider>
|
|
421
|
-
* </PersistQueryClientProvider>
|
|
422
|
-
* );
|
|
423
|
-
* }
|
|
424
|
-
* ```
|
|
425
|
-
*/
|
|
426
|
-
declare function useAugurPersistence(config: PersistenceConfig): {
|
|
427
|
-
persister: _tanstack_react_query_persist_client.Persister;
|
|
428
|
-
maxAge: number;
|
|
429
|
-
buster: string;
|
|
430
|
-
dehydrateOptions: {
|
|
431
|
-
shouldDehydrateQuery: (query: {
|
|
432
|
-
queryKey: readonly unknown[];
|
|
433
|
-
state: {
|
|
434
|
-
status: string;
|
|
435
|
-
};
|
|
436
|
-
}) => boolean;
|
|
437
|
-
};
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Lightweight registry for a query action function.
|
|
442
|
-
*
|
|
443
|
-
* augur-server/hooks.ts registers its queryAction as a side effect when
|
|
444
|
-
* imported. augur-hooks consumers (useCartPricing, useStock, the provider)
|
|
445
|
-
* read from this registry to route data through server actions automatically.
|
|
446
|
-
*
|
|
447
|
-
* No circular dependency: augur-server depends on augur-hooks and writes here.
|
|
448
|
-
* augur-hooks reads from its own module.
|
|
449
|
-
*/
|
|
450
|
-
type QueryActionFn = (methodPath: string, ...args: unknown[]) => Promise<unknown>;
|
|
451
|
-
/** Register a query action function (called by augur-server/hooks.ts on import). */
|
|
452
|
-
declare function registerQueryAction(fn: QueryActionFn): void;
|
|
453
|
-
/** Returns the registered query action, or null if none registered. */
|
|
454
|
-
declare function getRegisteredQueryAction(): QueryActionFn | null;
|
|
455
|
-
|
|
456
|
-
export { type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type CheckoutPersistField, type FormatPriceCallOptions, PersistenceConfig, type UseFormatPriceOptions, type UseStockOptions, clearCheckoutPersistence, clearFromSession, getRegisteredQueryAction, loadFromSession, registerQueryAction, saveToSession, useAugurPersistence, useCartActions, useCartHdrUid, useCartInitialization, useCartLineCount, useCartLines, useCartPricing, useCartQuantityTotal, useCartStore, useCheckoutPersistence, useClearCart, useDebounce, useFormatPrice, useItemFiltersStore, useModalLifecycle, usePaginationPrefetch, useSetCartHdrUid, useSetCartLines, useStock };
|
package/dist/server.d.cts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { QueryActionFn, CacheConfig, DeepQueryOptions } from '@simpleapps-com/augur-core';
|
|
3
|
-
export { AugurAuthContext, CacheConfig, InfiniteScrollPage } from '@simpleapps-com/augur-core';
|
|
4
|
-
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
5
|
-
export { A as AugurApiClient, B as BatchQueryConfig, b as PageData, e as executeBatchQuery } from './batch-query-CTlvxSmL.cjs';
|
|
6
|
-
import 'react/jsx-runtime';
|
|
7
|
-
import 'react';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Returns a per-request singleton QueryClient for React Server Components.
|
|
11
|
-
*
|
|
12
|
-
* React's `cache()` deduplicates calls within a single server request,
|
|
13
|
-
* so layout, page, and header all share the same prefetch cache without
|
|
14
|
-
* leaking state between requests.
|
|
15
|
-
*/
|
|
16
|
-
declare const getQueryClient: () => QueryClient;
|
|
17
|
-
/**
|
|
18
|
-
* Creates server-side query options proxy for prefetching.
|
|
19
|
-
*
|
|
20
|
-
* Uses the same augur-core proxy as `useAugurOptions()`, so query keys
|
|
21
|
-
* are identical on server and client — SSR hydration is automatic.
|
|
22
|
-
*
|
|
23
|
-
* Accepts either an SDK client instance or a queryAction function.
|
|
24
|
-
* When called with no arguments, uses the auto-registered queryAction
|
|
25
|
-
* (registered by augur-server/hooks on import).
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* // With SDK client (traditional)
|
|
30
|
-
* const q = createAugurOptions(site.client, cacheConfig);
|
|
31
|
-
*
|
|
32
|
-
* // With queryAction (server-only JWT sites)
|
|
33
|
-
* import { queryAction } from "@simpleapps-com/augur-server/query-action";
|
|
34
|
-
* const q = createAugurOptions(queryAction, cacheConfig);
|
|
35
|
-
*
|
|
36
|
-
* // With auto-registered queryAction (zero args -- requires augur-server/hooks import)
|
|
37
|
-
* const q = createAugurOptions();
|
|
38
|
-
*
|
|
39
|
-
* await queryClient.prefetchQuery(q.items.invMast.doc.get(42));
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
declare function createAugurOptions<TApi extends object = AugurAPI>(apiOrQueryAction?: TApi | QueryActionFn, cacheConfig?: CacheConfig): DeepQueryOptions<TApi>;
|
|
43
|
-
|
|
44
|
-
export { createAugurOptions, getQueryClient };
|
|
@@ -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 };
|