@jay-framework/wix-cart 0.15.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.
@@ -0,0 +1,436 @@
1
+ import * as _jay_framework_runtime from '@jay-framework/runtime';
2
+ import { HTMLElementProxy, HTMLElementCollectionProxy } from '@jay-framework/runtime';
3
+ import { Getter } from '@jay-framework/reactive';
4
+ import { currentCart } from '@wix/ecom';
5
+ import { LineItem, Cart } from '@wix/auto_sdk_ecom_current-cart';
6
+ import { BuildDescriptors } from '@wix/sdk-types';
7
+ import * as _jay_framework_fullstack_component from '@jay-framework/fullstack-component';
8
+ import { Signals, PageProps } from '@jay-framework/fullstack-component';
9
+ import * as _jay_framework_component from '@jay-framework/component';
10
+
11
+ /**
12
+ * Cart Helper Types and Functions
13
+ *
14
+ * Shared types and mappers for cart operations.
15
+ * Used by both context and components.
16
+ */
17
+
18
+ type CurrentCartClient = BuildDescriptors<typeof currentCart, {}>;
19
+ type EstimateMethod = CurrentCartClient['estimateCurrentCartTotals'];
20
+ type EstimateTotalsResult = Awaited<ReturnType<EstimateMethod>>;
21
+ /**
22
+ * Cart line item for display
23
+ */
24
+ interface CartLineItem {
25
+ lineItemId: string;
26
+ productId: string;
27
+ productName: string;
28
+ productUrl: string;
29
+ variantName: string;
30
+ sku: string;
31
+ image: {
32
+ url: string;
33
+ altText: string;
34
+ };
35
+ quantity: number;
36
+ unitPrice: {
37
+ amount: string;
38
+ formattedAmount: string;
39
+ };
40
+ lineTotal: {
41
+ amount: string;
42
+ formattedAmount: string;
43
+ };
44
+ lineDiscount: {
45
+ amount: string;
46
+ formattedAmount: string;
47
+ };
48
+ hasDiscount: boolean;
49
+ }
50
+ /**
51
+ * Cart summary for display
52
+ */
53
+ interface CartSummary {
54
+ itemCount: number;
55
+ subtotal: {
56
+ amount: string;
57
+ formattedAmount: string;
58
+ };
59
+ discount: {
60
+ amount: string;
61
+ formattedAmount: string;
62
+ };
63
+ hasDiscount: boolean;
64
+ estimatedTax: {
65
+ amount: string;
66
+ formattedAmount: string;
67
+ };
68
+ showTax: boolean;
69
+ estimatedTotal: {
70
+ amount: string;
71
+ formattedAmount: string;
72
+ };
73
+ currency: string;
74
+ }
75
+ /**
76
+ * Full cart state
77
+ */
78
+ interface CartState {
79
+ cartId: string;
80
+ isEmpty: boolean;
81
+ lineItems: CartLineItem[];
82
+ summary: CartSummary;
83
+ appliedCoupon: string;
84
+ hasAppliedCoupon: boolean;
85
+ }
86
+ /**
87
+ * Cart indicator data (lightweight)
88
+ */
89
+ interface CartIndicatorState {
90
+ itemCount: number;
91
+ hasItems: boolean;
92
+ }
93
+ /**
94
+ * Map cart line item from Wix API to our format
95
+ */
96
+ declare function mapLineItem(item: LineItem): CartLineItem;
97
+ /**
98
+ * Map cart to our summary format (basic - without estimate totals)
99
+ */
100
+ declare function mapCartSummary(cart: Cart | null): CartSummary;
101
+ /**
102
+ * Map cart to full state (basic - without estimate totals)
103
+ */
104
+ declare function mapCartToState(cart: Cart | null): CartState;
105
+ /**
106
+ * Get empty cart state
107
+ */
108
+ declare function getEmptyCartState(): CartState;
109
+ /**
110
+ * Map cart to indicator state (lightweight)
111
+ */
112
+ declare function mapCartToIndicator(cart: Cart | null): CartIndicatorState;
113
+ /**
114
+ * Get the current cart, treating 404 as an empty cart.
115
+ *
116
+ * The Wix Cart API returns 404 when no cart exists (before first item is added).
117
+ * This helper normalizes that case to return null, which the mappers handle as empty.
118
+ */
119
+ declare function getCurrentCartOrNull(cartClient: CurrentCartClient): Promise<Cart | null>;
120
+ /**
121
+ * Estimate the current cart totals, treating 404 as an empty cart.
122
+ *
123
+ * This API provides complete price totals including tax calculations.
124
+ * Use this for cart pages where accurate totals are needed.
125
+ *
126
+ * @see https://dev.wix.com/docs/sdk/backend-modules/ecom/current-cart/estimate-current-cart-totals
127
+ */
128
+ declare function estimateCurrentCartTotalsOrNull(cartClient: CurrentCartClient): Promise<EstimateTotalsResult | null>;
129
+ /**
130
+ * Map estimate totals response to CartState.
131
+ * The estimate response includes calculated totals with tax.
132
+ */
133
+ declare function mapEstimateTotalsToState(estimate: EstimateTotalsResult | null): CartState;
134
+
135
+ /**
136
+ * Configuration passed from server to client for Wix Cart.
137
+ */
138
+ interface WixCartInitData {
139
+ /** Enable client-side cart operations */
140
+ enableClientCart: boolean;
141
+ }
142
+ /**
143
+ * Reactive cart indicator state.
144
+ * Signals update automatically when cart operations occur.
145
+ */
146
+ interface ReactiveCartIndicator {
147
+ /** Number of items in cart (reactive signal) */
148
+ itemCount: Getter<number>;
149
+ /** Whether cart has items (reactive signal) */
150
+ hasItems: Getter<boolean>;
151
+ }
152
+ /**
153
+ * Result of a cart operation that modifies items.
154
+ */
155
+ interface CartOperationResult {
156
+ /** Updated cart state after the operation */
157
+ cartState: CartState;
158
+ }
159
+ /**
160
+ * Options for add to cart operation.
161
+ * Used by consumers (wix-stores, wix-stores-v1) to pass variant information.
162
+ */
163
+ interface AddToCartOptions {
164
+ /** Variant ID for the product */
165
+ variantId?: string;
166
+ /** Custom text fields as (key, value) pairs */
167
+ customTextFields?: Record<string, string>;
168
+ /** Modifiers as (key, value) pairs */
169
+ modifiers?: Record<string, string>;
170
+ /** Product slug for building the correct product page URL in cart */
171
+ productSlug?: string;
172
+ }
173
+ /**
174
+ * Client-side Wix Cart context interface.
175
+ * Provides reactive cart indicator and encapsulated cart operations.
176
+ */
177
+ interface WixCartContext {
178
+ /**
179
+ * Reactive cart indicator signals.
180
+ * Use these in render functions for automatic updates.
181
+ */
182
+ cartIndicator: ReactiveCartIndicator;
183
+ /**
184
+ * Refresh cart indicator from server.
185
+ * Call this after external cart changes or on page load.
186
+ */
187
+ refreshCartIndicator(): Promise<void>;
188
+ /**
189
+ * Get full cart state with estimated totals (subtotal, tax, total).
190
+ * Handles 404 (no cart) as empty cart.
191
+ * Use this for cart pages where accurate totals are needed.
192
+ */
193
+ getEstimatedCart(): Promise<CartState>;
194
+ /**
195
+ * Add a product to the cart.
196
+ * Automatically updates the cart indicator signals.
197
+ *
198
+ * @param productId - The product ID to add
199
+ * @param quantity - Number of items to add (default: 1)
200
+ * @param options - Variant and modifier options
201
+ * @returns Updated cart state
202
+ */
203
+ addToCart(productId: string, quantity?: number, options?: AddToCartOptions): Promise<CartOperationResult>;
204
+ /**
205
+ * Remove line items from the cart.
206
+ * Automatically updates the cart indicator signals.
207
+ *
208
+ * @param lineItemIds - Array of line item IDs to remove
209
+ * @returns Updated cart state
210
+ */
211
+ removeLineItems(lineItemIds: string[]): Promise<CartOperationResult>;
212
+ /**
213
+ * Update a line item's quantity.
214
+ * If quantity is 0, the item is removed.
215
+ * Automatically updates the cart indicator signals.
216
+ *
217
+ * @param lineItemId - The line item ID to update
218
+ * @param quantity - New quantity (0 removes the item)
219
+ * @returns Updated cart state
220
+ */
221
+ updateLineItemQuantity(lineItemId: string, quantity: number): Promise<CartOperationResult>;
222
+ /**
223
+ * Clear all items from the cart.
224
+ * Automatically updates the cart indicator signals.
225
+ */
226
+ clearCart(): Promise<void>;
227
+ /**
228
+ * Apply a coupon code to the cart.
229
+ * Automatically updates the cart indicator signals.
230
+ *
231
+ * @param couponCode - The coupon code to apply
232
+ * @returns Updated cart state
233
+ */
234
+ applyCoupon(couponCode: string): Promise<CartOperationResult>;
235
+ /**
236
+ * Remove applied coupon from the cart.
237
+ * Automatically updates the cart indicator signals.
238
+ *
239
+ * @returns Updated cart state
240
+ */
241
+ removeCoupon(): Promise<CartOperationResult>;
242
+ }
243
+ /**
244
+ * Context marker for client-side Wix Cart operations.
245
+ */
246
+ declare const WIX_CART_CONTEXT: _jay_framework_runtime.ContextMarker<WixCartContext>;
247
+ /**
248
+ * Initialize and register the Wix Cart client context.
249
+ * Called during client-side initialization.
250
+ *
251
+ * Assumes WIX_CLIENT_CONTEXT is already initialized with a valid client.
252
+ *
253
+ * @returns The created context for immediate use (e.g., to call refreshCartIndicator)
254
+ */
255
+ declare function provideWixCartContext(): WixCartContext;
256
+
257
+ interface CartIndicatorViewState {
258
+ itemCount: number,
259
+ hasItems: boolean,
260
+ isLoading: boolean,
261
+ justAdded: boolean
262
+ }
263
+
264
+ type CartIndicatorSlowViewState = {};
265
+
266
+ type CartIndicatorFastViewState = Pick<CartIndicatorViewState, 'itemCount' | 'hasItems' | 'isLoading' | 'justAdded'>;
267
+
268
+ type CartIndicatorInteractiveViewState = Pick<CartIndicatorViewState, 'itemCount' | 'hasItems' | 'isLoading' | 'justAdded'>;
269
+
270
+
271
+ interface CartIndicatorRefs {
272
+ cartButton: HTMLElementProxy<CartIndicatorViewState, HTMLButtonElement>,
273
+ cartLink: HTMLElementProxy<CartIndicatorViewState, HTMLAnchorElement>
274
+ }
275
+
276
+ interface WixCartService {
277
+ cart: BuildDescriptors<typeof currentCart, {}>;
278
+ }
279
+ /**
280
+ * Server service marker for Wix Cart.
281
+ * Use with `.withServices(WIX_CART_SERVICE)` in component definitions.
282
+ */
283
+ declare const WIX_CART_SERVICE: _jay_framework_fullstack_component.ServiceMarker<WixCartService>;
284
+
285
+ interface CartIndicatorFastCarryForward {
286
+ }
287
+ /**
288
+ * Cart Indicator Component
289
+ *
290
+ * Displays cart item count in site header.
291
+ * Automatically updates when items are added to cart.
292
+ */
293
+ declare const cartIndicator: _jay_framework_fullstack_component.JayStackComponentDefinition<CartIndicatorRefs, CartIndicatorSlowViewState, CartIndicatorFastViewState, CartIndicatorInteractiveViewState, [WixCartService], [Signals<CartIndicatorFastViewState>, CartIndicatorFastCarryForward, WixCartContext], PageProps, {}, _jay_framework_component.JayComponentCore<PageProps, CartIndicatorInteractiveViewState>>;
294
+
295
+ interface ImageOfLineItemOfCartPageViewState {
296
+ url: string,
297
+ altText: string
298
+ }
299
+
300
+ interface UnitPriceOfLineItemOfCartPageViewState {
301
+ amount: string,
302
+ formattedAmount: string
303
+ }
304
+
305
+ interface LineTotalOfLineItemOfCartPageViewState {
306
+ amount: string,
307
+ formattedAmount: string
308
+ }
309
+
310
+ interface LineDiscountOfLineItemOfCartPageViewState {
311
+ amount: string,
312
+ formattedAmount: string
313
+ }
314
+
315
+ interface LineItemOfCartPageViewState {
316
+ lineItemId: string,
317
+ productId: string,
318
+ productName: string,
319
+ productUrl: string,
320
+ variantName: string,
321
+ sku: string,
322
+ image: ImageOfLineItemOfCartPageViewState,
323
+ quantity: number,
324
+ isUpdatingQuantity: boolean,
325
+ unitPrice: UnitPriceOfLineItemOfCartPageViewState,
326
+ lineTotal: LineTotalOfLineItemOfCartPageViewState,
327
+ lineDiscount: LineDiscountOfLineItemOfCartPageViewState,
328
+ hasDiscount: boolean,
329
+ isRemoving: boolean
330
+ }
331
+
332
+ interface SubtotalOfSummaryOfCartPageViewState {
333
+ amount: string,
334
+ formattedAmount: string
335
+ }
336
+
337
+ interface DiscountOfSummaryOfCartPageViewState {
338
+ amount: string,
339
+ formattedAmount: string
340
+ }
341
+
342
+ interface EstimatedTaxOfSummaryOfCartPageViewState {
343
+ amount: string,
344
+ formattedAmount: string
345
+ }
346
+
347
+ interface EstimatedTotalOfSummaryOfCartPageViewState {
348
+ amount: string,
349
+ formattedAmount: string
350
+ }
351
+
352
+ interface SummaryOfCartPageViewState {
353
+ itemCount: number,
354
+ subtotal: SubtotalOfSummaryOfCartPageViewState,
355
+ discount: DiscountOfSummaryOfCartPageViewState,
356
+ hasDiscount: boolean,
357
+ estimatedTax: EstimatedTaxOfSummaryOfCartPageViewState,
358
+ showTax: boolean,
359
+ estimatedTotal: EstimatedTotalOfSummaryOfCartPageViewState,
360
+ currency: string
361
+ }
362
+
363
+ interface CouponOfCartPageViewState {
364
+ code: string,
365
+ isApplying: boolean,
366
+ appliedCode: string,
367
+ hasAppliedCoupon: boolean,
368
+ errorMessage: string,
369
+ hasError: boolean
370
+ }
371
+
372
+ interface CartPageViewState {
373
+ cartId: string,
374
+ isEmpty: boolean,
375
+ isLoading: boolean,
376
+ lineItems: Array<LineItemOfCartPageViewState>,
377
+ summary: SummaryOfCartPageViewState,
378
+ coupon: CouponOfCartPageViewState,
379
+ isCheckingOut: boolean,
380
+ emptyCartMessage: string
381
+ }
382
+
383
+ type CartPageSlowViewState = Pick<CartPageViewState, 'cartId' | 'emptyCartMessage'>;
384
+
385
+ type CartPageFastViewState = Pick<CartPageViewState, 'isEmpty' | 'isLoading' | 'isCheckingOut'> & {
386
+ lineItems: Array<CartPageViewState['lineItems'][number]>;
387
+ summary: CartPageViewState['summary'];
388
+ coupon: CartPageViewState['coupon'];
389
+ };
390
+
391
+ type CartPageInteractiveViewState = Pick<CartPageViewState, 'isEmpty' | 'isLoading' | 'isCheckingOut'> & {
392
+ lineItems: Array<CartPageViewState['lineItems'][number]>;
393
+ summary: CartPageViewState['summary'];
394
+ coupon: CartPageViewState['coupon'];
395
+ };
396
+
397
+
398
+ interface CartPageRefs {
399
+ checkoutButton: HTMLElementProxy<CartPageViewState, HTMLButtonElement>,
400
+ continueShoppingLink: HTMLElementProxy<CartPageViewState, HTMLAnchorElement>,
401
+ clearCartButton: HTMLElementProxy<CartPageViewState, HTMLButtonElement>,
402
+ emptyCartLink: HTMLElementProxy<CartPageViewState, HTMLAnchorElement>,
403
+ lineItems: {
404
+ productLink: HTMLElementCollectionProxy<LineItemOfCartPageViewState, HTMLAnchorElement>,
405
+ quantity: HTMLElementCollectionProxy<LineItemOfCartPageViewState, HTMLInputElement>,
406
+ decrementButton: HTMLElementCollectionProxy<LineItemOfCartPageViewState, HTMLButtonElement>,
407
+ incrementButton: HTMLElementCollectionProxy<LineItemOfCartPageViewState, HTMLButtonElement>,
408
+ removeButton: HTMLElementCollectionProxy<LineItemOfCartPageViewState, HTMLButtonElement>
409
+ },
410
+ coupon: {
411
+ code: HTMLElementProxy<CouponOfCartPageViewState, HTMLInputElement>,
412
+ applyButton: HTMLElementProxy<CouponOfCartPageViewState, HTMLButtonElement>,
413
+ removeButton: HTMLElementProxy<CouponOfCartPageViewState, HTMLButtonElement>
414
+ }
415
+ }
416
+
417
+ interface CartPageSlowCarryForward {
418
+ }
419
+ interface CartPageFastCarryForward {
420
+ }
421
+ /**
422
+ * Cart Page Component
423
+ *
424
+ * Full shopping cart page with:
425
+ * - Line item display with images, names, variants
426
+ * - Quantity adjustment (increment/decrement/input)
427
+ * - Item removal
428
+ * - Cart summary (subtotal, discounts, total)
429
+ * - Coupon code application
430
+ * - Checkout button
431
+ */
432
+ declare const cartPage: _jay_framework_fullstack_component.JayStackComponentDefinition<CartPageRefs, CartPageSlowViewState, CartPageFastViewState, CartPageInteractiveViewState, [CartPageSlowCarryForward, WixCartService], [Signals<CartPageFastViewState>, CartPageFastCarryForward, WixCartContext], PageProps, {}, _jay_framework_component.JayComponentCore<PageProps, CartPageInteractiveViewState>>;
433
+
434
+ declare const init: _jay_framework_fullstack_component.JayInit<WixCartInitData>;
435
+
436
+ export { type AddToCartOptions as A, type CartOperationResult as C, type ReactiveCartIndicator as R, type WixCartService as W, WIX_CART_SERVICE as a, WIX_CART_CONTEXT as b, type WixCartContext as c, type WixCartInitData as d, mapCartSummary as e, mapCartToState as f, mapCartToIndicator as g, getEmptyCartState as h, getCurrentCartOrNull as i, estimateCurrentCartTotalsOrNull as j, mapEstimateTotalsToState as k, type CartState as l, mapLineItem as m, type CartLineItem as n, type CartSummary as o, provideWixCartContext as p, type CartIndicatorState as q, cartIndicator as r, cartPage as s, init as t };
@@ -0,0 +1,8 @@
1
+ export { A as AddToCartOptions, q as CartIndicatorState, n as CartLineItem, C as CartOperationResult, l as CartState, o as CartSummary, R as ReactiveCartIndicator, b as WIX_CART_CONTEXT, c as WixCartContext, r as cartIndicator, s as cartPage, t as init } from './index.client-VoD54p4E.js';
2
+ import '@jay-framework/runtime';
3
+ import '@jay-framework/reactive';
4
+ import '@wix/ecom';
5
+ import '@wix/auto_sdk_ecom_current-cart';
6
+ import '@wix/sdk-types';
7
+ import '@jay-framework/fullstack-component';
8
+ import '@jay-framework/component';