@basedone/core 0.1.8 → 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/chunk-4GAKANLT.mjs +1987 -0
- package/dist/chunk-4UEJOM6W.mjs +1 -3
- package/dist/chunk-VBC6EQ7Q.mjs +235 -0
- package/dist/client-CgmiTuEX.d.mts +179 -0
- package/dist/client-CgmiTuEX.d.ts +179 -0
- package/dist/ecommerce.d.mts +3732 -0
- package/dist/ecommerce.d.ts +3732 -0
- package/dist/ecommerce.js +2031 -0
- package/dist/ecommerce.mjs +2 -0
- package/dist/index.d.mts +79 -4
- package/dist/index.d.ts +79 -4
- package/dist/index.js +3674 -331
- package/dist/index.mjs +107 -104
- package/dist/{meta-57AY44US.mjs → meta-JB5ITE27.mjs} +6 -14
- package/dist/{meta-RSZFFH63.mjs → meta-UOGUG3OW.mjs} +5 -11
- package/dist/{perpDexs-PBKWKKQU.mjs → perpDexs-3LRJ5ZHM.mjs} +100 -13
- package/dist/{perpDexs-XSB4Y2BP.mjs → perpDexs-4ISLD7NX.mjs} +798 -121
- package/dist/react.d.mts +39 -0
- package/dist/react.d.ts +39 -0
- package/dist/react.js +268 -0
- package/dist/react.mjs +31 -0
- package/dist/{spotMeta-WQ4PXRNY.mjs → spotMeta-GHXX7C5M.mjs} +85 -14
- package/dist/{spotMeta-Y7G2GI7B.mjs → spotMeta-IBBUP2SG.mjs} +249 -12
- package/dist/staticMeta-GM7T3OYL.mjs +3 -6
- package/dist/staticMeta-QV2KMX57.mjs +3 -6
- package/ecommerce.ts +15 -0
- package/index.ts +7 -0
- package/lib/cloid/cloid.ts +2 -0
- package/lib/ecommerce/QUICK_REFERENCE.md +211 -0
- package/lib/ecommerce/README.md +385 -0
- package/lib/ecommerce/USAGE_EXAMPLES.md +704 -0
- package/lib/ecommerce/client/base.ts +272 -0
- package/lib/ecommerce/client/customer.ts +522 -0
- package/lib/ecommerce/client/merchant.ts +1341 -0
- package/lib/ecommerce/index.ts +51 -0
- package/lib/ecommerce/types/entities.ts +722 -0
- package/lib/ecommerce/types/enums.ts +270 -0
- package/lib/ecommerce/types/index.ts +18 -0
- package/lib/ecommerce/types/requests.ts +525 -0
- package/lib/ecommerce/types/responses.ts +805 -0
- package/lib/ecommerce/utils/errors.ts +113 -0
- package/lib/ecommerce/utils/helpers.ts +131 -0
- package/lib/fee.ts +10 -10
- package/lib/hip3/market-info.ts +36 -8
- package/lib/hip3/utils.ts +15 -2
- package/lib/instrument/client.ts +351 -0
- package/lib/meta/data/mainnet/meta.json +2 -4
- package/lib/meta/data/mainnet/perpDexs.json +97 -9
- package/lib/meta/data/mainnet/spotMeta.json +82 -8
- package/lib/meta/data/testnet/meta.json +3 -7
- package/lib/meta/data/testnet/perpDexs.json +795 -117
- package/lib/meta/data/testnet/spotMeta.json +246 -6
- package/lib/meta/metadata.ts +8 -1
- package/lib/meta/types.ts +36 -0
- package/lib/react/InstrumentProvider.tsx +69 -0
- package/lib/utils/flooredDateTime.ts +55 -0
- package/lib/utils/time.ts +51 -0
- package/package.json +37 -11
- package/react.ts +1 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
# Ecommerce SDK
|
|
2
|
+
|
|
3
|
+
A comprehensive TypeScript SDK for the Based One marketplace/ecommerce API, designed for use in mobile apps (React Native) and web applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Full TypeScript support** with extensive type definitions
|
|
8
|
+
- ✅ **Customer & Merchant APIs** - Complete coverage of all endpoints
|
|
9
|
+
- ✅ **Authentication** - Built-in Bearer token authentication
|
|
10
|
+
- ✅ **Error handling** - Comprehensive error types and retry logic
|
|
11
|
+
- ✅ **Automatic retries** - Exponential backoff for failed requests
|
|
12
|
+
- ✅ **JSDoc documentation** - IntelliSense support in your IDE
|
|
13
|
+
- ✅ **Mobile-friendly** - Works with React Native and Expo
|
|
14
|
+
- ✅ **Multi-merchant support** - Automatic order splitting for multi-merchant carts
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @basedone/core
|
|
20
|
+
# or
|
|
21
|
+
pnpm add @basedone/core
|
|
22
|
+
# or
|
|
23
|
+
yarn add @basedone/core
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Customer/End-User Client
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { CustomerEcommerceClient } from "@basedone/core/ecommerce";
|
|
32
|
+
|
|
33
|
+
const client = new CustomerEcommerceClient({
|
|
34
|
+
baseURL: "https://api.basedone.com",
|
|
35
|
+
authToken: "your-user-auth-token",
|
|
36
|
+
timeout: 30000,
|
|
37
|
+
maxRetries: 3,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Browse products
|
|
41
|
+
const products = await client.listProducts({
|
|
42
|
+
limit: 20,
|
|
43
|
+
category: "electronics",
|
|
44
|
+
sortBy: "price_asc",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Place an order
|
|
48
|
+
const order = await client.createOrder({
|
|
49
|
+
items: [
|
|
50
|
+
{ productId: "prod_123", quantity: 2 },
|
|
51
|
+
{ productId: "prod_456", quantity: 1 },
|
|
52
|
+
],
|
|
53
|
+
paymentMethod: "USDC_ESCROW",
|
|
54
|
+
shippingAddress: {
|
|
55
|
+
fullName: "John Doe",
|
|
56
|
+
phone: "+1234567890",
|
|
57
|
+
addressLine1: "123 Main St",
|
|
58
|
+
city: "New York",
|
|
59
|
+
stateProvince: "NY",
|
|
60
|
+
postalCode: "10001",
|
|
61
|
+
country: "US",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// For USDC escrow payment
|
|
66
|
+
if (order.escrow) {
|
|
67
|
+
console.log(`Deposit ${order.escrow.amountUSDC} USDC to ${order.escrow.address}`);
|
|
68
|
+
// After depositing, confirm the transaction
|
|
69
|
+
await client.confirmEscrowDeposit(order.orders[0].id);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Merchant Client
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { MerchantEcommerceClient } from "@basedone/core/ecommerce";
|
|
77
|
+
|
|
78
|
+
const client = new MerchantEcommerceClient({
|
|
79
|
+
baseURL: "https://api.basedone.com",
|
|
80
|
+
authToken: "your-merchant-auth-token",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Create a product
|
|
84
|
+
const product = await client.createProduct({
|
|
85
|
+
title: "Awesome Product",
|
|
86
|
+
images: ["https://..."],
|
|
87
|
+
priceUSDC: 49.99,
|
|
88
|
+
inventory: 100,
|
|
89
|
+
category: "electronics",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Get analytics
|
|
93
|
+
const analytics = await client.getAnalytics({ range: "30days" });
|
|
94
|
+
console.log("Revenue:", analytics.overview.totalRevenue);
|
|
95
|
+
console.log("Orders:", analytics.overview.totalOrders);
|
|
96
|
+
|
|
97
|
+
// Fulfill an order
|
|
98
|
+
await client.updateOrderStatus("ord_123", {
|
|
99
|
+
status: "SHIPPED",
|
|
100
|
+
tracking: {
|
|
101
|
+
trackingNumber: "1Z999AA10123456784",
|
|
102
|
+
carrier: "UPS",
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## API Reference
|
|
108
|
+
|
|
109
|
+
### Customer APIs
|
|
110
|
+
|
|
111
|
+
#### Products
|
|
112
|
+
- `listProducts(params?)` - List products with filtering and pagination
|
|
113
|
+
- `getProduct(productId)` - Get product details
|
|
114
|
+
- `trackProductView(productId)` - Track product view
|
|
115
|
+
- `getProductDiscounts(productId)` - Get active discounts for a product
|
|
116
|
+
|
|
117
|
+
#### Orders
|
|
118
|
+
- `createOrder(request)` - Create order from cart (supports multi-merchant)
|
|
119
|
+
- `listOrders(params?)` - List user's orders
|
|
120
|
+
- `getOrder(orderId)` - Get order details
|
|
121
|
+
- `confirmEscrowDeposit(orderId)` - Confirm USDC escrow payment
|
|
122
|
+
- `getOrderReceipt(orderId)` - Get order receipt
|
|
123
|
+
|
|
124
|
+
#### Reviews
|
|
125
|
+
- `listProductReviews(productId, params?)` - List product reviews
|
|
126
|
+
- `createReview(productId, request)` - Create a review
|
|
127
|
+
|
|
128
|
+
#### Shipping Addresses
|
|
129
|
+
- `listShippingAddresses()` - List saved addresses
|
|
130
|
+
- `createShippingAddress(request)` - Add new address
|
|
131
|
+
- `updateShippingAddress(addressId, request)` - Update address
|
|
132
|
+
- `deleteShippingAddress(addressId)` - Delete address
|
|
133
|
+
|
|
134
|
+
#### Cart & Discounts
|
|
135
|
+
- `calculateCartDiscounts(request)` - Calculate automatic discounts
|
|
136
|
+
- `validateDiscountCode(request)` - Validate coupon code
|
|
137
|
+
|
|
138
|
+
#### Tax
|
|
139
|
+
- `calculateTax(request)` - Calculate tax for cart
|
|
140
|
+
|
|
141
|
+
#### Banners
|
|
142
|
+
- `getActiveBanners(params?)` - Get active promotional banners
|
|
143
|
+
- `trackBanner(bannerId, request)` - Track banner impression/click
|
|
144
|
+
|
|
145
|
+
### Merchant APIs
|
|
146
|
+
|
|
147
|
+
#### Profile
|
|
148
|
+
- `getMerchantProfile()` - Get merchant profile
|
|
149
|
+
- `upsertMerchantProfile(request)` - Create/update profile
|
|
150
|
+
|
|
151
|
+
#### Products
|
|
152
|
+
- `listMerchantProducts(params?)` - List merchant's products
|
|
153
|
+
- `createProduct(request)` - Create product
|
|
154
|
+
- `updateProduct(productId, request)` - Update product
|
|
155
|
+
- `deleteProduct(productId)` - Delete product
|
|
156
|
+
- `setProductFeatured(productId, featured)` - Toggle featured status
|
|
157
|
+
- `getProductMetrics()` - Get product performance metrics
|
|
158
|
+
|
|
159
|
+
#### Product Variants
|
|
160
|
+
- `listProductVariants(productId)` - List variants
|
|
161
|
+
- `createProductVariant(productId, request)` - Create variant
|
|
162
|
+
- `getProductVariant(productId, variantId)` - Get variant
|
|
163
|
+
- `updateProductVariant(productId, variantId, request)` - Update variant
|
|
164
|
+
- `deleteProductVariant(productId, variantId)` - Delete variant
|
|
165
|
+
|
|
166
|
+
#### Orders
|
|
167
|
+
- `listMerchantOrders(params?)` - List merchant's orders
|
|
168
|
+
- `getMerchantOrder(orderId)` - Get order details
|
|
169
|
+
- `updateOrderStatus(orderId, request)` - Update order status
|
|
170
|
+
- `createOrderEvent(orderId, request)` - Create custom order event
|
|
171
|
+
|
|
172
|
+
#### Customers
|
|
173
|
+
- `listCustomers(params?)` - List customers with stats
|
|
174
|
+
|
|
175
|
+
#### Coupons
|
|
176
|
+
- `listCoupons()` - List coupons
|
|
177
|
+
- `createCoupon(request)` - Create coupon
|
|
178
|
+
- `getCoupon(couponId)` - Get coupon with usage history
|
|
179
|
+
- `updateCoupon(couponId, request)` - Update coupon
|
|
180
|
+
- `deleteCoupon(couponId)` - Delete coupon
|
|
181
|
+
|
|
182
|
+
#### Shipping
|
|
183
|
+
- `listShippingMethods()` - List shipping methods
|
|
184
|
+
- `createShippingMethod(request)` - Create method
|
|
185
|
+
- `updateShippingMethod(methodId, request)` - Update method
|
|
186
|
+
- `deleteShippingMethod(methodId)` - Delete method
|
|
187
|
+
- `listShipments()` - List shipments
|
|
188
|
+
- `updateShipment(shipmentId, request)` - Update shipment
|
|
189
|
+
|
|
190
|
+
#### Returns
|
|
191
|
+
- `listReturns()` - List returns
|
|
192
|
+
- `approveReturn(returnId)` - Approve return
|
|
193
|
+
- `rejectReturn(returnId)` - Reject return
|
|
194
|
+
- `markReturnReceived(returnId)` - Mark as received
|
|
195
|
+
- `processRefund(returnId)` - Process refund
|
|
196
|
+
|
|
197
|
+
#### Reviews
|
|
198
|
+
- `listMerchantReviews()` - List reviews
|
|
199
|
+
- `respondToReview(reviewId, request)` - Respond to review
|
|
200
|
+
- `flagReview(reviewId)` - Flag inappropriate review
|
|
201
|
+
|
|
202
|
+
#### Messages
|
|
203
|
+
- `listMessages()` - List conversations
|
|
204
|
+
- `sendMessage(request)` - Send message to customer
|
|
205
|
+
- `markMessageRead(messageId)` - Mark as read
|
|
206
|
+
|
|
207
|
+
#### Media
|
|
208
|
+
- `listMediaAssets(params?)` - List media library
|
|
209
|
+
- `uploadMediaAsset(formData)` - Upload image
|
|
210
|
+
- `deleteMediaAsset(assetId)` - Delete asset
|
|
211
|
+
|
|
212
|
+
#### Banners
|
|
213
|
+
- `listMerchantBanners()` - List banners
|
|
214
|
+
- `createBanner(request)` - Create banner
|
|
215
|
+
- `getBanner(bannerId)` - Get banner
|
|
216
|
+
- `updateBanner(bannerId, request)` - Update banner
|
|
217
|
+
- `deleteBanner(bannerId)` - Delete banner
|
|
218
|
+
|
|
219
|
+
#### Analytics
|
|
220
|
+
- `getAnalytics(params?)` - Get merchant analytics
|
|
221
|
+
|
|
222
|
+
#### Inventory
|
|
223
|
+
- `getInventoryAudit()` - Get inventory audit log
|
|
224
|
+
|
|
225
|
+
#### Tax Management
|
|
226
|
+
- `getTaxSettings()` - Get tax settings
|
|
227
|
+
- `updateTaxSettings(request)` - Update settings
|
|
228
|
+
- `listTaxRules()` - List tax rules
|
|
229
|
+
- `createTaxRule(request)` - Create rule
|
|
230
|
+
- `getTaxRule(ruleId)` - Get rule
|
|
231
|
+
- `updateTaxRule(ruleId, request)` - Update rule
|
|
232
|
+
- `deleteTaxRule(ruleId)` - Delete rule
|
|
233
|
+
- `listTaxNexus()` - List nexus locations
|
|
234
|
+
- `createTaxNexus(request)` - Add nexus
|
|
235
|
+
- `updateTaxNexus(nexusId, request)` - Update nexus
|
|
236
|
+
- `deleteTaxNexus(nexusId)` - Delete nexus
|
|
237
|
+
- `listTaxReports(params?)` - List tax reports
|
|
238
|
+
- `generateTaxReport(request)` - Generate report
|
|
239
|
+
- `getTaxReport(reportId)` - Get report details
|
|
240
|
+
- `updateTaxReportStatus(reportId, request)` - Update status
|
|
241
|
+
- `exportTaxReport(reportId)` - Export as CSV
|
|
242
|
+
|
|
243
|
+
## Configuration
|
|
244
|
+
|
|
245
|
+
### Client Options
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
interface EcommerceClientConfig {
|
|
249
|
+
/** Base API URL */
|
|
250
|
+
baseURL: string;
|
|
251
|
+
|
|
252
|
+
/** Authentication token (Bearer token) */
|
|
253
|
+
authToken?: string;
|
|
254
|
+
|
|
255
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
256
|
+
timeout?: number;
|
|
257
|
+
|
|
258
|
+
/** Maximum number of retries for failed requests (default: 3) */
|
|
259
|
+
maxRetries?: number;
|
|
260
|
+
|
|
261
|
+
/** Base delay for exponential backoff in ms (default: 1000) */
|
|
262
|
+
retryBaseDelay?: number;
|
|
263
|
+
|
|
264
|
+
/** Custom headers */
|
|
265
|
+
headers?: Record<string, string>;
|
|
266
|
+
|
|
267
|
+
/** Enable automatic retry on retryable errors (default: true) */
|
|
268
|
+
enableRetry?: boolean;
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Authentication
|
|
273
|
+
|
|
274
|
+
Update the auth token dynamically:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
// Set token
|
|
278
|
+
client.setAuthToken("new-token");
|
|
279
|
+
|
|
280
|
+
// Clear token
|
|
281
|
+
client.clearAuthToken();
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Error Handling
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
import { EcommerceApiError } from "@basedone/core/ecommerce";
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
const products = await client.listProducts();
|
|
291
|
+
} catch (error) {
|
|
292
|
+
if (error instanceof EcommerceApiError) {
|
|
293
|
+
console.error("Status:", error.statusCode);
|
|
294
|
+
console.error("Message:", error.message);
|
|
295
|
+
|
|
296
|
+
if (error.isAuthError) {
|
|
297
|
+
// Handle authentication error (401/403)
|
|
298
|
+
console.log("Please log in again");
|
|
299
|
+
} else if (error.isNetworkError) {
|
|
300
|
+
// Handle network error
|
|
301
|
+
console.log("Check your internet connection");
|
|
302
|
+
} else if (error.isTimeoutError) {
|
|
303
|
+
// Handle timeout
|
|
304
|
+
console.log("Request timed out");
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## TypeScript Types
|
|
311
|
+
|
|
312
|
+
All types are fully documented and exported:
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
import type {
|
|
316
|
+
Product,
|
|
317
|
+
Order,
|
|
318
|
+
OrderStatus,
|
|
319
|
+
PaymentMethod,
|
|
320
|
+
CreateOrderRequest,
|
|
321
|
+
ListProductsParams,
|
|
322
|
+
// ... and many more
|
|
323
|
+
} from "@basedone/core/ecommerce";
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## React Native / Expo
|
|
327
|
+
|
|
328
|
+
The SDK works seamlessly with React Native and Expo:
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
import { CustomerEcommerceClient } from "@basedone/core/ecommerce";
|
|
332
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
333
|
+
|
|
334
|
+
// Store auth token
|
|
335
|
+
const authToken = await AsyncStorage.getItem("authToken");
|
|
336
|
+
|
|
337
|
+
const client = new CustomerEcommerceClient({
|
|
338
|
+
baseURL: "https://api.basedone.com",
|
|
339
|
+
authToken,
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// Use in your components
|
|
343
|
+
const [products, setProducts] = useState([]);
|
|
344
|
+
|
|
345
|
+
useEffect(() => {
|
|
346
|
+
client.listProducts({ limit: 20 }).then(setProducts);
|
|
347
|
+
}, []);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Advanced Usage
|
|
351
|
+
|
|
352
|
+
### Custom Axios Configuration
|
|
353
|
+
|
|
354
|
+
Access the underlying axios instance for advanced use cases:
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
const axios = client.getAxiosInstance();
|
|
358
|
+
axios.interceptors.request.use(/* custom interceptor */);
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Retry Logic
|
|
362
|
+
|
|
363
|
+
The SDK automatically retries failed requests with exponential backoff for:
|
|
364
|
+
- Network errors
|
|
365
|
+
- Timeout errors
|
|
366
|
+
- 5xx server errors
|
|
367
|
+
- 429 rate limit errors
|
|
368
|
+
|
|
369
|
+
You can disable retry:
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
const client = new CustomerEcommerceClient({
|
|
373
|
+
baseURL: "https://api.basedone.com",
|
|
374
|
+
enableRetry: false,
|
|
375
|
+
});
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## Support
|
|
379
|
+
|
|
380
|
+
For issues or questions, please open an issue on GitHub or contact support.
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
ISC
|
|
385
|
+
|