@commercengine/checkout 0.1.4 → 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/dist/{index.d.cts → index.d.mts} +1 -1
- package/dist/{index.js → index.mjs} +1 -1
- package/dist/{react.d.cts → react.d.mts} +2 -4
- package/dist/react.d.mts.map +1 -0
- package/dist/{react.js → react.mjs} +2 -2
- package/dist/react.mjs.map +1 -0
- package/dist/{solid.d.cts → solid.d.mts} +2 -4
- package/dist/solid.d.mts.map +1 -0
- package/dist/{solid.js → solid.mjs} +2 -2
- package/dist/solid.mjs.map +1 -0
- package/dist/{store.d.ts → store.d.mts} +1 -3
- package/dist/store.d.mts.map +1 -0
- package/dist/{store.js → store.mjs} +1 -1
- package/dist/store.mjs.map +1 -0
- package/dist/{svelte.d.cts → svelte.d.mts} +2 -4
- package/dist/svelte.d.mts.map +1 -0
- package/dist/{svelte.js → svelte.mjs} +2 -2
- package/dist/svelte.mjs.map +1 -0
- package/dist/{vue.d.cts → vue.d.mts} +2 -4
- package/dist/vue.d.mts.map +1 -0
- package/dist/{vue.js → vue.mjs} +2 -2
- package/dist/vue.mjs.map +1 -0
- package/package.json +20 -51
- package/dist/index.cjs +0 -7
- package/dist/index.d.ts +0 -3
- package/dist/react.cjs +0 -70
- package/dist/react.cjs.map +0 -1
- package/dist/react.d.cts.map +0 -1
- package/dist/react.d.ts +0 -73
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/solid.cjs +0 -136
- package/dist/solid.cjs.map +0 -1
- package/dist/solid.d.cts.map +0 -1
- package/dist/solid.d.ts +0 -96
- package/dist/solid.d.ts.map +0 -1
- package/dist/solid.js.map +0 -1
- package/dist/store.cjs +0 -266
- package/dist/store.cjs.map +0 -1
- package/dist/store.d.cts +0 -180
- package/dist/store.d.cts.map +0 -1
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/svelte.cjs +0 -99
- package/dist/svelte.cjs.map +0 -1
- package/dist/svelte.d.cts.map +0 -1
- package/dist/svelte.d.ts +0 -81
- package/dist/svelte.d.ts.map +0 -1
- package/dist/svelte.js.map +0 -1
- package/dist/vue.cjs +0 -72
- package/dist/vue.cjs.map +0 -1
- package/dist/vue.d.cts.map +0 -1
- package/dist/vue.d.ts +0 -63
- package/dist/vue.d.ts.map +0 -1
- package/dist/vue.js.map +0 -1
package/dist/store.d.cts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { Checkout, CheckoutConfig, UserInfo } from "@commercengine/js";
|
|
2
|
-
import * as zustand0 from "zustand";
|
|
3
|
-
|
|
4
|
-
//#region src/store.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Checkout state
|
|
8
|
-
*/
|
|
9
|
-
interface CheckoutState {
|
|
10
|
-
/** Internal checkout instance */
|
|
11
|
-
checkout: Checkout | null;
|
|
12
|
-
/** Whether checkout is ready to use */
|
|
13
|
-
isReady: boolean;
|
|
14
|
-
/** Whether checkout overlay is currently open */
|
|
15
|
-
isOpen: boolean;
|
|
16
|
-
/** Number of items in cart */
|
|
17
|
-
cartCount: number;
|
|
18
|
-
/** Cart subtotal amount */
|
|
19
|
-
cartTotal: number;
|
|
20
|
-
/** Cart currency code */
|
|
21
|
-
cartCurrency: string;
|
|
22
|
-
/** Whether user is logged in */
|
|
23
|
-
isLoggedIn: boolean;
|
|
24
|
-
/** Current user info (null if not logged in) */
|
|
25
|
-
user: UserInfo | null;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Checkout actions
|
|
29
|
-
*/
|
|
30
|
-
interface CheckoutActions {
|
|
31
|
-
/**
|
|
32
|
-
* Initialize checkout with configuration
|
|
33
|
-
* Call this once at app startup
|
|
34
|
-
*/
|
|
35
|
-
init: (config: CheckoutConfig) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Destroy checkout instance and reset state
|
|
38
|
-
*/
|
|
39
|
-
destroy: () => void;
|
|
40
|
-
/**
|
|
41
|
-
* Open the cart drawer
|
|
42
|
-
*/
|
|
43
|
-
openCart: () => void;
|
|
44
|
-
/**
|
|
45
|
-
* Open the checkout drawer directly (for Buy Now flow)
|
|
46
|
-
*/
|
|
47
|
-
openCheckout: () => void;
|
|
48
|
-
/**
|
|
49
|
-
* Close the checkout overlay
|
|
50
|
-
*/
|
|
51
|
-
close: () => void;
|
|
52
|
-
/**
|
|
53
|
-
* Add item to cart
|
|
54
|
-
* @param productId - Product ID (required)
|
|
55
|
-
* @param variantId - Variant ID (required, null for non-variant products)
|
|
56
|
-
* @param quantity - Quantity to add (default: 1)
|
|
57
|
-
*/
|
|
58
|
-
addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
|
|
59
|
-
/**
|
|
60
|
-
* Update authentication tokens
|
|
61
|
-
* Use this when user logs in/out on the parent site
|
|
62
|
-
*/
|
|
63
|
-
updateTokens: (accessToken: string, refreshToken?: string) => void;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Complete checkout store type
|
|
67
|
-
*/
|
|
68
|
-
type CheckoutStore = CheckoutState & CheckoutActions;
|
|
69
|
-
/**
|
|
70
|
-
* Vanilla Zustand store for checkout state
|
|
71
|
-
*
|
|
72
|
-
* This is framework-agnostic and can be used directly or via framework bindings.
|
|
73
|
-
*
|
|
74
|
-
* @example Direct usage (vanilla JS)
|
|
75
|
-
* ```ts
|
|
76
|
-
* import { checkoutStore } from "@commercengine/checkout";
|
|
77
|
-
*
|
|
78
|
-
* // Initialize
|
|
79
|
-
* checkoutStore.getState().init({ storeId: "...", apiKey: "..." });
|
|
80
|
-
*
|
|
81
|
-
* // Get current state
|
|
82
|
-
* const { cartCount, isReady } = checkoutStore.getState();
|
|
83
|
-
*
|
|
84
|
-
* // Subscribe to changes
|
|
85
|
-
* checkoutStore.subscribe((state) => {
|
|
86
|
-
* console.log("Cart count:", state.cartCount);
|
|
87
|
-
* });
|
|
88
|
-
*
|
|
89
|
-
* // Call actions
|
|
90
|
-
* checkoutStore.getState().openCart();
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
declare const checkoutStore: Omit<zustand0.StoreApi<CheckoutStore>, "subscribe"> & {
|
|
94
|
-
subscribe: {
|
|
95
|
-
(listener: (selectedState: CheckoutStore, previousSelectedState: CheckoutStore) => void): () => void;
|
|
96
|
-
<U>(selector: (state: CheckoutStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
|
|
97
|
-
equalityFn?: ((a: U, b: U) => boolean) | undefined;
|
|
98
|
-
fireImmediately?: boolean;
|
|
99
|
-
} | undefined): () => void;
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Initialize checkout
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```ts
|
|
107
|
-
* import { initCheckout } from "@commercengine/checkout";
|
|
108
|
-
*
|
|
109
|
-
* initCheckout({
|
|
110
|
-
* storeId: "store_xxx",
|
|
111
|
-
* apiKey: "ak_xxx",
|
|
112
|
-
* onComplete: (order) => console.log("Order placed:", order.orderNumber),
|
|
113
|
-
* });
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
declare function initCheckout(config: CheckoutConfig): void;
|
|
117
|
-
/**
|
|
118
|
-
* Destroy checkout instance
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```ts
|
|
122
|
-
* import { destroyCheckout } from "@commercengine/checkout";
|
|
123
|
-
*
|
|
124
|
-
* destroyCheckout();
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
declare function destroyCheckout(): void;
|
|
128
|
-
/**
|
|
129
|
-
* Get checkout state and methods (non-reactive)
|
|
130
|
-
*
|
|
131
|
-
* Use this outside of reactive frameworks or when you don't need reactivity.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```ts
|
|
135
|
-
* import { getCheckout } from "@commercengine/checkout";
|
|
136
|
-
*
|
|
137
|
-
* document.getElementById("cart-btn").onclick = () => {
|
|
138
|
-
* getCheckout().openCart();
|
|
139
|
-
* };
|
|
140
|
-
*
|
|
141
|
-
* // Check state
|
|
142
|
-
* if (getCheckout().isReady) {
|
|
143
|
-
* console.log("Cart has", getCheckout().cartCount, "items");
|
|
144
|
-
* }
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
declare function getCheckout(): Omit<CheckoutStore, "checkout" | "init" | "destroy">;
|
|
148
|
-
/**
|
|
149
|
-
* Subscribe to checkout state changes
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```ts
|
|
153
|
-
* import { subscribeToCheckout } from "@commercengine/checkout";
|
|
154
|
-
*
|
|
155
|
-
* // Subscribe to all changes
|
|
156
|
-
* const unsubscribe = subscribeToCheckout((state) => {
|
|
157
|
-
* console.log("State changed:", state);
|
|
158
|
-
* });
|
|
159
|
-
*
|
|
160
|
-
* // Subscribe to specific state with selector
|
|
161
|
-
* const unsubscribe = subscribeToCheckout(
|
|
162
|
-
* (state) => state.cartCount,
|
|
163
|
-
* (cartCount) => console.log("Cart count:", cartCount)
|
|
164
|
-
* );
|
|
165
|
-
*
|
|
166
|
-
* // Cleanup
|
|
167
|
-
* unsubscribe();
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
declare const subscribeToCheckout: {
|
|
171
|
-
(listener: (selectedState: CheckoutStore, previousSelectedState: CheckoutStore) => void): () => void;
|
|
172
|
-
<U>(selector: (state: CheckoutStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
|
|
173
|
-
equalityFn?: ((a: U, b: U) => boolean) | undefined;
|
|
174
|
-
fireImmediately?: boolean;
|
|
175
|
-
} | undefined): () => void;
|
|
176
|
-
};
|
|
177
|
-
//# sourceMappingURL=store.d.ts.map
|
|
178
|
-
//#endregion
|
|
179
|
-
export { destroyCheckout as a, subscribeToCheckout as c, checkoutStore as i, CheckoutState as n, getCheckout as o, CheckoutStore as r, initCheckout as s, CheckoutActions as t };
|
|
180
|
-
//# sourceMappingURL=store.d.cts.map
|
package/dist/store.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.cts","names":[],"sources":["../src/store.ts"],"sourcesContent":[],"mappings":";;;;;;;;UA6CiB,aAAA;;EAuOD,QAAA,EArOJ,QAqOgB,GAAA,IAAA;EAcZ;EAuBA,OAAA,EAAA,OAAW;EAAA;QAAS,EAAA,OAAA;;EAAD,SAAA,EAAA,MAAA;EAwCtB;EAA6C,SAAA,EAAA,MAAA;;;;;;QApSlD;;;;;UAMS,eAAA;;;;;iBAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwCL,aAAA,GAAgB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;cA6C/B,eAAa,KAAA,QAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;iBAuHV,YAAA,SAAqB;;;;;;;;;;;iBAcrB,eAAA,CAAA;;;;;;;;;;;;;;;;;;;;iBAuBA,WAAA,CAAA,GAAe,KAAK;;;;;;;;;;;;;;;;;;;;;;;cAwCvB"}
|
package/dist/store.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","names":[],"sources":["../src/store.ts"],"sourcesContent":[],"mappings":";;;;;;;;UA6CiB,aAAA;;EAuOD,QAAA,EArOJ,QAqOgB,GAAA,IAAA;EAcZ;EAuBA,OAAA,EAAA,OAAW;EAAA;QAAS,EAAA,OAAA;;EAAD,SAAA,EAAA,MAAA;EAwCtB;EAA6C,SAAA,EAAA,MAAA;;;;;;QApSlD;;;;;UAMS,eAAA;;;;;iBAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwCL,aAAA,GAAgB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;cA6C/B,eAAa,KAAA,QAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;iBAuHV,YAAA,SAAqB;;;;;;;;;;;iBAcrB,eAAA,CAAA;;;;;;;;;;;;;;;;;;;;iBAuBA,WAAA,CAAA,GAAe,KAAK;;;;;;;;;;;;;;;;;;;;;;;cAwCvB"}
|
package/dist/store.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","names":[],"sources":["../src/store.ts"],"sourcesContent":["/**\n * Commerce Engine Checkout - Universal Store\n *\n * Framework-agnostic state management using Zustand vanilla.\n * This is the core store that all framework bindings use.\n *\n * ## Architecture\n *\n * - **Singleton**: One store instance shared across all components/routes\n * - **Non-blocking**: Checkout iframe loads asynchronously in the background\n * - **SSR-safe**: Initialization is skipped on server, only runs on client\n * - **Zero CWV impact**: Hidden iframe, no layout shifts, no main thread blocking\n *\n * ## Lifecycle\n *\n * 1. `initCheckout()` creates a hidden iframe and returns immediately\n * 2. Iframe loads in background (non-blocking)\n * 3. `onReady` callback fires when checkout is ready\n * 4. `useCheckout()` can be called from any component to access state\n * 5. Same instance persists across route changes (SPA navigation)\n *\n * @commercengine/checkout\n */\n\nimport {\n type AuthLoginData,\n type AuthLogoutData,\n type AuthRefreshData,\n type CartData,\n Checkout,\n type CheckoutConfig,\n type ErrorData,\n type OrderData,\n type UserInfo,\n} from \"@commercengine/js\";\nimport { subscribeWithSelector } from \"zustand/middleware\";\nimport { createStore } from \"zustand/vanilla\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\n/**\n * Checkout state\n */\nexport interface CheckoutState {\n /** Internal checkout instance */\n checkout: Checkout | null;\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}\n\n/**\n * Checkout actions\n */\nexport interface CheckoutActions {\n /**\n * Initialize checkout with configuration\n * Call this once at app startup\n */\n init: (config: CheckoutConfig) => void;\n\n /**\n * Destroy checkout instance and reset state\n */\n destroy: () => void;\n\n /**\n * Open the cart drawer\n */\n openCart: () => void;\n\n /**\n * Open the checkout drawer directly (for Buy Now flow)\n */\n openCheckout: () => void;\n\n /**\n * Close the checkout overlay\n */\n close: () => void;\n\n /**\n * Add item to cart\n * @param productId - Product ID (required)\n * @param variantId - Variant ID (required, null for non-variant products)\n * @param quantity - Quantity to add (default: 1)\n */\n addToCart: (productId: string, variantId: string | null, quantity?: number) => void;\n\n /**\n * Update authentication tokens\n * Use this when user logs in/out on the parent site\n */\n updateTokens: (accessToken: string, refreshToken?: string) => void;\n}\n\n/**\n * Complete checkout store type\n */\nexport type CheckoutStore = CheckoutState & CheckoutActions;\n\n// =============================================================================\n// DEFAULT STATE\n// =============================================================================\n\nconst DEFAULT_STATE: CheckoutState = {\n checkout: null,\n isReady: false,\n isOpen: false,\n cartCount: 0,\n cartTotal: 0,\n cartCurrency: \"INR\",\n isLoggedIn: false,\n user: null,\n};\n\n// =============================================================================\n// STORE\n// =============================================================================\n\n/**\n * Vanilla Zustand store for checkout state\n *\n * This is framework-agnostic and can be used directly or via framework bindings.\n *\n * @example Direct usage (vanilla JS)\n * ```ts\n * import { checkoutStore } from \"@commercengine/checkout\";\n *\n * // Initialize\n * checkoutStore.getState().init({ storeId: \"...\", apiKey: \"...\" });\n *\n * // Get current state\n * const { cartCount, isReady } = checkoutStore.getState();\n *\n * // Subscribe to changes\n * checkoutStore.subscribe((state) => {\n * console.log(\"Cart count:\", state.cartCount);\n * });\n *\n * // Call actions\n * checkoutStore.getState().openCart();\n * ```\n */\nexport const checkoutStore = createStore<CheckoutStore>()(\n subscribeWithSelector((set, get) => ({\n // State\n ...DEFAULT_STATE,\n\n // Actions\n init: (config) => {\n // Skip on server\n if (typeof window === \"undefined\") return;\n\n // Destroy existing instance if reinitializing\n const existing = get().checkout;\n if (existing) {\n existing.destroy();\n }\n\n // Create new checkout instance with callbacks that update store\n const checkout = new Checkout({\n ...config,\n onReady: () => {\n set({ isReady: true });\n config.onReady?.();\n },\n onOpen: () => {\n set({ isOpen: true });\n config.onOpen?.();\n },\n onClose: () => {\n set({ isOpen: false });\n config.onClose?.();\n },\n onCartUpdate: (cart: CartData) => {\n set({\n cartCount: cart.count,\n cartTotal: cart.total,\n cartCurrency: cart.currency,\n });\n config.onCartUpdate?.(cart);\n },\n onComplete: (order: OrderData) => {\n config.onComplete?.(order);\n },\n onLogin: (data: AuthLoginData) => {\n if (data.user) {\n set({ user: data.user, isLoggedIn: data.user.isLoggedIn });\n }\n config.onLogin?.(data);\n },\n onLogout: (data: AuthLogoutData) => {\n // On logout, user becomes anonymous\n set({ user: data.user ?? null, isLoggedIn: false });\n config.onLogout?.(data);\n },\n onTokenRefresh: (data: AuthRefreshData) => {\n config.onTokenRefresh?.(data);\n },\n onSessionError: () => {\n // Session corrupted - clear user state\n set({ user: null, isLoggedIn: false });\n config.onSessionError?.();\n },\n onError: (error: ErrorData) => {\n // Still set ready so buttons are enabled (error drawer will show)\n set({ isReady: true });\n config.onError?.(error);\n },\n });\n\n set({ checkout });\n },\n\n destroy: () => {\n const { checkout } = get();\n if (checkout) {\n checkout.destroy();\n }\n set(DEFAULT_STATE);\n },\n\n openCart: () => {\n get().checkout?.openCart();\n },\n\n openCheckout: () => {\n get().checkout?.openCheckout();\n },\n\n close: () => {\n get().checkout?.close();\n },\n\n addToCart: (productId, variantId, quantity) => {\n get().checkout?.addToCart(productId, variantId, quantity);\n },\n\n updateTokens: (accessToken, refreshToken) => {\n get().checkout?.updateTokens(accessToken, refreshToken);\n },\n }))\n);\n\n// =============================================================================\n// CONVENIENCE EXPORTS\n// =============================================================================\n\n/**\n * Initialize checkout\n *\n * @example\n * ```ts\n * import { initCheckout } from \"@commercengine/checkout\";\n *\n * initCheckout({\n * storeId: \"store_xxx\",\n * apiKey: \"ak_xxx\",\n * onComplete: (order) => console.log(\"Order placed:\", order.orderNumber),\n * });\n * ```\n */\nexport function initCheckout(config: CheckoutConfig): void {\n checkoutStore.getState().init(config);\n}\n\n/**\n * Destroy checkout instance\n *\n * @example\n * ```ts\n * import { destroyCheckout } from \"@commercengine/checkout\";\n *\n * destroyCheckout();\n * ```\n */\nexport function destroyCheckout(): void {\n checkoutStore.getState().destroy();\n}\n\n/**\n * Get checkout state and methods (non-reactive)\n *\n * Use this outside of reactive frameworks or when you don't need reactivity.\n *\n * @example\n * ```ts\n * import { getCheckout } from \"@commercengine/checkout\";\n *\n * document.getElementById(\"cart-btn\").onclick = () => {\n * getCheckout().openCart();\n * };\n *\n * // Check state\n * if (getCheckout().isReady) {\n * console.log(\"Cart has\", getCheckout().cartCount, \"items\");\n * }\n * ```\n */\nexport function getCheckout(): Omit<CheckoutStore, \"checkout\" | \"init\" | \"destroy\"> {\n const state = checkoutStore.getState();\n return {\n isReady: state.isReady,\n isOpen: state.isOpen,\n cartCount: state.cartCount,\n cartTotal: state.cartTotal,\n cartCurrency: state.cartCurrency,\n isLoggedIn: state.isLoggedIn,\n user: state.user,\n openCart: state.openCart,\n openCheckout: state.openCheckout,\n close: state.close,\n addToCart: state.addToCart,\n updateTokens: state.updateTokens,\n };\n}\n\n/**\n * Subscribe to checkout state changes\n *\n * @example\n * ```ts\n * import { subscribeToCheckout } from \"@commercengine/checkout\";\n *\n * // Subscribe to all changes\n * const unsubscribe = subscribeToCheckout((state) => {\n * console.log(\"State changed:\", state);\n * });\n *\n * // Subscribe to specific state with selector\n * const unsubscribe = subscribeToCheckout(\n * (state) => state.cartCount,\n * (cartCount) => console.log(\"Cart count:\", cartCount)\n * );\n *\n * // Cleanup\n * unsubscribe();\n * ```\n */\nexport const subscribeToCheckout = checkoutStore.subscribe;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,MAAM,gBAA+B;CACnC,UAAU;CACV,SAAS;CACT,QAAQ;CACR,WAAW;CACX,WAAW;CACX,cAAc;CACd,YAAY;CACZ,MAAM;CACP;;;;;;;;;;;;;;;;;;;;;;;;;AA8BD,MAAa,gBAAgB,aAA4B,CACvD,uBAAuB,KAAK,SAAS;CAEnC,GAAG;CAGH,OAAO,WAAW;AAEhB,MAAI,OAAO,WAAW,YAAa;EAGnC,MAAM,WAAW,KAAK,CAAC;AACvB,MAAI,SACF,UAAS,SAAS;AAuDpB,MAAI,EAAE,UAnDW,IAAI,SAAS;GAC5B,GAAG;GACH,eAAe;AACb,QAAI,EAAE,SAAS,MAAM,CAAC;AACtB,WAAO,WAAW;;GAEpB,cAAc;AACZ,QAAI,EAAE,QAAQ,MAAM,CAAC;AACrB,WAAO,UAAU;;GAEnB,eAAe;AACb,QAAI,EAAE,QAAQ,OAAO,CAAC;AACtB,WAAO,WAAW;;GAEpB,eAAe,SAAmB;AAChC,QAAI;KACF,WAAW,KAAK;KAChB,WAAW,KAAK;KAChB,cAAc,KAAK;KACpB,CAAC;AACF,WAAO,eAAe,KAAK;;GAE7B,aAAa,UAAqB;AAChC,WAAO,aAAa,MAAM;;GAE5B,UAAU,SAAwB;AAChC,QAAI,KAAK,KACP,KAAI;KAAE,MAAM,KAAK;KAAM,YAAY,KAAK,KAAK;KAAY,CAAC;AAE5D,WAAO,UAAU,KAAK;;GAExB,WAAW,SAAyB;AAElC,QAAI;KAAE,MAAM,KAAK,QAAQ;KAAM,YAAY;KAAO,CAAC;AACnD,WAAO,WAAW,KAAK;;GAEzB,iBAAiB,SAA0B;AACzC,WAAO,iBAAiB,KAAK;;GAE/B,sBAAsB;AAEpB,QAAI;KAAE,MAAM;KAAM,YAAY;KAAO,CAAC;AACtC,WAAO,kBAAkB;;GAE3B,UAAU,UAAqB;AAE7B,QAAI,EAAE,SAAS,MAAM,CAAC;AACtB,WAAO,UAAU,MAAM;;GAE1B,CAAC,EAEc,CAAC;;CAGnB,eAAe;EACb,MAAM,EAAE,aAAa,KAAK;AAC1B,MAAI,SACF,UAAS,SAAS;AAEpB,MAAI,cAAc;;CAGpB,gBAAgB;AACd,OAAK,CAAC,UAAU,UAAU;;CAG5B,oBAAoB;AAClB,OAAK,CAAC,UAAU,cAAc;;CAGhC,aAAa;AACX,OAAK,CAAC,UAAU,OAAO;;CAGzB,YAAY,WAAW,WAAW,aAAa;AAC7C,OAAK,CAAC,UAAU,UAAU,WAAW,WAAW,SAAS;;CAG3D,eAAe,aAAa,iBAAiB;AAC3C,OAAK,CAAC,UAAU,aAAa,aAAa,aAAa;;CAE1D,EAAE,CACJ;;;;;;;;;;;;;;;AAoBD,SAAgB,aAAa,QAA8B;AACzD,eAAc,UAAU,CAAC,KAAK,OAAO;;;;;;;;;;;;AAavC,SAAgB,kBAAwB;AACtC,eAAc,UAAU,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;AAsBpC,SAAgB,cAAoE;CAClF,MAAM,QAAQ,cAAc,UAAU;AACtC,QAAO;EACL,SAAS,MAAM;EACf,QAAQ,MAAM;EACd,WAAW,MAAM;EACjB,WAAW,MAAM;EACjB,cAAc,MAAM;EACpB,YAAY,MAAM;EAClB,MAAM,MAAM;EACZ,UAAU,MAAM;EAChB,cAAc,MAAM;EACpB,OAAO,MAAM;EACb,WAAW,MAAM;EACjB,cAAc,MAAM;EACrB;;;;;;;;;;;;;;;;;;;;;;;;AAyBH,MAAa,sBAAsB,cAAc"}
|
package/dist/svelte.cjs
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
const require_store = require('./store.cjs');
|
|
2
|
-
let svelte_store = require("svelte/store");
|
|
3
|
-
|
|
4
|
-
//#region src/svelte.ts
|
|
5
|
-
/**
|
|
6
|
-
* Get current checkout value from Zustand store
|
|
7
|
-
*/
|
|
8
|
-
function getCheckoutValue() {
|
|
9
|
-
const state = require_store.checkoutStore.getState();
|
|
10
|
-
return {
|
|
11
|
-
isReady: state.isReady,
|
|
12
|
-
isOpen: state.isOpen,
|
|
13
|
-
cartCount: state.cartCount,
|
|
14
|
-
cartTotal: state.cartTotal,
|
|
15
|
-
cartCurrency: state.cartCurrency,
|
|
16
|
-
isLoggedIn: state.isLoggedIn,
|
|
17
|
-
user: state.user,
|
|
18
|
-
openCart: state.openCart,
|
|
19
|
-
openCheckout: state.openCheckout,
|
|
20
|
-
close: state.close,
|
|
21
|
-
addToCart: state.addToCart,
|
|
22
|
-
updateTokens: state.updateTokens
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Svelte readable store for checkout state and actions
|
|
27
|
-
*
|
|
28
|
-
* Syncs with the Zustand store automatically.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```svelte
|
|
32
|
-
* <script>
|
|
33
|
-
* import { checkout } from "@commercengine/checkout/svelte";
|
|
34
|
-
* <\/script>
|
|
35
|
-
*
|
|
36
|
-
* <button on:click={() => $checkout.openCart()} disabled={!$checkout.isReady}>
|
|
37
|
-
* Cart ({$checkout.cartCount})
|
|
38
|
-
* </button>
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
const checkout = (0, svelte_store.readable)(getCheckoutValue(), (set) => {
|
|
42
|
-
return require_store.checkoutStore.subscribe(() => {
|
|
43
|
-
set(getCheckoutValue());
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
/**
|
|
47
|
-
* Individual store for cart count (for fine-grained reactivity)
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```svelte
|
|
51
|
-
* <script>
|
|
52
|
-
* import { cartCount } from "@commercengine/checkout/svelte";
|
|
53
|
-
* <\/script>
|
|
54
|
-
*
|
|
55
|
-
* <span class="badge">{$cartCount}</span>
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
const cartCount = (0, svelte_store.readable)(require_store.checkoutStore.getState().cartCount, (set) => {
|
|
59
|
-
return require_store.checkoutStore.subscribe((state, prevState) => {
|
|
60
|
-
if (state.cartCount !== prevState.cartCount) set(state.cartCount);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
/**
|
|
64
|
-
* Individual store for cart total
|
|
65
|
-
*/
|
|
66
|
-
const cartTotal = (0, svelte_store.readable)(require_store.checkoutStore.getState().cartTotal, (set) => {
|
|
67
|
-
return require_store.checkoutStore.subscribe((state, prevState) => {
|
|
68
|
-
if (state.cartTotal !== prevState.cartTotal) set(state.cartTotal);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
/**
|
|
72
|
-
* Individual store for ready state
|
|
73
|
-
*/
|
|
74
|
-
const isReady = (0, svelte_store.readable)(require_store.checkoutStore.getState().isReady, (set) => {
|
|
75
|
-
return require_store.checkoutStore.subscribe((state, prevState) => {
|
|
76
|
-
if (state.isReady !== prevState.isReady) set(state.isReady);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
/**
|
|
80
|
-
* Individual store for open state
|
|
81
|
-
*/
|
|
82
|
-
const isOpen = (0, svelte_store.readable)(require_store.checkoutStore.getState().isOpen, (set) => {
|
|
83
|
-
return require_store.checkoutStore.subscribe((state, prevState) => {
|
|
84
|
-
if (state.isOpen !== prevState.isOpen) set(state.isOpen);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
//#endregion
|
|
89
|
-
exports.cartCount = cartCount;
|
|
90
|
-
exports.cartTotal = cartTotal;
|
|
91
|
-
exports.checkout = checkout;
|
|
92
|
-
exports.checkoutStore = require_store.checkoutStore;
|
|
93
|
-
exports.destroyCheckout = require_store.destroyCheckout;
|
|
94
|
-
exports.getCheckout = require_store.getCheckout;
|
|
95
|
-
exports.initCheckout = require_store.initCheckout;
|
|
96
|
-
exports.isOpen = isOpen;
|
|
97
|
-
exports.isReady = isReady;
|
|
98
|
-
exports.subscribeToCheckout = require_store.subscribeToCheckout;
|
|
99
|
-
//# sourceMappingURL=svelte.cjs.map
|
package/dist/svelte.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.cjs","names":["checkoutStore"],"sources":["../src/svelte.ts"],"sourcesContent":["/**\n * Commerce Engine Checkout - Svelte Binding\n *\n * Svelte stores for checkout integration with automatic reactivity.\n *\n * @example\n * ```svelte\n * <script>\n * import { checkout, initCheckout } from \"@commercengine/checkout/svelte\";\n * import { onMount } from \"svelte\";\n *\n * // Initialize once at app root (+layout.svelte)\n * onMount(() => {\n * initCheckout({\n * storeId: \"store_xxx\",\n * apiKey: \"ak_xxx\",\n * });\n * });\n * </script>\n *\n * <button on:click={() => $checkout.openCart()} disabled={!$checkout.isReady}>\n * Cart ({$checkout.cartCount})\n * </button>\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { UserInfo } from \"@commercengine/js\";\nimport { type Readable, readable } from \"svelte/store\";\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 * Checkout store value type\n */\nexport interface CheckoutValue {\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// STORES\n// =============================================================================\n\n/**\n * Get current checkout value from Zustand store\n */\nfunction getCheckoutValue(): CheckoutValue {\n const state = checkoutStore.getState();\n return {\n isReady: state.isReady,\n isOpen: state.isOpen,\n cartCount: state.cartCount,\n cartTotal: state.cartTotal,\n cartCurrency: state.cartCurrency,\n isLoggedIn: state.isLoggedIn,\n user: state.user,\n openCart: state.openCart,\n openCheckout: state.openCheckout,\n close: state.close,\n addToCart: state.addToCart,\n updateTokens: state.updateTokens,\n };\n}\n\n/**\n * Svelte readable store for checkout state and actions\n *\n * Syncs with the Zustand store automatically.\n *\n * @example\n * ```svelte\n * <script>\n * import { checkout } from \"@commercengine/checkout/svelte\";\n * </script>\n *\n * <button on:click={() => $checkout.openCart()} disabled={!$checkout.isReady}>\n * Cart ({$checkout.cartCount})\n * </button>\n * ```\n */\nexport const checkout: Readable<CheckoutValue> = readable(getCheckoutValue(), (set) => {\n // Subscribe to Zustand store and update Svelte store\n return checkoutStore.subscribe(() => {\n set(getCheckoutValue());\n });\n});\n\n/**\n * Individual store for cart count (for fine-grained reactivity)\n *\n * @example\n * ```svelte\n * <script>\n * import { cartCount } from \"@commercengine/checkout/svelte\";\n * </script>\n *\n * <span class=\"badge\">{$cartCount}</span>\n * ```\n */\nexport const cartCount: Readable<number> = readable(checkoutStore.getState().cartCount, (set) => {\n return checkoutStore.subscribe((state, prevState) => {\n if (state.cartCount !== prevState.cartCount) {\n set(state.cartCount);\n }\n });\n});\n\n/**\n * Individual store for cart total\n */\nexport const cartTotal: Readable<number> = readable(checkoutStore.getState().cartTotal, (set) => {\n return checkoutStore.subscribe((state, prevState) => {\n if (state.cartTotal !== prevState.cartTotal) {\n set(state.cartTotal);\n }\n });\n});\n\n/**\n * Individual store for ready state\n */\nexport const isReady: Readable<boolean> = readable(checkoutStore.getState().isReady, (set) => {\n return checkoutStore.subscribe((state, prevState) => {\n if (state.isReady !== prevState.isReady) {\n set(state.isReady);\n }\n });\n});\n\n/**\n * Individual store for open state\n */\nexport const isOpen: Readable<boolean> = readable(checkoutStore.getState().isOpen, (set) => {\n return checkoutStore.subscribe((state, prevState) => {\n if (state.isOpen !== prevState.isOpen) {\n set(state.isOpen);\n }\n });\n});\n"],"mappings":";;;;;;;AAwGA,SAAS,mBAAkC;CACzC,MAAM,QAAQA,4BAAc,UAAU;AACtC,QAAO;EACL,SAAS,MAAM;EACf,QAAQ,MAAM;EACd,WAAW,MAAM;EACjB,WAAW,MAAM;EACjB,cAAc,MAAM;EACpB,YAAY,MAAM;EAClB,MAAM,MAAM;EACZ,UAAU,MAAM;EAChB,cAAc,MAAM;EACpB,OAAO,MAAM;EACb,WAAW,MAAM;EACjB,cAAc,MAAM;EACrB;;;;;;;;;;;;;;;;;;AAmBH,MAAa,sCAA6C,kBAAkB,GAAG,QAAQ;AAErF,QAAOA,4BAAc,gBAAgB;AACnC,MAAI,kBAAkB,CAAC;GACvB;EACF;;;;;;;;;;;;;AAcF,MAAa,uCAAuCA,4BAAc,UAAU,CAAC,YAAY,QAAQ;AAC/F,QAAOA,4BAAc,WAAW,OAAO,cAAc;AACnD,MAAI,MAAM,cAAc,UAAU,UAChC,KAAI,MAAM,UAAU;GAEtB;EACF;;;;AAKF,MAAa,uCAAuCA,4BAAc,UAAU,CAAC,YAAY,QAAQ;AAC/F,QAAOA,4BAAc,WAAW,OAAO,cAAc;AACnD,MAAI,MAAM,cAAc,UAAU,UAChC,KAAI,MAAM,UAAU;GAEtB;EACF;;;;AAKF,MAAa,qCAAsCA,4BAAc,UAAU,CAAC,UAAU,QAAQ;AAC5F,QAAOA,4BAAc,WAAW,OAAO,cAAc;AACnD,MAAI,MAAM,YAAY,UAAU,QAC9B,KAAI,MAAM,QAAQ;GAEpB;EACF;;;;AAKF,MAAa,oCAAqCA,4BAAc,UAAU,CAAC,SAAS,QAAQ;AAC1F,QAAOA,4BAAc,WAAW,OAAO,cAAc;AACnD,MAAI,MAAM,WAAW,UAAU,OAC7B,KAAI,MAAM,OAAO;GAEnB;EACF"}
|
package/dist/svelte.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.d.cts","names":[],"sources":["../src/svelte.ts"],"sourcesContent":[],"mappings":";;;;;;;;;UAsEiB,aAAA;;;;;;;;;;;;;;QAcT;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsDK,UAAU,SAAS;;;;;;;;;;;;;cAmBnB,WAAW;;;;cAWX,WAAW;;;;cAWX,SAAS;;;;cAWT,QAAQ"}
|
package/dist/svelte.d.ts
DELETED
|
@@ -1,81 +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.js";
|
|
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 { Readable } from "svelte/store";
|
|
4
|
-
|
|
5
|
-
//#region src/svelte.d.ts
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Checkout store value type
|
|
9
|
-
*/
|
|
10
|
-
interface CheckoutValue {
|
|
11
|
-
/** Whether checkout is ready to use */
|
|
12
|
-
isReady: boolean;
|
|
13
|
-
/** Whether checkout overlay is currently open */
|
|
14
|
-
isOpen: boolean;
|
|
15
|
-
/** Number of items in cart */
|
|
16
|
-
cartCount: number;
|
|
17
|
-
/** Cart subtotal amount */
|
|
18
|
-
cartTotal: number;
|
|
19
|
-
/** Cart currency code */
|
|
20
|
-
cartCurrency: string;
|
|
21
|
-
/** Whether user is logged in */
|
|
22
|
-
isLoggedIn: boolean;
|
|
23
|
-
/** Current user info (null if not logged in) */
|
|
24
|
-
user: UserInfo$1 | null;
|
|
25
|
-
/** Open the cart drawer */
|
|
26
|
-
openCart: () => void;
|
|
27
|
-
/** Open the checkout drawer directly */
|
|
28
|
-
openCheckout: () => void;
|
|
29
|
-
/** Close the checkout overlay */
|
|
30
|
-
close: () => void;
|
|
31
|
-
/** Add item to cart */
|
|
32
|
-
addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
|
|
33
|
-
/** Update authentication tokens */
|
|
34
|
-
updateTokens: (accessToken: string, refreshToken?: string) => void;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Svelte readable store for checkout state and actions
|
|
38
|
-
*
|
|
39
|
-
* Syncs with the Zustand store automatically.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```svelte
|
|
43
|
-
* <script>
|
|
44
|
-
* import { checkout } from "@commercengine/checkout/svelte";
|
|
45
|
-
* </script>
|
|
46
|
-
*
|
|
47
|
-
* <button on:click={() => $checkout.openCart()} disabled={!$checkout.isReady}>
|
|
48
|
-
* Cart ({$checkout.cartCount})
|
|
49
|
-
* </button>
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
declare const checkout: Readable<CheckoutValue>;
|
|
53
|
-
/**
|
|
54
|
-
* Individual store for cart count (for fine-grained reactivity)
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```svelte
|
|
58
|
-
* <script>
|
|
59
|
-
* import { cartCount } from "@commercengine/checkout/svelte";
|
|
60
|
-
* </script>
|
|
61
|
-
*
|
|
62
|
-
* <span class="badge">{$cartCount}</span>
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
declare const cartCount: Readable<number>;
|
|
66
|
-
/**
|
|
67
|
-
* Individual store for cart total
|
|
68
|
-
*/
|
|
69
|
-
declare const cartTotal: Readable<number>;
|
|
70
|
-
/**
|
|
71
|
-
* Individual store for ready state
|
|
72
|
-
*/
|
|
73
|
-
declare const isReady: Readable<boolean>;
|
|
74
|
-
/**
|
|
75
|
-
* Individual store for open state
|
|
76
|
-
*/
|
|
77
|
-
declare const isOpen: Readable<boolean>;
|
|
78
|
-
//# sourceMappingURL=svelte.d.ts.map
|
|
79
|
-
//#endregion
|
|
80
|
-
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, CheckoutValue, type Environment, type ErrorData, type LoginMethod, type OrderData, type QuickBuyConfig, type SessionMode, type UserInfo, cartCount, cartTotal, checkout, checkoutStore, destroyCheckout, getCheckout, initCheckout, isOpen, isReady, subscribeToCheckout };
|
|
81
|
-
//# sourceMappingURL=svelte.d.ts.map
|
package/dist/svelte.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.d.ts","names":[],"sources":["../src/svelte.ts"],"sourcesContent":[],"mappings":";;;;;;;;;UAsEiB,aAAA;;;;;;;;;;;;;;QAcT;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsDK,UAAU,SAAS;;;;;;;;;;;;;cAmBnB,WAAW;;;;cAWX,WAAW;;;;cAWX,SAAS;;;;cAWT,QAAQ"}
|
package/dist/svelte.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.js","names":[],"sources":["../src/svelte.ts"],"sourcesContent":["/**\n * Commerce Engine Checkout - Svelte Binding\n *\n * Svelte stores for checkout integration with automatic reactivity.\n *\n * @example\n * ```svelte\n * <script>\n * import { checkout, initCheckout } from \"@commercengine/checkout/svelte\";\n * import { onMount } from \"svelte\";\n *\n * // Initialize once at app root (+layout.svelte)\n * onMount(() => {\n * initCheckout({\n * storeId: \"store_xxx\",\n * apiKey: \"ak_xxx\",\n * });\n * });\n * </script>\n *\n * <button on:click={() => $checkout.openCart()} disabled={!$checkout.isReady}>\n * Cart ({$checkout.cartCount})\n * </button>\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { UserInfo } from \"@commercengine/js\";\nimport { type Readable, readable } from \"svelte/store\";\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 * Checkout store value type\n */\nexport interface CheckoutValue {\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// STORES\n// =============================================================================\n\n/**\n * Get current checkout value from Zustand store\n */\nfunction getCheckoutValue(): CheckoutValue {\n const state = checkoutStore.getState();\n return {\n isReady: state.isReady,\n isOpen: state.isOpen,\n cartCount: state.cartCount,\n cartTotal: state.cartTotal,\n cartCurrency: state.cartCurrency,\n isLoggedIn: state.isLoggedIn,\n user: state.user,\n openCart: state.openCart,\n openCheckout: state.openCheckout,\n close: state.close,\n addToCart: state.addToCart,\n updateTokens: state.updateTokens,\n };\n}\n\n/**\n * Svelte readable store for checkout state and actions\n *\n * Syncs with the Zustand store automatically.\n *\n * @example\n * ```svelte\n * <script>\n * import { checkout } from \"@commercengine/checkout/svelte\";\n * </script>\n *\n * <button on:click={() => $checkout.openCart()} disabled={!$checkout.isReady}>\n * Cart ({$checkout.cartCount})\n * </button>\n * ```\n */\nexport const checkout: Readable<CheckoutValue> = readable(getCheckoutValue(), (set) => {\n // Subscribe to Zustand store and update Svelte store\n return checkoutStore.subscribe(() => {\n set(getCheckoutValue());\n });\n});\n\n/**\n * Individual store for cart count (for fine-grained reactivity)\n *\n * @example\n * ```svelte\n * <script>\n * import { cartCount } from \"@commercengine/checkout/svelte\";\n * </script>\n *\n * <span class=\"badge\">{$cartCount}</span>\n * ```\n */\nexport const cartCount: Readable<number> = readable(checkoutStore.getState().cartCount, (set) => {\n return checkoutStore.subscribe((state, prevState) => {\n if (state.cartCount !== prevState.cartCount) {\n set(state.cartCount);\n }\n });\n});\n\n/**\n * Individual store for cart total\n */\nexport const cartTotal: Readable<number> = readable(checkoutStore.getState().cartTotal, (set) => {\n return checkoutStore.subscribe((state, prevState) => {\n if (state.cartTotal !== prevState.cartTotal) {\n set(state.cartTotal);\n }\n });\n});\n\n/**\n * Individual store for ready state\n */\nexport const isReady: Readable<boolean> = readable(checkoutStore.getState().isReady, (set) => {\n return checkoutStore.subscribe((state, prevState) => {\n if (state.isReady !== prevState.isReady) {\n set(state.isReady);\n }\n });\n});\n\n/**\n * Individual store for open state\n */\nexport const isOpen: Readable<boolean> = readable(checkoutStore.getState().isOpen, (set) => {\n return checkoutStore.subscribe((state, prevState) => {\n if (state.isOpen !== prevState.isOpen) {\n set(state.isOpen);\n }\n });\n});\n"],"mappings":";;;;;;;AAwGA,SAAS,mBAAkC;CACzC,MAAM,QAAQ,cAAc,UAAU;AACtC,QAAO;EACL,SAAS,MAAM;EACf,QAAQ,MAAM;EACd,WAAW,MAAM;EACjB,WAAW,MAAM;EACjB,cAAc,MAAM;EACpB,YAAY,MAAM;EAClB,MAAM,MAAM;EACZ,UAAU,MAAM;EAChB,cAAc,MAAM;EACpB,OAAO,MAAM;EACb,WAAW,MAAM;EACjB,cAAc,MAAM;EACrB;;;;;;;;;;;;;;;;;;AAmBH,MAAa,WAAoC,SAAS,kBAAkB,GAAG,QAAQ;AAErF,QAAO,cAAc,gBAAgB;AACnC,MAAI,kBAAkB,CAAC;GACvB;EACF;;;;;;;;;;;;;AAcF,MAAa,YAA8B,SAAS,cAAc,UAAU,CAAC,YAAY,QAAQ;AAC/F,QAAO,cAAc,WAAW,OAAO,cAAc;AACnD,MAAI,MAAM,cAAc,UAAU,UAChC,KAAI,MAAM,UAAU;GAEtB;EACF;;;;AAKF,MAAa,YAA8B,SAAS,cAAc,UAAU,CAAC,YAAY,QAAQ;AAC/F,QAAO,cAAc,WAAW,OAAO,cAAc;AACnD,MAAI,MAAM,cAAc,UAAU,UAChC,KAAI,MAAM,UAAU;GAEtB;EACF;;;;AAKF,MAAa,UAA6B,SAAS,cAAc,UAAU,CAAC,UAAU,QAAQ;AAC5F,QAAO,cAAc,WAAW,OAAO,cAAc;AACnD,MAAI,MAAM,YAAY,UAAU,QAC9B,KAAI,MAAM,QAAQ;GAEpB;EACF;;;;AAKF,MAAa,SAA4B,SAAS,cAAc,UAAU,CAAC,SAAS,QAAQ;AAC1F,QAAO,cAAc,WAAW,OAAO,cAAc;AACnD,MAAI,MAAM,WAAW,UAAU,OAC7B,KAAI,MAAM,OAAO;GAEnB;EACF"}
|
package/dist/vue.cjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const require_store = require('./store.cjs');
|
|
2
|
-
let vue = require("vue");
|
|
3
|
-
|
|
4
|
-
//#region src/vue.ts
|
|
5
|
-
/**
|
|
6
|
-
* Vue composable for checkout integration
|
|
7
|
-
*
|
|
8
|
-
* Provides reactive access to checkout state and methods.
|
|
9
|
-
* No provider required - works anywhere in your component tree.
|
|
10
|
-
*
|
|
11
|
-
* @returns Checkout state (reactive refs) and methods
|
|
12
|
-
*
|
|
13
|
-
* @example Basic usage
|
|
14
|
-
* ```vue
|
|
15
|
-
* <script setup>
|
|
16
|
-
* import { useCheckout } from "@commercengine/checkout/vue";
|
|
17
|
-
*
|
|
18
|
-
* const { cartCount, openCart, isReady } = useCheckout();
|
|
19
|
-
* <\/script>
|
|
20
|
-
*
|
|
21
|
-
* <template>
|
|
22
|
-
* <button @click="openCart" :disabled="!isReady">
|
|
23
|
-
* Cart ({{ cartCount }})
|
|
24
|
-
* </button>
|
|
25
|
-
* </template>
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
function useCheckout() {
|
|
29
|
-
const initialState = require_store.checkoutStore.getState();
|
|
30
|
-
const isReady = (0, vue.ref)(initialState.isReady);
|
|
31
|
-
const isOpen = (0, vue.ref)(initialState.isOpen);
|
|
32
|
-
const cartCount = (0, vue.ref)(initialState.cartCount);
|
|
33
|
-
const cartTotal = (0, vue.ref)(initialState.cartTotal);
|
|
34
|
-
const cartCurrency = (0, vue.ref)(initialState.cartCurrency);
|
|
35
|
-
const isLoggedIn = (0, vue.ref)(initialState.isLoggedIn);
|
|
36
|
-
const user = (0, vue.ref)(initialState.user);
|
|
37
|
-
const unsubscribe = require_store.checkoutStore.subscribe((state) => {
|
|
38
|
-
isReady.value = state.isReady;
|
|
39
|
-
isOpen.value = state.isOpen;
|
|
40
|
-
cartCount.value = state.cartCount;
|
|
41
|
-
cartTotal.value = state.cartTotal;
|
|
42
|
-
cartCurrency.value = state.cartCurrency;
|
|
43
|
-
isLoggedIn.value = state.isLoggedIn;
|
|
44
|
-
user.value = state.user;
|
|
45
|
-
});
|
|
46
|
-
(0, vue.onUnmounted)(() => {
|
|
47
|
-
unsubscribe();
|
|
48
|
-
});
|
|
49
|
-
return {
|
|
50
|
-
isReady: (0, vue.readonly)(isReady),
|
|
51
|
-
isOpen: (0, vue.readonly)(isOpen),
|
|
52
|
-
cartCount: (0, vue.readonly)(cartCount),
|
|
53
|
-
cartTotal: (0, vue.readonly)(cartTotal),
|
|
54
|
-
cartCurrency: (0, vue.readonly)(cartCurrency),
|
|
55
|
-
isLoggedIn: (0, vue.readonly)(isLoggedIn),
|
|
56
|
-
user: (0, vue.readonly)(user),
|
|
57
|
-
openCart: () => require_store.checkoutStore.getState().openCart(),
|
|
58
|
-
openCheckout: () => require_store.checkoutStore.getState().openCheckout(),
|
|
59
|
-
close: () => require_store.checkoutStore.getState().close(),
|
|
60
|
-
addToCart: (productId, variantId, quantity) => require_store.checkoutStore.getState().addToCart(productId, variantId, quantity),
|
|
61
|
-
updateTokens: (accessToken, refreshToken) => require_store.checkoutStore.getState().updateTokens(accessToken, refreshToken)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
exports.checkoutStore = require_store.checkoutStore;
|
|
67
|
-
exports.destroyCheckout = require_store.destroyCheckout;
|
|
68
|
-
exports.getCheckout = require_store.getCheckout;
|
|
69
|
-
exports.initCheckout = require_store.initCheckout;
|
|
70
|
-
exports.subscribeToCheckout = require_store.subscribeToCheckout;
|
|
71
|
-
exports.useCheckout = useCheckout;
|
|
72
|
-
//# sourceMappingURL=vue.cjs.map
|
package/dist/vue.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vue.cjs","names":["checkoutStore"],"sources":["../src/vue.ts"],"sourcesContent":["/**\n * Commerce Engine Checkout - Vue Binding\n *\n * Vue composable for checkout integration with automatic reactivity.\n *\n * @example\n * ```vue\n * <script setup>\n * import { useCheckout, initCheckout } from \"@commercengine/checkout/vue\";\n * import { onMounted, onUnmounted } from \"vue\";\n *\n * // Initialize once at app root (App.vue or plugin)\n * onMounted(() => {\n * initCheckout({\n * storeId: \"store_xxx\",\n * apiKey: \"ak_xxx\",\n * });\n * });\n *\n * // Use anywhere\n * const { cartCount, openCart, isReady } = useCheckout();\n * </script>\n *\n * <template>\n * <button @click=\"openCart\" :disabled=\"!isReady\">\n * Cart ({{ cartCount }})\n * </button>\n * </template>\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { UserInfo } from \"@commercengine/js\";\nimport { type DeepReadonly, onUnmounted, type Ref, readonly, ref } from \"vue\";\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 composable\n */\nexport interface UseCheckoutReturn {\n /** Whether checkout is ready to use (reactive) */\n isReady: DeepReadonly<Ref<boolean>>;\n /** Whether checkout overlay is currently open (reactive) */\n isOpen: DeepReadonly<Ref<boolean>>;\n /** Number of items in cart (reactive) */\n cartCount: DeepReadonly<Ref<number>>;\n /** Cart subtotal amount (reactive) */\n cartTotal: DeepReadonly<Ref<number>>;\n /** Cart currency code (reactive) */\n cartCurrency: DeepReadonly<Ref<string>>;\n /** Whether user is logged in (reactive) */\n isLoggedIn: DeepReadonly<Ref<boolean>>;\n /** Current user info (reactive, null if not logged in) */\n user: DeepReadonly<Ref<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// COMPOSABLE\n// =============================================================================\n\n/**\n * Vue composable 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 (reactive refs) and methods\n *\n * @example Basic usage\n * ```vue\n * <script setup>\n * import { useCheckout } from \"@commercengine/checkout/vue\";\n *\n * const { cartCount, openCart, isReady } = useCheckout();\n * </script>\n *\n * <template>\n * <button @click=\"openCart\" :disabled=\"!isReady\">\n * Cart ({{ cartCount }})\n * </button>\n * </template>\n * ```\n */\nexport function useCheckout(): UseCheckoutReturn {\n // Create reactive refs for state\n const initialState = checkoutStore.getState();\n\n const isReady = ref(initialState.isReady);\n const isOpen = ref(initialState.isOpen);\n const cartCount = ref(initialState.cartCount);\n const cartTotal = ref(initialState.cartTotal);\n const cartCurrency = ref(initialState.cartCurrency);\n const isLoggedIn = ref(initialState.isLoggedIn);\n const user = ref(initialState.user);\n\n // Subscribe to store changes and update refs\n const unsubscribe = checkoutStore.subscribe((state) => {\n isReady.value = state.isReady;\n isOpen.value = state.isOpen;\n cartCount.value = state.cartCount;\n cartTotal.value = state.cartTotal;\n cartCurrency.value = state.cartCurrency;\n isLoggedIn.value = state.isLoggedIn;\n user.value = state.user;\n });\n\n // Cleanup subscription on unmount\n onUnmounted(() => {\n unsubscribe();\n });\n\n return {\n // Reactive state (readonly to prevent direct mutation)\n isReady: readonly(isReady),\n isOpen: readonly(isOpen),\n cartCount: readonly(cartCount),\n cartTotal: readonly(cartTotal),\n cartCurrency: readonly(cartCurrency),\n isLoggedIn: readonly(isLoggedIn),\n user: readonly(user) as DeepReadonly<Ref<UserInfo | null>>,\n // Actions\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiIA,SAAgB,cAAiC;CAE/C,MAAM,eAAeA,4BAAc,UAAU;CAE7C,MAAM,uBAAc,aAAa,QAAQ;CACzC,MAAM,sBAAa,aAAa,OAAO;CACvC,MAAM,yBAAgB,aAAa,UAAU;CAC7C,MAAM,yBAAgB,aAAa,UAAU;CAC7C,MAAM,4BAAmB,aAAa,aAAa;CACnD,MAAM,0BAAiB,aAAa,WAAW;CAC/C,MAAM,oBAAW,aAAa,KAAK;CAGnC,MAAM,cAAcA,4BAAc,WAAW,UAAU;AACrD,UAAQ,QAAQ,MAAM;AACtB,SAAO,QAAQ,MAAM;AACrB,YAAU,QAAQ,MAAM;AACxB,YAAU,QAAQ,MAAM;AACxB,eAAa,QAAQ,MAAM;AAC3B,aAAW,QAAQ,MAAM;AACzB,OAAK,QAAQ,MAAM;GACnB;AAGF,4BAAkB;AAChB,eAAa;GACb;AAEF,QAAO;EAEL,2BAAkB,QAAQ;EAC1B,0BAAiB,OAAO;EACxB,6BAAoB,UAAU;EAC9B,6BAAoB,UAAU;EAC9B,gCAAuB,aAAa;EACpC,8BAAqB,WAAW;EAChC,wBAAe,KAAK;EAEpB,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"}
|
package/dist/vue.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.cts","names":[],"sources":["../src/vue.ts"],"sourcesContent":[],"mappings":";;;;;;;;;UA2EiB,iBAAA;;WAEN,aAAa;;UAEd,aAAa;;aAEV,aAAa;;aAEb,aAAa;;gBAEV,aAAa;;cAEf,aAAa;;QAEnB,aAAa,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwCT,WAAA,CAAA,GAAe"}
|
package/dist/vue.d.ts
DELETED
|
@@ -1,63 +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.js";
|
|
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 { DeepReadonly, Ref } from "vue";
|
|
4
|
-
|
|
5
|
-
//#region src/vue.d.ts
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Return type from useCheckout composable
|
|
9
|
-
*/
|
|
10
|
-
interface UseCheckoutReturn {
|
|
11
|
-
/** Whether checkout is ready to use (reactive) */
|
|
12
|
-
isReady: DeepReadonly<Ref<boolean>>;
|
|
13
|
-
/** Whether checkout overlay is currently open (reactive) */
|
|
14
|
-
isOpen: DeepReadonly<Ref<boolean>>;
|
|
15
|
-
/** Number of items in cart (reactive) */
|
|
16
|
-
cartCount: DeepReadonly<Ref<number>>;
|
|
17
|
-
/** Cart subtotal amount (reactive) */
|
|
18
|
-
cartTotal: DeepReadonly<Ref<number>>;
|
|
19
|
-
/** Cart currency code (reactive) */
|
|
20
|
-
cartCurrency: DeepReadonly<Ref<string>>;
|
|
21
|
-
/** Whether user is logged in (reactive) */
|
|
22
|
-
isLoggedIn: DeepReadonly<Ref<boolean>>;
|
|
23
|
-
/** Current user info (reactive, null if not logged in) */
|
|
24
|
-
user: DeepReadonly<Ref<UserInfo$1 | null>>;
|
|
25
|
-
/** Open the cart drawer */
|
|
26
|
-
openCart: () => void;
|
|
27
|
-
/** Open the checkout drawer directly */
|
|
28
|
-
openCheckout: () => void;
|
|
29
|
-
/** Close the checkout overlay */
|
|
30
|
-
close: () => void;
|
|
31
|
-
/** Add item to cart */
|
|
32
|
-
addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
|
|
33
|
-
/** Update authentication tokens */
|
|
34
|
-
updateTokens: (accessToken: string, refreshToken?: string) => void;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Vue composable for checkout integration
|
|
38
|
-
*
|
|
39
|
-
* Provides reactive access to checkout state and methods.
|
|
40
|
-
* No provider required - works anywhere in your component tree.
|
|
41
|
-
*
|
|
42
|
-
* @returns Checkout state (reactive refs) and methods
|
|
43
|
-
*
|
|
44
|
-
* @example Basic usage
|
|
45
|
-
* ```vue
|
|
46
|
-
* <script setup>
|
|
47
|
-
* import { useCheckout } from "@commercengine/checkout/vue";
|
|
48
|
-
*
|
|
49
|
-
* const { cartCount, openCart, isReady } = useCheckout();
|
|
50
|
-
* </script>
|
|
51
|
-
*
|
|
52
|
-
* <template>
|
|
53
|
-
* <button @click="openCart" :disabled="!isReady">
|
|
54
|
-
* Cart ({{ cartCount }})
|
|
55
|
-
* </button>
|
|
56
|
-
* </template>
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
declare function useCheckout(): UseCheckoutReturn;
|
|
60
|
-
//# sourceMappingURL=vue.d.ts.map
|
|
61
|
-
//#endregion
|
|
62
|
-
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 };
|
|
63
|
-
//# sourceMappingURL=vue.d.ts.map
|
package/dist/vue.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"sourcesContent":[],"mappings":";;;;;;;;;UA2EiB,iBAAA;;WAEN,aAAa;;UAEd,aAAa;;aAEV,aAAa;;aAEb,aAAa;;gBAEV,aAAa;;cAEf,aAAa;;QAEnB,aAAa,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwCT,WAAA,CAAA,GAAe"}
|
package/dist/vue.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vue.js","names":[],"sources":["../src/vue.ts"],"sourcesContent":["/**\n * Commerce Engine Checkout - Vue Binding\n *\n * Vue composable for checkout integration with automatic reactivity.\n *\n * @example\n * ```vue\n * <script setup>\n * import { useCheckout, initCheckout } from \"@commercengine/checkout/vue\";\n * import { onMounted, onUnmounted } from \"vue\";\n *\n * // Initialize once at app root (App.vue or plugin)\n * onMounted(() => {\n * initCheckout({\n * storeId: \"store_xxx\",\n * apiKey: \"ak_xxx\",\n * });\n * });\n *\n * // Use anywhere\n * const { cartCount, openCart, isReady } = useCheckout();\n * </script>\n *\n * <template>\n * <button @click=\"openCart\" :disabled=\"!isReady\">\n * Cart ({{ cartCount }})\n * </button>\n * </template>\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { UserInfo } from \"@commercengine/js\";\nimport { type DeepReadonly, onUnmounted, type Ref, readonly, ref } from \"vue\";\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 composable\n */\nexport interface UseCheckoutReturn {\n /** Whether checkout is ready to use (reactive) */\n isReady: DeepReadonly<Ref<boolean>>;\n /** Whether checkout overlay is currently open (reactive) */\n isOpen: DeepReadonly<Ref<boolean>>;\n /** Number of items in cart (reactive) */\n cartCount: DeepReadonly<Ref<number>>;\n /** Cart subtotal amount (reactive) */\n cartTotal: DeepReadonly<Ref<number>>;\n /** Cart currency code (reactive) */\n cartCurrency: DeepReadonly<Ref<string>>;\n /** Whether user is logged in (reactive) */\n isLoggedIn: DeepReadonly<Ref<boolean>>;\n /** Current user info (reactive, null if not logged in) */\n user: DeepReadonly<Ref<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// COMPOSABLE\n// =============================================================================\n\n/**\n * Vue composable 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 (reactive refs) and methods\n *\n * @example Basic usage\n * ```vue\n * <script setup>\n * import { useCheckout } from \"@commercengine/checkout/vue\";\n *\n * const { cartCount, openCart, isReady } = useCheckout();\n * </script>\n *\n * <template>\n * <button @click=\"openCart\" :disabled=\"!isReady\">\n * Cart ({{ cartCount }})\n * </button>\n * </template>\n * ```\n */\nexport function useCheckout(): UseCheckoutReturn {\n // Create reactive refs for state\n const initialState = checkoutStore.getState();\n\n const isReady = ref(initialState.isReady);\n const isOpen = ref(initialState.isOpen);\n const cartCount = ref(initialState.cartCount);\n const cartTotal = ref(initialState.cartTotal);\n const cartCurrency = ref(initialState.cartCurrency);\n const isLoggedIn = ref(initialState.isLoggedIn);\n const user = ref(initialState.user);\n\n // Subscribe to store changes and update refs\n const unsubscribe = checkoutStore.subscribe((state) => {\n isReady.value = state.isReady;\n isOpen.value = state.isOpen;\n cartCount.value = state.cartCount;\n cartTotal.value = state.cartTotal;\n cartCurrency.value = state.cartCurrency;\n isLoggedIn.value = state.isLoggedIn;\n user.value = state.user;\n });\n\n // Cleanup subscription on unmount\n onUnmounted(() => {\n unsubscribe();\n });\n\n return {\n // Reactive state (readonly to prevent direct mutation)\n isReady: readonly(isReady),\n isOpen: readonly(isOpen),\n cartCount: readonly(cartCount),\n cartTotal: readonly(cartTotal),\n cartCurrency: readonly(cartCurrency),\n isLoggedIn: readonly(isLoggedIn),\n user: readonly(user) as DeepReadonly<Ref<UserInfo | null>>,\n // Actions\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiIA,SAAgB,cAAiC;CAE/C,MAAM,eAAe,cAAc,UAAU;CAE7C,MAAM,UAAU,IAAI,aAAa,QAAQ;CACzC,MAAM,SAAS,IAAI,aAAa,OAAO;CACvC,MAAM,YAAY,IAAI,aAAa,UAAU;CAC7C,MAAM,YAAY,IAAI,aAAa,UAAU;CAC7C,MAAM,eAAe,IAAI,aAAa,aAAa;CACnD,MAAM,aAAa,IAAI,aAAa,WAAW;CAC/C,MAAM,OAAO,IAAI,aAAa,KAAK;CAGnC,MAAM,cAAc,cAAc,WAAW,UAAU;AACrD,UAAQ,QAAQ,MAAM;AACtB,SAAO,QAAQ,MAAM;AACrB,YAAU,QAAQ,MAAM;AACxB,YAAU,QAAQ,MAAM;AACxB,eAAa,QAAQ,MAAM;AAC3B,aAAW,QAAQ,MAAM;AACzB,OAAK,QAAQ,MAAM;GACnB;AAGF,mBAAkB;AAChB,eAAa;GACb;AAEF,QAAO;EAEL,SAAS,SAAS,QAAQ;EAC1B,QAAQ,SAAS,OAAO;EACxB,WAAW,SAAS,UAAU;EAC9B,WAAW,SAAS,UAAU;EAC9B,cAAc,SAAS,aAAa;EACpC,YAAY,SAAS,WAAW;EAChC,MAAM,SAAS,KAAK;EAEpB,gBAAgB,cAAc,UAAU,CAAC,UAAU;EACnD,oBAAoB,cAAc,UAAU,CAAC,cAAc;EAC3D,aAAa,cAAc,UAAU,CAAC,OAAO;EAC7C,YAAY,WAAW,WAAW,aAChC,cAAc,UAAU,CAAC,UAAU,WAAW,WAAW,SAAS;EACpE,eAAe,aAAa,iBAC1B,cAAc,UAAU,CAAC,aAAa,aAAa,aAAa;EACnE"}
|