@simpleapps-com/augur-hooks 2.2.29 → 2.3.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 (39) hide show
  1. package/EXPORTS.md +28 -9
  2. package/README.md +20 -25
  3. package/dist/{cart-pricing-CTMlA3nE.d.cts → batch-query-CTlvxSmL.d.cts} +3 -35
  4. package/dist/{cart-pricing-CTMlA3nE.d.ts → batch-query-CTlvxSmL.d.ts} +3 -35
  5. package/dist/checkout/index.cjs +110 -39
  6. package/dist/checkout/index.cjs.map +1 -1
  7. package/dist/checkout/index.d.cts +55 -6
  8. package/dist/checkout/index.d.ts +55 -6
  9. package/dist/checkout/index.js +87 -16
  10. package/dist/checkout/index.js.map +1 -1
  11. package/dist/chunk-6Z6JGK2C.cjs +41 -0
  12. package/dist/chunk-6Z6JGK2C.cjs.map +1 -0
  13. package/dist/chunk-D5C6WWFO.js +41 -0
  14. package/dist/chunk-D5C6WWFO.js.map +1 -0
  15. package/dist/{chunk-XLBU5PCT.cjs → chunk-I4A5L2I6.cjs} +3 -2
  16. package/dist/chunk-I4A5L2I6.cjs.map +1 -0
  17. package/dist/{chunk-5YN2RPZ4.js → chunk-NRWH2BMN.js} +3 -2
  18. package/dist/{chunk-5YN2RPZ4.js.map → chunk-NRWH2BMN.js.map} +1 -1
  19. package/dist/index.cjs +12 -18
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +4 -45
  22. package/dist/index.d.ts +4 -45
  23. package/dist/index.js +2 -8
  24. package/dist/index.js.map +1 -1
  25. package/dist/server.cjs +3 -9
  26. package/dist/server.cjs.map +1 -1
  27. package/dist/server.d.cts +1 -2
  28. package/dist/server.d.ts +1 -2
  29. package/dist/server.js +3 -9
  30. package/dist/server.js.map +1 -1
  31. package/dist/{use-payment-flow-u8RwBTbO.d.ts → use-order-readiness-DZTIfRzw.d.cts} +48 -1
  32. package/dist/{use-payment-flow-u8RwBTbO.d.cts → use-order-readiness-DZTIfRzw.d.ts} +48 -1
  33. package/llms.txt +31 -22
  34. package/package.json +3 -3
  35. package/dist/chunk-GHON6UMJ.js +0 -144
  36. package/dist/chunk-GHON6UMJ.js.map +0 -1
  37. package/dist/chunk-XJJ6DZDK.cjs +0 -144
  38. package/dist/chunk-XJJ6DZDK.cjs.map +0 -1
  39. package/dist/chunk-XLBU5PCT.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.10
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
- | `getStockKey` | value | |
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 | Manages the full Element/Unified payment lifecycle: |
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` | 50 exports, 14 types |
24
- | `@simpleapps-com/augur-hooks/server` | 9 exports, 3 types |
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
- | `usePaymentFlow` | function | Manages the full Element/Unified payment lifecycle: |
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 };
@@ -4,7 +4,9 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkXLBU5PCTcjs = require('../chunk-XLBU5PCT.cjs');
7
+
8
+
9
+ var _chunkI4A5L2I6cjs = require('../chunk-I4A5L2I6.cjs');
8
10
 
9
11
  // src/checkout/create-checkout-provider.tsx
10
12
 
@@ -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) {
@@ -61,14 +64,66 @@ function resolveCartHdrUid(cartHdrUid) {
61
64
  if (typeof cartHdrUid === "string") return Number(cartHdrUid);
62
65
  return _nullishCoalesce(cartHdrUid, () => ( 0));
63
66
  }
67
+ function resolveDefaultPaymentMethod(config) {
68
+ const explicit = _optionalChain([config, 'access', _18 => _18.hooks, 'optionalAccess', _19 => _19.getDefaultPaymentMethod, 'optionalCall', _20 => _20()]);
69
+ if (explicit) return explicit;
70
+ return _optionalChain([config, 'access', _21 => _21.payments, 'optionalAccess', _22 => _22.callbacks]) ? "credit-card" : "invoice";
71
+ }
72
+ function buildReadinessOverride(config, ctxRef) {
73
+ const siteIsOrderReady = _optionalChain([config, 'access', _23 => _23.hooks, 'optionalAccess', _24 => _24.isOrderReady]);
74
+ if (!siteIsOrderReady) return void 0;
75
+ return (params) => siteIsOrderReady(ctxRef.current, params);
76
+ }
64
77
  function assembleOrderPayload(config, ctx, contextValue, stateSnapshot) {
65
- if (_optionalChain([config, 'access', _18 => _18.hooks, 'optionalAccess', _19 => _19.assembleOrder])) {
78
+ if (_optionalChain([config, 'access', _25 => _25.hooks, 'optionalAccess', _26 => _26.assembleOrder])) {
66
79
  const assembled = config.hooks.assembleOrder(ctx, contextValue);
67
80
  if (assembled.error) return { orderData: {}, error: assembled.error };
68
81
  return { orderData: assembled.order };
69
82
  }
70
83
  return { orderData: buildOrderData(stateSnapshot) };
71
84
  }
85
+ function validateOrderPayload(orderData) {
86
+ if (orderData === null || typeof orderData !== "object" || Array.isArray(orderData)) {
87
+ return "Order payload is empty or malformed.";
88
+ }
89
+ if ("lines" in orderData) {
90
+ const lines = orderData["lines"];
91
+ if (!Array.isArray(lines) || lines.length === 0) {
92
+ return "Order has no line items.";
93
+ }
94
+ }
95
+ if ("header" in orderData) {
96
+ const header = orderData["header"];
97
+ if (header !== null && typeof header === "object" && !Array.isArray(header)) {
98
+ const customerId = header["customer_id"];
99
+ if (customerId == null || String(customerId).trim() === "") {
100
+ return "Order is missing a customer.";
101
+ }
102
+ }
103
+ }
104
+ return null;
105
+ }
106
+ function prepareOrderPayload(config, ctx, contextValue, stateSnapshot, setProcessingOrder) {
107
+ const { orderData, error: assemblyError } = assembleOrderPayload(
108
+ config,
109
+ ctx,
110
+ contextValue,
111
+ stateSnapshot
112
+ );
113
+ if (assemblyError) {
114
+ setProcessingOrder(false);
115
+ _optionalChain([config, 'access', _27 => _27.ui, 'optionalAccess', _28 => _28.onError, 'optionalCall', _29 => _29("Order Error", assemblyError)]);
116
+ return null;
117
+ }
118
+ const validationError = validateOrderPayload(orderData);
119
+ if (validationError) {
120
+ console.error("Order payload validation failed:", orderData);
121
+ setProcessingOrder(false);
122
+ _optionalChain([config, 'access', _30 => _30.ui, 'optionalAccess', _31 => _31.onError, 'optionalCall', _32 => _32("Order Error", validationError)]);
123
+ return null;
124
+ }
125
+ return orderData;
126
+ }
72
127
  function buildOrderConfirmation(orderData, resultData, state, orderCartLines) {
73
128
  return {
74
129
  orderData,
@@ -83,41 +138,42 @@ function buildOrderConfirmation(orderData, resultData, state, orderCartLines) {
83
138
  orderCartLines
84
139
  };
85
140
  }
86
- function handleOrderSuccess(config, ctx, resultData, confirmation, setProcessingOrder, redirect) {
87
- if (_optionalChain([config, 'access', _20 => _20.payments, 'optionalAccess', _21 => _21.persistence])) {
88
- _chunkXLBU5PCTcjs.clearFromSession.call(void 0, _chunkXLBU5PCTcjs.PAYMENT_STORAGE_KEY);
141
+ function handleOrderSuccess(config, ctx, resultData, confirmation, setProcessingOrder, redirect, queryClient, clearCart) {
142
+ if (_optionalChain([config, 'access', _33 => _33.payments, 'optionalAccess', _34 => _34.persistence])) {
143
+ _chunkI4A5L2I6cjs.clearFromSession.call(void 0, _chunkI4A5L2I6cjs.PAYMENT_STORAGE_KEY);
89
144
  }
90
- _optionalChain([config, 'access', _22 => _22.hooks, 'optionalAccess', _23 => _23.onAfterSubmit, 'optionalCall', _24 => _24(ctx, resultData)]);
145
+ _optionalChain([config, 'access', _35 => _35.hooks, 'optionalAccess', _36 => _36.onAfterSubmit, 'optionalCall', _37 => _37(ctx, resultData)]);
91
146
  if (config.order.persistence !== false) {
92
147
  try {
93
148
  sessionStorage.setItem(ORDER_CONFIRMATION_KEY, JSON.stringify(confirmation));
94
149
  } catch (e) {
95
150
  }
96
151
  }
152
+ clearCart();
153
+ void queryClient.invalidateQueries({ queryKey: ["cartLines"] });
154
+ void queryClient.invalidateQueries({ queryKey: ["cart-also-bought"] });
155
+ void queryClient.invalidateQueries({ queryKey: ["commerce", "cartLine"] });
97
156
  redirect(config.order.successRedirect);
98
157
  setProcessingOrder(false);
99
158
  }
100
- async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUid, setProcessingOrder, redirect) {
159
+ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUid, setProcessingOrder, redirect, queryClient, clearCart) {
101
160
  const ctx = ctxRef.current;
102
161
  const s = stateRef.current;
103
162
  const preCheck = runPreSubmitChecks(config, ctx, s.shippingAddress);
104
163
  if (preCheck === "__cancelled__") return;
105
164
  if (preCheck) {
106
- _optionalChain([config, 'access', _25 => _25.ui, 'optionalAccess', _26 => _26.onError, 'optionalCall', _27 => _27("Missing Information", preCheck)]);
165
+ _optionalChain([config, 'access', _38 => _38.ui, 'optionalAccess', _39 => _39.onError, 'optionalCall', _40 => _40("Missing Information", preCheck)]);
107
166
  return;
108
167
  }
109
168
  setProcessingOrder(true);
110
- const { orderData, error: assemblyError } = assembleOrderPayload(
169
+ const orderData = prepareOrderPayload(
111
170
  config,
112
171
  ctx,
113
172
  contextValueRef.current,
114
- s
173
+ s,
174
+ setProcessingOrder
115
175
  );
116
- if (assemblyError) {
117
- setProcessingOrder(false);
118
- _optionalChain([config, 'access', _28 => _28.ui, 'optionalAccess', _29 => _29.onError, 'optionalCall', _30 => _30("Order Error", assemblyError)]);
119
- return;
120
- }
176
+ if (!orderData) return;
121
177
  let result;
122
178
  try {
123
179
  result = await config.order.submitOrder(orderData, resolveCartHdrUid(cartHdrUid));
@@ -127,7 +183,7 @@ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUi
127
183
  }
128
184
  if (!result.ok) {
129
185
  setProcessingOrder(false);
130
- _optionalChain([config, 'access', _31 => _31.ui, 'optionalAccess', _32 => _32.onError, 'optionalCall', _33 => _33("Order Failed", _nullishCoalesce(result.error, () => ( "Something went wrong.")))]);
186
+ _optionalChain([config, 'access', _41 => _41.ui, 'optionalAccess', _42 => _42.onError, 'optionalCall', _43 => _43("Order Failed", _nullishCoalesce(result.error, () => ( "Something went wrong.")))]);
131
187
  return;
132
188
  }
133
189
  const confirmation = buildOrderConfirmation(
@@ -136,7 +192,16 @@ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUi
136
192
  s,
137
193
  contextValueRef.current.orderCartLines
138
194
  );
139
- handleOrderSuccess(config, ctx, result.data, confirmation, setProcessingOrder, redirect);
195
+ handleOrderSuccess(
196
+ config,
197
+ ctx,
198
+ result.data,
199
+ confirmation,
200
+ setProcessingOrder,
201
+ redirect,
202
+ queryClient,
203
+ clearCart
204
+ );
140
205
  }
141
206
  var NOOP_PAYMENT_CALLBACKS = {
142
207
  transactionSetup: async () => void 0,
@@ -147,7 +212,7 @@ var NOOP_PAYMENT_CALLBACKS = {
147
212
  };
148
213
  var Ctx = _react.createContext.call(void 0, null);
149
214
  function createCheckoutProvider(config) {
150
- const hasPaymentFlow = !!_optionalChain([config, 'access', _34 => _34.payments, 'optionalAccess', _35 => _35.callbacks]);
215
+ const hasPaymentFlow = !!_optionalChain([config, 'access', _44 => _44.payments, 'optionalAccess', _45 => _45.callbacks]);
151
216
  function CheckoutProvider({
152
217
  children,
153
218
  identity: propsIdentity
@@ -161,8 +226,7 @@ function createCheckoutProvider(config) {
161
226
  const [carrierId, setCarrierId] = _react.useState.call(void 0, config.shipping.defaultCarrierId);
162
227
  const [showShippingMethod, setShowShippingMethod] = _react.useState.call(void 0, false);
163
228
  const [billingAddress, setBillingAddress] = _react.useState.call(void 0, );
164
- const defaultPaymentMethod = _nullishCoalesce(_optionalChain([config, 'access', _36 => _36.hooks, 'optionalAccess', _37 => _37.getDefaultPaymentMethod, 'optionalCall', _38 => _38()]), () => ( "credit-card"));
165
- const [paymentMethod, setPaymentMethod] = _react.useState.call(void 0, defaultPaymentMethod);
229
+ const [paymentMethod, setPaymentMethod] = _react.useState.call(void 0, () => resolveDefaultPaymentMethod(config));
166
230
  const [showBillingInfoSummary, setShowBillingInfoSummary] = _react.useState.call(void 0, false);
167
231
  const [orderCartLines, setOrderCartLines] = _react.useState.call(void 0, );
168
232
  const [processingOrder, setProcessingOrder] = _react.useState.call(void 0, false);
@@ -181,13 +245,13 @@ function createCheckoutProvider(config) {
181
245
  setCustomState((prev) => ({ ...prev, [key]: value2 }));
182
246
  }, []);
183
247
  const identity = _nullishCoalesce(propsIdentity, () => ( config.identity));
184
- const payment = _chunkXLBU5PCTcjs.usePaymentFlow.call(void 0, {
185
- callbacks: _nullishCoalesce(_optionalChain([config, 'access', _39 => _39.payments, 'optionalAccess', _40 => _40.callbacks]), () => ( NOOP_PAYMENT_CALLBACKS)),
186
- customerId: _optionalChain([identity, 'optionalAccess', _41 => _41.customerId]),
248
+ const payment = _chunkI4A5L2I6cjs.usePaymentFlow.call(void 0, {
249
+ callbacks: _nullishCoalesce(_optionalChain([config, 'access', _46 => _46.payments, 'optionalAccess', _47 => _47.callbacks]), () => ( NOOP_PAYMENT_CALLBACKS)),
250
+ customerId: _optionalChain([identity, 'optionalAccess', _48 => _48.customerId]),
187
251
  billingAddress,
188
252
  paymentMethod,
189
253
  shippingAccepted,
190
- persistPayment: _optionalChain([config, 'access', _42 => _42.payments, 'optionalAccess', _43 => _43.persistence])
254
+ persistPayment: _optionalChain([config, 'access', _49 => _49.payments, 'optionalAccess', _50 => _50.persistence])
191
255
  });
192
256
  const paymentModal = hasPaymentFlow ? {
193
257
  isOpen: payment.isOpen,
@@ -200,7 +264,7 @@ function createCheckoutProvider(config) {
200
264
  unifiedBilling: payment.unifiedBilling,
201
265
  unifiedPayment: payment.unifiedPayment,
202
266
  handleBinCapture: payment.handleBinCapture,
203
- hasValidPayment: !!_optionalChain([payment, 'access', _44 => _44.unifiedPayment, 'optionalAccess', _45 => _45.PaymentAccountID])
267
+ hasValidPayment: !!_optionalChain([payment, 'access', _51 => _51.unifiedPayment, 'optionalAccess', _52 => _52.PaymentAccountID])
204
268
  } : void 0;
205
269
  const ctxRef = _react.useRef.call(void 0, null);
206
270
  ctxRef.current = {
@@ -226,15 +290,18 @@ function createCheckoutProvider(config) {
226
290
  const goToStep = _react.useCallback.call(void 0,
227
291
  (step) => {
228
292
  const from = currentStep;
229
- if (_optionalChain([config, 'access', _46 => _46.hooks, 'optionalAccess', _47 => _47.onStepChange])) {
293
+ if (_optionalChain([config, 'access', _53 => _53.hooks, 'optionalAccess', _54 => _54.onStepChange])) {
230
294
  config.hooks.onStepChange(ctxRef.current, from, step);
231
295
  }
232
296
  setCurrentStep(step);
233
297
  },
234
298
  [currentStep]
235
299
  );
236
- const cartHdrUid = _chunkXLBU5PCTcjs.useCartHdrUid.call(void 0, );
237
- const { enableProcessOrderBtn, processingValidation } = _chunkXLBU5PCTcjs.useOrderReadiness.call(void 0, {
300
+ const cartHdrUid = _chunkI4A5L2I6cjs.useCartHdrUid.call(void 0, );
301
+ const cartLines = _chunkI4A5L2I6cjs.useCartLines.call(void 0, );
302
+ const clearCart = _chunkI4A5L2I6cjs.useClearCart.call(void 0, );
303
+ const queryClient = _reactquery.useQueryClient.call(void 0, );
304
+ const { enableProcessOrderBtn, processingValidation } = _chunkI4A5L2I6cjs.useOrderReadiness.call(void 0, {
238
305
  cartHdrUid,
239
306
  shippingAddress,
240
307
  billingAddress,
@@ -242,7 +309,7 @@ function createCheckoutProvider(config) {
242
309
  showBillingInfoSummary,
243
310
  processingOrder,
244
311
  paymentMethod,
245
- unifiedPaymentAccountId: _optionalChain([payment, 'access', _48 => _48.unifiedPayment, 'optionalAccess', _49 => _49.PaymentAccountID]),
312
+ unifiedPaymentAccountId: _optionalChain([payment, 'access', _55 => _55.unifiedPayment, 'optionalAccess', _56 => _56.PaymentAccountID]),
246
313
  unifiedBilling: payment.unifiedBilling,
247
314
  isFreeShipping,
248
315
  carrierId,
@@ -250,7 +317,8 @@ function createCheckoutProvider(config) {
250
317
  isEditShippingInfo,
251
318
  isEditShippingMethods,
252
319
  isEditBillingInfo,
253
- editCc: payment.editCc
320
+ editCc: payment.editCc,
321
+ customReadinessCheck: buildReadinessOverride(config, ctxRef)
254
322
  });
255
323
  _react.useEffect.call(void 0, () => {
256
324
  if (config.order.fetchClientIp) {
@@ -258,29 +326,29 @@ function createCheckoutProvider(config) {
258
326
  }
259
327
  }, []);
260
328
  _react.useEffect.call(void 0, () => {
261
- const custId = _optionalChain([identity, 'optionalAccess', _50 => _50.customerId]);
262
- if (custId && _optionalChain([identity, 'optionalAccess', _51 => _51.fetchCustomerDoc])) {
329
+ const custId = _optionalChain([identity, 'optionalAccess', _57 => _57.customerId]);
330
+ if (custId && _optionalChain([identity, 'optionalAccess', _58 => _58.fetchCustomerDoc])) {
263
331
  void identity.fetchCustomerDoc(custId).then(setCustomerDoc).catch(() => setCustomerDoc(null));
264
332
  }
265
- }, [_optionalChain([identity, 'optionalAccess', _52 => _52.customerId])]);
333
+ }, [_optionalChain([identity, 'optionalAccess', _59 => _59.customerId])]);
266
334
  _react.useEffect.call(void 0, () => {
267
- if (!config.order.calculateTax || !_optionalChain([billingAddress, 'optionalAccess', _53 => _53.postalCode])) return;
335
+ if (!config.order.calculateTax || !_optionalChain([billingAddress, 'optionalAccess', _60 => _60.postalCode])) return;
268
336
  void config.order.calculateTax({
269
- customerId: _optionalChain([identity, 'optionalAccess', _54 => _54.customerId]),
337
+ customerId: _optionalChain([identity, 'optionalAccess', _61 => _61.customerId]),
270
338
  postalCode: billingAddress.postalCode,
271
339
  items: _nullishCoalesce(orderCartLines, () => ( [])),
272
340
  customerDoc
273
341
  }).then((tax) => {
274
342
  if (tax !== void 0) setTaxRate(tax);
275
343
  });
276
- }, [_optionalChain([billingAddress, 'optionalAccess', _55 => _55.postalCode]), orderCartLines]);
344
+ }, [_optionalChain([billingAddress, 'optionalAccess', _62 => _62.postalCode]), orderCartLines]);
277
345
  _react.useEffect.call(void 0, () => {
278
346
  if (shippingAccepted && shippingAddress && !billingAddress) {
279
347
  setBillingAddress(shippingAddress);
280
348
  }
281
349
  }, [shippingAccepted, shippingAddress, billingAddress]);
282
350
  _react.useEffect.call(void 0, () => {
283
- if (_optionalChain([config, 'access', _56 => _56.hooks, 'optionalAccess', _57 => _57.onShippingAccepted]) && shippingAccepted && shippingAddress) {
351
+ if (_optionalChain([config, 'access', _63 => _63.hooks, 'optionalAccess', _64 => _64.onShippingAccepted]) && shippingAccepted && shippingAddress) {
284
352
  config.hooks.onShippingAccepted(ctxRef.current, shippingAddress, _nullishCoalesce(orderCartLines, () => ( [])));
285
353
  }
286
354
  }, [shippingAccepted, shippingAddress]);
@@ -342,12 +410,14 @@ function createCheckoutProvider(config) {
342
410
  contextValueRef,
343
411
  cartHdrUid,
344
412
  setProcessingOrder,
345
- redirect
413
+ redirect,
414
+ queryClient,
415
+ clearCart
346
416
  );
347
417
  } finally {
348
418
  isProcessingRef.current = false;
349
419
  }
350
- }, [cartHdrUid, redirect]);
420
+ }, [cartHdrUid, redirect, queryClient, clearCart]);
351
421
  const value = {
352
422
  shippingAddress,
353
423
  setShippingAddress,
@@ -372,6 +442,7 @@ function createCheckoutProvider(config) {
372
442
  showBillingInfoSummary,
373
443
  setShowBillingInfoSummary,
374
444
  paymentModal,
445
+ cartLines,
375
446
  orderCartLines,
376
447
  setOrderCartLines,
377
448
  processingOrder,