@commercengine/checkout 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/store.d.cts DELETED
@@ -1,178 +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
- * Checkout state
7
- */
8
- interface CheckoutState {
9
- /** Internal checkout instance */
10
- checkout: Checkout | null;
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 | null;
25
- }
26
- /**
27
- * Checkout actions
28
- */
29
- interface CheckoutActions {
30
- /**
31
- * Initialize checkout with configuration
32
- * Call this once at app startup
33
- */
34
- init: (config: CheckoutConfig) => void;
35
- /**
36
- * Destroy checkout instance and reset state
37
- */
38
- destroy: () => void;
39
- /**
40
- * Open the cart drawer
41
- */
42
- openCart: () => void;
43
- /**
44
- * Open the checkout drawer directly (for Buy Now flow)
45
- */
46
- openCheckout: () => void;
47
- /**
48
- * Close the checkout overlay
49
- */
50
- close: () => void;
51
- /**
52
- * Add item to cart
53
- * @param productId - Product ID (required)
54
- * @param variantId - Variant ID (required, null for non-variant products)
55
- * @param quantity - Quantity to add (default: 1)
56
- */
57
- addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
58
- /**
59
- * Update authentication tokens
60
- * Use this when user logs in/out on the parent site
61
- */
62
- updateTokens: (accessToken: string, refreshToken?: string) => void;
63
- }
64
- /**
65
- * Complete checkout store type
66
- */
67
- type CheckoutStore = CheckoutState & CheckoutActions;
68
- /**
69
- * Vanilla Zustand store for checkout state
70
- *
71
- * This is framework-agnostic and can be used directly or via framework bindings.
72
- *
73
- * @example Direct usage (vanilla JS)
74
- * ```ts
75
- * import { checkoutStore } from "@commercengine/checkout";
76
- *
77
- * // Initialize
78
- * checkoutStore.getState().init({ storeId: "...", apiKey: "..." });
79
- *
80
- * // Get current state
81
- * const { cartCount, isReady } = checkoutStore.getState();
82
- *
83
- * // Subscribe to changes
84
- * checkoutStore.subscribe((state) => {
85
- * console.log("Cart count:", state.cartCount);
86
- * });
87
- *
88
- * // Call actions
89
- * checkoutStore.getState().openCart();
90
- * ```
91
- */
92
- declare const checkoutStore: Omit<zustand0.StoreApi<CheckoutStore>, "subscribe"> & {
93
- subscribe: {
94
- (listener: (selectedState: CheckoutStore, previousSelectedState: CheckoutStore) => void): () => void;
95
- <U>(selector: (state: CheckoutStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
96
- equalityFn?: ((a: U, b: U) => boolean) | undefined;
97
- fireImmediately?: boolean;
98
- } | undefined): () => void;
99
- };
100
- };
101
- /**
102
- * Initialize checkout
103
- *
104
- * @example
105
- * ```ts
106
- * import { initCheckout } from "@commercengine/checkout";
107
- *
108
- * initCheckout({
109
- * storeId: "store_xxx",
110
- * apiKey: "ak_xxx",
111
- * onComplete: (order) => console.log("Order placed:", order.orderNumber),
112
- * });
113
- * ```
114
- */
115
- declare function initCheckout(config: CheckoutConfig): void;
116
- /**
117
- * Destroy checkout instance
118
- *
119
- * @example
120
- * ```ts
121
- * import { destroyCheckout } from "@commercengine/checkout";
122
- *
123
- * destroyCheckout();
124
- * ```
125
- */
126
- declare function destroyCheckout(): void;
127
- /**
128
- * Get checkout state and methods (non-reactive)
129
- *
130
- * Use this outside of reactive frameworks or when you don't need reactivity.
131
- *
132
- * @example
133
- * ```ts
134
- * import { getCheckout } from "@commercengine/checkout";
135
- *
136
- * document.getElementById("cart-btn").onclick = () => {
137
- * getCheckout().openCart();
138
- * };
139
- *
140
- * // Check state
141
- * if (getCheckout().isReady) {
142
- * console.log("Cart has", getCheckout().cartCount, "items");
143
- * }
144
- * ```
145
- */
146
- declare function getCheckout(): Omit<CheckoutStore, "checkout" | "init" | "destroy">;
147
- /**
148
- * Subscribe to checkout state changes
149
- *
150
- * @example
151
- * ```ts
152
- * import { subscribeToCheckout } from "@commercengine/checkout";
153
- *
154
- * // Subscribe to all changes
155
- * const unsubscribe = subscribeToCheckout((state) => {
156
- * console.log("State changed:", state);
157
- * });
158
- *
159
- * // Subscribe to specific state with selector
160
- * const unsubscribe = subscribeToCheckout(
161
- * (state) => state.cartCount,
162
- * (cartCount) => console.log("Cart count:", cartCount)
163
- * );
164
- *
165
- * // Cleanup
166
- * unsubscribe();
167
- * ```
168
- */
169
- declare const subscribeToCheckout: {
170
- (listener: (selectedState: CheckoutStore, previousSelectedState: CheckoutStore) => void): () => void;
171
- <U>(selector: (state: CheckoutStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
172
- equalityFn?: ((a: U, b: U) => boolean) | undefined;
173
- fireImmediately?: boolean;
174
- } | undefined): () => void;
175
- };
176
- //#endregion
177
- 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 };
178
- //# sourceMappingURL=store.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.d.cts","names":[],"sources":["../src/store.ts"],"mappings":";;;;;;;UA6CiB,aAAA;EAqCf;EAnCA,QAAA,EAAU,QAAA;EA6CV;EA3CA,OAAA;EAmDY;EAjDZ,MAAA;EAiDyD;EA/CzD,SAAA;EAqDe;EAnDf,SAAA;EAmDyD;EAjDzD,YAAA;EAuDU;EArDV,UAAA;;EAEA,IAAA,EAAM,QAAA;AAAA;AAgGR;;;AAAA,UA1FiB,eAAA;EA0FS;;;;EArFxB,IAAA,GAAO,MAAA,EAAQ,cAAA;;;;EAKf,OAAA;;;;EAKA,QAAA;EA2EwB;;;EAtExB,YAAA;;;;EAKA,KAAA;;;;;;;EAQA,SAAA,GAAY,SAAA,UAAmB,SAAA,iBAA0B,QAAA;;;;;EAMzD,YAAA,GAAe,WAAA,UAAqB,YAAA;AAAA;;;;KAM1B,aAAA,GAAgB,aAAA,GAAgB,eAAA;;;AAoK5C;;;;;AAcA;;;;;AAuBA;;;;;AAwCA;;;;;;;cApMa,aAAA,EAAa,IAAA,CAAA,QAAA,CAAA,QAAA,CAAA,aAAA;;;;;;;;;;;;;;;;;;;;;;;iBAuHV,YAAA,CAAa,MAAA,EAAQ,cAAA;;;;;;;;;;;iBAcrB,eAAA,CAAA;;;;;;;;;;;;;;;;;;;;iBAuBA,WAAA,CAAA,GAAe,IAAA,CAAK,aAAA;;;;;;;;;;;;;;;;;;;;;;;cAwCvB,mBAAA;EAAA"}
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
@@ -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 DELETED
@@ -1,79 +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 { Readable } from "svelte/store";
4
-
5
- //#region src/svelte.d.ts
6
- /**
7
- * Checkout store value type
8
- */
9
- interface CheckoutValue {
10
- /** Whether checkout is ready to use */
11
- isReady: boolean;
12
- /** Whether checkout overlay is currently open */
13
- isOpen: boolean;
14
- /** Number of items in cart */
15
- cartCount: number;
16
- /** Cart subtotal amount */
17
- cartTotal: number;
18
- /** Cart currency code */
19
- cartCurrency: string;
20
- /** Whether user is logged in */
21
- isLoggedIn: boolean;
22
- /** Current user info (null if not logged in) */
23
- user: UserInfo$1 | null;
24
- /** Open the cart drawer */
25
- openCart: () => void;
26
- /** Open the checkout drawer directly */
27
- openCheckout: () => void;
28
- /** Close the checkout overlay */
29
- close: () => void;
30
- /** Add item to cart */
31
- addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
32
- /** Update authentication tokens */
33
- updateTokens: (accessToken: string, refreshToken?: string) => void;
34
- }
35
- /**
36
- * Svelte readable store for checkout state and actions
37
- *
38
- * Syncs with the Zustand store automatically.
39
- *
40
- * @example
41
- * ```svelte
42
- * <script>
43
- * import { checkout } from "@commercengine/checkout/svelte";
44
- * </script>
45
- *
46
- * <button on:click={() => $checkout.openCart()} disabled={!$checkout.isReady}>
47
- * Cart ({$checkout.cartCount})
48
- * </button>
49
- * ```
50
- */
51
- declare const checkout: Readable<CheckoutValue>;
52
- /**
53
- * Individual store for cart count (for fine-grained reactivity)
54
- *
55
- * @example
56
- * ```svelte
57
- * <script>
58
- * import { cartCount } from "@commercengine/checkout/svelte";
59
- * </script>
60
- *
61
- * <span class="badge">{$cartCount}</span>
62
- * ```
63
- */
64
- declare const cartCount: Readable<number>;
65
- /**
66
- * Individual store for cart total
67
- */
68
- declare const cartTotal: Readable<number>;
69
- /**
70
- * Individual store for ready state
71
- */
72
- declare const isReady: Readable<boolean>;
73
- /**
74
- * Individual store for open state
75
- */
76
- declare const isOpen: Readable<boolean>;
77
- //#endregion
78
- 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 };
79
- //# sourceMappingURL=svelte.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"svelte.d.cts","names":[],"sources":["../src/svelte.ts"],"mappings":";;;;;;;;UAsEiB,aAAA;EA6Ff;EA3FA,OAAA;EAqFsB;EAnFtB,MAAA;EA8FW;EA5FX,SAAA;;EAEA,SAAA;EA0F8B;EAxF9B,YAAA;EAyGA;EAvGA,UAAA;EAiGoB;EA/FpB,IAAA,EAAM,UAAA;EA0GK;EAxGX,QAAA;;EAEA,YAAA;EAsG2B;EApG3B,KAAA;;EAEA,SAAA,GAAY,SAAA,UAAmB,SAAA,iBAA0B,QAAA;;EAEzD,YAAA,GAAe,WAAA,UAAqB,YAAA;AAAA;;;;;;;;;;;;;;;;;cA4CzB,QAAA,EAAU,QAAA,CAAS,aAAA;;;;;;;;;;;;;cAmBnB,SAAA,EAAW,QAAA;;;;cAWX,SAAA,EAAW,QAAA;;;;cAWX,OAAA,EAAS,QAAA;;;;cAWT,MAAA,EAAQ,QAAA"}
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 DELETED
@@ -1,61 +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 { DeepReadonly, Ref } from "vue";
4
-
5
- //#region src/vue.d.ts
6
- /**
7
- * Return type from useCheckout composable
8
- */
9
- interface UseCheckoutReturn {
10
- /** Whether checkout is ready to use (reactive) */
11
- isReady: DeepReadonly<Ref<boolean>>;
12
- /** Whether checkout overlay is currently open (reactive) */
13
- isOpen: DeepReadonly<Ref<boolean>>;
14
- /** Number of items in cart (reactive) */
15
- cartCount: DeepReadonly<Ref<number>>;
16
- /** Cart subtotal amount (reactive) */
17
- cartTotal: DeepReadonly<Ref<number>>;
18
- /** Cart currency code (reactive) */
19
- cartCurrency: DeepReadonly<Ref<string>>;
20
- /** Whether user is logged in (reactive) */
21
- isLoggedIn: DeepReadonly<Ref<boolean>>;
22
- /** Current user info (reactive, null if not logged in) */
23
- user: DeepReadonly<Ref<UserInfo$1 | null>>;
24
- /** Open the cart drawer */
25
- openCart: () => void;
26
- /** Open the checkout drawer directly */
27
- openCheckout: () => void;
28
- /** Close the checkout overlay */
29
- close: () => void;
30
- /** Add item to cart */
31
- addToCart: (productId: string, variantId: string | null, quantity?: number) => void;
32
- /** Update authentication tokens */
33
- updateTokens: (accessToken: string, refreshToken?: string) => void;
34
- }
35
- /**
36
- * Vue composable for checkout integration
37
- *
38
- * Provides reactive access to checkout state and methods.
39
- * No provider required - works anywhere in your component tree.
40
- *
41
- * @returns Checkout state (reactive refs) and methods
42
- *
43
- * @example Basic usage
44
- * ```vue
45
- * <script setup>
46
- * import { useCheckout } from "@commercengine/checkout/vue";
47
- *
48
- * const { cartCount, openCart, isReady } = useCheckout();
49
- * </script>
50
- *
51
- * <template>
52
- * <button @click="openCart" :disabled="!isReady">
53
- * Cart ({{ cartCount }})
54
- * </button>
55
- * </template>
56
- * ```
57
- */
58
- declare function useCheckout(): UseCheckoutReturn;
59
- //#endregion
60
- 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 };
61
- //# sourceMappingURL=vue.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vue.d.cts","names":[],"sources":["../src/vue.ts"],"mappings":";;;;;;;;UA2EiB,iBAAA;EAYf;EAVA,OAAA,EAAS,YAAA,CAAa,GAAA;EAUG;EARzB,MAAA,EAAQ,YAAA,CAAa,GAAA;EAUf;EARN,SAAA,EAAW,YAAA,CAAa,GAAA;EAQD;EANvB,SAAA,EAAW,YAAA,CAAa,GAAA;EAUxB;EARA,YAAA,EAAc,YAAA,CAAa,GAAA;EAY3B;EAVA,UAAA,EAAY,YAAA,CAAa,GAAA;EAUM;EAR/B,IAAA,EAAM,YAAA,CAAa,GAAA,CAAI,UAAA;EAUvB;EARA,QAAA;EAQoC;EANpC,YAAA;EAMyD;EAJzD,KAAA;EAkCyB;EAhCzB,SAAA,GAAY,SAAA,UAAmB,SAAA,iBAA0B,QAAA;EAgC5B;EA9B7B,YAAA,GAAe,WAAA,UAAqB,YAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;iBA8BtB,WAAA,CAAA,GAAe,iBAAA"}