@simpleapps-com/augur-hooks 2.2.28 → 2.3.0
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 +28 -9
- package/README.md +20 -25
- package/dist/{cart-pricing-CTMlA3nE.d.cts → batch-query-CTlvxSmL.d.cts} +3 -35
- package/dist/{cart-pricing-CTMlA3nE.d.ts → batch-query-CTlvxSmL.d.ts} +3 -35
- package/dist/checkout/index.cjs +92 -31
- package/dist/checkout/index.cjs.map +1 -1
- package/dist/checkout/index.d.cts +19 -3
- package/dist/checkout/index.d.ts +19 -3
- package/dist/checkout/index.js +73 -12
- package/dist/checkout/index.js.map +1 -1
- package/dist/chunk-6Z6JGK2C.cjs +41 -0
- package/dist/chunk-6Z6JGK2C.cjs.map +1 -0
- package/dist/chunk-D5C6WWFO.js +41 -0
- package/dist/chunk-D5C6WWFO.js.map +1 -0
- package/dist/index.cjs +3 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -7
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +3 -9
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -2
- package/dist/server.d.ts +1 -2
- package/dist/server.js +3 -9
- package/dist/server.js.map +1 -1
- package/llms.txt +31 -22
- package/package.json +3 -3
- package/dist/chunk-GHON6UMJ.js +0 -144
- package/dist/chunk-GHON6UMJ.js.map +0 -1
- package/dist/chunk-XJJ6DZDK.cjs +0 -144
- package/dist/chunk-XJJ6DZDK.cjs.map +0 -1
package/EXPORTS.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @simpleapps-com/augur-hooks exports
|
|
2
2
|
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.29
|
|
4
4
|
|
|
5
5
|
> Auto-generated from built type declarations. Do not edit manually.
|
|
6
6
|
> Regenerate with: `pnpm run generate-exports`
|
|
@@ -31,12 +31,14 @@ Version: 2.2.10
|
|
|
31
31
|
| `ResolvedStock` | value | |
|
|
32
32
|
| `SearchSuggestion` | value | |
|
|
33
33
|
| `SearchSuggestionsResponse` | value | |
|
|
34
|
+
| `clearCheckoutPersistence` | function | Clears all checkout persistence keys from sessionStorage. |
|
|
35
|
+
| `clearFromSession` | function | Removes a checkout persistence key from sessionStorage. |
|
|
36
|
+
| `determineOrderReadiness` | function | Pure function that determines if an order is ready to submit. |
|
|
34
37
|
| `executeBatchQuery` | function | |
|
|
35
|
-
| `getCartPricingQueryOptions` | function | |
|
|
36
38
|
| `getRegisteredQueryAction` | function | Returns the registered query action, or null if none registered. |
|
|
37
|
-
| `
|
|
38
|
-
| `getStockOptions` | value | |
|
|
39
|
+
| `loadFromSession` | function | Loads a value from sessionStorage, checking TTL and optionally validating. |
|
|
39
40
|
| `registerQueryAction` | function | Register a query action function (called by augur-server/hooks.ts on import). |
|
|
41
|
+
| `saveToSession` | function | Saves a value to sessionStorage with a timestamp for TTL expiration. |
|
|
40
42
|
| `useAugurApi` | function | |
|
|
41
43
|
| `useAugurApiOptional` | value | |
|
|
42
44
|
| `useAugurAuth` | value | |
|
|
@@ -52,19 +54,22 @@ Version: 2.2.10
|
|
|
52
54
|
| `useCartPricing` | function | Centralized hook for cart/checkout pricing. |
|
|
53
55
|
| `useCartQuantityTotal` | const | Select the total quantity summed across all cart lines. |
|
|
54
56
|
| `useCartStore` | const | Zustand store for cart state. Prefer the individual selector hooks below for optimal re-renders. |
|
|
57
|
+
| `useCheckoutPersistence` | function | Hook that persists checkout state fields to sessionStorage and restores on mount. |
|
|
55
58
|
| `useClearCart` | const | Get the `clearCart` action (stable reference). |
|
|
56
59
|
| `useDebounce` | function | Debounces a rapidly-changing value. |
|
|
57
60
|
| `useFormatPrice` | function | Hook that returns a price formatter. |
|
|
58
61
|
| `useItemFiltersStore` | const | Zustand store for item list filters, sorting, and pagination state. |
|
|
62
|
+
| `useModalLifecycle` | function | Shared modal lifecycle hook -- scroll lock, Escape key, client-side hydration gate. |
|
|
63
|
+
| `useOrderReadiness` | function | Debounced order readiness hook. |
|
|
59
64
|
| `usePaginationPrefetch` | const | Prefetch adjacent pages on hover for instant pagination. |
|
|
60
|
-
| `usePaymentFlow` | function |
|
|
65
|
+
| `usePaymentFlow` | function | |
|
|
61
66
|
| `useSetCartHdrUid` | const | Get the `setCartHdrUid` action (stable reference). |
|
|
62
67
|
| `useSetCartLines` | const | Get the `setCartLines` action (stable reference). Also recomputes totals. |
|
|
63
68
|
| `useStock` | function | Fetches full TStock data and resolves it into a normalized stock object. |
|
|
64
69
|
|
|
65
70
|
### Types
|
|
66
71
|
|
|
67
|
-
`AugurApiClient`, `BatchQueryConfig`, `CartActionCallbacks`, `CartInitCallbacks`, `CartPriceData`, `CartPricingResult`, `CartSessionInfo`, `FormatPriceCallOptions`, `GetItemCategoryApiOptions`, `PageData`, `PaymentBillingAddress`, `PaymentFlowCallbacks`, `UseFormatPriceOptions`, `UseStockOptions`
|
|
72
|
+
`AugurApiClient`, `BatchQueryConfig`, `CartActionCallbacks`, `CartInitCallbacks`, `CartPriceData`, `CartPricingResult`, `CartSessionInfo`, `CheckoutPersistField`, `FormatPriceCallOptions`, `GetItemCategoryApiOptions`, `OrderReadinessParams`, `PageData`, `PaymentBillingAddress`, `PaymentFlowCallbacks`, `UseFormatPriceOptions`, `UseStockOptions`
|
|
68
73
|
|
|
69
74
|
```ts
|
|
70
75
|
import { AugurAuthContext, AugurHooksProvider, AugurSiteConfig } from "@simpleapps-com/augur-hooks";
|
|
@@ -81,10 +86,7 @@ import { AugurAuthContext, AugurHooksProvider, AugurSiteConfig } from "@simpleap
|
|
|
81
86
|
| `InfiniteScrollPage` | value | |
|
|
82
87
|
| `createAugurOptions` | function | Creates server-side query options proxy for prefetching. |
|
|
83
88
|
| `executeBatchQuery` | function | |
|
|
84
|
-
| `getCartPricingQueryOptions` | function | |
|
|
85
89
|
| `getQueryClient` | const | Returns a per-request singleton QueryClient for React Server Components. |
|
|
86
|
-
| `getStockKey` | value | |
|
|
87
|
-
| `getStockOptions` | value | |
|
|
88
90
|
|
|
89
91
|
### Types
|
|
90
92
|
|
|
@@ -109,3 +111,20 @@ import { AugurAuthContext, CacheConfig, InfiniteScrollPage } from "@simpleapps-c
|
|
|
109
111
|
```ts
|
|
110
112
|
import { MobileProvider, useImageWithFallback, useIsHydrated } from "@simpleapps-com/augur-hooks/web";
|
|
111
113
|
```
|
|
114
|
+
|
|
115
|
+
## `@simpleapps-com/augur-hooks/checkout`
|
|
116
|
+
|
|
117
|
+
### Values
|
|
118
|
+
|
|
119
|
+
| Export | Kind | Description |
|
|
120
|
+
|--------|------|-------------|
|
|
121
|
+
| `ORDER_CONFIRMATION_KEY` | const | sessionStorage key for persisted order confirmation data. |
|
|
122
|
+
| `createCheckoutProvider` | function | |
|
|
123
|
+
|
|
124
|
+
### Types
|
|
125
|
+
|
|
126
|
+
`CheckoutAddress`, `CheckoutContext`, `CheckoutContextValue`, `CheckoutIdentityConfig`, `CheckoutLifecycleHooks`, `CheckoutOrderConfig`, `CheckoutPaymentConfig`, `CheckoutPaymentModal`, `CheckoutProviderConfig`, `CheckoutProviderProps`, `CheckoutShippingConfig`, `CheckoutUIConfig`, `DefaultCheckoutStep`, `OrderConfirmation`
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { ORDER_CONFIRMATION_KEY, createCheckoutProvider } from "@simpleapps-com/augur-hooks/checkout";
|
|
130
|
+
```
|
package/README.md
CHANGED
|
@@ -20,9 +20,10 @@ pnpm add @simpleapps-com/augur-hooks
|
|
|
20
20
|
|
|
21
21
|
| Import | Description |
|
|
22
22
|
|--------|-------------|
|
|
23
|
-
| `@simpleapps-com/augur-hooks` |
|
|
24
|
-
| `@simpleapps-com/augur-hooks/server` |
|
|
23
|
+
| `@simpleapps-com/augur-hooks` | 55 exports, 16 types |
|
|
24
|
+
| `@simpleapps-com/augur-hooks/server` | 6 exports, 3 types |
|
|
25
25
|
| `@simpleapps-com/augur-hooks/web` | 5 exports, 0 types |
|
|
26
|
+
| `@simpleapps-com/augur-hooks/checkout` | 2 exports, 14 types |
|
|
26
27
|
|
|
27
28
|
## Exports
|
|
28
29
|
|
|
@@ -39,6 +40,9 @@ pnpm add @simpleapps-com/augur-hooks
|
|
|
39
40
|
| `DeepQueryOptions` | value | |
|
|
40
41
|
| `ProxyMutationOptions` | value | |
|
|
41
42
|
| `ProxyQueryOptions` | value | |
|
|
43
|
+
| `clearFromSession` | function | Removes a checkout persistence key from sessionStorage. |
|
|
44
|
+
| `loadFromSession` | function | Loads a value from sessionStorage, checking TTL and optionally validating. |
|
|
45
|
+
| `saveToSession` | function | Saves a value to sessionStorage with a timestamp for TTL expiration. |
|
|
42
46
|
| `useAugurApi` | function | |
|
|
43
47
|
| `useAugurAuth` | value | |
|
|
44
48
|
| `useAugurOptions` | value | |
|
|
@@ -46,12 +50,12 @@ pnpm add @simpleapps-com/augur-hooks
|
|
|
46
50
|
| `AugurAuthContext` | value | |
|
|
47
51
|
| `createAugurOptions` | function | Creates server-side query options proxy for prefetching. |
|
|
48
52
|
| `MobileProvider` | function | Optional provider that tracks hydration state. |
|
|
53
|
+
| `createCheckoutProvider` | function | |
|
|
49
54
|
|
|
50
55
|
### Cart
|
|
51
56
|
|
|
52
57
|
| Export | Kind | Description |
|
|
53
58
|
|--------|------|-------------|
|
|
54
|
-
| `getCartPricingQueryOptions` | function | |
|
|
55
59
|
| `useCartActions` | function | Optimistic cart actions hook with automatic rollback on failure. |
|
|
56
60
|
| `useCartHdrUid` | const | Select the current cart header UID. |
|
|
57
61
|
| `useCartInitialization` | function | Initialize cart state from session (authenticated) or cookie (guest). |
|
|
@@ -63,7 +67,6 @@ pnpm add @simpleapps-com/augur-hooks
|
|
|
63
67
|
| `useClearCart` | const | Get the `clearCart` action (stable reference). |
|
|
64
68
|
| `useSetCartHdrUid` | const | Get the `setCartHdrUid` action (stable reference). |
|
|
65
69
|
| `useSetCartLines` | const | Get the `setCartLines` action (stable reference). Also recomputes totals. |
|
|
66
|
-
| `getCartPricingQueryOptions` | function | |
|
|
67
70
|
|
|
68
71
|
### Configuration
|
|
69
72
|
|
|
@@ -85,11 +88,21 @@ pnpm add @simpleapps-com/augur-hooks
|
|
|
85
88
|
|--------|------|-------------|
|
|
86
89
|
| `useItemFiltersStore` | const | Zustand store for item list filters, sorting, and pagination state. |
|
|
87
90
|
|
|
91
|
+
### Orders
|
|
92
|
+
|
|
93
|
+
| Export | Kind | Description |
|
|
94
|
+
|--------|------|-------------|
|
|
95
|
+
| `determineOrderReadiness` | function | Pure function that determines if an order is ready to submit. |
|
|
96
|
+
| `useOrderReadiness` | function | Debounced order readiness hook. |
|
|
97
|
+
| `ORDER_CONFIRMATION_KEY` | const | sessionStorage key for persisted order confirmation data. |
|
|
98
|
+
|
|
88
99
|
### Payment & Checkout
|
|
89
100
|
|
|
90
101
|
| Export | Kind | Description |
|
|
91
102
|
|--------|------|-------------|
|
|
92
|
-
| `
|
|
103
|
+
| `clearCheckoutPersistence` | function | Clears all checkout persistence keys from sessionStorage. |
|
|
104
|
+
| `useCheckoutPersistence` | function | Hook that persists checkout state fields to sessionStorage and restores on mount. |
|
|
105
|
+
| `usePaymentFlow` | function | |
|
|
93
106
|
|
|
94
107
|
### Persistence
|
|
95
108
|
|
|
@@ -119,11 +132,7 @@ pnpm add @simpleapps-com/augur-hooks
|
|
|
119
132
|
|--------|------|-------------|
|
|
120
133
|
| `ResolveStockInput` | value | |
|
|
121
134
|
| `ResolvedStock` | value | |
|
|
122
|
-
| `getStockKey` | value | |
|
|
123
|
-
| `getStockOptions` | value | |
|
|
124
135
|
| `useStock` | function | Fetches full TStock data and resolves it into a normalized stock object. |
|
|
125
|
-
| `getStockKey` | value | |
|
|
126
|
-
| `getStockOptions` | value | |
|
|
127
136
|
|
|
128
137
|
### Utilities
|
|
129
138
|
|
|
@@ -145,6 +154,7 @@ pnpm add @simpleapps-com/augur-hooks
|
|
|
145
154
|
| `registerQueryAction` | function | Register a query action function (called by augur-server/hooks.ts on import). |
|
|
146
155
|
| `useAugurApiOptional` | value | |
|
|
147
156
|
| `useAugurCache` | value | |
|
|
157
|
+
| `useModalLifecycle` | function | Shared modal lifecycle hook -- scroll lock, Escape key, client-side hydration gate. |
|
|
148
158
|
| `usePaginationPrefetch` | const | Prefetch adjacent pages on hover for instant pagination. |
|
|
149
159
|
| `InfiniteScrollPage` | value | |
|
|
150
160
|
| `executeBatchQuery` | function | |
|
|
@@ -216,21 +226,6 @@ function CartInitializer() {
|
|
|
216
226
|
}
|
|
217
227
|
```
|
|
218
228
|
|
|
219
|
-
### usePaymentFlow
|
|
220
|
-
|
|
221
|
-
```tsx
|
|
222
|
-
import { usePaymentFlow } from "@simpleapps-com/augur-hooks";
|
|
223
|
-
import { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } from "@/lib/actions/payments";
|
|
224
|
-
|
|
225
|
-
const payment = usePaymentFlow({
|
|
226
|
-
callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate },
|
|
227
|
-
customerId,
|
|
228
|
-
billingAddress,
|
|
229
|
-
paymentMethod: "credit-card",
|
|
230
|
-
shippingAccepted: true,
|
|
231
|
-
});
|
|
232
|
-
```
|
|
233
|
-
|
|
234
229
|
### createAugurOptions
|
|
235
230
|
|
|
236
231
|
```ts
|
|
@@ -249,7 +244,7 @@ await queryClient.prefetchQuery(q.items.invMast.doc.get(42));
|
|
|
249
244
|
|
|
250
245
|
## Types
|
|
251
246
|
|
|
252
|
-
`AugurApiClient`, `BatchQueryConfig`, `CartActionCallbacks`, `CartInitCallbacks`, `CartPriceData`, `CartPricingResult`, `CartSessionInfo`, `FormatPriceCallOptions`, `GetItemCategoryApiOptions`, `PageData`, `PaymentBillingAddress`, `PaymentFlowCallbacks`, `UseFormatPriceOptions`, `UseStockOptions`, `AugurApiClient`, `BatchQueryConfig`, `PageData`
|
|
247
|
+
`AugurApiClient`, `BatchQueryConfig`, `CartActionCallbacks`, `CartInitCallbacks`, `CartPriceData`, `CartPricingResult`, `CartSessionInfo`, `CheckoutPersistField`, `FormatPriceCallOptions`, `GetItemCategoryApiOptions`, `OrderReadinessParams`, `PageData`, `PaymentBillingAddress`, `PaymentFlowCallbacks`, `UseFormatPriceOptions`, `UseStockOptions`, `AugurApiClient`, `BatchQueryConfig`, `PageData`, `CheckoutAddress`, `CheckoutContext`, `CheckoutContextValue`, `CheckoutIdentityConfig`, `CheckoutLifecycleHooks`, `CheckoutOrderConfig`, `CheckoutPaymentConfig`, `CheckoutPaymentModal`, `CheckoutProviderConfig`, `CheckoutProviderProps`, `CheckoutShippingConfig`, `CheckoutUIConfig`, `DefaultCheckoutStep`, `OrderConfirmation`
|
|
253
248
|
|
|
254
249
|
|
|
255
250
|
## Related Packages
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { TStock, TPriceData } from '@simpleapps-com/augur-utils';
|
|
2
|
-
import { AugurAuthContext, CacheConfig, AugurSiteConfig, DeepQueryOptions } from '@simpleapps-com/augur-core';
|
|
3
|
-
import { QueryClient } from '@tanstack/react-query';
|
|
4
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
2
|
import { ReactNode } from 'react';
|
|
3
|
+
import { AugurAuthContext, CacheConfig, AugurSiteConfig, DeepQueryOptions } from '@simpleapps-com/augur-core';
|
|
6
4
|
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
5
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Minimal type for the augur-api SDK instance.
|
|
@@ -141,16 +140,6 @@ interface GetItemCategoryApiOptions {
|
|
|
141
140
|
rootItemCategoryId?: string;
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
/** Returns the React Query cache key for a stock lookup by invMastUid. */
|
|
145
|
-
declare const getStockKey: (invMastUid: number | string) => readonly ["stock", string | number];
|
|
146
|
-
/** @deprecated Use createServerQueryProxy() from augur-server/hooks instead. */
|
|
147
|
-
declare const getStockOptions: (api: AugurApiClient, invMastUid: number | string, cache?: CacheConfig) => {
|
|
148
|
-
queryKey: readonly ["stock", string | number];
|
|
149
|
-
queryFn: () => Promise<TStock>;
|
|
150
|
-
staleTime: number | undefined;
|
|
151
|
-
gcTime: number | undefined;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
143
|
interface BatchQueryConfig<TParam, TData> {
|
|
155
144
|
params: TParam[];
|
|
156
145
|
queryClient: QueryClient;
|
|
@@ -173,25 +162,4 @@ interface BatchQueryConfig<TParam, TData> {
|
|
|
173
162
|
*/
|
|
174
163
|
declare function executeBatchQuery<TParam, TData>(config: BatchQueryConfig<TParam, TData>): Promise<Record<string, TData>>;
|
|
175
164
|
|
|
176
|
-
|
|
177
|
-
* Get cart pricing query options for prefetching or parent components.
|
|
178
|
-
*
|
|
179
|
-
* @deprecated Use createServerQueryProxy() from augur-server/hooks instead.
|
|
180
|
-
*/
|
|
181
|
-
declare function getCartPricingQueryOptions(api: AugurApiClient, cartLines: Array<{
|
|
182
|
-
itemId: string;
|
|
183
|
-
quantity: number;
|
|
184
|
-
}>, customerId: string | number | undefined, cache?: CacheConfig): {
|
|
185
|
-
enabled: boolean;
|
|
186
|
-
queryKey: readonly ["price", string, string | number | undefined, number];
|
|
187
|
-
queryFn: () => Promise<TPriceData>;
|
|
188
|
-
staleTime: number | undefined;
|
|
189
|
-
gcTime: number | undefined;
|
|
190
|
-
refetchOnReconnect: boolean;
|
|
191
|
-
refetchOnWindowFocus: boolean;
|
|
192
|
-
meta: {
|
|
193
|
-
persist: boolean;
|
|
194
|
-
};
|
|
195
|
-
}[];
|
|
196
|
-
|
|
197
|
-
export { type AugurApiClient as A, type BatchQueryConfig as B, type GetItemCategoryApiOptions as G, type PersistenceConfig as P, AugurHooksProvider as a, type PageData as b, getStockKey as c, getStockOptions as d, executeBatchQuery as e, useAugurApiOptional as f, getCartPricingQueryOptions as g, useAugurAuth as h, useAugurCache as i, useAugurOptions as j, useAugurSite as k, useAugurApi as u };
|
|
165
|
+
export { type AugurApiClient as A, type BatchQueryConfig as B, type GetItemCategoryApiOptions as G, type PersistenceConfig as P, AugurHooksProvider as a, type PageData as b, useAugurApiOptional as c, useAugurAuth as d, executeBatchQuery as e, useAugurCache as f, useAugurOptions as g, useAugurSite as h, useAugurApi as u };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { TStock, TPriceData } from '@simpleapps-com/augur-utils';
|
|
2
|
-
import { AugurAuthContext, CacheConfig, AugurSiteConfig, DeepQueryOptions } from '@simpleapps-com/augur-core';
|
|
3
|
-
import { QueryClient } from '@tanstack/react-query';
|
|
4
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
2
|
import { ReactNode } from 'react';
|
|
3
|
+
import { AugurAuthContext, CacheConfig, AugurSiteConfig, DeepQueryOptions } from '@simpleapps-com/augur-core';
|
|
6
4
|
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
5
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Minimal type for the augur-api SDK instance.
|
|
@@ -141,16 +140,6 @@ interface GetItemCategoryApiOptions {
|
|
|
141
140
|
rootItemCategoryId?: string;
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
/** Returns the React Query cache key for a stock lookup by invMastUid. */
|
|
145
|
-
declare const getStockKey: (invMastUid: number | string) => readonly ["stock", string | number];
|
|
146
|
-
/** @deprecated Use createServerQueryProxy() from augur-server/hooks instead. */
|
|
147
|
-
declare const getStockOptions: (api: AugurApiClient, invMastUid: number | string, cache?: CacheConfig) => {
|
|
148
|
-
queryKey: readonly ["stock", string | number];
|
|
149
|
-
queryFn: () => Promise<TStock>;
|
|
150
|
-
staleTime: number | undefined;
|
|
151
|
-
gcTime: number | undefined;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
143
|
interface BatchQueryConfig<TParam, TData> {
|
|
155
144
|
params: TParam[];
|
|
156
145
|
queryClient: QueryClient;
|
|
@@ -173,25 +162,4 @@ interface BatchQueryConfig<TParam, TData> {
|
|
|
173
162
|
*/
|
|
174
163
|
declare function executeBatchQuery<TParam, TData>(config: BatchQueryConfig<TParam, TData>): Promise<Record<string, TData>>;
|
|
175
164
|
|
|
176
|
-
|
|
177
|
-
* Get cart pricing query options for prefetching or parent components.
|
|
178
|
-
*
|
|
179
|
-
* @deprecated Use createServerQueryProxy() from augur-server/hooks instead.
|
|
180
|
-
*/
|
|
181
|
-
declare function getCartPricingQueryOptions(api: AugurApiClient, cartLines: Array<{
|
|
182
|
-
itemId: string;
|
|
183
|
-
quantity: number;
|
|
184
|
-
}>, customerId: string | number | undefined, cache?: CacheConfig): {
|
|
185
|
-
enabled: boolean;
|
|
186
|
-
queryKey: readonly ["price", string, string | number | undefined, number];
|
|
187
|
-
queryFn: () => Promise<TPriceData>;
|
|
188
|
-
staleTime: number | undefined;
|
|
189
|
-
gcTime: number | undefined;
|
|
190
|
-
refetchOnReconnect: boolean;
|
|
191
|
-
refetchOnWindowFocus: boolean;
|
|
192
|
-
meta: {
|
|
193
|
-
persist: boolean;
|
|
194
|
-
};
|
|
195
|
-
}[];
|
|
196
|
-
|
|
197
|
-
export { type AugurApiClient as A, type BatchQueryConfig as B, type GetItemCategoryApiOptions as G, type PersistenceConfig as P, AugurHooksProvider as a, type PageData as b, getStockKey as c, getStockOptions as d, executeBatchQuery as e, useAugurApiOptional as f, getCartPricingQueryOptions as g, useAugurAuth as h, useAugurCache as i, useAugurOptions as j, useAugurSite as k, useAugurApi as u };
|
|
165
|
+
export { type AugurApiClient as A, type BatchQueryConfig as B, type GetItemCategoryApiOptions as G, type PersistenceConfig as P, AugurHooksProvider as a, type PageData as b, useAugurApiOptional as c, useAugurAuth as d, executeBatchQuery as e, useAugurCache as f, useAugurOptions as g, useAugurSite as h, useAugurApi as u };
|
package/dist/checkout/index.cjs
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
var _chunkXLBU5PCTcjs = require('../chunk-XLBU5PCT.cjs');
|
|
8
10
|
|
|
9
11
|
// src/checkout/create-checkout-provider.tsx
|
|
@@ -15,6 +17,7 @@ var _chunkXLBU5PCTcjs = require('../chunk-XLBU5PCT.cjs');
|
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
var _react = require('react');
|
|
20
|
+
var _reactquery = require('@tanstack/react-query');
|
|
18
21
|
var _jsxruntime = require('react/jsx-runtime');
|
|
19
22
|
var ORDER_CONFIRMATION_KEY = "orderConfirmation";
|
|
20
23
|
function defaultRedirect(url) {
|
|
@@ -69,6 +72,48 @@ function assembleOrderPayload(config, ctx, contextValue, stateSnapshot) {
|
|
|
69
72
|
}
|
|
70
73
|
return { orderData: buildOrderData(stateSnapshot) };
|
|
71
74
|
}
|
|
75
|
+
function validateOrderPayload(orderData) {
|
|
76
|
+
if (orderData === null || typeof orderData !== "object" || Array.isArray(orderData)) {
|
|
77
|
+
return "Order payload is empty or malformed.";
|
|
78
|
+
}
|
|
79
|
+
if ("lines" in orderData) {
|
|
80
|
+
const lines = orderData["lines"];
|
|
81
|
+
if (!Array.isArray(lines) || lines.length === 0) {
|
|
82
|
+
return "Order has no line items.";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if ("header" in orderData) {
|
|
86
|
+
const header = orderData["header"];
|
|
87
|
+
if (header !== null && typeof header === "object" && !Array.isArray(header)) {
|
|
88
|
+
const customerId = header["customer_id"];
|
|
89
|
+
if (customerId == null || String(customerId).trim() === "") {
|
|
90
|
+
return "Order is missing a customer.";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function prepareOrderPayload(config, ctx, contextValue, stateSnapshot, setProcessingOrder) {
|
|
97
|
+
const { orderData, error: assemblyError } = assembleOrderPayload(
|
|
98
|
+
config,
|
|
99
|
+
ctx,
|
|
100
|
+
contextValue,
|
|
101
|
+
stateSnapshot
|
|
102
|
+
);
|
|
103
|
+
if (assemblyError) {
|
|
104
|
+
setProcessingOrder(false);
|
|
105
|
+
_optionalChain([config, 'access', _20 => _20.ui, 'optionalAccess', _21 => _21.onError, 'optionalCall', _22 => _22("Order Error", assemblyError)]);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const validationError = validateOrderPayload(orderData);
|
|
109
|
+
if (validationError) {
|
|
110
|
+
console.error("Order payload validation failed:", orderData);
|
|
111
|
+
setProcessingOrder(false);
|
|
112
|
+
_optionalChain([config, 'access', _23 => _23.ui, 'optionalAccess', _24 => _24.onError, 'optionalCall', _25 => _25("Order Error", validationError)]);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return orderData;
|
|
116
|
+
}
|
|
72
117
|
function buildOrderConfirmation(orderData, resultData, state, orderCartLines) {
|
|
73
118
|
return {
|
|
74
119
|
orderData,
|
|
@@ -83,41 +128,42 @@ function buildOrderConfirmation(orderData, resultData, state, orderCartLines) {
|
|
|
83
128
|
orderCartLines
|
|
84
129
|
};
|
|
85
130
|
}
|
|
86
|
-
function handleOrderSuccess(config, ctx, resultData, confirmation, setProcessingOrder, redirect) {
|
|
87
|
-
if (_optionalChain([config, 'access',
|
|
131
|
+
function handleOrderSuccess(config, ctx, resultData, confirmation, setProcessingOrder, redirect, queryClient, clearCart) {
|
|
132
|
+
if (_optionalChain([config, 'access', _26 => _26.payments, 'optionalAccess', _27 => _27.persistence])) {
|
|
88
133
|
_chunkXLBU5PCTcjs.clearFromSession.call(void 0, _chunkXLBU5PCTcjs.PAYMENT_STORAGE_KEY);
|
|
89
134
|
}
|
|
90
|
-
_optionalChain([config, 'access',
|
|
135
|
+
_optionalChain([config, 'access', _28 => _28.hooks, 'optionalAccess', _29 => _29.onAfterSubmit, 'optionalCall', _30 => _30(ctx, resultData)]);
|
|
91
136
|
if (config.order.persistence !== false) {
|
|
92
137
|
try {
|
|
93
138
|
sessionStorage.setItem(ORDER_CONFIRMATION_KEY, JSON.stringify(confirmation));
|
|
94
139
|
} catch (e) {
|
|
95
140
|
}
|
|
96
141
|
}
|
|
142
|
+
clearCart();
|
|
143
|
+
void queryClient.invalidateQueries({ queryKey: ["cartLines"] });
|
|
144
|
+
void queryClient.invalidateQueries({ queryKey: ["cart-also-bought"] });
|
|
145
|
+
void queryClient.invalidateQueries({ queryKey: ["commerce", "cartLine"] });
|
|
97
146
|
redirect(config.order.successRedirect);
|
|
98
147
|
setProcessingOrder(false);
|
|
99
148
|
}
|
|
100
|
-
async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUid, setProcessingOrder, redirect) {
|
|
149
|
+
async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUid, setProcessingOrder, redirect, queryClient, clearCart) {
|
|
101
150
|
const ctx = ctxRef.current;
|
|
102
151
|
const s = stateRef.current;
|
|
103
152
|
const preCheck = runPreSubmitChecks(config, ctx, s.shippingAddress);
|
|
104
153
|
if (preCheck === "__cancelled__") return;
|
|
105
154
|
if (preCheck) {
|
|
106
|
-
_optionalChain([config, 'access',
|
|
155
|
+
_optionalChain([config, 'access', _31 => _31.ui, 'optionalAccess', _32 => _32.onError, 'optionalCall', _33 => _33("Missing Information", preCheck)]);
|
|
107
156
|
return;
|
|
108
157
|
}
|
|
109
158
|
setProcessingOrder(true);
|
|
110
|
-
const
|
|
159
|
+
const orderData = prepareOrderPayload(
|
|
111
160
|
config,
|
|
112
161
|
ctx,
|
|
113
162
|
contextValueRef.current,
|
|
114
|
-
s
|
|
163
|
+
s,
|
|
164
|
+
setProcessingOrder
|
|
115
165
|
);
|
|
116
|
-
if (
|
|
117
|
-
setProcessingOrder(false);
|
|
118
|
-
_optionalChain([config, 'access', _28 => _28.ui, 'optionalAccess', _29 => _29.onError, 'optionalCall', _30 => _30("Order Error", assemblyError)]);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
166
|
+
if (!orderData) return;
|
|
121
167
|
let result;
|
|
122
168
|
try {
|
|
123
169
|
result = await config.order.submitOrder(orderData, resolveCartHdrUid(cartHdrUid));
|
|
@@ -127,7 +173,7 @@ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUi
|
|
|
127
173
|
}
|
|
128
174
|
if (!result.ok) {
|
|
129
175
|
setProcessingOrder(false);
|
|
130
|
-
_optionalChain([config, 'access',
|
|
176
|
+
_optionalChain([config, 'access', _34 => _34.ui, 'optionalAccess', _35 => _35.onError, 'optionalCall', _36 => _36("Order Failed", _nullishCoalesce(result.error, () => ( "Something went wrong.")))]);
|
|
131
177
|
return;
|
|
132
178
|
}
|
|
133
179
|
const confirmation = buildOrderConfirmation(
|
|
@@ -136,7 +182,16 @@ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUi
|
|
|
136
182
|
s,
|
|
137
183
|
contextValueRef.current.orderCartLines
|
|
138
184
|
);
|
|
139
|
-
handleOrderSuccess(
|
|
185
|
+
handleOrderSuccess(
|
|
186
|
+
config,
|
|
187
|
+
ctx,
|
|
188
|
+
result.data,
|
|
189
|
+
confirmation,
|
|
190
|
+
setProcessingOrder,
|
|
191
|
+
redirect,
|
|
192
|
+
queryClient,
|
|
193
|
+
clearCart
|
|
194
|
+
);
|
|
140
195
|
}
|
|
141
196
|
var NOOP_PAYMENT_CALLBACKS = {
|
|
142
197
|
transactionSetup: async () => void 0,
|
|
@@ -147,7 +202,7 @@ var NOOP_PAYMENT_CALLBACKS = {
|
|
|
147
202
|
};
|
|
148
203
|
var Ctx = _react.createContext.call(void 0, null);
|
|
149
204
|
function createCheckoutProvider(config) {
|
|
150
|
-
const hasPaymentFlow = !!_optionalChain([config, 'access',
|
|
205
|
+
const hasPaymentFlow = !!_optionalChain([config, 'access', _37 => _37.payments, 'optionalAccess', _38 => _38.callbacks]);
|
|
151
206
|
function CheckoutProvider({
|
|
152
207
|
children,
|
|
153
208
|
identity: propsIdentity
|
|
@@ -161,7 +216,7 @@ function createCheckoutProvider(config) {
|
|
|
161
216
|
const [carrierId, setCarrierId] = _react.useState.call(void 0, config.shipping.defaultCarrierId);
|
|
162
217
|
const [showShippingMethod, setShowShippingMethod] = _react.useState.call(void 0, false);
|
|
163
218
|
const [billingAddress, setBillingAddress] = _react.useState.call(void 0, );
|
|
164
|
-
const defaultPaymentMethod = _nullishCoalesce(_optionalChain([config, 'access',
|
|
219
|
+
const defaultPaymentMethod = _nullishCoalesce(_optionalChain([config, 'access', _39 => _39.hooks, 'optionalAccess', _40 => _40.getDefaultPaymentMethod, 'optionalCall', _41 => _41()]), () => ( "credit-card"));
|
|
165
220
|
const [paymentMethod, setPaymentMethod] = _react.useState.call(void 0, defaultPaymentMethod);
|
|
166
221
|
const [showBillingInfoSummary, setShowBillingInfoSummary] = _react.useState.call(void 0, false);
|
|
167
222
|
const [orderCartLines, setOrderCartLines] = _react.useState.call(void 0, );
|
|
@@ -182,12 +237,12 @@ function createCheckoutProvider(config) {
|
|
|
182
237
|
}, []);
|
|
183
238
|
const identity = _nullishCoalesce(propsIdentity, () => ( config.identity));
|
|
184
239
|
const payment = _chunkXLBU5PCTcjs.usePaymentFlow.call(void 0, {
|
|
185
|
-
callbacks: _nullishCoalesce(_optionalChain([config, 'access',
|
|
186
|
-
customerId: _optionalChain([identity, 'optionalAccess',
|
|
240
|
+
callbacks: _nullishCoalesce(_optionalChain([config, 'access', _42 => _42.payments, 'optionalAccess', _43 => _43.callbacks]), () => ( NOOP_PAYMENT_CALLBACKS)),
|
|
241
|
+
customerId: _optionalChain([identity, 'optionalAccess', _44 => _44.customerId]),
|
|
187
242
|
billingAddress,
|
|
188
243
|
paymentMethod,
|
|
189
244
|
shippingAccepted,
|
|
190
|
-
persistPayment: _optionalChain([config, 'access',
|
|
245
|
+
persistPayment: _optionalChain([config, 'access', _45 => _45.payments, 'optionalAccess', _46 => _46.persistence])
|
|
191
246
|
});
|
|
192
247
|
const paymentModal = hasPaymentFlow ? {
|
|
193
248
|
isOpen: payment.isOpen,
|
|
@@ -200,7 +255,7 @@ function createCheckoutProvider(config) {
|
|
|
200
255
|
unifiedBilling: payment.unifiedBilling,
|
|
201
256
|
unifiedPayment: payment.unifiedPayment,
|
|
202
257
|
handleBinCapture: payment.handleBinCapture,
|
|
203
|
-
hasValidPayment: !!_optionalChain([payment, 'access',
|
|
258
|
+
hasValidPayment: !!_optionalChain([payment, 'access', _47 => _47.unifiedPayment, 'optionalAccess', _48 => _48.PaymentAccountID])
|
|
204
259
|
} : void 0;
|
|
205
260
|
const ctxRef = _react.useRef.call(void 0, null);
|
|
206
261
|
ctxRef.current = {
|
|
@@ -226,7 +281,7 @@ function createCheckoutProvider(config) {
|
|
|
226
281
|
const goToStep = _react.useCallback.call(void 0,
|
|
227
282
|
(step) => {
|
|
228
283
|
const from = currentStep;
|
|
229
|
-
if (_optionalChain([config, 'access',
|
|
284
|
+
if (_optionalChain([config, 'access', _49 => _49.hooks, 'optionalAccess', _50 => _50.onStepChange])) {
|
|
230
285
|
config.hooks.onStepChange(ctxRef.current, from, step);
|
|
231
286
|
}
|
|
232
287
|
setCurrentStep(step);
|
|
@@ -234,6 +289,9 @@ function createCheckoutProvider(config) {
|
|
|
234
289
|
[currentStep]
|
|
235
290
|
);
|
|
236
291
|
const cartHdrUid = _chunkXLBU5PCTcjs.useCartHdrUid.call(void 0, );
|
|
292
|
+
const cartLines = _chunkXLBU5PCTcjs.useCartLines.call(void 0, );
|
|
293
|
+
const clearCart = _chunkXLBU5PCTcjs.useClearCart.call(void 0, );
|
|
294
|
+
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
237
295
|
const { enableProcessOrderBtn, processingValidation } = _chunkXLBU5PCTcjs.useOrderReadiness.call(void 0, {
|
|
238
296
|
cartHdrUid,
|
|
239
297
|
shippingAddress,
|
|
@@ -242,7 +300,7 @@ function createCheckoutProvider(config) {
|
|
|
242
300
|
showBillingInfoSummary,
|
|
243
301
|
processingOrder,
|
|
244
302
|
paymentMethod,
|
|
245
|
-
unifiedPaymentAccountId: _optionalChain([payment, 'access',
|
|
303
|
+
unifiedPaymentAccountId: _optionalChain([payment, 'access', _51 => _51.unifiedPayment, 'optionalAccess', _52 => _52.PaymentAccountID]),
|
|
246
304
|
unifiedBilling: payment.unifiedBilling,
|
|
247
305
|
isFreeShipping,
|
|
248
306
|
carrierId,
|
|
@@ -258,29 +316,29 @@ function createCheckoutProvider(config) {
|
|
|
258
316
|
}
|
|
259
317
|
}, []);
|
|
260
318
|
_react.useEffect.call(void 0, () => {
|
|
261
|
-
const custId = _optionalChain([identity, 'optionalAccess',
|
|
262
|
-
if (custId && _optionalChain([identity, 'optionalAccess',
|
|
319
|
+
const custId = _optionalChain([identity, 'optionalAccess', _53 => _53.customerId]);
|
|
320
|
+
if (custId && _optionalChain([identity, 'optionalAccess', _54 => _54.fetchCustomerDoc])) {
|
|
263
321
|
void identity.fetchCustomerDoc(custId).then(setCustomerDoc).catch(() => setCustomerDoc(null));
|
|
264
322
|
}
|
|
265
|
-
}, [_optionalChain([identity, 'optionalAccess',
|
|
323
|
+
}, [_optionalChain([identity, 'optionalAccess', _55 => _55.customerId])]);
|
|
266
324
|
_react.useEffect.call(void 0, () => {
|
|
267
|
-
if (!config.order.calculateTax || !_optionalChain([billingAddress, 'optionalAccess',
|
|
325
|
+
if (!config.order.calculateTax || !_optionalChain([billingAddress, 'optionalAccess', _56 => _56.postalCode])) return;
|
|
268
326
|
void config.order.calculateTax({
|
|
269
|
-
customerId: _optionalChain([identity, 'optionalAccess',
|
|
327
|
+
customerId: _optionalChain([identity, 'optionalAccess', _57 => _57.customerId]),
|
|
270
328
|
postalCode: billingAddress.postalCode,
|
|
271
329
|
items: _nullishCoalesce(orderCartLines, () => ( [])),
|
|
272
330
|
customerDoc
|
|
273
331
|
}).then((tax) => {
|
|
274
332
|
if (tax !== void 0) setTaxRate(tax);
|
|
275
333
|
});
|
|
276
|
-
}, [_optionalChain([billingAddress, 'optionalAccess',
|
|
334
|
+
}, [_optionalChain([billingAddress, 'optionalAccess', _58 => _58.postalCode]), orderCartLines]);
|
|
277
335
|
_react.useEffect.call(void 0, () => {
|
|
278
336
|
if (shippingAccepted && shippingAddress && !billingAddress) {
|
|
279
337
|
setBillingAddress(shippingAddress);
|
|
280
338
|
}
|
|
281
339
|
}, [shippingAccepted, shippingAddress, billingAddress]);
|
|
282
340
|
_react.useEffect.call(void 0, () => {
|
|
283
|
-
if (_optionalChain([config, 'access',
|
|
341
|
+
if (_optionalChain([config, 'access', _59 => _59.hooks, 'optionalAccess', _60 => _60.onShippingAccepted]) && shippingAccepted && shippingAddress) {
|
|
284
342
|
config.hooks.onShippingAccepted(ctxRef.current, shippingAddress, _nullishCoalesce(orderCartLines, () => ( [])));
|
|
285
343
|
}
|
|
286
344
|
}, [shippingAccepted, shippingAddress]);
|
|
@@ -342,12 +400,14 @@ function createCheckoutProvider(config) {
|
|
|
342
400
|
contextValueRef,
|
|
343
401
|
cartHdrUid,
|
|
344
402
|
setProcessingOrder,
|
|
345
|
-
redirect
|
|
403
|
+
redirect,
|
|
404
|
+
queryClient,
|
|
405
|
+
clearCart
|
|
346
406
|
);
|
|
347
407
|
} finally {
|
|
348
408
|
isProcessingRef.current = false;
|
|
349
409
|
}
|
|
350
|
-
}, [cartHdrUid, redirect]);
|
|
410
|
+
}, [cartHdrUid, redirect, queryClient, clearCart]);
|
|
351
411
|
const value = {
|
|
352
412
|
shippingAddress,
|
|
353
413
|
setShippingAddress,
|
|
@@ -372,6 +432,7 @@ function createCheckoutProvider(config) {
|
|
|
372
432
|
showBillingInfoSummary,
|
|
373
433
|
setShowBillingInfoSummary,
|
|
374
434
|
paymentModal,
|
|
435
|
+
cartLines,
|
|
375
436
|
orderCartLines,
|
|
376
437
|
setOrderCartLines,
|
|
377
438
|
processingOrder,
|