@commercengine/checkout 0.1.5 → 0.1.6

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/package.json CHANGED
@@ -1,61 +1,30 @@
1
1
  {
2
2
  "name": "@commercengine/checkout",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Universal checkout SDK for Commerce Engine - works with React, Vue, Svelte, Solid, and vanilla JS",
5
5
  "type": "module",
6
- "main": "dist/index.cjs",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.mts",
9
8
  "exports": {
10
9
  ".": {
11
- "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/index.js"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.cts",
17
- "default": "./dist/index.cjs"
18
- }
10
+ "types": "./dist/index.d.mts",
11
+ "default": "./dist/index.mjs"
19
12
  },
20
13
  "./react": {
21
- "import": {
22
- "types": "./dist/react.d.ts",
23
- "default": "./dist/react.js"
24
- },
25
- "require": {
26
- "types": "./dist/react.d.cts",
27
- "default": "./dist/react.cjs"
28
- }
14
+ "types": "./dist/react.d.mts",
15
+ "default": "./dist/react.mjs"
29
16
  },
30
17
  "./vue": {
31
- "import": {
32
- "types": "./dist/vue.d.ts",
33
- "default": "./dist/vue.js"
34
- },
35
- "require": {
36
- "types": "./dist/vue.d.cts",
37
- "default": "./dist/vue.cjs"
38
- }
18
+ "types": "./dist/vue.d.mts",
19
+ "default": "./dist/vue.mjs"
39
20
  },
40
21
  "./svelte": {
41
- "import": {
42
- "types": "./dist/svelte.d.ts",
43
- "default": "./dist/svelte.js"
44
- },
45
- "require": {
46
- "types": "./dist/svelte.d.cts",
47
- "default": "./dist/svelte.cjs"
48
- }
22
+ "types": "./dist/svelte.d.mts",
23
+ "default": "./dist/svelte.mjs"
49
24
  },
50
25
  "./solid": {
51
- "import": {
52
- "types": "./dist/solid.d.ts",
53
- "default": "./dist/solid.js"
54
- },
55
- "require": {
56
- "types": "./dist/solid.d.cts",
57
- "default": "./dist/solid.cjs"
58
- }
26
+ "types": "./dist/solid.d.mts",
27
+ "default": "./dist/solid.mjs"
59
28
  },
60
29
  "./package.json": "./package.json"
61
30
  },
@@ -66,7 +35,7 @@
66
35
  ],
67
36
  "dependencies": {
68
37
  "zustand": "^5.0.0",
69
- "@commercengine/js": "0.3.4"
38
+ "@commercengine/js": "0.3.5"
70
39
  },
71
40
  "peerDependencies": {
72
41
  "react": ">=18.0.0",
package/dist/index.cjs DELETED
@@ -1,7 +0,0 @@
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;
package/dist/index.d.cts DELETED
@@ -1,3 +0,0 @@
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, CheckoutFeatures, 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 CheckoutFeatures, 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/react.cjs DELETED
@@ -1,70 +0,0 @@
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
- * React hook for checkout integration
8
- *
9
- * Provides reactive access to checkout state and methods.
10
- * No provider required - works anywhere in your component tree.
11
- *
12
- * @returns Checkout state and methods
13
- *
14
- * @example Basic usage
15
- * ```tsx
16
- * function CartButton() {
17
- * const { cartCount, openCart, isReady } = useCheckout();
18
- *
19
- * return (
20
- * <button onClick={openCart} disabled={!isReady}>
21
- * Cart ({cartCount})
22
- * </button>
23
- * );
24
- * }
25
- * ```
26
- *
27
- * @example Add to cart
28
- * ```tsx
29
- * function ProductCard({ product }) {
30
- * const { addToCart } = useCheckout();
31
- *
32
- * return (
33
- * <button onClick={() => addToCart(product.id, product.variantId, 1)}>
34
- * Add to Cart
35
- * </button>
36
- * );
37
- * }
38
- * ```
39
- */
40
- function useCheckout() {
41
- const state = (0, zustand.useStore)(require_store.checkoutStore, (0, zustand_react_shallow.useShallow)((s) => ({
42
- isReady: s.isReady,
43
- isOpen: s.isOpen,
44
- cartCount: s.cartCount,
45
- cartTotal: s.cartTotal,
46
- cartCurrency: s.cartCurrency,
47
- isLoggedIn: s.isLoggedIn,
48
- user: s.user
49
- })));
50
- const actions = (0, zustand.useStore)(require_store.checkoutStore, (0, zustand_react_shallow.useShallow)((s) => ({
51
- openCart: s.openCart,
52
- openCheckout: s.openCheckout,
53
- close: s.close,
54
- addToCart: s.addToCart,
55
- updateTokens: s.updateTokens
56
- })));
57
- return {
58
- ...state,
59
- ...actions
60
- };
61
- }
62
-
63
- //#endregion
64
- exports.checkoutStore = require_store.checkoutStore;
65
- exports.destroyCheckout = require_store.destroyCheckout;
66
- exports.getCheckout = require_store.getCheckout;
67
- exports.initCheckout = require_store.initCheckout;
68
- exports.subscribeToCheckout = require_store.subscribeToCheckout;
69
- exports.useCheckout = useCheckout;
70
- //# sourceMappingURL=react.cjs.map
@@ -1 +0,0 @@
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 type { UserInfo } from \"@commercengine/js\";\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 /** Whether user is logged in */\n isLoggedIn: boolean;\n /** Current user info (null if not logged in) */\n user: UserInfo | null;\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 isLoggedIn: s.isLoggedIn,\n user: s.user,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkJA,SAAgB,cAAiC;CAE/C,MAAM,8BACJA,oEACY,OAAsB;EAChC,SAAS,EAAE;EACX,QAAQ,EAAE;EACV,WAAW,EAAE;EACb,WAAW,EAAE;EACb,cAAc,EAAE;EAChB,YAAY,EAAE;EACd,MAAM,EAAE;EACT,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"}
package/dist/react.d.cts DELETED
@@ -1,71 +0,0 @@
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, UserInfo as UserInfo$1 } from "@commercengine/js";
3
-
4
- //#region src/react.d.ts
5
- /**
6
- * Return type from useCheckout hook
7
- */
8
- interface UseCheckoutReturn {
9
- /** Whether checkout is ready to use */
10
- isReady: boolean;
11
- /** Whether checkout overlay is currently open */
12
- isOpen: boolean;
13
- /** Number of items in cart */
14
- cartCount: number;
15
- /** Cart subtotal amount */
16
- cartTotal: number;
17
- /** Cart currency code */
18
- cartCurrency: string;
19
- /** Whether user is logged in */
20
- isLoggedIn: boolean;
21
- /** Current user info (null if not logged in) */
22
- user: UserInfo$1 | null;
23
- /** Open the cart drawer */
24
- openCart: () => void;
25
- /** Open the checkout drawer directly */
26
- openCheckout: () => void;
27
- /** Close the checkout overlay */
28
- close: () => void;
29
- /** Add item to cart */
30
- addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
31
- /** Update authentication tokens */
32
- updateTokens: (accessToken: string, refreshToken?: string) => void;
33
- }
34
- /**
35
- * React hook for checkout integration
36
- *
37
- * Provides reactive access to checkout state and methods.
38
- * No provider required - works anywhere in your component tree.
39
- *
40
- * @returns Checkout state and methods
41
- *
42
- * @example Basic usage
43
- * ```tsx
44
- * function CartButton() {
45
- * const { cartCount, openCart, isReady } = useCheckout();
46
- *
47
- * return (
48
- * <button onClick={openCart} disabled={!isReady}>
49
- * Cart ({cartCount})
50
- * </button>
51
- * );
52
- * }
53
- * ```
54
- *
55
- * @example Add to cart
56
- * ```tsx
57
- * function ProductCard({ product }) {
58
- * const { addToCart } = useCheckout();
59
- *
60
- * return (
61
- * <button onClick={() => addToCart(product.id, product.variantId, 1)}>
62
- * Add to Cart
63
- * </button>
64
- * );
65
- * }
66
- * ```
67
- */
68
- declare function useCheckout(): UseCheckoutReturn;
69
- //#endregion
70
- 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 };
71
- //# sourceMappingURL=react.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.d.cts","names":[],"sources":["../src/react.ts"],"mappings":";;;;;;;UAiFiB,iBAAA;;EAEf,OAAA;;EAEA,MAAA;;EAEA,SAAA;;EAEA,SAAA;;EAEA,YAAA;;EAEA,UAAA;;EAEA,IAAA,EAAM,UAAA;;EAEN,QAAA;;EAEA,YAAA;;EAEA,KAAA;;EAEA,SAAA,GAAY,SAAA,UAAmB,SAAA,iBAA0B,QAAA;;EAEzD,YAAA,GAAe,WAAA,UAAqB,YAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyCtB,WAAA,CAAA,GAAe,iBAAA"}
package/dist/solid.cjs DELETED
@@ -1,136 +0,0 @@
1
- const require_store = require('./store.cjs');
2
- let solid_js = require("solid-js");
3
-
4
- //#region src/solid.ts
5
- /**
6
- * Solid.js primitive for checkout integration
7
- *
8
- * Returns an object with reactive getters for state and methods for actions.
9
- * Uses Solid's fine-grained reactivity - components only re-render when
10
- * accessed values change.
11
- *
12
- * @returns Checkout state (reactive getters) and methods
13
- *
14
- * @example Basic usage
15
- * ```tsx
16
- * function CartButton() {
17
- * const checkout = useCheckout();
18
- *
19
- * return (
20
- * <button onClick={() => checkout.openCart()} disabled={!checkout.isReady}>
21
- * Cart ({checkout.cartCount})
22
- * </button>
23
- * );
24
- * }
25
- * ```
26
- *
27
- * @example Add to cart
28
- * ```tsx
29
- * function ProductCard(props) {
30
- * const checkout = useCheckout();
31
- *
32
- * return (
33
- * <button onClick={() => checkout.addToCart(props.product.id, props.product.variantId, 1)}>
34
- * Add to Cart
35
- * </button>
36
- * );
37
- * }
38
- * ```
39
- */
40
- function useCheckout() {
41
- const initialState = require_store.checkoutStore.getState();
42
- const [isReady, setIsReady] = (0, solid_js.createSignal)(initialState.isReady);
43
- const [isOpen, setIsOpen] = (0, solid_js.createSignal)(initialState.isOpen);
44
- const [cartCount, setCartCount] = (0, solid_js.createSignal)(initialState.cartCount);
45
- const [cartTotal, setCartTotal] = (0, solid_js.createSignal)(initialState.cartTotal);
46
- const [cartCurrency, setCartCurrency] = (0, solid_js.createSignal)(initialState.cartCurrency);
47
- const [isLoggedIn, setIsLoggedIn] = (0, solid_js.createSignal)(initialState.isLoggedIn);
48
- const [user, setUser] = (0, solid_js.createSignal)(initialState.user);
49
- const unsubscribe = require_store.checkoutStore.subscribe((state) => {
50
- setIsReady(state.isReady);
51
- setIsOpen(state.isOpen);
52
- setCartCount(state.cartCount);
53
- setCartTotal(state.cartTotal);
54
- setCartCurrency(state.cartCurrency);
55
- setIsLoggedIn(state.isLoggedIn);
56
- setUser(state.user);
57
- });
58
- (0, solid_js.onCleanup)(() => {
59
- unsubscribe();
60
- });
61
- return {
62
- get isReady() {
63
- return isReady();
64
- },
65
- get isOpen() {
66
- return isOpen();
67
- },
68
- get cartCount() {
69
- return cartCount();
70
- },
71
- get cartTotal() {
72
- return cartTotal();
73
- },
74
- get cartCurrency() {
75
- return cartCurrency();
76
- },
77
- get isLoggedIn() {
78
- return isLoggedIn();
79
- },
80
- get user() {
81
- return user();
82
- },
83
- openCart: () => require_store.checkoutStore.getState().openCart(),
84
- openCheckout: () => require_store.checkoutStore.getState().openCheckout(),
85
- close: () => require_store.checkoutStore.getState().close(),
86
- addToCart: (productId, variantId, quantity) => require_store.checkoutStore.getState().addToCart(productId, variantId, quantity),
87
- updateTokens: (accessToken, refreshToken) => require_store.checkoutStore.getState().updateTokens(accessToken, refreshToken)
88
- };
89
- }
90
- /**
91
- * Create a reactive signal for cart count only
92
- *
93
- * Use this when you only need cart count and want minimal re-renders.
94
- *
95
- * @example
96
- * ```tsx
97
- * function Badge() {
98
- * const count = createCartCountSignal();
99
- * return <span class="badge">{count()}</span>;
100
- * }
101
- * ```
102
- */
103
- function createCartCountSignal() {
104
- const [cartCount, setCartCount] = (0, solid_js.createSignal)(require_store.checkoutStore.getState().cartCount);
105
- const unsubscribe = require_store.checkoutStore.subscribe((state, prevState) => {
106
- if (state.cartCount !== prevState.cartCount) setCartCount(state.cartCount);
107
- });
108
- (0, solid_js.onCleanup)(() => {
109
- unsubscribe();
110
- });
111
- return cartCount;
112
- }
113
- /**
114
- * Create a reactive signal for ready state only
115
- */
116
- function createIsReadySignal() {
117
- const [isReady, setIsReady] = (0, solid_js.createSignal)(require_store.checkoutStore.getState().isReady);
118
- const unsubscribe = require_store.checkoutStore.subscribe((state, prevState) => {
119
- if (state.isReady !== prevState.isReady) setIsReady(state.isReady);
120
- });
121
- (0, solid_js.onCleanup)(() => {
122
- unsubscribe();
123
- });
124
- return isReady;
125
- }
126
-
127
- //#endregion
128
- exports.checkoutStore = require_store.checkoutStore;
129
- exports.createCartCountSignal = createCartCountSignal;
130
- exports.createIsReadySignal = createIsReadySignal;
131
- exports.destroyCheckout = require_store.destroyCheckout;
132
- exports.getCheckout = require_store.getCheckout;
133
- exports.initCheckout = require_store.initCheckout;
134
- exports.subscribeToCheckout = require_store.subscribeToCheckout;
135
- exports.useCheckout = useCheckout;
136
- //# sourceMappingURL=solid.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"solid.cjs","names":["checkoutStore"],"sources":["../src/solid.ts"],"sourcesContent":["/**\n * Commerce Engine Checkout - Solid Binding\n *\n * Solid.js primitive for checkout integration with fine-grained reactivity.\n *\n * @example\n * ```tsx\n * import { useCheckout, initCheckout } from \"@commercengine/checkout/solid\";\n * import { onMount, onCleanup } from \"solid-js\";\n *\n * // Initialize once at app root\n * function App() {\n * onMount(() => {\n * initCheckout({\n * storeId: \"store_xxx\",\n * apiKey: \"ak_xxx\",\n * });\n * });\n *\n * return <>{props.children}</>;\n * }\n *\n * // Use anywhere\n * function Header() {\n * const checkout = useCheckout();\n *\n * return (\n * <button onClick={() => checkout.openCart()} disabled={!checkout.isReady}>\n * Cart ({checkout.cartCount})\n * </button>\n * );\n * }\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { UserInfo } from \"@commercengine/js\";\nimport { type Accessor, createSignal, onCleanup } from \"solid-js\";\nimport { 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\n *\n * State properties are getters that return reactive values.\n * Actions are regular functions.\n */\nexport interface UseCheckoutReturn {\n /** Whether checkout is ready to use (reactive getter) */\n readonly isReady: boolean;\n /** Whether checkout overlay is currently open (reactive getter) */\n readonly isOpen: boolean;\n /** Number of items in cart (reactive getter) */\n readonly cartCount: number;\n /** Cart subtotal amount (reactive getter) */\n readonly cartTotal: number;\n /** Cart currency code (reactive getter) */\n readonly cartCurrency: string;\n /** Whether user is logged in (reactive getter) */\n readonly isLoggedIn: boolean;\n /** Current user info (reactive getter, null if not logged in) */\n readonly user: UserInfo | null;\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// PRIMITIVE\n// =============================================================================\n\n/**\n * Solid.js primitive for checkout integration\n *\n * Returns an object with reactive getters for state and methods for actions.\n * Uses Solid's fine-grained reactivity - components only re-render when\n * accessed values change.\n *\n * @returns Checkout state (reactive getters) and methods\n *\n * @example Basic usage\n * ```tsx\n * function CartButton() {\n * const checkout = useCheckout();\n *\n * return (\n * <button onClick={() => checkout.openCart()} disabled={!checkout.isReady}>\n * Cart ({checkout.cartCount})\n * </button>\n * );\n * }\n * ```\n *\n * @example Add to cart\n * ```tsx\n * function ProductCard(props) {\n * const checkout = useCheckout();\n *\n * return (\n * <button onClick={() => checkout.addToCart(props.product.id, props.product.variantId, 1)}>\n * Add to Cart\n * </button>\n * );\n * }\n * ```\n */\nexport function useCheckout(): UseCheckoutReturn {\n // Create signals for each piece of state\n const initialState = checkoutStore.getState();\n\n const [isReady, setIsReady] = createSignal(initialState.isReady);\n const [isOpen, setIsOpen] = createSignal(initialState.isOpen);\n const [cartCount, setCartCount] = createSignal(initialState.cartCount);\n const [cartTotal, setCartTotal] = createSignal(initialState.cartTotal);\n const [cartCurrency, setCartCurrency] = createSignal(initialState.cartCurrency);\n const [isLoggedIn, setIsLoggedIn] = createSignal(initialState.isLoggedIn);\n const [user, setUser] = createSignal(initialState.user);\n\n // Subscribe to store changes\n const unsubscribe = checkoutStore.subscribe((state) => {\n setIsReady(state.isReady);\n setIsOpen(state.isOpen);\n setCartCount(state.cartCount);\n setCartTotal(state.cartTotal);\n setCartCurrency(state.cartCurrency);\n setIsLoggedIn(state.isLoggedIn);\n setUser(state.user);\n });\n\n // Cleanup on component unmount\n onCleanup(() => {\n unsubscribe();\n });\n\n // Return object with reactive getters\n return {\n get isReady() {\n return isReady();\n },\n get isOpen() {\n return isOpen();\n },\n get cartCount() {\n return cartCount();\n },\n get cartTotal() {\n return cartTotal();\n },\n get cartCurrency() {\n return cartCurrency();\n },\n get isLoggedIn() {\n return isLoggedIn();\n },\n get user() {\n return user();\n },\n openCart: () => checkoutStore.getState().openCart(),\n openCheckout: () => checkoutStore.getState().openCheckout(),\n close: () => checkoutStore.getState().close(),\n addToCart: (productId, variantId, quantity) =>\n checkoutStore.getState().addToCart(productId, variantId, quantity),\n updateTokens: (accessToken, refreshToken) =>\n checkoutStore.getState().updateTokens(accessToken, refreshToken),\n };\n}\n\n// =============================================================================\n// INDIVIDUAL SIGNALS (for fine-grained subscriptions)\n// =============================================================================\n\n/**\n * Create a reactive signal for cart count only\n *\n * Use this when you only need cart count and want minimal re-renders.\n *\n * @example\n * ```tsx\n * function Badge() {\n * const count = createCartCountSignal();\n * return <span class=\"badge\">{count()}</span>;\n * }\n * ```\n */\nexport function createCartCountSignal(): Accessor<number> {\n const [cartCount, setCartCount] = createSignal(checkoutStore.getState().cartCount);\n\n const unsubscribe = checkoutStore.subscribe((state, prevState) => {\n if (state.cartCount !== prevState.cartCount) {\n setCartCount(state.cartCount);\n }\n });\n\n onCleanup(() => {\n unsubscribe();\n });\n\n return cartCount;\n}\n\n/**\n * Create a reactive signal for ready state only\n */\nexport function createIsReadySignal(): Accessor<boolean> {\n const [isReady, setIsReady] = createSignal(checkoutStore.getState().isReady);\n\n const unsubscribe = checkoutStore.subscribe((state, prevState) => {\n if (state.isReady !== prevState.isReady) {\n setIsReady(state.isReady);\n }\n });\n\n onCleanup(() => {\n unsubscribe();\n });\n\n return isReady;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoJA,SAAgB,cAAiC;CAE/C,MAAM,eAAeA,4BAAc,UAAU;CAE7C,MAAM,CAAC,SAAS,yCAA2B,aAAa,QAAQ;CAChE,MAAM,CAAC,QAAQ,wCAA0B,aAAa,OAAO;CAC7D,MAAM,CAAC,WAAW,2CAA6B,aAAa,UAAU;CACtE,MAAM,CAAC,WAAW,2CAA6B,aAAa,UAAU;CACtE,MAAM,CAAC,cAAc,8CAAgC,aAAa,aAAa;CAC/E,MAAM,CAAC,YAAY,4CAA8B,aAAa,WAAW;CACzE,MAAM,CAAC,MAAM,sCAAwB,aAAa,KAAK;CAGvD,MAAM,cAAcA,4BAAc,WAAW,UAAU;AACrD,aAAW,MAAM,QAAQ;AACzB,YAAU,MAAM,OAAO;AACvB,eAAa,MAAM,UAAU;AAC7B,eAAa,MAAM,UAAU;AAC7B,kBAAgB,MAAM,aAAa;AACnC,gBAAc,MAAM,WAAW;AAC/B,UAAQ,MAAM,KAAK;GACnB;AAGF,+BAAgB;AACd,eAAa;GACb;AAGF,QAAO;EACL,IAAI,UAAU;AACZ,UAAO,SAAS;;EAElB,IAAI,SAAS;AACX,UAAO,QAAQ;;EAEjB,IAAI,YAAY;AACd,UAAO,WAAW;;EAEpB,IAAI,YAAY;AACd,UAAO,WAAW;;EAEpB,IAAI,eAAe;AACjB,UAAO,cAAc;;EAEvB,IAAI,aAAa;AACf,UAAO,YAAY;;EAErB,IAAI,OAAO;AACT,UAAO,MAAM;;EAEf,gBAAgBA,4BAAc,UAAU,CAAC,UAAU;EACnD,oBAAoBA,4BAAc,UAAU,CAAC,cAAc;EAC3D,aAAaA,4BAAc,UAAU,CAAC,OAAO;EAC7C,YAAY,WAAW,WAAW,aAChCA,4BAAc,UAAU,CAAC,UAAU,WAAW,WAAW,SAAS;EACpE,eAAe,aAAa,iBAC1BA,4BAAc,UAAU,CAAC,aAAa,aAAa,aAAa;EACnE;;;;;;;;;;;;;;;AAoBH,SAAgB,wBAA0C;CACxD,MAAM,CAAC,WAAW,2CAA6BA,4BAAc,UAAU,CAAC,UAAU;CAElF,MAAM,cAAcA,4BAAc,WAAW,OAAO,cAAc;AAChE,MAAI,MAAM,cAAc,UAAU,UAChC,cAAa,MAAM,UAAU;GAE/B;AAEF,+BAAgB;AACd,eAAa;GACb;AAEF,QAAO;;;;;AAMT,SAAgB,sBAAyC;CACvD,MAAM,CAAC,SAAS,yCAA2BA,4BAAc,UAAU,CAAC,QAAQ;CAE5E,MAAM,cAAcA,4BAAc,WAAW,OAAO,cAAc;AAChE,MAAI,MAAM,YAAY,UAAU,QAC9B,YAAW,MAAM,QAAQ;GAE3B;AAEF,+BAAgB;AACd,eAAa;GACb;AAEF,QAAO"}
package/dist/solid.d.cts DELETED
@@ -1,94 +0,0 @@
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, UserInfo as UserInfo$1 } from "@commercengine/js";
3
- import { Accessor } from "solid-js";
4
-
5
- //#region src/solid.d.ts
6
- /**
7
- * Return type from useCheckout
8
- *
9
- * State properties are getters that return reactive values.
10
- * Actions are regular functions.
11
- */
12
- interface UseCheckoutReturn {
13
- /** Whether checkout is ready to use (reactive getter) */
14
- readonly isReady: boolean;
15
- /** Whether checkout overlay is currently open (reactive getter) */
16
- readonly isOpen: boolean;
17
- /** Number of items in cart (reactive getter) */
18
- readonly cartCount: number;
19
- /** Cart subtotal amount (reactive getter) */
20
- readonly cartTotal: number;
21
- /** Cart currency code (reactive getter) */
22
- readonly cartCurrency: string;
23
- /** Whether user is logged in (reactive getter) */
24
- readonly isLoggedIn: boolean;
25
- /** Current user info (reactive getter, null if not logged in) */
26
- readonly user: UserInfo$1 | null;
27
- /** Open the cart drawer */
28
- openCart: () => void;
29
- /** Open the checkout drawer directly */
30
- openCheckout: () => void;
31
- /** Close the checkout overlay */
32
- close: () => void;
33
- /** Add item to cart */
34
- addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
35
- /** Update authentication tokens */
36
- updateTokens: (accessToken: string, refreshToken?: string) => void;
37
- }
38
- /**
39
- * Solid.js primitive for checkout integration
40
- *
41
- * Returns an object with reactive getters for state and methods for actions.
42
- * Uses Solid's fine-grained reactivity - components only re-render when
43
- * accessed values change.
44
- *
45
- * @returns Checkout state (reactive getters) and methods
46
- *
47
- * @example Basic usage
48
- * ```tsx
49
- * function CartButton() {
50
- * const checkout = useCheckout();
51
- *
52
- * return (
53
- * <button onClick={() => checkout.openCart()} disabled={!checkout.isReady}>
54
- * Cart ({checkout.cartCount})
55
- * </button>
56
- * );
57
- * }
58
- * ```
59
- *
60
- * @example Add to cart
61
- * ```tsx
62
- * function ProductCard(props) {
63
- * const checkout = useCheckout();
64
- *
65
- * return (
66
- * <button onClick={() => checkout.addToCart(props.product.id, props.product.variantId, 1)}>
67
- * Add to Cart
68
- * </button>
69
- * );
70
- * }
71
- * ```
72
- */
73
- declare function useCheckout(): UseCheckoutReturn;
74
- /**
75
- * Create a reactive signal for cart count only
76
- *
77
- * Use this when you only need cart count and want minimal re-renders.
78
- *
79
- * @example
80
- * ```tsx
81
- * function Badge() {
82
- * const count = createCartCountSignal();
83
- * return <span class="badge">{count()}</span>;
84
- * }
85
- * ```
86
- */
87
- declare function createCartCountSignal(): Accessor<number>;
88
- /**
89
- * Create a reactive signal for ready state only
90
- */
91
- declare function createIsReadySignal(): Accessor<boolean>;
92
- //#endregion
93
- 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, createCartCountSignal, createIsReadySignal, destroyCheckout, getCheckout, initCheckout, subscribeToCheckout, useCheckout };
94
- //# sourceMappingURL=solid.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"solid.d.cts","names":[],"sources":["../src/solid.ts"],"mappings":";;;;;;;;;;;UAkFiB,iBAAA;;WAEN,OAAA;;WAEA,MAAA;;WAEA,SAAA;;WAEA,SAAA;;WAEA,YAAA;;WAEA,UAAA;;WAEA,IAAA,EAAM,UAAA;;EAEf,QAAA;;EAEA,YAAA;;EAEA,KAAA;;EAEA,SAAA,GAAY,SAAA,UAAmB,SAAA,iBAA0B,QAAA;;EAEzD,YAAA,GAAe,WAAA,UAAqB,YAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0CtB,WAAA,CAAA,GAAe,iBAAA;;;;;;;;;;;;;;iBA8Ef,qBAAA,CAAA,GAAyB,QAAA;;;;iBAmBzB,mBAAA,CAAA,GAAuB,QAAA"}