@basedone/core 0.1.10 → 0.2.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.
Files changed (54) hide show
  1. package/dist/chunk-4UEJOM6W.mjs +1 -3
  2. package/dist/chunk-MVFO4WRF.mjs +2091 -0
  3. package/dist/chunk-VBC6EQ7Q.mjs +235 -0
  4. package/dist/client-CgmiTuEX.d.mts +179 -0
  5. package/dist/client-CgmiTuEX.d.ts +179 -0
  6. package/dist/ecommerce.d.mts +3986 -0
  7. package/dist/ecommerce.d.ts +3986 -0
  8. package/dist/ecommerce.js +2135 -0
  9. package/dist/ecommerce.mjs +2 -0
  10. package/dist/index.d.mts +51 -43
  11. package/dist/index.d.ts +51 -43
  12. package/dist/index.js +2795 -205
  13. package/dist/index.mjs +68 -90
  14. package/dist/{meta-FVJIMALT.mjs → meta-JB5ITE27.mjs} +4 -10
  15. package/dist/meta-UOGUG3OW.mjs +3 -7
  16. package/dist/{perpDexs-GGL32HT4.mjs → perpDexs-3LRJ5ZHM.mjs} +37 -8
  17. package/dist/{perpDexs-G7V2QIM6.mjs → perpDexs-4ISLD7NX.mjs} +177 -32
  18. package/dist/react.d.mts +39 -0
  19. package/dist/react.d.ts +39 -0
  20. package/dist/react.js +268 -0
  21. package/dist/react.mjs +31 -0
  22. package/dist/{spotMeta-OD7S6HGW.mjs → spotMeta-GHXX7C5M.mjs} +24 -9
  23. package/dist/{spotMeta-PCN4Z4R3.mjs → spotMeta-IBBUP2SG.mjs} +54 -6
  24. package/dist/staticMeta-GM7T3OYL.mjs +3 -6
  25. package/dist/staticMeta-QV2KMX57.mjs +3 -6
  26. package/ecommerce.ts +15 -0
  27. package/index.ts +6 -0
  28. package/lib/ecommerce/FLASH_SALES.md +340 -0
  29. package/lib/ecommerce/QUICK_REFERENCE.md +211 -0
  30. package/lib/ecommerce/README.md +391 -0
  31. package/lib/ecommerce/USAGE_EXAMPLES.md +704 -0
  32. package/lib/ecommerce/client/base.ts +272 -0
  33. package/lib/ecommerce/client/customer.ts +639 -0
  34. package/lib/ecommerce/client/merchant.ts +1341 -0
  35. package/lib/ecommerce/index.ts +51 -0
  36. package/lib/ecommerce/types/entities.ts +791 -0
  37. package/lib/ecommerce/types/enums.ts +270 -0
  38. package/lib/ecommerce/types/index.ts +18 -0
  39. package/lib/ecommerce/types/requests.ts +580 -0
  40. package/lib/ecommerce/types/responses.ts +857 -0
  41. package/lib/ecommerce/utils/errors.ts +113 -0
  42. package/lib/ecommerce/utils/helpers.ts +131 -0
  43. package/lib/hip3/market-info.ts +1 -1
  44. package/lib/instrument/client.ts +351 -0
  45. package/lib/meta/data/mainnet/perpDexs.json +34 -4
  46. package/lib/meta/data/mainnet/spotMeta.json +21 -3
  47. package/lib/meta/data/testnet/meta.json +1 -3
  48. package/lib/meta/data/testnet/perpDexs.json +174 -28
  49. package/lib/meta/data/testnet/spotMeta.json +51 -0
  50. package/lib/react/InstrumentProvider.tsx +69 -0
  51. package/lib/utils/flooredDateTime.ts +55 -0
  52. package/lib/utils/time.ts +51 -0
  53. package/package.json +37 -11
  54. package/react.ts +1 -0
@@ -0,0 +1,704 @@
1
+ # Ecommerce SDK Usage Examples
2
+
3
+ This document provides comprehensive examples of using the Ecommerce SDK in various scenarios.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Customer Examples](#customer-examples)
9
+ - [Browsing Products](#browsing-products)
10
+ - [Placing Orders](#placing-orders)
11
+ - [Managing Reviews](#managing-reviews)
12
+ - [Shipping Addresses](#shipping-addresses)
13
+ - [Cart & Discounts](#cart--discounts)
14
+ - [Merchant Examples](#merchant-examples)
15
+ - [Product Management](#product-management)
16
+ - [Order Fulfillment](#order-fulfillment)
17
+ - [Customer Management](#customer-management)
18
+ - [Analytics](#analytics)
19
+ - [Tax Management](#tax-management)
20
+ - [React Native Examples](#react-native-examples)
21
+ - [Error Handling](#error-handling)
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @basedone/core
27
+ # or
28
+ pnpm add @basedone/core
29
+ ```
30
+
31
+ ## Customer Examples
32
+
33
+ ### Browsing Products
34
+
35
+ ```typescript
36
+ import { CustomerEcommerceClient } from "@basedone/core/ecommerce";
37
+
38
+ const client = new CustomerEcommerceClient({
39
+ baseURL: "https://api.basedone.com",
40
+ authToken: "user-auth-token",
41
+ });
42
+
43
+ // List all products
44
+ const products = await client.listProducts({
45
+ limit: 20,
46
+ offset: 0,
47
+ });
48
+
49
+ // Search products
50
+ const searchResults = await client.listProducts({
51
+ search: "laptop",
52
+ category: "electronics",
53
+ minPrice: 500,
54
+ maxPrice: 2000,
55
+ sortBy: "price_asc",
56
+ });
57
+
58
+ // Get product details
59
+ const product = await client.getProduct("prod_123");
60
+ console.log(product.product.title, product.product.priceUSDC);
61
+
62
+ // Track product view (analytics)
63
+ await client.trackProductView("prod_123");
64
+
65
+ // Get active discounts for a product
66
+ const discounts = await client.getProductDiscounts("prod_123");
67
+ discounts.discounts.forEach(d => {
68
+ console.log(d.badge, d.description);
69
+ });
70
+ ```
71
+
72
+ ### Placing Orders
73
+
74
+ ```typescript
75
+ // Create order with USDC escrow payment
76
+ const order = await client.createOrder({
77
+ items: [
78
+ { productId: "prod_123", quantity: 2 },
79
+ { productId: "prod_456", quantity: 1, variantId: "var_789" },
80
+ ],
81
+ paymentMethod: "USDC_ESCROW",
82
+ shippingAddress: {
83
+ fullName: "John Doe",
84
+ phone: "+1234567890",
85
+ email: "john@example.com",
86
+ addressLine1: "123 Main St",
87
+ addressLine2: "Apt 4B",
88
+ city: "New York",
89
+ stateProvince: "NY",
90
+ postalCode: "10001",
91
+ country: "US",
92
+ },
93
+ couponCode: "SAVE10",
94
+ customerNotes: "Please leave at door",
95
+ });
96
+
97
+ // For USDC escrow, deposit to the escrow address
98
+ if (order.escrow) {
99
+ console.log(`Deposit ${order.escrow.amountUSDC} USDC to ${order.escrow.address}`);
100
+
101
+ // After depositing via Hyperliquid, confirm the transaction
102
+ const confirmation = await client.confirmEscrowDeposit(order.orders[0].id);
103
+ console.log("Payment confirmed:", confirmation.depositTxHash);
104
+ }
105
+
106
+ // Multi-merchant checkout (automatic order splitting)
107
+ const multiMerchantOrder = await client.createOrder({
108
+ items: [
109
+ { productId: "prod_from_merchant_a", quantity: 1 },
110
+ { productId: "prod_from_merchant_b", quantity: 2 },
111
+ ],
112
+ paymentMethod: "USDC_ESCROW",
113
+ shippingAddress: { /* ... */ },
114
+ });
115
+
116
+ console.log(`Created ${multiMerchantOrder.summary.orderCount} orders`);
117
+ console.log(`Merchants: ${multiMerchantOrder.summary.merchantNames.join(", ")}`);
118
+
119
+ // List user's orders
120
+ const orders = await client.listOrders({
121
+ limit: 10,
122
+ offset: 0,
123
+ status: "SHIPPED",
124
+ });
125
+
126
+ // Get order details
127
+ const orderDetails = await client.getOrder("ord_123");
128
+ console.log("Status:", orderDetails.order.status);
129
+ console.log("Tracking:", orderDetails.order.shipment?.trackingNumber);
130
+
131
+ // Get order receipt
132
+ const receipt = await client.getOrderReceipt("ord_123");
133
+ console.log("Order #", receipt.receipt.orderNumber);
134
+ ```
135
+
136
+ ### Managing Reviews
137
+
138
+ ```typescript
139
+ // List product reviews
140
+ const reviews = await client.listProductReviews("prod_123", {
141
+ limit: 10,
142
+ sortBy: "highest",
143
+ });
144
+
145
+ reviews.items.forEach(review => {
146
+ console.log(`${review.rating}/5 - ${review.title}`);
147
+ console.log(review.comment);
148
+ if (review.merchantResponse) {
149
+ console.log("Merchant:", review.merchantResponse);
150
+ }
151
+ });
152
+
153
+ // Create a review (requires verified purchase)
154
+ const review = await client.createReview("prod_123", {
155
+ rating: 5,
156
+ title: "Excellent product!",
157
+ comment: "Exactly what I needed. Fast shipping and great quality.",
158
+ });
159
+ ```
160
+
161
+ ### Shipping Addresses
162
+
163
+ ```typescript
164
+ // List saved addresses
165
+ const addresses = await client.listShippingAddresses();
166
+ const defaultAddress = addresses.addresses.find(a => a.isDefault);
167
+
168
+ // Add new address
169
+ const newAddress = await client.createShippingAddress({
170
+ fullName: "John Doe",
171
+ phone: "+1234567890",
172
+ addressLine1: "456 Oak Ave",
173
+ city: "Los Angeles",
174
+ stateProvince: "CA",
175
+ postalCode: "90001",
176
+ country: "US",
177
+ isDefault: true,
178
+ label: "Home",
179
+ });
180
+
181
+ // Update address
182
+ await client.updateShippingAddress("addr_123", {
183
+ phone: "+0987654321",
184
+ });
185
+
186
+ // Delete address
187
+ await client.deleteShippingAddress("addr_123");
188
+ ```
189
+
190
+ ### Cart & Discounts
191
+
192
+ ```typescript
193
+ // Calculate automatic discounts
194
+ const cart = [
195
+ { productId: "prod_123", quantity: 2 },
196
+ { productId: "prod_456", quantity: 1 },
197
+ ];
198
+
199
+ const discountResult = await client.calculateCartDiscounts({ items: cart });
200
+ console.log("Subtotal:", discountResult.subtotal);
201
+ console.log("Discount:", discountResult.discountAmount);
202
+ console.log("Total:", discountResult.total);
203
+
204
+ discountResult.appliedDiscounts.forEach(d => {
205
+ console.log(`${d.code}: -$${d.discountAmount}`);
206
+ });
207
+
208
+ // Validate coupon code
209
+ const validation = await client.validateDiscountCode({
210
+ code: "SAVE20",
211
+ items: cart,
212
+ });
213
+
214
+ if (validation.valid) {
215
+ console.log("Coupon valid! Discount:", validation.discount?.discountAmount);
216
+ } else {
217
+ console.log("Error:", validation.error);
218
+ }
219
+
220
+ // Calculate tax
221
+ const taxResult = await client.calculateTax({
222
+ items: cart,
223
+ shippingAddress: {
224
+ country: "US",
225
+ region: "NY",
226
+ postalCode: "10001",
227
+ },
228
+ });
229
+
230
+ console.log("Subtotal:", taxResult.subtotal);
231
+ console.log("Tax:", taxResult.taxAmount);
232
+ console.log("Total:", taxResult.total);
233
+
234
+ taxResult.breakdown.forEach(tax => {
235
+ console.log(`${tax.taxName}: ${tax.taxRate}% = $${tax.taxAmount}`);
236
+ });
237
+ ```
238
+
239
+ ## Merchant Examples
240
+
241
+ ### Product Management
242
+
243
+ ```typescript
244
+ import { MerchantEcommerceClient } from "@basedone/core/ecommerce";
245
+
246
+ const client = new MerchantEcommerceClient({
247
+ baseURL: "https://api.basedone.com",
248
+ authToken: "merchant-auth-token",
249
+ });
250
+
251
+ // Create merchant profile
252
+ await client.upsertMerchantProfile({
253
+ name: "My Awesome Store",
254
+ description: "We sell the best products",
255
+ payoutAddress: "0x1234567890abcdef...",
256
+ });
257
+
258
+ // List merchant's products
259
+ const products = await client.listMerchantProducts({ limit: 50 });
260
+
261
+ // Create a product
262
+ const product = await client.createProduct({
263
+ title: "Premium Laptop",
264
+ images: [
265
+ "https://storage.example.com/laptop-1.jpg",
266
+ "https://storage.example.com/laptop-2.jpg",
267
+ ],
268
+ priceUSDC: 1299.99,
269
+ compareAtPrice: 1499.99, // Show discount
270
+ inventory: 50,
271
+ sku: "LAPTOP-001",
272
+ category: "electronics",
273
+ richDescription: "<p>High-performance laptop with...</p>",
274
+ weight: 2.5,
275
+ dimensions: {
276
+ length: 35,
277
+ width: 25,
278
+ height: 2,
279
+ },
280
+ moq: 1,
281
+ isActive: true,
282
+ });
283
+
284
+ // Update product
285
+ await client.updateProduct("prod_123", {
286
+ priceUSDC: 1199.99,
287
+ inventory: 45,
288
+ });
289
+
290
+ // Set product as featured
291
+ await client.setProductFeatured("prod_123", true);
292
+
293
+ // Create product variants
294
+ const variant = await client.createProductVariant("prod_123", {
295
+ name: "16GB RAM / 512GB SSD",
296
+ sku: "LAPTOP-001-16-512",
297
+ attributes: {
298
+ ram: "16GB",
299
+ storage: "512GB",
300
+ },
301
+ priceUSDC: 1399.99,
302
+ inventory: 20,
303
+ sortOrder: 1,
304
+ });
305
+
306
+ // Get product metrics
307
+ const metrics = await client.getProductMetrics();
308
+ console.log("Total revenue:", metrics.summary.totalRevenue);
309
+ console.log("Total sales:", metrics.summary.totalSales);
310
+
311
+ metrics.products.forEach(p => {
312
+ console.log(`${p.name}: ${p.soldCount} sold, ${p.viewCount} views`);
313
+ console.log(`Conversion rate: ${p.conversionRate}%`);
314
+ });
315
+ ```
316
+
317
+ ### Order Fulfillment
318
+
319
+ ```typescript
320
+ // List orders
321
+ const orders = await client.listMerchantOrders({
322
+ limit: 20,
323
+ status: "PAYMENT_RESERVED",
324
+ });
325
+
326
+ // Get order details
327
+ const order = await client.getMerchantOrder("ord_123");
328
+
329
+ // Accept order
330
+ await client.updateOrderStatus("ord_123", {
331
+ status: "MERCHANT_ACCEPTED",
332
+ });
333
+
334
+ // Mark as shipped
335
+ await client.updateOrderStatus("ord_123", {
336
+ status: "SHIPPED",
337
+ tracking: {
338
+ trackingNumber: "1Z999AA10123456784",
339
+ carrier: "UPS",
340
+ },
341
+ });
342
+
343
+ // Mark as delivered
344
+ await client.updateOrderStatus("ord_123", {
345
+ status: "DELIVERED",
346
+ });
347
+
348
+ // Cancel order
349
+ await client.updateOrderStatus("ord_123", {
350
+ status: "CANCELLED",
351
+ });
352
+
353
+ // Add custom order event
354
+ await client.createOrderEvent("ord_123", {
355
+ eventType: "CUSTOM",
356
+ title: "Package delayed",
357
+ description: "Shipment delayed due to weather conditions",
358
+ metadata: {
359
+ reason: "weather",
360
+ estimatedDelay: "2 days",
361
+ },
362
+ });
363
+
364
+ // Manage shipments
365
+ const shipments = await client.listShipments();
366
+
367
+ await client.updateShipment("ship_123", {
368
+ status: "SHIPPED",
369
+ trackingNumber: "1Z999AA10123456784",
370
+ carrier: "UPS",
371
+ });
372
+ ```
373
+
374
+ ### Customer Management
375
+
376
+ ```typescript
377
+ // List customers with stats
378
+ const customers = await client.listCustomers({ limit: 100 });
379
+
380
+ customers.items.forEach(customer => {
381
+ console.log(`${customer.username || customer.email}`);
382
+ console.log(`Total orders: ${customer.totalOrders}`);
383
+ console.log(`Total spent: $${customer.totalSpent}`);
384
+ console.log(`Average order: $${customer.averageOrderValue}`);
385
+ console.log(`Last order: ${customer.lastOrderDate}`);
386
+ });
387
+
388
+ // Send message to customer
389
+ await client.sendMessage({
390
+ orderId: "ord_123",
391
+ recipientId: "user_456",
392
+ message: "Your order has been shipped! Tracking: 1Z999AA10123456784",
393
+ });
394
+
395
+ // List messages
396
+ const messages = await client.listMessages();
397
+ console.log(`Total conversations: ${messages.stats.total}`);
398
+ console.log(`Unread: ${messages.stats.unread}`);
399
+
400
+ messages.conversations.forEach(conv => {
401
+ console.log(`Order #${conv.orderNumber} - ${conv.customer.name}`);
402
+ console.log(`Last: ${conv.lastMessage.message}`);
403
+ console.log(`Unread: ${conv.unreadCount}`);
404
+ });
405
+
406
+ // Mark message as read
407
+ await client.markMessageRead("msg_123");
408
+ ```
409
+
410
+ ### Analytics
411
+
412
+ ```typescript
413
+ // Get analytics dashboard
414
+ const analytics = await client.getAnalytics({ range: "30days" });
415
+
416
+ // Overview stats
417
+ console.log("Total Revenue:", analytics.overview.totalRevenue);
418
+ console.log("Revenue Change:", analytics.overview.revenueChange, "%");
419
+ console.log("Total Orders:", analytics.overview.totalOrders);
420
+ console.log("Orders Change:", analytics.overview.ordersChange, "%");
421
+ console.log("Average Order Value:", analytics.overview.averageOrderValue);
422
+ console.log("Total Customers:", analytics.overview.totalCustomers);
423
+
424
+ // Revenue by day
425
+ analytics.revenueByDay.forEach(day => {
426
+ console.log(`${day.date}: $${day.revenue} (${day.orders} orders)`);
427
+ });
428
+
429
+ // Top products
430
+ analytics.topProducts.forEach((product, index) => {
431
+ console.log(`${index + 1}. ${product.name}`);
432
+ console.log(` Sold: ${product.soldCount}, Revenue: $${product.revenue}`);
433
+ });
434
+
435
+ // Orders by status
436
+ analytics.ordersByStatus.forEach(status => {
437
+ console.log(`${status.status}: ${status.count} (${status.percentage}%)`);
438
+ });
439
+
440
+ // Recent orders
441
+ analytics.recentOrders.forEach(order => {
442
+ console.log(`#${order.orderNumber} - $${order.totalAmount} - ${order.status}`);
443
+ });
444
+ ```
445
+
446
+ ### Tax Management
447
+
448
+ ```typescript
449
+ // Get tax settings
450
+ const settings = await client.getTaxSettings();
451
+ console.log("Tax enabled:", settings.settings.taxEnabled);
452
+
453
+ // Update tax settings
454
+ await client.updateTaxSettings({
455
+ taxEnabled: true,
456
+ pricesIncludeTax: false,
457
+ defaultTaxBehavior: "CHARGE",
458
+ taxRegistrationNumber: "123456789",
459
+ registrationCountry: "US",
460
+ });
461
+
462
+ // Create tax rule
463
+ await client.createTaxRule({
464
+ country: "US",
465
+ region: "NY",
466
+ taxType: "SALES_TAX",
467
+ taxName: "NY Sales Tax",
468
+ taxRate: 8.875,
469
+ priority: 1,
470
+ });
471
+
472
+ // Add tax nexus location
473
+ await client.createTaxNexus({
474
+ country: "US",
475
+ region: "CA",
476
+ registrationId: "987654321",
477
+ });
478
+
479
+ // Generate tax report
480
+ const report = await client.generateTaxReport({
481
+ periodType: "MONTHLY",
482
+ year: 2025,
483
+ period: 1, // January
484
+ });
485
+
486
+ // Get tax report details
487
+ const reportDetails = await client.getTaxReport("report_123");
488
+ console.log("Total taxable:", reportDetails.report.totalTaxable);
489
+ console.log("Total tax:", reportDetails.report.totalTax);
490
+
491
+ reportDetails.details.forEach(detail => {
492
+ console.log(`Order ${detail.orderId}: $${detail.taxAmount}`);
493
+ });
494
+
495
+ // Export tax report as CSV
496
+ const csv = await client.exportTaxReport("report_123");
497
+ // Save or download CSV
498
+ ```
499
+
500
+ ## React Native Examples
501
+
502
+ ```typescript
503
+ import { CustomerEcommerceClient } from "@basedone/core/ecommerce";
504
+ import AsyncStorage from "@react-native-async-storage/async-storage";
505
+ import { useEffect, useState } from "react";
506
+
507
+ // Create client with stored auth token
508
+ const createClient = async () => {
509
+ const authToken = await AsyncStorage.getItem("authToken");
510
+ return new CustomerEcommerceClient({
511
+ baseURL: "https://api.basedone.com",
512
+ authToken: authToken || undefined,
513
+ });
514
+ };
515
+
516
+ // Product list component
517
+ function ProductList() {
518
+ const [products, setProducts] = useState([]);
519
+ const [loading, setLoading] = useState(true);
520
+
521
+ useEffect(() => {
522
+ const loadProducts = async () => {
523
+ try {
524
+ const client = await createClient();
525
+ const result = await client.listProducts({ limit: 20 });
526
+ setProducts(result.items);
527
+ } catch (error) {
528
+ console.error("Failed to load products:", error);
529
+ } finally {
530
+ setLoading(false);
531
+ }
532
+ };
533
+
534
+ loadProducts();
535
+ }, []);
536
+
537
+ if (loading) {
538
+ return <ActivityIndicator />;
539
+ }
540
+
541
+ return (
542
+ <FlatList
543
+ data={products}
544
+ renderItem={({ item }) => (
545
+ <ProductCard product={item} />
546
+ )}
547
+ keyExtractor={(item) => item.id}
548
+ />
549
+ );
550
+ }
551
+
552
+ // Checkout component
553
+ function Checkout({ cartItems, shippingAddress }) {
554
+ const [loading, setLoading] = useState(false);
555
+
556
+ const handleCheckout = async () => {
557
+ setLoading(true);
558
+ try {
559
+ const client = await createClient();
560
+
561
+ const order = await client.createOrder({
562
+ items: cartItems,
563
+ paymentMethod: "USDC_ESCROW",
564
+ shippingAddress,
565
+ });
566
+
567
+ if (order.escrow) {
568
+ // Navigate to payment screen with escrow details
569
+ navigation.navigate("Payment", {
570
+ address: order.escrow.address,
571
+ amount: order.escrow.amountUSDC,
572
+ orderId: order.orders[0].id,
573
+ });
574
+ }
575
+ } catch (error) {
576
+ Alert.alert("Error", error.message);
577
+ } finally {
578
+ setLoading(false);
579
+ }
580
+ };
581
+
582
+ return (
583
+ <Button
584
+ title="Place Order"
585
+ onPress={handleCheckout}
586
+ disabled={loading}
587
+ />
588
+ );
589
+ }
590
+ ```
591
+
592
+ ## Error Handling
593
+
594
+ ```typescript
595
+ import { EcommerceApiError } from "@basedone/core/ecommerce";
596
+
597
+ try {
598
+ const products = await client.listProducts();
599
+ } catch (error) {
600
+ if (error instanceof EcommerceApiError) {
601
+ console.error("API Error:", error.message);
602
+ console.error("Status Code:", error.statusCode);
603
+
604
+ if (error.isAuthError) {
605
+ // Handle authentication error (401/403)
606
+ console.log("Please log in again");
607
+ // Redirect to login
608
+ } else if (error.isNetworkError) {
609
+ // Handle network error
610
+ console.log("Check your internet connection");
611
+ // Show retry button
612
+ } else if (error.isTimeoutError) {
613
+ // Handle timeout
614
+ console.log("Request timed out, please try again");
615
+ // Show retry button
616
+ } else if (error.statusCode === 400) {
617
+ // Handle validation error
618
+ console.log("Invalid request:", error.data);
619
+ } else if (error.statusCode === 404) {
620
+ // Handle not found
621
+ console.log("Resource not found");
622
+ } else if (error.statusCode && error.statusCode >= 500) {
623
+ // Handle server error
624
+ console.log("Server error, please try again later");
625
+ }
626
+ } else {
627
+ // Handle unexpected error
628
+ console.error("Unexpected error:", error);
629
+ }
630
+ }
631
+
632
+ // Automatic retry is enabled by default
633
+ // Disable it if needed:
634
+ const client = new CustomerEcommerceClient({
635
+ baseURL: "https://api.basedone.com",
636
+ enableRetry: false,
637
+ });
638
+
639
+ // Custom retry configuration
640
+ const client = new CustomerEcommerceClient({
641
+ baseURL: "https://api.basedone.com",
642
+ maxRetries: 5,
643
+ retryBaseDelay: 2000, // 2 seconds
644
+ });
645
+ ```
646
+
647
+ ## Advanced Usage
648
+
649
+ ### Custom Headers
650
+
651
+ ```typescript
652
+ const client = new CustomerEcommerceClient({
653
+ baseURL: "https://api.basedone.com",
654
+ headers: {
655
+ "X-Custom-Header": "value",
656
+ "X-App-Version": "1.0.0",
657
+ },
658
+ });
659
+ ```
660
+
661
+ ### Dynamic Auth Token
662
+
663
+ ```typescript
664
+ const client = new CustomerEcommerceClient({
665
+ baseURL: "https://api.basedone.com",
666
+ });
667
+
668
+ // Set token later
669
+ client.setAuthToken("new-token");
670
+
671
+ // Clear token
672
+ client.clearAuthToken();
673
+ ```
674
+
675
+ ### Access Underlying Axios Instance
676
+
677
+ ```typescript
678
+ const axios = client.getAxiosInstance();
679
+
680
+ // Add custom interceptor
681
+ axios.interceptors.request.use((config) => {
682
+ console.log("Request:", config.url);
683
+ return config;
684
+ });
685
+ ```
686
+
687
+ ## Best Practices
688
+
689
+ 1. **Reuse client instances** - Create one client per auth context and reuse it
690
+ 2. **Handle errors gracefully** - Always wrap API calls in try-catch
691
+ 3. **Use TypeScript** - Take advantage of full type safety
692
+ 4. **Store auth tokens securely** - Use secure storage (AsyncStorage, Keychain)
693
+ 5. **Implement loading states** - Show loading indicators during API calls
694
+ 6. **Cache data when appropriate** - Reduce API calls with local caching
695
+ 7. **Test error scenarios** - Handle network failures, timeouts, etc.
696
+ 8. **Monitor API usage** - Track API calls and performance
697
+
698
+ ## Support
699
+
700
+ For issues or questions:
701
+ - GitHub Issues: [github.com/basedone/issues](https://github.com/basedone/issues)
702
+ - Documentation: [docs.basedone.com](https://docs.basedone.com)
703
+ - Email: support@basedone.com
704
+