@commercengine/checkout 0.1.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/README.md ADDED
@@ -0,0 +1,402 @@
1
+ # @commercengine/checkout
2
+
3
+ Universal checkout SDK for Commerce Engine. Works with React, Vue, Svelte, Solid, and vanilla JavaScript.
4
+
5
+ ## Features
6
+
7
+ - **Universal** - One package for all frameworks
8
+ - **No Provider Required** - Initialize once, use anywhere
9
+ - **Reactive State** - Automatic UI updates when cart changes
10
+ - **Type Safe** - Full TypeScript support
11
+ - **Tree Shakeable** - Only bundle what you use
12
+
13
+ ## Architecture
14
+
15
+ Designed for large applications with multiple routes (Next.js, Remix, etc.):
16
+
17
+ - **Singleton Store** - One checkout instance shared across all components and routes
18
+ - **Non-blocking Init** - `initCheckout()` returns immediately, iframe loads in background
19
+ - **SSR Safe** - Initialization only runs on client, server renders with default state
20
+ - **Zero Core Web Vitals Impact**:
21
+ - **LCP**: Iframe is hidden, doesn't affect largest contentful paint
22
+ - **INP/FID**: No main thread blocking during initialization
23
+ - **CLS**: Fixed positioning, no layout shifts
24
+
25
+ ```
26
+ ┌─────────────────────────────────────────────────────────────┐
27
+ │ App Root (layout.tsx / _app.tsx) │
28
+ │ └─ initCheckout() ──► Creates hidden iframe (async) │
29
+ ├─────────────────────────────────────────────────────────────┤
30
+ │ Any Component (header, product page, cart page...) │
31
+ │ └─ useCheckout() ──► Same singleton store │
32
+ ├─────────────────────────────────────────────────────────────┤
33
+ │ Route Changes (SPA navigation) │
34
+ │ └─ Checkout instance persists, no re-initialization │
35
+ └─────────────────────────────────────────────────────────────┘
36
+ ```
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ npm install @commercengine/checkout
42
+ # or
43
+ pnpm add @commercengine/checkout
44
+ # or
45
+ yarn add @commercengine/checkout
46
+ ```
47
+
48
+ ## Quick Start
49
+
50
+ ### React / Next.js / Remix
51
+
52
+ ```tsx
53
+ import { useCheckout, initCheckout, destroyCheckout } from "@commercengine/checkout/react";
54
+ import { useEffect } from "react";
55
+
56
+ // Initialize once at app root
57
+ function App({ children }) {
58
+ useEffect(() => {
59
+ initCheckout({
60
+ storeId: "store_xxx",
61
+ apiKey: "ak_xxx",
62
+ onComplete: (order) => {
63
+ console.log("Order placed:", order.orderNumber);
64
+ },
65
+ });
66
+ return () => destroyCheckout();
67
+ }, []);
68
+
69
+ return <>{children}</>;
70
+ }
71
+
72
+ // Use anywhere - no provider needed
73
+ function Header() {
74
+ const { cartCount, openCart, isReady } = useCheckout();
75
+
76
+ return (
77
+ <button onClick={openCart} disabled={!isReady}>
78
+ Cart ({cartCount})
79
+ </button>
80
+ );
81
+ }
82
+
83
+ function ProductCard({ product }) {
84
+ const { addToCart } = useCheckout();
85
+
86
+ return (
87
+ <button onClick={() => addToCart(product.id, product.variantId, 1)}>
88
+ Add to Cart
89
+ </button>
90
+ );
91
+ }
92
+ ```
93
+
94
+ ### Vue / Nuxt
95
+
96
+ ```vue
97
+ <script setup>
98
+ import { useCheckout, initCheckout, destroyCheckout } from "@commercengine/checkout/vue";
99
+ import { onMounted, onUnmounted } from "vue";
100
+
101
+ // Initialize once at app root (App.vue or plugin)
102
+ onMounted(() => {
103
+ initCheckout({
104
+ storeId: "store_xxx",
105
+ apiKey: "ak_xxx",
106
+ });
107
+ });
108
+
109
+ onUnmounted(() => {
110
+ destroyCheckout();
111
+ });
112
+
113
+ // Use anywhere
114
+ const { cartCount, openCart, isReady } = useCheckout();
115
+ </script>
116
+
117
+ <template>
118
+ <button @click="openCart" :disabled="!isReady">
119
+ Cart ({{ cartCount }})
120
+ </button>
121
+ </template>
122
+ ```
123
+
124
+ ### Svelte / SvelteKit
125
+
126
+ ```svelte
127
+ <script>
128
+ import { checkout, initCheckout, destroyCheckout } from "@commercengine/checkout/svelte";
129
+ import { onMount, onDestroy } from "svelte";
130
+
131
+ // Initialize once at app root (+layout.svelte)
132
+ onMount(() => {
133
+ initCheckout({
134
+ storeId: "store_xxx",
135
+ apiKey: "ak_xxx",
136
+ });
137
+ });
138
+
139
+ onDestroy(() => {
140
+ destroyCheckout();
141
+ });
142
+ </script>
143
+
144
+ <button on:click={() => $checkout.openCart()} disabled={!$checkout.isReady}>
145
+ Cart ({$checkout.cartCount})
146
+ </button>
147
+ ```
148
+
149
+ Or use individual stores for fine-grained reactivity:
150
+
151
+ ```svelte
152
+ <script>
153
+ import { cartCount, isReady } from "@commercengine/checkout/svelte";
154
+ </script>
155
+
156
+ <span class="badge">{$cartCount}</span>
157
+ ```
158
+
159
+ ### Solid / SolidStart
160
+
161
+ ```tsx
162
+ import { useCheckout, initCheckout, destroyCheckout } from "@commercengine/checkout/solid";
163
+ import { onMount, onCleanup } from "solid-js";
164
+
165
+ // Initialize once at app root
166
+ function App(props) {
167
+ onMount(() => {
168
+ initCheckout({
169
+ storeId: "store_xxx",
170
+ apiKey: "ak_xxx",
171
+ });
172
+ });
173
+
174
+ onCleanup(() => {
175
+ destroyCheckout();
176
+ });
177
+
178
+ return <>{props.children}</>;
179
+ }
180
+
181
+ // Use anywhere
182
+ function Header() {
183
+ const checkout = useCheckout();
184
+
185
+ return (
186
+ <button onClick={() => checkout.openCart()} disabled={!checkout.isReady}>
187
+ Cart ({checkout.cartCount})
188
+ </button>
189
+ );
190
+ }
191
+ ```
192
+
193
+ ### Vanilla JavaScript
194
+
195
+ ```ts
196
+ import { initCheckout, getCheckout, subscribeToCheckout } from "@commercengine/checkout";
197
+
198
+ // Initialize
199
+ initCheckout({
200
+ storeId: "store_xxx",
201
+ apiKey: "ak_xxx",
202
+ onComplete: (order) => {
203
+ window.location.href = `/thank-you?order=${order.orderNumber}`;
204
+ },
205
+ });
206
+
207
+ // Use anywhere
208
+ document.getElementById("cart-btn").onclick = () => {
209
+ getCheckout().openCart();
210
+ };
211
+
212
+ // Subscribe to cart updates
213
+ subscribeToCheckout(
214
+ (state) => state.cartCount,
215
+ (count) => {
216
+ document.getElementById("cart-badge").textContent = count.toString();
217
+ }
218
+ );
219
+ ```
220
+
221
+ ## Configuration
222
+
223
+ Pass configuration to `initCheckout()`:
224
+
225
+ ```ts
226
+ initCheckout({
227
+ // Required
228
+ storeId: "store_xxx",
229
+ apiKey: "ak_xxx",
230
+
231
+ // Environment (default: "production")
232
+ environment: "production", // or "staging"
233
+
234
+ // Or use custom URL for local development
235
+ url: "http://localhost:8080",
236
+
237
+ // Theme (default: "system")
238
+ theme: "light", // or "dark" or "system"
239
+
240
+ // Appearance
241
+ appearance: {
242
+ zIndex: 99999,
243
+ },
244
+
245
+ // Authentication
246
+ authMode: "managed", // or "provided"
247
+ accessToken: "...", // if user already logged in
248
+ refreshToken: "...",
249
+
250
+ // Quick Buy (add product on init)
251
+ quickBuy: {
252
+ productId: "prod_xxx",
253
+ variantId: "var_xxx", // or null
254
+ quantity: 1,
255
+ },
256
+ sessionMode: "continue-existing", // or "force-new"
257
+ autoDetectQuickBuy: false, // parse URL params
258
+
259
+ // Callbacks
260
+ onReady: () => {},
261
+ onOpen: () => {},
262
+ onClose: () => {},
263
+ onComplete: (order) => {},
264
+ onCartUpdate: (cart) => {},
265
+ onLogin: (data) => {},
266
+ onLogout: (data) => {},
267
+ onTokenRefresh: (data) => {},
268
+ onSessionError: () => {},
269
+ onError: (error) => {},
270
+ });
271
+ ```
272
+
273
+ ## API Reference
274
+
275
+ ### Initialization
276
+
277
+ | Function | Description |
278
+ |----------|-------------|
279
+ | `initCheckout(config)` | Initialize checkout with configuration |
280
+ | `destroyCheckout()` | Destroy checkout instance and cleanup |
281
+
282
+ ### Hooks / Composables
283
+
284
+ | Framework | Import |
285
+ |-----------|--------|
286
+ | React | `useCheckout()` from `@commercengine/checkout/react` |
287
+ | Vue | `useCheckout()` from `@commercengine/checkout/vue` |
288
+ | Svelte | `checkout` store from `@commercengine/checkout/svelte` |
289
+ | Solid | `useCheckout()` from `@commercengine/checkout/solid` |
290
+
291
+ ### Return Values
292
+
293
+ | Property | Type | Description |
294
+ |----------|------|-------------|
295
+ | `isReady` | `boolean` | Whether checkout is ready to use |
296
+ | `isOpen` | `boolean` | Whether checkout overlay is open |
297
+ | `cartCount` | `number` | Number of items in cart |
298
+ | `cartTotal` | `number` | Cart subtotal amount |
299
+ | `cartCurrency` | `string` | Currency code (e.g., "USD") |
300
+
301
+ | Method | Description |
302
+ |--------|-------------|
303
+ | `openCart()` | Open the cart drawer |
304
+ | `openCheckout()` | Open checkout directly (Buy Now flow) |
305
+ | `close()` | Close the checkout overlay |
306
+ | `addToCart(productId, variantId, quantity?)` | Add item to cart |
307
+ | `updateTokens(accessToken, refreshToken?)` | Update auth tokens |
308
+
309
+ ### Vanilla JS Helpers
310
+
311
+ | Function | Description |
312
+ |----------|-------------|
313
+ | `getCheckout()` | Get current state and methods (non-reactive) |
314
+ | `subscribeToCheckout(listener)` | Subscribe to all state changes |
315
+ | `subscribeToCheckout(selector, listener)` | Subscribe to specific state |
316
+ | `checkoutStore` | Direct access to Zustand store |
317
+
318
+ ## TypeScript
319
+
320
+ All types are exported for convenience:
321
+
322
+ ```ts
323
+ import type {
324
+ // Configuration
325
+ CheckoutConfig,
326
+ Environment,
327
+ AuthMode,
328
+ SessionMode,
329
+ QuickBuyConfig,
330
+
331
+ // State
332
+ CartData,
333
+ OrderData,
334
+ UserInfo,
335
+ ErrorData,
336
+
337
+ // Auth events
338
+ AuthLoginData,
339
+ AuthLogoutData,
340
+ AuthRefreshData,
341
+
342
+ // Store types
343
+ CheckoutState,
344
+ CheckoutActions,
345
+ CheckoutStore,
346
+ } from "@commercengine/checkout/react"; // or /vue, /svelte, /solid
347
+ ```
348
+
349
+ ## Migration from @commercengine/react
350
+
351
+ If you're migrating from the old `@commercengine/react` package:
352
+
353
+ **Before:**
354
+ ```tsx
355
+ import { useCheckout } from "@commercengine/react";
356
+
357
+ function App() {
358
+ const { openCart, cartCount } = useCheckout({
359
+ storeId: "store_xxx",
360
+ apiKey: "ak_xxx",
361
+ onComplete: (order) => { ... },
362
+ });
363
+
364
+ return <button onClick={openCart}>Cart ({cartCount})</button>;
365
+ }
366
+ ```
367
+
368
+ **After:**
369
+ ```tsx
370
+ import { useCheckout, initCheckout, destroyCheckout } from "@commercengine/checkout/react";
371
+ import { useEffect } from "react";
372
+
373
+ // Initialize once at app root
374
+ function App({ children }) {
375
+ useEffect(() => {
376
+ initCheckout({
377
+ storeId: "store_xxx",
378
+ apiKey: "ak_xxx",
379
+ onComplete: (order) => { ... },
380
+ });
381
+ return () => destroyCheckout();
382
+ }, []);
383
+
384
+ return <>{children}</>;
385
+ }
386
+
387
+ // Use anywhere without config
388
+ function Header() {
389
+ const { openCart, cartCount } = useCheckout();
390
+ return <button onClick={openCart}>Cart ({cartCount})</button>;
391
+ }
392
+ ```
393
+
394
+ **Key differences:**
395
+ 1. Initialize once at app root with `initCheckout()` instead of passing config to every hook
396
+ 2. `useCheckout()` takes no parameters - just returns state and methods
397
+ 3. Cleanup with `destroyCheckout()` in app unmount
398
+ 4. Works across the entire app without prop drilling or providers
399
+
400
+ ## License
401
+
402
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ const require_store = require('./store.cjs');
2
+
3
+ exports.checkoutStore = require_store.checkoutStore;
4
+ exports.destroyCheckout = require_store.destroyCheckout;
5
+ exports.getCheckout = require_store.getCheckout;
6
+ exports.initCheckout = require_store.initCheckout;
7
+ exports.subscribeToCheckout = require_store.subscribeToCheckout;
@@ -0,0 +1,3 @@
1
+ import { a as destroyCheckout, c as subscribeToCheckout, i as checkoutStore, n as CheckoutState, o as getCheckout, r as CheckoutStore, s as initCheckout, t as CheckoutActions } from "./store.cjs";
2
+ import { AddToCartItem, AuthLoginData, AuthLogoutData, AuthMode, AuthRefreshData, CartData, Channel, CheckoutConfig, CheckoutEventType, Environment, ErrorData, LoginMethod, OrderData, QuickBuyConfig, SessionMode, UserInfo } from "@commercengine/js";
3
+ export { type AddToCartItem, type AuthLoginData, type AuthLogoutData, type AuthMode, type AuthRefreshData, type CartData, type Channel, type CheckoutActions, type CheckoutConfig, type CheckoutEventType, type CheckoutState, type CheckoutStore, type Environment, type ErrorData, type LoginMethod, type OrderData, type QuickBuyConfig, type SessionMode, type UserInfo, checkoutStore, destroyCheckout, getCheckout, initCheckout, subscribeToCheckout };
@@ -0,0 +1,3 @@
1
+ import { a as destroyCheckout, c as subscribeToCheckout, i as checkoutStore, n as CheckoutState, o as getCheckout, r as CheckoutStore, s as initCheckout, t as CheckoutActions } from "./store.js";
2
+ import { AddToCartItem, AuthLoginData, AuthLogoutData, AuthMode, AuthRefreshData, CartData, Channel, CheckoutConfig, CheckoutEventType, Environment, ErrorData, LoginMethod, OrderData, QuickBuyConfig, SessionMode, UserInfo } from "@commercengine/js";
3
+ export { type AddToCartItem, type AuthLoginData, type AuthLogoutData, type AuthMode, type AuthRefreshData, type CartData, type Channel, type CheckoutActions, type CheckoutConfig, type CheckoutEventType, type CheckoutState, type CheckoutStore, type Environment, type ErrorData, type LoginMethod, type OrderData, type QuickBuyConfig, type SessionMode, type UserInfo, checkoutStore, destroyCheckout, getCheckout, initCheckout, subscribeToCheckout };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { a as subscribeToCheckout, i as initCheckout, n as destroyCheckout, r as getCheckout, t as checkoutStore } from "./store.js";
2
+
3
+ export { checkoutStore, destroyCheckout, getCheckout, initCheckout, subscribeToCheckout };
package/dist/react.cjs ADDED
@@ -0,0 +1,105 @@
1
+ const require_store = require('./store.cjs');
2
+ let zustand = require("zustand");
3
+ let zustand_react_shallow = require("zustand/react/shallow");
4
+
5
+ //#region src/react.ts
6
+ /**
7
+ * Commerce Engine Checkout - React Binding
8
+ *
9
+ * React hook for checkout integration with automatic state synchronization.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * import { useCheckout, initCheckout } from "@commercengine/checkout/react";
14
+ *
15
+ * // Initialize once at app root
16
+ * function App() {
17
+ * useEffect(() => {
18
+ * initCheckout({
19
+ * storeId: "store_xxx",
20
+ * apiKey: "ak_xxx",
21
+ * onComplete: (order) => router.push("/thank-you"),
22
+ * });
23
+ * return () => destroyCheckout();
24
+ * }, []);
25
+ *
26
+ * return <>{children}</>;
27
+ * }
28
+ *
29
+ * // Use anywhere - no provider needed
30
+ * function Header() {
31
+ * const { cartCount, openCart, isReady } = useCheckout();
32
+ *
33
+ * return (
34
+ * <button onClick={openCart} disabled={!isReady}>
35
+ * Cart ({cartCount})
36
+ * </button>
37
+ * );
38
+ * }
39
+ * ```
40
+ *
41
+ * @packageDocumentation
42
+ */
43
+ /**
44
+ * React hook for checkout integration
45
+ *
46
+ * Provides reactive access to checkout state and methods.
47
+ * No provider required - works anywhere in your component tree.
48
+ *
49
+ * @returns Checkout state and methods
50
+ *
51
+ * @example Basic usage
52
+ * ```tsx
53
+ * function CartButton() {
54
+ * const { cartCount, openCart, isReady } = useCheckout();
55
+ *
56
+ * return (
57
+ * <button onClick={openCart} disabled={!isReady}>
58
+ * Cart ({cartCount})
59
+ * </button>
60
+ * );
61
+ * }
62
+ * ```
63
+ *
64
+ * @example Add to cart
65
+ * ```tsx
66
+ * function ProductCard({ product }) {
67
+ * const { addToCart } = useCheckout();
68
+ *
69
+ * return (
70
+ * <button onClick={() => addToCart(product.id, product.variantId, 1)}>
71
+ * Add to Cart
72
+ * </button>
73
+ * );
74
+ * }
75
+ * ```
76
+ */
77
+ function useCheckout() {
78
+ const state = (0, zustand.useStore)(require_store.checkoutStore, (0, zustand_react_shallow.useShallow)((s) => ({
79
+ isReady: s.isReady,
80
+ isOpen: s.isOpen,
81
+ cartCount: s.cartCount,
82
+ cartTotal: s.cartTotal,
83
+ cartCurrency: s.cartCurrency
84
+ })));
85
+ const actions = (0, zustand.useStore)(require_store.checkoutStore, (0, zustand_react_shallow.useShallow)((s) => ({
86
+ openCart: s.openCart,
87
+ openCheckout: s.openCheckout,
88
+ close: s.close,
89
+ addToCart: s.addToCart,
90
+ updateTokens: s.updateTokens
91
+ })));
92
+ return {
93
+ ...state,
94
+ ...actions
95
+ };
96
+ }
97
+
98
+ //#endregion
99
+ exports.checkoutStore = require_store.checkoutStore;
100
+ exports.destroyCheckout = require_store.destroyCheckout;
101
+ exports.getCheckout = require_store.getCheckout;
102
+ exports.initCheckout = require_store.initCheckout;
103
+ exports.subscribeToCheckout = require_store.subscribeToCheckout;
104
+ exports.useCheckout = useCheckout;
105
+ //# sourceMappingURL=react.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.cjs","names":["checkoutStore"],"sources":["../src/react.ts"],"sourcesContent":["/**\n * Commerce Engine Checkout - React Binding\n *\n * React hook for checkout integration with automatic state synchronization.\n *\n * @example\n * ```tsx\n * import { useCheckout, initCheckout } from \"@commercengine/checkout/react\";\n *\n * // Initialize once at app root\n * function App() {\n * useEffect(() => {\n * initCheckout({\n * storeId: \"store_xxx\",\n * apiKey: \"ak_xxx\",\n * onComplete: (order) => router.push(\"/thank-you\"),\n * });\n * return () => destroyCheckout();\n * }, []);\n *\n * return <>{children}</>;\n * }\n *\n * // Use anywhere - no provider needed\n * function Header() {\n * const { cartCount, openCart, isReady } = useCheckout();\n *\n * return (\n * <button onClick={openCart} disabled={!isReady}>\n * Cart ({cartCount})\n * </button>\n * );\n * }\n * ```\n *\n * @packageDocumentation\n */\n\nimport { useStore } from \"zustand\";\nimport { useShallow } from \"zustand/react/shallow\";\nimport { type CheckoutActions, type CheckoutState, checkoutStore } from \"./store\";\n\n// Re-export types from @commercengine/js\nexport type {\n AddToCartItem,\n AuthLoginData,\n AuthLogoutData,\n AuthMode,\n AuthRefreshData,\n CartData,\n Channel,\n CheckoutConfig,\n CheckoutEventType,\n Environment,\n ErrorData,\n LoginMethod,\n OrderData,\n QuickBuyConfig,\n SessionMode,\n UserInfo,\n} from \"@commercengine/js\";\n// Re-export everything from vanilla for convenience\nexport {\n type CheckoutActions,\n type CheckoutState,\n type CheckoutStore,\n checkoutStore,\n destroyCheckout,\n getCheckout,\n initCheckout,\n subscribeToCheckout,\n} from \"./store\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\n/**\n * Return type from useCheckout hook\n */\nexport interface UseCheckoutReturn {\n /** Whether checkout is ready to use */\n isReady: boolean;\n /** Whether checkout overlay is currently open */\n isOpen: boolean;\n /** Number of items in cart */\n cartCount: number;\n /** Cart subtotal amount */\n cartTotal: number;\n /** Cart currency code */\n cartCurrency: string;\n /** Open the cart drawer */\n openCart: () => void;\n /** Open the checkout drawer directly */\n openCheckout: () => void;\n /** Close the checkout overlay */\n close: () => void;\n /** Add item to cart */\n addToCart: (productId: string, variantId: string | null, quantity?: number) => void;\n /** Update authentication tokens */\n updateTokens: (accessToken: string, refreshToken?: string) => void;\n}\n\n// =============================================================================\n// HOOK\n// =============================================================================\n\n/**\n * React hook for checkout integration\n *\n * Provides reactive access to checkout state and methods.\n * No provider required - works anywhere in your component tree.\n *\n * @returns Checkout state and methods\n *\n * @example Basic usage\n * ```tsx\n * function CartButton() {\n * const { cartCount, openCart, isReady } = useCheckout();\n *\n * return (\n * <button onClick={openCart} disabled={!isReady}>\n * Cart ({cartCount})\n * </button>\n * );\n * }\n * ```\n *\n * @example Add to cart\n * ```tsx\n * function ProductCard({ product }) {\n * const { addToCart } = useCheckout();\n *\n * return (\n * <button onClick={() => addToCart(product.id, product.variantId, 1)}>\n * Add to Cart\n * </button>\n * );\n * }\n * ```\n */\nexport function useCheckout(): UseCheckoutReturn {\n // Subscribe to state with shallow comparison to prevent unnecessary re-renders\n const state = useStore(\n checkoutStore,\n useShallow((s: CheckoutState) => ({\n isReady: s.isReady,\n isOpen: s.isOpen,\n cartCount: s.cartCount,\n cartTotal: s.cartTotal,\n cartCurrency: s.cartCurrency,\n }))\n );\n\n // Actions are stable references from the store\n const actions = useStore(\n checkoutStore,\n useShallow((s: CheckoutActions) => ({\n openCart: s.openCart,\n openCheckout: s.openCheckout,\n close: s.close,\n addToCart: s.addToCart,\n updateTokens: s.updateTokens,\n }))\n );\n\n return {\n ...state,\n ...actions,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6IA,SAAgB,cAAiC;CAE/C,MAAM,8BACJA,oEACY,OAAsB;EAChC,SAAS,EAAE;EACX,QAAQ,EAAE;EACV,WAAW,EAAE;EACb,WAAW,EAAE;EACb,cAAc,EAAE;EACjB,EAAE,CACJ;CAGD,MAAM,gCACJA,oEACY,OAAwB;EAClC,UAAU,EAAE;EACZ,cAAc,EAAE;EAChB,OAAO,EAAE;EACT,WAAW,EAAE;EACb,cAAc,EAAE;EACjB,EAAE,CACJ;AAED,QAAO;EACL,GAAG;EACH,GAAG;EACJ"}
@@ -0,0 +1,69 @@
1
+ import { a as destroyCheckout, c as subscribeToCheckout, i as checkoutStore, n as CheckoutState, o as getCheckout, r as CheckoutStore, s as initCheckout, t as CheckoutActions } from "./store.cjs";
2
+ import { AddToCartItem, AuthLoginData, AuthLogoutData, AuthMode, AuthRefreshData, CartData, Channel, CheckoutConfig, CheckoutEventType, Environment, ErrorData, LoginMethod, OrderData, QuickBuyConfig, SessionMode, UserInfo } from "@commercengine/js";
3
+
4
+ //#region src/react.d.ts
5
+
6
+ /**
7
+ * Return type from useCheckout hook
8
+ */
9
+ interface UseCheckoutReturn {
10
+ /** Whether checkout is ready to use */
11
+ isReady: boolean;
12
+ /** Whether checkout overlay is currently open */
13
+ isOpen: boolean;
14
+ /** Number of items in cart */
15
+ cartCount: number;
16
+ /** Cart subtotal amount */
17
+ cartTotal: number;
18
+ /** Cart currency code */
19
+ cartCurrency: string;
20
+ /** Open the cart drawer */
21
+ openCart: () => void;
22
+ /** Open the checkout drawer directly */
23
+ openCheckout: () => void;
24
+ /** Close the checkout overlay */
25
+ close: () => void;
26
+ /** Add item to cart */
27
+ addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
28
+ /** Update authentication tokens */
29
+ updateTokens: (accessToken: string, refreshToken?: string) => void;
30
+ }
31
+ /**
32
+ * React hook for checkout integration
33
+ *
34
+ * Provides reactive access to checkout state and methods.
35
+ * No provider required - works anywhere in your component tree.
36
+ *
37
+ * @returns Checkout state and methods
38
+ *
39
+ * @example Basic usage
40
+ * ```tsx
41
+ * function CartButton() {
42
+ * const { cartCount, openCart, isReady } = useCheckout();
43
+ *
44
+ * return (
45
+ * <button onClick={openCart} disabled={!isReady}>
46
+ * Cart ({cartCount})
47
+ * </button>
48
+ * );
49
+ * }
50
+ * ```
51
+ *
52
+ * @example Add to cart
53
+ * ```tsx
54
+ * function ProductCard({ product }) {
55
+ * const { addToCart } = useCheckout();
56
+ *
57
+ * return (
58
+ * <button onClick={() => addToCart(product.id, product.variantId, 1)}>
59
+ * Add to Cart
60
+ * </button>
61
+ * );
62
+ * }
63
+ * ```
64
+ */
65
+ declare function useCheckout(): UseCheckoutReturn;
66
+ //# sourceMappingURL=react.d.ts.map
67
+ //#endregion
68
+ export { type AddToCartItem, type AuthLoginData, type AuthLogoutData, type AuthMode, type AuthRefreshData, type CartData, type Channel, type CheckoutActions, type CheckoutConfig, type CheckoutEventType, type CheckoutState, type CheckoutStore, type Environment, type ErrorData, type LoginMethod, type OrderData, type QuickBuyConfig, type SessionMode, UseCheckoutReturn, type UserInfo, checkoutStore, destroyCheckout, getCheckout, initCheckout, subscribeToCheckout, useCheckout };
69
+ //# sourceMappingURL=react.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.cts","names":[],"sources":["../src/react.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAgFiB,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6DD,WAAA,CAAA,GAAe"}
@@ -0,0 +1,69 @@
1
+ import { a as destroyCheckout, c as subscribeToCheckout, i as checkoutStore, n as CheckoutState, o as getCheckout, r as CheckoutStore, s as initCheckout, t as CheckoutActions } from "./store.js";
2
+ import { AddToCartItem, AuthLoginData, AuthLogoutData, AuthMode, AuthRefreshData, CartData, Channel, CheckoutConfig, CheckoutEventType, Environment, ErrorData, LoginMethod, OrderData, QuickBuyConfig, SessionMode, UserInfo } from "@commercengine/js";
3
+
4
+ //#region src/react.d.ts
5
+
6
+ /**
7
+ * Return type from useCheckout hook
8
+ */
9
+ interface UseCheckoutReturn {
10
+ /** Whether checkout is ready to use */
11
+ isReady: boolean;
12
+ /** Whether checkout overlay is currently open */
13
+ isOpen: boolean;
14
+ /** Number of items in cart */
15
+ cartCount: number;
16
+ /** Cart subtotal amount */
17
+ cartTotal: number;
18
+ /** Cart currency code */
19
+ cartCurrency: string;
20
+ /** Open the cart drawer */
21
+ openCart: () => void;
22
+ /** Open the checkout drawer directly */
23
+ openCheckout: () => void;
24
+ /** Close the checkout overlay */
25
+ close: () => void;
26
+ /** Add item to cart */
27
+ addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
28
+ /** Update authentication tokens */
29
+ updateTokens: (accessToken: string, refreshToken?: string) => void;
30
+ }
31
+ /**
32
+ * React hook for checkout integration
33
+ *
34
+ * Provides reactive access to checkout state and methods.
35
+ * No provider required - works anywhere in your component tree.
36
+ *
37
+ * @returns Checkout state and methods
38
+ *
39
+ * @example Basic usage
40
+ * ```tsx
41
+ * function CartButton() {
42
+ * const { cartCount, openCart, isReady } = useCheckout();
43
+ *
44
+ * return (
45
+ * <button onClick={openCart} disabled={!isReady}>
46
+ * Cart ({cartCount})
47
+ * </button>
48
+ * );
49
+ * }
50
+ * ```
51
+ *
52
+ * @example Add to cart
53
+ * ```tsx
54
+ * function ProductCard({ product }) {
55
+ * const { addToCart } = useCheckout();
56
+ *
57
+ * return (
58
+ * <button onClick={() => addToCart(product.id, product.variantId, 1)}>
59
+ * Add to Cart
60
+ * </button>
61
+ * );
62
+ * }
63
+ * ```
64
+ */
65
+ declare function useCheckout(): UseCheckoutReturn;
66
+ //# sourceMappingURL=react.d.ts.map
67
+ //#endregion
68
+ export { type AddToCartItem, type AuthLoginData, type AuthLogoutData, type AuthMode, type AuthRefreshData, type CartData, type Channel, type CheckoutActions, type CheckoutConfig, type CheckoutEventType, type CheckoutState, type CheckoutStore, type Environment, type ErrorData, type LoginMethod, type OrderData, type QuickBuyConfig, type SessionMode, UseCheckoutReturn, type UserInfo, checkoutStore, destroyCheckout, getCheckout, initCheckout, subscribeToCheckout, useCheckout };
69
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","names":[],"sources":["../src/react.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAgFiB,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6DD,WAAA,CAAA,GAAe"}