@eetech-commerce/cart-react 0.4.1

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,663 @@
1
+ import * as _tanstack_react_query from '@tanstack/react-query';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import react from 'react';
5
+
6
+ interface StorageAdapter {
7
+ get(key: string): string | null;
8
+ set(key: string, value: string): void;
9
+ remove(key: string): void;
10
+ }
11
+
12
+ declare const localStorageAdapter: StorageAdapter;
13
+
14
+ interface CartContextValue {
15
+ tenantSlug: string;
16
+ cartApiUrl: string;
17
+ storage: StorageAdapter;
18
+ cartSessionId: string | null;
19
+ setCartSessionId: (id: string | null) => void;
20
+ isInitializing: boolean;
21
+ setIsInitializing: (value: boolean) => void;
22
+ }
23
+ declare function useCartContext(): CartContextValue;
24
+
25
+ type TaxJurisdictionDto = {
26
+ /**
27
+ * ISO 3166-1 alpha-2 country code
28
+ */
29
+ country: string;
30
+ /**
31
+ * State/province code (if applicable)
32
+ */
33
+ state?: string;
34
+ /**
35
+ * Type of tax (e.g., sales_tax, vat, gst)
36
+ */
37
+ taxType: string;
38
+ };
39
+ type LineItemResponseDto = {
40
+ /**
41
+ * Unique identifier for the line item
42
+ */
43
+ id: string;
44
+ /**
45
+ * Product identifier
46
+ */
47
+ productId: string;
48
+ /**
49
+ * Product variant identifier
50
+ */
51
+ variantId?: string | null;
52
+ /**
53
+ * Offer identifier
54
+ */
55
+ offerId: string;
56
+ /**
57
+ * Seller identifier
58
+ */
59
+ sellerId: string;
60
+ /**
61
+ * Seller display name
62
+ */
63
+ sellerName?: string | null;
64
+ /**
65
+ * Product manufacturer name
66
+ */
67
+ manufacturer: string;
68
+ /**
69
+ * Product title
70
+ */
71
+ title: string;
72
+ /**
73
+ * Product variant title
74
+ */
75
+ variantTitle?: string | null;
76
+ /**
77
+ * Product thumbnail URL
78
+ */
79
+ thumbnail?: string | null;
80
+ /**
81
+ * Quantity of items
82
+ */
83
+ quantity: number;
84
+ /**
85
+ * Unit price in cents
86
+ */
87
+ unitPriceCents: number;
88
+ /**
89
+ * Subtotal in cents (quantity × unit price)
90
+ */
91
+ subtotalCents: number;
92
+ /**
93
+ * Product availability status
94
+ */
95
+ availability?: 'available' | 'unavailable' | 'not_found';
96
+ /**
97
+ * Additional metadata
98
+ */
99
+ metadata?: {
100
+ [key: string]: unknown;
101
+ } | null;
102
+ /**
103
+ * Product weight in pounds (from MarketPush product data)
104
+ */
105
+ weightPounds?: string | null;
106
+ /**
107
+ * Calculated tax amount in cents (populated after shipping address is set)
108
+ */
109
+ taxAmountCents?: number;
110
+ /**
111
+ * Tax rate as percentage (populated after shipping address is set)
112
+ */
113
+ taxRatePercentage?: number;
114
+ /**
115
+ * Tax jurisdiction details (populated after shipping address is set)
116
+ */
117
+ taxJurisdiction?: TaxJurisdictionDto | null;
118
+ /**
119
+ * Stripe Tax Calculation ID for audit trail
120
+ */
121
+ taxCalculationId?: string;
122
+ /**
123
+ * Timestamp when tax was calculated
124
+ */
125
+ taxCalculatedAt?: Date;
126
+ /**
127
+ * Reason for tax rate applied or exemption
128
+ */
129
+ taxabilityReason?: 'standard_rated' | 'reduced_rated' | 'zero_rated' | 'exempt' | 'reverse_charge' | 'not_collecting';
130
+ /**
131
+ * Creation timestamp
132
+ */
133
+ createdAt: Date;
134
+ /**
135
+ * Last update timestamp
136
+ */
137
+ updatedAt: Date;
138
+ };
139
+ type CustomerContactDto = {
140
+ /**
141
+ * Customer email address
142
+ */
143
+ email: string;
144
+ /**
145
+ * Customer first name
146
+ */
147
+ firstName: string;
148
+ /**
149
+ * Customer last name
150
+ */
151
+ lastName: string;
152
+ /**
153
+ * Primary phone number (minimum 10 characters)
154
+ */
155
+ phone: string;
156
+ /**
157
+ * Alternative phone number (minimum 10 characters)
158
+ */
159
+ alterPhone?: string;
160
+ };
161
+ type Address = {
162
+ /**
163
+ * Address ID
164
+ */
165
+ id: string;
166
+ /**
167
+ * Tenant ID
168
+ */
169
+ tenantId: string;
170
+ /**
171
+ * Recipient name
172
+ */
173
+ recipientName?: string | null;
174
+ /**
175
+ * Company name
176
+ */
177
+ company?: string | null;
178
+ /**
179
+ * Address line 1
180
+ */
181
+ line1: string;
182
+ /**
183
+ * Address line 2
184
+ */
185
+ line2?: string | null;
186
+ /**
187
+ * City
188
+ */
189
+ city: string;
190
+ /**
191
+ * State
192
+ */
193
+ state: string;
194
+ /**
195
+ * Zipcode
196
+ */
197
+ zipcode: string;
198
+ /**
199
+ * Country
200
+ */
201
+ country: string;
202
+ /**
203
+ * Creation timestamp
204
+ */
205
+ createdAt: Date;
206
+ /**
207
+ * Full formatted address
208
+ */
209
+ fullAddress: string;
210
+ };
211
+ type CartResponseDto = {
212
+ /**
213
+ * Internal database ID
214
+ */
215
+ id: string;
216
+ /**
217
+ * Public cart session identifier (nanoid)
218
+ */
219
+ sessionId: string;
220
+ /**
221
+ * Three-letter currency code (ISO 4217)
222
+ */
223
+ currency: string;
224
+ /**
225
+ * Cart subtotal in cents
226
+ */
227
+ subtotalCents: number;
228
+ /**
229
+ * Completion timestamp (null if cart is active)
230
+ */
231
+ completedAt?: Date | null;
232
+ /**
233
+ * Line items in the cart
234
+ */
235
+ items: Array<LineItemResponseDto>;
236
+ /**
237
+ * Optional cart metadata
238
+ */
239
+ metadata?: {
240
+ [key: string]: unknown;
241
+ } | null;
242
+ /**
243
+ * Cart creation timestamp
244
+ */
245
+ createdAt: Date;
246
+ /**
247
+ * Last update timestamp
248
+ */
249
+ updatedAt: Date;
250
+ /**
251
+ * Web order ID (nanoid) - present when checkout session created
252
+ */
253
+ webOrderId?: string | null;
254
+ /**
255
+ * Customer contact information - present when checkout session created
256
+ */
257
+ customerContact?: CustomerContactDto | null;
258
+ /**
259
+ * Shipping address - present when checkout session created
260
+ */
261
+ shippingAddress?: Address | null;
262
+ /**
263
+ * Billing address - present when checkout session created
264
+ */
265
+ billingAddress?: Address | null;
266
+ /**
267
+ * Shipping selections by seller ID - present when shipping methods selected
268
+ */
269
+ shippingSelections?: {
270
+ [key: string]: {
271
+ [key: string]: unknown;
272
+ };
273
+ } | null;
274
+ /**
275
+ * Purchase order number
276
+ */
277
+ poNumber?: string | null;
278
+ };
279
+ type DiscrepancyDto = {
280
+ /**
281
+ * Type of discrepancy detected
282
+ */
283
+ type: 'price_change' | 'unavailable' | 'insufficient_stock' | 'offer_removed' | 'seller_inactive' | 'below_minimum_order';
284
+ /**
285
+ * Cart line item ID
286
+ */
287
+ itemId: string;
288
+ /**
289
+ * Product offer ID
290
+ */
291
+ offerId: string;
292
+ /**
293
+ * Human-readable description of the discrepancy
294
+ */
295
+ message: string;
296
+ /**
297
+ * Original price in cents (for price_change)
298
+ */
299
+ oldPrice?: number;
300
+ /**
301
+ * New price in cents (for price_change)
302
+ */
303
+ newPrice?: number;
304
+ /**
305
+ * Quantity requested (for insufficient_stock)
306
+ */
307
+ requested?: number;
308
+ /**
309
+ * Quantity available (for insufficient_stock)
310
+ */
311
+ available?: number;
312
+ /**
313
+ * Reason for unavailability
314
+ */
315
+ reason?: 'out_of_stock' | 'inactive';
316
+ /**
317
+ * Seller ID (for seller-level discrepancies)
318
+ */
319
+ sellerId?: string;
320
+ /**
321
+ * Seller name (for seller-level discrepancies)
322
+ */
323
+ sellerName?: string;
324
+ /**
325
+ * Minimum order value in dollars (for below_minimum_order)
326
+ */
327
+ minimumOrderValue?: number;
328
+ /**
329
+ * Current order subtotal in dollars (for below_minimum_order)
330
+ */
331
+ currentSubtotal?: number;
332
+ };
333
+ type VerificationResultDto = {
334
+ /**
335
+ * Whether all cart items passed verification
336
+ */
337
+ valid: boolean;
338
+ /**
339
+ * Cart session ID that was verified
340
+ */
341
+ cartId: string;
342
+ /**
343
+ * List of discrepancies found during verification
344
+ */
345
+ discrepancies: Array<DiscrepancyDto>;
346
+ /**
347
+ * Total number of items verified
348
+ */
349
+ itemCount: number;
350
+ /**
351
+ * ISO timestamp of verification
352
+ */
353
+ verifiedAt: string;
354
+ };
355
+ type AddressDto = {
356
+ /**
357
+ * Name of the recipient
358
+ */
359
+ recipientName?: string;
360
+ /**
361
+ * Company name
362
+ */
363
+ company?: string;
364
+ /**
365
+ * First line of the address
366
+ */
367
+ line1: string;
368
+ /**
369
+ * Second line of the address (apartment, suite, etc.)
370
+ */
371
+ line2?: string;
372
+ /**
373
+ * City name
374
+ */
375
+ city: string;
376
+ /**
377
+ * State or province
378
+ */
379
+ state: string;
380
+ /**
381
+ * Postal/ZIP code
382
+ */
383
+ zipcode: string;
384
+ /**
385
+ * Three-letter country code (ISO 3166-1 alpha-3)
386
+ */
387
+ country: string;
388
+ };
389
+ type CreateCheckoutDto = {
390
+ /**
391
+ * Customer contact information
392
+ */
393
+ customerContact: CustomerContactDto;
394
+ /**
395
+ * Shipping address
396
+ */
397
+ shippingAddress: AddressDto;
398
+ /**
399
+ * Billing address (can be same as shipping)
400
+ */
401
+ billingAddress: AddressDto;
402
+ /**
403
+ * Purchase order number (optional)
404
+ */
405
+ poNumber?: string;
406
+ };
407
+ type ShippingOptionDto = {
408
+ /**
409
+ * Shipping option UUID (used as shippingRateId in selections)
410
+ */
411
+ id: string;
412
+ /**
413
+ * Seller this option belongs to
414
+ */
415
+ sellerId: string;
416
+ /**
417
+ * Delivery method name
418
+ */
419
+ deliveryMethod: string;
420
+ /**
421
+ * Carrier name
422
+ */
423
+ carrierName: string;
424
+ /**
425
+ * Carrier key for API integration
426
+ */
427
+ carrierKey: string;
428
+ /**
429
+ * Shipping option type (pricing model)
430
+ */
431
+ shippingOptionType: 'FreeShipping' | 'FlatRate' | 'PriceBasedRate' | 'WeightBasedRate';
432
+ /**
433
+ * Shipping cost in dollars
434
+ */
435
+ cost: number;
436
+ /**
437
+ * Creation timestamp (ISO 8601)
438
+ */
439
+ createdDate: string;
440
+ /**
441
+ * Last update timestamp (ISO 8601)
442
+ */
443
+ updatedDate: string;
444
+ };
445
+ type SellerShippingOptions = {
446
+ /**
447
+ * Seller UUID
448
+ */
449
+ sellerId: string;
450
+ /**
451
+ * Seller display name
452
+ */
453
+ sellerName: string | null;
454
+ /**
455
+ * Available shipping options for this seller
456
+ */
457
+ shippingOptions: Array<ShippingOptionDto>;
458
+ };
459
+ type ShippingOptionsResponse = {
460
+ /**
461
+ * Cart session ID
462
+ */
463
+ cartSessionId: string;
464
+ /**
465
+ * Shipping options grouped by seller
466
+ */
467
+ sellers: Array<SellerShippingOptions>;
468
+ };
469
+ type ShippingSelectionDto = {
470
+ /**
471
+ * Seller UUID this selection applies to
472
+ */
473
+ sellerId: string;
474
+ /**
475
+ * MarketPush shipping rate ID used for this selection
476
+ */
477
+ shippingRateId: string;
478
+ /**
479
+ * Optional carrier account identifier (max 50 chars, alphanumeric + dash/underscore/slash)
480
+ */
481
+ carrierAccount?: string;
482
+ };
483
+ type ShippingSelectionsResponseDto = {
484
+ /**
485
+ * Cart session ID
486
+ */
487
+ cartSessionId: string;
488
+ /**
489
+ * Shipping selections by seller ID
490
+ */
491
+ shippingSelections: {
492
+ [key: string]: {
493
+ [key: string]: unknown;
494
+ };
495
+ };
496
+ };
497
+ type PaymentSessionResponseDto = {
498
+ /**
499
+ * Unique payment session identifier
500
+ */
501
+ paymentSessionId: string;
502
+ /**
503
+ * Stripe Checkout Session URL
504
+ */
505
+ paymentLink: string;
506
+ /**
507
+ * Payment amount in cents
508
+ */
509
+ amount: number;
510
+ /**
511
+ * Three-letter currency code
512
+ */
513
+ currency: string;
514
+ /**
515
+ * Payment session status
516
+ */
517
+ status: 'pending' | 'succeeded' | 'failed' | 'expired';
518
+ /**
519
+ * Session expiration timestamp
520
+ */
521
+ expiresAt: Date;
522
+ };
523
+ type CreateEmbeddedPaymentSessionDto = {
524
+ /**
525
+ * Cart session ID (nanoid format) to create payment for
526
+ */
527
+ cartSessionId: string;
528
+ /**
529
+ * URL where Stripe redirects after payment completion
530
+ */
531
+ returnUrl: string;
532
+ };
533
+ type EmbeddedPaymentSessionResponseDto = {
534
+ /**
535
+ * Unique payment session identifier
536
+ */
537
+ paymentSessionId: string;
538
+ /**
539
+ * Stripe client secret for initEmbeddedCheckout()
540
+ */
541
+ clientSecret: string;
542
+ /**
543
+ * Payment amount in cents
544
+ */
545
+ amount: number;
546
+ /**
547
+ * Three-letter currency code (lowercase)
548
+ */
549
+ currency: string;
550
+ };
551
+
552
+ interface MutationCallbacks<TData = unknown, TError = Error> {
553
+ onSuccess?: (data: TData) => void;
554
+ onError?: (error: TError) => void;
555
+ }
556
+
557
+ declare function useCart(): _tanstack_react_query.UseQueryResult<CartResponseDto, Error>;
558
+ interface CreateCartParams {
559
+ currency?: string;
560
+ metadata?: Record<string, unknown>;
561
+ }
562
+ declare function useCreateCart(): {
563
+ createCart: (params?: CreateCartParams, callbacks?: MutationCallbacks<CartResponseDto>) => void;
564
+ isPending: boolean;
565
+ error: Error | null;
566
+ };
567
+ interface AddToCartParams {
568
+ offerId: string;
569
+ quantity?: number;
570
+ metadata?: Record<string, unknown>;
571
+ }
572
+ declare function useAddToCart(): {
573
+ addToCart: (params: AddToCartParams, callbacks?: MutationCallbacks<CartResponseDto>) => void;
574
+ isPending: boolean;
575
+ error: Error | null;
576
+ };
577
+ interface UpdateItemQtyParams {
578
+ offerId: string;
579
+ quantity: number;
580
+ }
581
+ declare function useUpdateItemQty(): {
582
+ updateItemQty: (params: UpdateItemQtyParams, callbacks?: MutationCallbacks<CartResponseDto>) => void;
583
+ isPending: boolean;
584
+ error: Error | null;
585
+ };
586
+ interface RemoveItemParams {
587
+ offerId: string;
588
+ }
589
+ declare function useRemoveItem(): {
590
+ removeItem: (params: RemoveItemParams, callbacks?: MutationCallbacks<CartResponseDto>) => void;
591
+ isPending: boolean;
592
+ error: Error | null;
593
+ };
594
+ declare function useClearCart(): {
595
+ clearCart: (callbacks?: MutationCallbacks<CartResponseDto>) => void;
596
+ isPending: boolean;
597
+ error: Error | null;
598
+ };
599
+ declare function useInitializeCart(): {
600
+ isInitializing: boolean;
601
+ };
602
+
603
+ declare function useVerifyCart(): {
604
+ verifyCart: (params: {
605
+ cartSessionId: string;
606
+ }, callbacks?: MutationCallbacks<VerificationResultDto>) => void;
607
+ isPending: boolean;
608
+ error: Error | null;
609
+ };
610
+ declare function useCreateCheckoutSession(): {
611
+ createCheckoutSession: (params: CreateCheckoutDto & {
612
+ cartSessionId?: string;
613
+ }, callbacks?: MutationCallbacks<CartResponseDto>) => void;
614
+ isPending: boolean;
615
+ error: Error | null;
616
+ };
617
+ declare function useShippingOptions(cartSessionId: string | null): _tanstack_react_query.UseQueryResult<ShippingOptionsResponse, Error>;
618
+ interface UpdateShippingSelectionsParams {
619
+ selections: ShippingSelectionDto[];
620
+ }
621
+ declare function useUpdateShippingSelections(): {
622
+ updateShippingSelections: (params: UpdateShippingSelectionsParams, callbacks?: MutationCallbacks<ShippingSelectionsResponseDto>) => void;
623
+ isPending: boolean;
624
+ error: Error | null;
625
+ };
626
+
627
+ declare function useStripePromise(): Promise<unknown> | null;
628
+ declare function useCreateEmbeddedCheckoutSession(): {
629
+ createEmbeddedCheckoutSession: (params: CreateEmbeddedPaymentSessionDto, callbacks?: MutationCallbacks<EmbeddedPaymentSessionResponseDto>) => void;
630
+ isPending: boolean;
631
+ error: Error | null;
632
+ data: EmbeddedPaymentSessionResponseDto | undefined;
633
+ };
634
+ declare function usePaymentSession(sessionId: string | null): _tanstack_react_query.UseQueryResult<PaymentSessionResponseDto, Error>;
635
+
636
+ declare const cartKeys: {
637
+ all: () => readonly [{
638
+ readonly _id: "cartControllerGetCartV1";
639
+ }];
640
+ };
641
+ declare const shippingKeys: {
642
+ all: () => readonly [{
643
+ readonly _id: "checkoutControllerGetShippingOptionsV1";
644
+ }];
645
+ };
646
+ declare const paymentKeys: {
647
+ all: () => readonly [{
648
+ readonly _id: "paymentControllerGetPaymentSessionV1";
649
+ }];
650
+ };
651
+
652
+ interface CartProviderProps {
653
+ children: react.ReactNode;
654
+ tenantSlug: string;
655
+ cartApiUrl: string;
656
+ storageAdapter?: StorageAdapter;
657
+ autoInitialize?: boolean;
658
+ /** Optional external QueryClient. If provided, CartProvider will not create its own. */
659
+ queryClient?: QueryClient;
660
+ }
661
+ declare function CartProvider({ children, tenantSlug, cartApiUrl, storageAdapter, autoInitialize, queryClient, }: CartProviderProps): react_jsx_runtime.JSX.Element;
662
+
663
+ export { type CartContextValue, CartProvider, type CartProviderProps, type CartResponseDto, type CreateCheckoutDto, type CreateEmbeddedPaymentSessionDto, type EmbeddedPaymentSessionResponseDto, type LineItemResponseDto, type MutationCallbacks, type ShippingOptionDto, type ShippingSelectionDto, type StorageAdapter, type VerificationResultDto, cartKeys, localStorageAdapter, paymentKeys, shippingKeys, useAddToCart, useCart, useCartContext, useClearCart, useCreateCart, useCreateCheckoutSession, useCreateEmbeddedCheckoutSession, useInitializeCart, usePaymentSession, useRemoveItem, useShippingOptions, useStripePromise, useUpdateItemQty, useUpdateShippingSelections, useVerifyCart };