@basedone/core 0.1.10 → 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.
Files changed (53) hide show
  1. package/dist/chunk-4GAKANLT.mjs +1987 -0
  2. package/dist/chunk-4UEJOM6W.mjs +1 -3
  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 +3732 -0
  7. package/dist/ecommerce.d.ts +3732 -0
  8. package/dist/ecommerce.js +2031 -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 +2691 -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/QUICK_REFERENCE.md +211 -0
  29. package/lib/ecommerce/README.md +385 -0
  30. package/lib/ecommerce/USAGE_EXAMPLES.md +704 -0
  31. package/lib/ecommerce/client/base.ts +272 -0
  32. package/lib/ecommerce/client/customer.ts +522 -0
  33. package/lib/ecommerce/client/merchant.ts +1341 -0
  34. package/lib/ecommerce/index.ts +51 -0
  35. package/lib/ecommerce/types/entities.ts +722 -0
  36. package/lib/ecommerce/types/enums.ts +270 -0
  37. package/lib/ecommerce/types/index.ts +18 -0
  38. package/lib/ecommerce/types/requests.ts +525 -0
  39. package/lib/ecommerce/types/responses.ts +805 -0
  40. package/lib/ecommerce/utils/errors.ts +113 -0
  41. package/lib/ecommerce/utils/helpers.ts +131 -0
  42. package/lib/hip3/market-info.ts +1 -1
  43. package/lib/instrument/client.ts +351 -0
  44. package/lib/meta/data/mainnet/perpDexs.json +34 -4
  45. package/lib/meta/data/mainnet/spotMeta.json +21 -3
  46. package/lib/meta/data/testnet/meta.json +1 -3
  47. package/lib/meta/data/testnet/perpDexs.json +174 -28
  48. package/lib/meta/data/testnet/spotMeta.json +51 -0
  49. package/lib/react/InstrumentProvider.tsx +69 -0
  50. package/lib/utils/flooredDateTime.ts +55 -0
  51. package/lib/utils/time.ts +51 -0
  52. package/package.json +37 -11
  53. package/react.ts +1 -0
@@ -0,0 +1,1341 @@
1
+ /**
2
+ * Merchant Ecommerce API Client
3
+ *
4
+ * This module provides methods for merchant operations including product management,
5
+ * order fulfillment, customer management, analytics, and more.
6
+ */
7
+
8
+ import { BaseEcommerceClient } from "./base";
9
+ import { buildQueryString } from "../utils/helpers";
10
+ import type {
11
+ // Request types
12
+ MerchantProfileRequest,
13
+ CreateProductRequest,
14
+ UpdateProductRequest,
15
+ CreateProductVariantRequest,
16
+ UpdateProductVariantRequest,
17
+ ListOrdersParams,
18
+ UpdateOrderStatusRequest,
19
+ CreateOrderEventRequest,
20
+ ListCustomersParams,
21
+ CreateCouponRequest,
22
+ UpdateCouponRequest,
23
+ CreateShippingMethodRequest,
24
+ UpdateShippingMethodRequest,
25
+ UpdateShipmentRequest,
26
+ CreateBannerRequest,
27
+ UpdateBannerRequest,
28
+ SendMessageRequest,
29
+ UpdateTaxSettingsRequest,
30
+ CreateTaxRuleRequest,
31
+ UpdateTaxRuleRequest,
32
+ CreateTaxNexusRequest,
33
+ UpdateTaxNexusRequest,
34
+ GenerateTaxReportRequest,
35
+ UpdateTaxReportStatusRequest,
36
+ ListTaxReportsParams,
37
+ GetAnalyticsParams,
38
+ RespondToReviewRequest,
39
+ PaginationParams,
40
+
41
+ // Response types
42
+ MerchantProfileResponse,
43
+ ListProductsResponse,
44
+ ProductResponse,
45
+ GetProductResponse,
46
+ ListProductVariantsResponse,
47
+ ProductVariantResponse,
48
+ ListOrdersResponse,
49
+ GetOrderResponse,
50
+ UpdateOrderResponse,
51
+ CreateOrderEventResponse,
52
+ ListCustomersResponse,
53
+ ListCouponsResponse,
54
+ CouponResponse,
55
+ GetCouponResponse,
56
+ ListShippingMethodsResponse,
57
+ ShippingMethodResponse,
58
+ ListShipmentsResponse,
59
+ ShipmentResponse,
60
+ ListReturnsResponse,
61
+ ReturnResponse,
62
+ ListReviewsResponse,
63
+ ReviewResponse,
64
+ ListBannersResponse,
65
+ BannerResponse,
66
+ ListMediaAssetsResponse,
67
+ MediaAssetResponse,
68
+ ListMessagesResponse,
69
+ MessageResponse,
70
+ GetAnalyticsResponse,
71
+ GetProductMetricsResponse,
72
+ ListInventoryAuditResponse,
73
+ TaxSettingsResponse,
74
+ ListTaxRulesResponse,
75
+ TaxRuleResponse,
76
+ ListTaxNexusResponse,
77
+ TaxNexusResponse,
78
+ ListTaxReportsResponse,
79
+ GetTaxReportResponse,
80
+ TaxReportResponse,
81
+ SuccessResponse,
82
+ } from "../types";
83
+
84
+ /**
85
+ * Merchant API client for merchant operations
86
+ *
87
+ * Provides comprehensive methods for managing products, orders, customers,
88
+ * shipping, returns, reviews, analytics, and more.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const client = new MerchantEcommerceClient({
93
+ * baseURL: "https://api.example.com",
94
+ * authToken: "merchant-auth-token"
95
+ * });
96
+ *
97
+ * // Create a product
98
+ * const product = await client.createProduct({
99
+ * title: "New Product",
100
+ * images: ["https://..."],
101
+ * priceUSDC: 99.99,
102
+ * inventory: 100
103
+ * });
104
+ *
105
+ * // Get analytics
106
+ * const analytics = await client.getAnalytics({ range: "30days" });
107
+ * ```
108
+ */
109
+ export class MerchantEcommerceClient extends BaseEcommerceClient {
110
+
111
+ // ============================================================================
112
+ // Profile Management
113
+ // ============================================================================
114
+
115
+ /**
116
+ * Get merchant profile
117
+ *
118
+ * @returns Merchant profile
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const profile = await client.getMerchantProfile();
123
+ * console.log(profile.merchant.name);
124
+ * ```
125
+ */
126
+ async getMerchantProfile(): Promise<MerchantProfileResponse> {
127
+ return this.get("/api/marketplace/merchant/profile");
128
+ }
129
+
130
+ /**
131
+ * Get merchant profile (alias for getMerchantProfile)
132
+ *
133
+ * @returns Merchant profile
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const profile = await client.getProfile();
138
+ * console.log(profile.merchant.name);
139
+ * ```
140
+ */
141
+ async getProfile(): Promise<MerchantProfileResponse> {
142
+ return this.getMerchantProfile();
143
+ }
144
+
145
+ /**
146
+ * Create or update merchant profile
147
+ *
148
+ * @param request - Profile data
149
+ * @returns Updated merchant profile
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const profile = await client.upsertMerchantProfile({
154
+ * name: "My Store",
155
+ * description: "We sell great products",
156
+ * payoutAddress: "0x1234..."
157
+ * });
158
+ * ```
159
+ */
160
+ async upsertMerchantProfile(request: MerchantProfileRequest): Promise<MerchantProfileResponse> {
161
+ return this.post("/api/marketplace/merchant/profile", request);
162
+ }
163
+
164
+ // ============================================================================
165
+ // Products Management
166
+ // ============================================================================
167
+
168
+ /**
169
+ * List merchant's products
170
+ *
171
+ * @param params - Query parameters
172
+ * @returns Paginated list of products
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const products = await client.listMerchantProducts({ limit: 20, offset: 0 });
177
+ * ```
178
+ */
179
+ async listMerchantProducts(params?: PaginationParams): Promise<ListProductsResponse> {
180
+ const queryString = params ? buildQueryString(params) : "";
181
+ return this.get(`/api/marketplace/merchant/products${queryString}`);
182
+ }
183
+
184
+ /**
185
+ * Get a single product by ID
186
+ *
187
+ * @param productId - Product ID
188
+ * @returns Product details
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const product = await client.getProduct("prod_123");
193
+ * console.log(product.product?.title, product.product?.priceUSDC);
194
+ * ```
195
+ */
196
+ async getProduct(productId: string): Promise<GetProductResponse> {
197
+ return this.get(`/api/marketplace/products/${productId}`);
198
+ }
199
+
200
+ /**
201
+ * Create a new product
202
+ *
203
+ * @param request - Product data
204
+ * @returns Created product
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * const product = await client.createProduct({
209
+ * title: "Awesome Product",
210
+ * images: ["https://..."],
211
+ * priceUSDC: 49.99,
212
+ * inventory: 50,
213
+ * category: "electronics",
214
+ * moq: 1
215
+ * });
216
+ * ```
217
+ */
218
+ async createProduct(request: CreateProductRequest): Promise<ProductResponse> {
219
+ return this.post("/api/marketplace/merchant/products", request);
220
+ }
221
+
222
+ /**
223
+ * Update a product
224
+ *
225
+ * @param productId - Product ID
226
+ * @param request - Updated product data
227
+ * @returns Updated product
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const product = await client.updateProduct("prod_123", {
232
+ * priceUSDC: 39.99,
233
+ * inventory: 75
234
+ * });
235
+ * ```
236
+ */
237
+ async updateProduct(productId: string, request: UpdateProductRequest): Promise<ProductResponse> {
238
+ return this.put(`/api/marketplace/products/${productId}`, request);
239
+ }
240
+
241
+ /**
242
+ * Delete a product
243
+ *
244
+ * @param productId - Product ID
245
+ * @returns Success response
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * await client.deleteProduct("prod_123");
250
+ * ```
251
+ */
252
+ async deleteProduct(productId: string): Promise<SuccessResponse> {
253
+ return this.delete(`/api/marketplace/products/${productId}`);
254
+ }
255
+
256
+ /**
257
+ * Toggle product featured status
258
+ *
259
+ * @param productId - Product ID
260
+ * @param featured - Featured status
261
+ * @returns Updated product
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * await client.setProductFeatured("prod_123", true);
266
+ * ```
267
+ */
268
+ async setProductFeatured(productId: string, featured: boolean): Promise<ProductResponse> {
269
+ return this.patch(`/api/marketplace/merchant/products/${productId}/featured`, { featured });
270
+ }
271
+
272
+ /**
273
+ * List product variants
274
+ *
275
+ * @param productId - Product ID
276
+ * @returns List of variants
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * const variants = await client.listProductVariants("prod_123");
281
+ * ```
282
+ */
283
+ async listProductVariants(productId: string): Promise<ListProductVariantsResponse> {
284
+ return this.get(`/api/marketplace/merchant/products/${productId}/variants`);
285
+ }
286
+
287
+ /**
288
+ * Create a product variant
289
+ *
290
+ * @param productId - Product ID
291
+ * @param request - Variant data
292
+ * @returns Created variant
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * const variant = await client.createProductVariant("prod_123", {
297
+ * name: "Large / Red",
298
+ * attributes: { size: "L", color: "Red" },
299
+ * priceUSDC: 54.99,
300
+ * inventory: 20
301
+ * });
302
+ * ```
303
+ */
304
+ async createProductVariant(
305
+ productId: string,
306
+ request: CreateProductVariantRequest
307
+ ): Promise<ProductVariantResponse> {
308
+ return this.post(`/api/marketplace/merchant/products/${productId}/variants`, request);
309
+ }
310
+
311
+ /**
312
+ * Get a product variant
313
+ *
314
+ * @param productId - Product ID
315
+ * @param variantId - Variant ID
316
+ * @returns Variant details
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * const variant = await client.getProductVariant("prod_123", "var_456");
321
+ * ```
322
+ */
323
+ async getProductVariant(productId: string, variantId: string): Promise<ProductVariantResponse> {
324
+ return this.get(`/api/marketplace/merchant/products/${productId}/variants/${variantId}`);
325
+ }
326
+
327
+ /**
328
+ * Update a product variant
329
+ *
330
+ * @param productId - Product ID
331
+ * @param variantId - Variant ID
332
+ * @param request - Updated variant data
333
+ * @returns Updated variant
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * const variant = await client.updateProductVariant("prod_123", "var_456", {
338
+ * inventory: 30
339
+ * });
340
+ * ```
341
+ */
342
+ async updateProductVariant(
343
+ productId: string,
344
+ variantId: string,
345
+ request: UpdateProductVariantRequest
346
+ ): Promise<ProductVariantResponse> {
347
+ return this.put(`/api/marketplace/merchant/products/${productId}/variants/${variantId}`, request);
348
+ }
349
+
350
+ /**
351
+ * Delete a product variant
352
+ *
353
+ * @param productId - Product ID
354
+ * @param variantId - Variant ID
355
+ * @returns Success response
356
+ *
357
+ * @example
358
+ * ```typescript
359
+ * await client.deleteProductVariant("prod_123", "var_456");
360
+ * ```
361
+ */
362
+ async deleteProductVariant(productId: string, variantId: string): Promise<SuccessResponse> {
363
+ return this.delete(`/api/marketplace/merchant/products/${productId}/variants/${variantId}`);
364
+ }
365
+
366
+ /**
367
+ * Get product metrics
368
+ *
369
+ * @returns Product performance metrics
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * const metrics = await client.getProductMetrics();
374
+ * console.log("Total revenue:", metrics.summary.totalRevenue);
375
+ * ```
376
+ */
377
+ async getProductMetrics(): Promise<GetProductMetricsResponse> {
378
+ return this.get("/api/marketplace/merchant/products/metrics");
379
+ }
380
+
381
+ // ============================================================================
382
+ // Orders Management
383
+ // ============================================================================
384
+
385
+ /**
386
+ * List merchant's orders
387
+ *
388
+ * @param params - Query parameters
389
+ * @returns Paginated list of orders
390
+ *
391
+ * @example
392
+ * ```typescript
393
+ * const orders = await client.listMerchantOrders({ limit: 20, offset: 0 });
394
+ * ```
395
+ */
396
+ async listMerchantOrders(params?: ListOrdersParams): Promise<ListOrdersResponse> {
397
+ const queryString = params ? buildQueryString(params) : "";
398
+ return this.get(`/api/marketplace/merchant/orders${queryString}`);
399
+ }
400
+
401
+ /**
402
+ * Get order details
403
+ *
404
+ * @param orderId - Order ID
405
+ * @returns Order details with full information
406
+ *
407
+ * @example
408
+ * ```typescript
409
+ * const order = await client.getMerchantOrder("ord_123");
410
+ * console.log(order.order.status, order.order.items);
411
+ * ```
412
+ */
413
+ async getMerchantOrder(orderId: string): Promise<GetOrderResponse> {
414
+ return this.get(`/api/marketplace/merchant/orders/${orderId}`);
415
+ }
416
+
417
+ /**
418
+ * Update order status
419
+ *
420
+ * @param orderId - Order ID
421
+ * @param request - Status update request
422
+ * @returns Updated order
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * // Accept order
427
+ * await client.updateOrderStatus("ord_123", {
428
+ * status: "MERCHANT_ACCEPTED"
429
+ * });
430
+ *
431
+ * // Mark as shipped
432
+ * await client.updateOrderStatus("ord_123", {
433
+ * status: "SHIPPED",
434
+ * tracking: {
435
+ * trackingNumber: "1Z999AA10123456784",
436
+ * carrier: "UPS"
437
+ * }
438
+ * });
439
+ * ```
440
+ */
441
+ async updateOrderStatus(
442
+ orderId: string,
443
+ request: UpdateOrderStatusRequest
444
+ ): Promise<UpdateOrderResponse> {
445
+ return this.patch(`/api/marketplace/merchant/orders/${orderId}`, request);
446
+ }
447
+
448
+ /**
449
+ * Create a custom order event
450
+ *
451
+ * @param orderId - Order ID
452
+ * @param request - Event data
453
+ * @returns Created event
454
+ *
455
+ * @example
456
+ * ```typescript
457
+ * await client.createOrderEvent("ord_123", {
458
+ * eventType: "CUSTOM",
459
+ * title: "Package delayed",
460
+ * description: "Shipment delayed due to weather"
461
+ * });
462
+ * ```
463
+ */
464
+ async createOrderEvent(
465
+ orderId: string,
466
+ request: CreateOrderEventRequest
467
+ ): Promise<CreateOrderEventResponse> {
468
+ return this.post(`/api/marketplace/merchant/orders/${orderId}/events`, request);
469
+ }
470
+
471
+ // ============================================================================
472
+ // Customers Management
473
+ // ============================================================================
474
+
475
+ /**
476
+ * List customers with order history and stats
477
+ *
478
+ * @param params - Query parameters
479
+ * @returns Paginated list of customers
480
+ *
481
+ * @example
482
+ * ```typescript
483
+ * const customers = await client.listCustomers({ limit: 50, offset: 0 });
484
+ * customers.items.forEach(c => {
485
+ * console.log(c.username, "Total spent:", c.totalSpent);
486
+ * });
487
+ * ```
488
+ */
489
+ async listCustomers(params?: ListCustomersParams): Promise<ListCustomersResponse> {
490
+ const queryString = params ? buildQueryString(params) : "";
491
+ return this.get(`/api/marketplace/merchant/customers${queryString}`);
492
+ }
493
+
494
+ // ============================================================================
495
+ // Coupons & Discounts Management
496
+ // ============================================================================
497
+
498
+ /**
499
+ * List merchant's coupons
500
+ *
501
+ * @returns List of coupons with stats
502
+ *
503
+ * @example
504
+ * ```typescript
505
+ * const result = await client.listCoupons();
506
+ * console.log("Total coupons:", result.stats.total);
507
+ * console.log("Active:", result.stats.active);
508
+ * ```
509
+ */
510
+ async listCoupons(): Promise<ListCouponsResponse> {
511
+ return this.get("/api/marketplace/merchant/coupons");
512
+ }
513
+
514
+ /**
515
+ * Create a coupon
516
+ *
517
+ * @param request - Coupon data
518
+ * @returns Created coupon
519
+ *
520
+ * @example
521
+ * ```typescript
522
+ * const coupon = await client.createCoupon({
523
+ * code: "SAVE20",
524
+ * discountType: "PERCENTAGE",
525
+ * discountValue: 20,
526
+ * startsAt: "2025-01-01T00:00:00Z",
527
+ * expiresAt: "2025-12-31T23:59:59Z",
528
+ * maxUses: 100
529
+ * });
530
+ * ```
531
+ */
532
+ async createCoupon(request: CreateCouponRequest): Promise<CouponResponse> {
533
+ return this.post("/api/marketplace/merchant/coupons", request);
534
+ }
535
+
536
+ /**
537
+ * Get coupon details with usage history
538
+ *
539
+ * @param couponId - Coupon ID
540
+ * @returns Coupon with usages
541
+ *
542
+ * @example
543
+ * ```typescript
544
+ * const coupon = await client.getCoupon("coupon_123");
545
+ * console.log("Used", coupon.coupon.usedCount, "times");
546
+ * ```
547
+ */
548
+ async getCoupon(couponId: string): Promise<GetCouponResponse> {
549
+ return this.get(`/api/marketplace/merchant/coupons/${couponId}`);
550
+ }
551
+
552
+ /**
553
+ * Update a coupon
554
+ *
555
+ * @param couponId - Coupon ID
556
+ * @param request - Updated coupon data
557
+ * @returns Updated coupon
558
+ *
559
+ * @example
560
+ * ```typescript
561
+ * await client.updateCoupon("coupon_123", {
562
+ * isActive: false
563
+ * });
564
+ * ```
565
+ */
566
+ async updateCoupon(couponId: string, request: UpdateCouponRequest): Promise<CouponResponse> {
567
+ return this.put(`/api/marketplace/merchant/coupons/${couponId}`, request);
568
+ }
569
+
570
+ /**
571
+ * Delete a coupon
572
+ *
573
+ * @param couponId - Coupon ID
574
+ * @returns Success response
575
+ *
576
+ * @example
577
+ * ```typescript
578
+ * await client.deleteCoupon("coupon_123");
579
+ * ```
580
+ */
581
+ async deleteCoupon(couponId: string): Promise<SuccessResponse> {
582
+ return this.delete(`/api/marketplace/merchant/coupons/${couponId}`);
583
+ }
584
+
585
+ // ============================================================================
586
+ // Shipping & Fulfillment
587
+ // ============================================================================
588
+
589
+ /**
590
+ * List shipping methods
591
+ *
592
+ * @returns List of shipping methods
593
+ *
594
+ * @example
595
+ * ```typescript
596
+ * const methods = await client.listShippingMethods();
597
+ * ```
598
+ */
599
+ async listShippingMethods(): Promise<ListShippingMethodsResponse> {
600
+ return this.get("/api/marketplace/merchant/shipping/methods");
601
+ }
602
+
603
+ /**
604
+ * Create a shipping method
605
+ *
606
+ * @param request - Shipping method data
607
+ * @returns Created method
608
+ *
609
+ * @example
610
+ * ```typescript
611
+ * const method = await client.createShippingMethod({
612
+ * name: "Standard Shipping",
613
+ * carrier: "USPS",
614
+ * estimatedDays: "3-5 business days",
615
+ * flatRate: 5.99
616
+ * });
617
+ * ```
618
+ */
619
+ async createShippingMethod(
620
+ request: CreateShippingMethodRequest
621
+ ): Promise<ShippingMethodResponse> {
622
+ return this.post("/api/marketplace/merchant/shipping/methods", request);
623
+ }
624
+
625
+ /**
626
+ * Update a shipping method
627
+ *
628
+ * @param methodId - Method ID
629
+ * @param request - Updated method data
630
+ * @returns Updated method
631
+ *
632
+ * @example
633
+ * ```typescript
634
+ * await client.updateShippingMethod("method_123", {
635
+ * flatRate: 6.99
636
+ * });
637
+ * ```
638
+ */
639
+ async updateShippingMethod(
640
+ methodId: string,
641
+ request: UpdateShippingMethodRequest
642
+ ): Promise<ShippingMethodResponse> {
643
+ return this.put(`/api/marketplace/merchant/shipping/methods/${methodId}`, request);
644
+ }
645
+
646
+ /**
647
+ * Delete a shipping method
648
+ *
649
+ * @param methodId - Method ID
650
+ * @returns Success response
651
+ *
652
+ * @example
653
+ * ```typescript
654
+ * await client.deleteShippingMethod("method_123");
655
+ * ```
656
+ */
657
+ async deleteShippingMethod(methodId: string): Promise<SuccessResponse> {
658
+ return this.delete(`/api/marketplace/merchant/shipping/methods/${methodId}`);
659
+ }
660
+
661
+ /**
662
+ * List shipments
663
+ *
664
+ * @returns List of shipments for merchant's orders
665
+ *
666
+ * @example
667
+ * ```typescript
668
+ * const shipments = await client.listShipments();
669
+ * ```
670
+ */
671
+ async listShipments(): Promise<ListShipmentsResponse> {
672
+ return this.get("/api/marketplace/merchant/shipping/shipments");
673
+ }
674
+
675
+ /**
676
+ * Update shipment status and tracking
677
+ *
678
+ * @param shipmentId - Shipment ID
679
+ * @param request - Updated shipment data
680
+ * @returns Updated shipment
681
+ *
682
+ * @example
683
+ * ```typescript
684
+ * await client.updateShipment("ship_123", {
685
+ * status: "SHIPPED",
686
+ * trackingNumber: "1Z999AA10123456784",
687
+ * carrier: "UPS"
688
+ * });
689
+ * ```
690
+ */
691
+ async updateShipment(shipmentId: string, request: UpdateShipmentRequest): Promise<ShipmentResponse> {
692
+ return this.patch(`/api/marketplace/merchant/shipping/shipments/${shipmentId}`, request);
693
+ }
694
+
695
+ // ============================================================================
696
+ // Returns & Refunds
697
+ // ============================================================================
698
+
699
+ /**
700
+ * List returns
701
+ *
702
+ * @returns List of returns for merchant's orders
703
+ *
704
+ * @example
705
+ * ```typescript
706
+ * const returns = await client.listReturns();
707
+ * ```
708
+ */
709
+ async listReturns(): Promise<ListReturnsResponse> {
710
+ return this.get("/api/marketplace/merchant/returns");
711
+ }
712
+
713
+ /**
714
+ * Approve a return request
715
+ *
716
+ * @param returnId - Return ID
717
+ * @returns Updated return
718
+ *
719
+ * @example
720
+ * ```typescript
721
+ * await client.approveReturn("return_123");
722
+ * ```
723
+ */
724
+ async approveReturn(returnId: string): Promise<ReturnResponse> {
725
+ return this.post(`/api/marketplace/merchant/returns/${returnId}/approve`);
726
+ }
727
+
728
+ /**
729
+ * Reject a return request
730
+ *
731
+ * @param returnId - Return ID
732
+ * @returns Updated return
733
+ *
734
+ * @example
735
+ * ```typescript
736
+ * await client.rejectReturn("return_123");
737
+ * ```
738
+ */
739
+ async rejectReturn(returnId: string): Promise<ReturnResponse> {
740
+ return this.post(`/api/marketplace/merchant/returns/${returnId}/reject`);
741
+ }
742
+
743
+ /**
744
+ * Mark return as received
745
+ *
746
+ * @param returnId - Return ID
747
+ * @returns Updated return
748
+ *
749
+ * @example
750
+ * ```typescript
751
+ * await client.markReturnReceived("return_123");
752
+ * ```
753
+ */
754
+ async markReturnReceived(returnId: string): Promise<ReturnResponse> {
755
+ return this.post(`/api/marketplace/merchant/returns/${returnId}/received`);
756
+ }
757
+
758
+ /**
759
+ * Process refund for return
760
+ *
761
+ * @param returnId - Return ID
762
+ * @returns Updated return
763
+ *
764
+ * @example
765
+ * ```typescript
766
+ * await client.processRefund("return_123");
767
+ * ```
768
+ */
769
+ async processRefund(returnId: string): Promise<ReturnResponse> {
770
+ return this.post(`/api/marketplace/merchant/returns/${returnId}/refunded`);
771
+ }
772
+
773
+ // ============================================================================
774
+ // Reviews Management
775
+ // ============================================================================
776
+
777
+ /**
778
+ * List reviews for merchant's products
779
+ *
780
+ * @returns List of reviews
781
+ *
782
+ * @example
783
+ * ```typescript
784
+ * const reviews = await client.listMerchantReviews();
785
+ * ```
786
+ */
787
+ async listMerchantReviews(): Promise<ListReviewsResponse> {
788
+ return this.get("/api/marketplace/merchant/reviews");
789
+ }
790
+
791
+ /**
792
+ * Respond to a review
793
+ *
794
+ * @param reviewId - Review ID
795
+ * @param request - Response data
796
+ * @returns Updated review
797
+ *
798
+ * @example
799
+ * ```typescript
800
+ * await client.respondToReview("review_123", {
801
+ * merchantResponse: "Thank you for your feedback!"
802
+ * });
803
+ * ```
804
+ */
805
+ async respondToReview(reviewId: string, request: RespondToReviewRequest): Promise<ReviewResponse> {
806
+ return this.post(`/api/marketplace/merchant/reviews/${reviewId}/respond`, request);
807
+ }
808
+
809
+ /**
810
+ * Flag a review as inappropriate
811
+ *
812
+ * @param reviewId - Review ID
813
+ * @returns Updated review
814
+ *
815
+ * @example
816
+ * ```typescript
817
+ * await client.flagReview("review_123");
818
+ * ```
819
+ */
820
+ async flagReview(reviewId: string): Promise<ReviewResponse> {
821
+ return this.post(`/api/marketplace/merchant/reviews/${reviewId}/flag`);
822
+ }
823
+
824
+ // ============================================================================
825
+ // Messages
826
+ // ============================================================================
827
+
828
+ /**
829
+ * List messages/conversations
830
+ *
831
+ * @returns List of conversations grouped by order
832
+ *
833
+ * @example
834
+ * ```typescript
835
+ * const messages = await client.listMessages();
836
+ * console.log("Unread:", messages.stats.unread);
837
+ * ```
838
+ */
839
+ async listMessages(): Promise<ListMessagesResponse> {
840
+ return this.get("/api/marketplace/merchant/messages");
841
+ }
842
+
843
+ /**
844
+ * Send a message to customer
845
+ *
846
+ * @param request - Message data
847
+ * @returns Sent message
848
+ *
849
+ * @example
850
+ * ```typescript
851
+ * await client.sendMessage({
852
+ * orderId: "ord_123",
853
+ * recipientId: "user_456",
854
+ * message: "Your order has been shipped!"
855
+ * });
856
+ * ```
857
+ */
858
+ async sendMessage(request: SendMessageRequest): Promise<MessageResponse> {
859
+ return this.post("/api/marketplace/merchant/messages/send", request);
860
+ }
861
+
862
+ /**
863
+ * Mark message as read
864
+ *
865
+ * @param messageId - Message ID
866
+ * @returns Updated message
867
+ *
868
+ * @example
869
+ * ```typescript
870
+ * await client.markMessageRead("msg_123");
871
+ * ```
872
+ */
873
+ async markMessageRead(messageId: string): Promise<MessageResponse> {
874
+ return this.patch(`/api/marketplace/merchant/messages/${messageId}/read`);
875
+ }
876
+
877
+ // ============================================================================
878
+ // Media Library
879
+ // ============================================================================
880
+
881
+ /**
882
+ * List media assets
883
+ *
884
+ * @param params - Query parameters
885
+ * @returns Paginated list of media assets
886
+ *
887
+ * @example
888
+ * ```typescript
889
+ * const media = await client.listMediaAssets({ limit: 50, offset: 0 });
890
+ * ```
891
+ */
892
+ async listMediaAssets(params?: PaginationParams): Promise<ListMediaAssetsResponse> {
893
+ const queryString = params ? buildQueryString(params) : "";
894
+ return this.get(`/api/marketplace/merchant/media${queryString}`);
895
+ }
896
+
897
+ /**
898
+ * Upload a media asset
899
+ *
900
+ * @param file - File to upload (max 10MB, images only)
901
+ * @returns Uploaded asset
902
+ *
903
+ * @example
904
+ * ```typescript
905
+ * const formData = new FormData();
906
+ * formData.append("file", imageFile);
907
+ *
908
+ * const asset = await client.uploadMediaAsset(formData);
909
+ * console.log("Uploaded:", asset.asset.blobUrl);
910
+ * ```
911
+ */
912
+ async uploadMediaAsset(formData: FormData): Promise<MediaAssetResponse> {
913
+ return this.post("/api/marketplace/merchant/media/upload", formData, {
914
+ headers: { "Content-Type": "multipart/form-data" },
915
+ });
916
+ }
917
+
918
+ /**
919
+ * Delete a media asset
920
+ *
921
+ * @param assetId - Asset ID
922
+ * @returns Success response
923
+ *
924
+ * @example
925
+ * ```typescript
926
+ * await client.deleteMediaAsset("asset_123");
927
+ * ```
928
+ */
929
+ async deleteMediaAsset(assetId: string): Promise<SuccessResponse> {
930
+ return this.delete(`/api/marketplace/merchant/media?id=${assetId}`);
931
+ }
932
+
933
+ // ============================================================================
934
+ // Banners
935
+ // ============================================================================
936
+
937
+ /**
938
+ * List merchant's banners
939
+ *
940
+ * @returns List of banners
941
+ *
942
+ * @example
943
+ * ```typescript
944
+ * const banners = await client.listMerchantBanners();
945
+ * ```
946
+ */
947
+ async listMerchantBanners(): Promise<ListBannersResponse> {
948
+ return this.get("/api/marketplace/merchant/banners");
949
+ }
950
+
951
+ /**
952
+ * Create a promotional banner
953
+ *
954
+ * @param request - Banner data
955
+ * @returns Created banner
956
+ *
957
+ * @example
958
+ * ```typescript
959
+ * const banner = await client.createBanner({
960
+ * title: "Summer Sale",
961
+ * imageUrl: "https://...",
962
+ * linkUrl: "/products?category=summer",
963
+ * ctaText: "Shop Now",
964
+ * priority: 10
965
+ * });
966
+ * ```
967
+ */
968
+ async createBanner(request: CreateBannerRequest): Promise<BannerResponse> {
969
+ return this.post("/api/marketplace/merchant/banners", request);
970
+ }
971
+
972
+ /**
973
+ * Get banner details
974
+ *
975
+ * @param bannerId - Banner ID
976
+ * @returns Banner details
977
+ *
978
+ * @example
979
+ * ```typescript
980
+ * const banner = await client.getBanner("banner_123");
981
+ * ```
982
+ */
983
+ async getBanner(bannerId: string): Promise<BannerResponse> {
984
+ return this.get(`/api/marketplace/merchant/banners/${bannerId}`);
985
+ }
986
+
987
+ /**
988
+ * Update a banner
989
+ *
990
+ * @param bannerId - Banner ID
991
+ * @param request - Updated banner data
992
+ * @returns Updated banner
993
+ *
994
+ * @example
995
+ * ```typescript
996
+ * await client.updateBanner("banner_123", {
997
+ * isActive: false
998
+ * });
999
+ * ```
1000
+ */
1001
+ async updateBanner(bannerId: string, request: UpdateBannerRequest): Promise<BannerResponse> {
1002
+ return this.put(`/api/marketplace/merchant/banners/${bannerId}`, request);
1003
+ }
1004
+
1005
+ /**
1006
+ * Delete a banner
1007
+ *
1008
+ * @param bannerId - Banner ID
1009
+ * @returns Success response
1010
+ *
1011
+ * @example
1012
+ * ```typescript
1013
+ * await client.deleteBanner("banner_123");
1014
+ * ```
1015
+ */
1016
+ async deleteBanner(bannerId: string): Promise<SuccessResponse> {
1017
+ return this.delete(`/api/marketplace/merchant/banners/${bannerId}`);
1018
+ }
1019
+
1020
+ // ============================================================================
1021
+ // Analytics
1022
+ // ============================================================================
1023
+
1024
+ /**
1025
+ * Get merchant analytics
1026
+ *
1027
+ * @param params - Query parameters
1028
+ * @returns Analytics data with overview, charts, and insights
1029
+ *
1030
+ * @example
1031
+ * ```typescript
1032
+ * const analytics = await client.getAnalytics({ range: "30days" });
1033
+ * console.log("Revenue:", analytics.overview.totalRevenue);
1034
+ * console.log("Orders:", analytics.overview.totalOrders);
1035
+ * ```
1036
+ */
1037
+ async getAnalytics(params?: GetAnalyticsParams): Promise<GetAnalyticsResponse> {
1038
+ const queryString = params ? buildQueryString(params) : "";
1039
+ return this.get(`/api/marketplace/merchant/analytics${queryString}`);
1040
+ }
1041
+
1042
+ // ============================================================================
1043
+ // Inventory
1044
+ // ============================================================================
1045
+
1046
+ /**
1047
+ * Get inventory audit log
1048
+ *
1049
+ * @returns Recent inventory audit entries (last 500)
1050
+ *
1051
+ * @example
1052
+ * ```typescript
1053
+ * const audit = await client.getInventoryAudit();
1054
+ * audit.entries.forEach(e => {
1055
+ * console.log(e.action, e.product.title, e.changeAmount);
1056
+ * });
1057
+ * ```
1058
+ */
1059
+ async getInventoryAudit(): Promise<ListInventoryAuditResponse> {
1060
+ return this.get("/api/marketplace/merchant/inventory/audit");
1061
+ }
1062
+
1063
+ // ============================================================================
1064
+ // Tax Management
1065
+ // ============================================================================
1066
+
1067
+ /**
1068
+ * Get tax settings
1069
+ *
1070
+ * @returns Tax settings
1071
+ *
1072
+ * @example
1073
+ * ```typescript
1074
+ * const settings = await client.getTaxSettings();
1075
+ * console.log("Tax enabled:", settings.settings.taxEnabled);
1076
+ * ```
1077
+ */
1078
+ async getTaxSettings(): Promise<TaxSettingsResponse> {
1079
+ return this.get("/api/marketplace/merchant/tax-settings");
1080
+ }
1081
+
1082
+ /**
1083
+ * Update tax settings
1084
+ *
1085
+ * @param request - Updated settings
1086
+ * @returns Updated tax settings
1087
+ *
1088
+ * @example
1089
+ * ```typescript
1090
+ * await client.updateTaxSettings({
1091
+ * taxEnabled: true,
1092
+ * pricesIncludeTax: false,
1093
+ * defaultTaxBehavior: "CHARGE"
1094
+ * });
1095
+ * ```
1096
+ */
1097
+ async updateTaxSettings(request: UpdateTaxSettingsRequest): Promise<TaxSettingsResponse> {
1098
+ return this.put("/api/marketplace/merchant/tax-settings", request);
1099
+ }
1100
+
1101
+ /**
1102
+ * List tax rules
1103
+ *
1104
+ * @returns List of tax rules
1105
+ *
1106
+ * @example
1107
+ * ```typescript
1108
+ * const rules = await client.listTaxRules();
1109
+ * ```
1110
+ */
1111
+ async listTaxRules(): Promise<ListTaxRulesResponse> {
1112
+ return this.get("/api/marketplace/merchant/tax-rules");
1113
+ }
1114
+
1115
+ /**
1116
+ * Create a tax rule
1117
+ *
1118
+ * @param request - Tax rule data
1119
+ * @returns Created tax rule
1120
+ *
1121
+ * @example
1122
+ * ```typescript
1123
+ * const rule = await client.createTaxRule({
1124
+ * country: "US",
1125
+ * region: "NY",
1126
+ * taxType: "SALES_TAX",
1127
+ * taxName: "NY Sales Tax",
1128
+ * taxRate: 8.875
1129
+ * });
1130
+ * ```
1131
+ */
1132
+ async createTaxRule(request: CreateTaxRuleRequest): Promise<TaxRuleResponse> {
1133
+ return this.post("/api/marketplace/merchant/tax-rules", request);
1134
+ }
1135
+
1136
+ /**
1137
+ * Get tax rule details
1138
+ *
1139
+ * @param ruleId - Rule ID
1140
+ * @returns Tax rule details
1141
+ *
1142
+ * @example
1143
+ * ```typescript
1144
+ * const rule = await client.getTaxRule("rule_123");
1145
+ * ```
1146
+ */
1147
+ async getTaxRule(ruleId: string): Promise<TaxRuleResponse> {
1148
+ return this.get(`/api/marketplace/merchant/tax-rules/${ruleId}`);
1149
+ }
1150
+
1151
+ /**
1152
+ * Update a tax rule
1153
+ *
1154
+ * @param ruleId - Rule ID
1155
+ * @param request - Updated rule data
1156
+ * @returns Updated tax rule
1157
+ *
1158
+ * @example
1159
+ * ```typescript
1160
+ * await client.updateTaxRule("rule_123", {
1161
+ * taxRate: 9.0
1162
+ * });
1163
+ * ```
1164
+ */
1165
+ async updateTaxRule(ruleId: string, request: UpdateTaxRuleRequest): Promise<TaxRuleResponse> {
1166
+ return this.put(`/api/marketplace/merchant/tax-rules/${ruleId}`, request);
1167
+ }
1168
+
1169
+ /**
1170
+ * Delete a tax rule
1171
+ *
1172
+ * @param ruleId - Rule ID
1173
+ * @returns Success response
1174
+ *
1175
+ * @example
1176
+ * ```typescript
1177
+ * await client.deleteTaxRule("rule_123");
1178
+ * ```
1179
+ */
1180
+ async deleteTaxRule(ruleId: string): Promise<SuccessResponse> {
1181
+ return this.delete(`/api/marketplace/merchant/tax-rules/${ruleId}`);
1182
+ }
1183
+
1184
+ /**
1185
+ * List tax nexus locations
1186
+ *
1187
+ * @returns List of nexus locations
1188
+ *
1189
+ * @example
1190
+ * ```typescript
1191
+ * const nexus = await client.listTaxNexus();
1192
+ * ```
1193
+ */
1194
+ async listTaxNexus(): Promise<ListTaxNexusResponse> {
1195
+ return this.get("/api/marketplace/merchant/tax-nexus");
1196
+ }
1197
+
1198
+ /**
1199
+ * Add a tax nexus location
1200
+ *
1201
+ * @param request - Nexus data
1202
+ * @returns Created nexus
1203
+ *
1204
+ * @example
1205
+ * ```typescript
1206
+ * const nexus = await client.createTaxNexus({
1207
+ * country: "US",
1208
+ * region: "CA",
1209
+ * registrationId: "123456789"
1210
+ * });
1211
+ * ```
1212
+ */
1213
+ async createTaxNexus(request: CreateTaxNexusRequest): Promise<TaxNexusResponse> {
1214
+ return this.post("/api/marketplace/merchant/tax-nexus", request);
1215
+ }
1216
+
1217
+ /**
1218
+ * Update a tax nexus location
1219
+ *
1220
+ * @param nexusId - Nexus ID
1221
+ * @param request - Updated nexus data
1222
+ * @returns Updated nexus
1223
+ *
1224
+ * @example
1225
+ * ```typescript
1226
+ * await client.updateTaxNexus("nexus_123", {
1227
+ * registrationId: "987654321"
1228
+ * });
1229
+ * ```
1230
+ */
1231
+ async updateTaxNexus(nexusId: string, request: UpdateTaxNexusRequest): Promise<TaxNexusResponse> {
1232
+ return this.put(`/api/marketplace/merchant/tax-nexus/${nexusId}`, request);
1233
+ }
1234
+
1235
+ /**
1236
+ * Delete a tax nexus location
1237
+ *
1238
+ * @param nexusId - Nexus ID
1239
+ * @returns Success response
1240
+ *
1241
+ * @example
1242
+ * ```typescript
1243
+ * await client.deleteTaxNexus("nexus_123");
1244
+ * ```
1245
+ */
1246
+ async deleteTaxNexus(nexusId: string): Promise<SuccessResponse> {
1247
+ return this.delete(`/api/marketplace/merchant/tax-nexus/${nexusId}`);
1248
+ }
1249
+
1250
+ /**
1251
+ * List tax reports
1252
+ *
1253
+ * @param params - Query parameters
1254
+ * @returns Paginated list of tax reports
1255
+ *
1256
+ * @example
1257
+ * ```typescript
1258
+ * const reports = await client.listTaxReports({ limit: 20, offset: 0 });
1259
+ *
1260
+ * // Get summary for a specific year
1261
+ * const summary = await client.listTaxReports({ year: 2025 });
1262
+ * ```
1263
+ */
1264
+ async listTaxReports(params?: ListTaxReportsParams): Promise<ListTaxReportsResponse> {
1265
+ const queryString = params ? buildQueryString(params) : "";
1266
+ return this.get(`/api/marketplace/merchant/tax-reports${queryString}`);
1267
+ }
1268
+
1269
+ /**
1270
+ * Generate a tax report
1271
+ *
1272
+ * @param request - Report generation request
1273
+ * @returns Generated report
1274
+ *
1275
+ * @example
1276
+ * ```typescript
1277
+ * const report = await client.generateTaxReport({
1278
+ * periodType: "MONTHLY",
1279
+ * year: 2025,
1280
+ * period: 1 // January
1281
+ * });
1282
+ * ```
1283
+ */
1284
+ async generateTaxReport(request: GenerateTaxReportRequest): Promise<TaxReportResponse> {
1285
+ return this.post("/api/marketplace/merchant/tax-reports/generate", request);
1286
+ }
1287
+
1288
+ /**
1289
+ * Get tax report details
1290
+ *
1291
+ * @param reportId - Report ID
1292
+ * @returns Report with detailed records
1293
+ *
1294
+ * @example
1295
+ * ```typescript
1296
+ * const report = await client.getTaxReport("report_123");
1297
+ * console.log("Total tax:", report.report.totalTax);
1298
+ * ```
1299
+ */
1300
+ async getTaxReport(reportId: string): Promise<GetTaxReportResponse> {
1301
+ return this.get(`/api/marketplace/merchant/tax-reports/${reportId}`);
1302
+ }
1303
+
1304
+ /**
1305
+ * Update tax report status
1306
+ *
1307
+ * @param reportId - Report ID
1308
+ * @param request - Status update
1309
+ * @returns Updated report
1310
+ *
1311
+ * @example
1312
+ * ```typescript
1313
+ * await client.updateTaxReportStatus("report_123", {
1314
+ * status: "FINALIZED"
1315
+ * });
1316
+ * ```
1317
+ */
1318
+ async updateTaxReportStatus(
1319
+ reportId: string,
1320
+ request: UpdateTaxReportStatusRequest
1321
+ ): Promise<TaxReportResponse> {
1322
+ return this.put(`/api/marketplace/merchant/tax-reports/${reportId}`, request);
1323
+ }
1324
+
1325
+ /**
1326
+ * Export tax report as CSV
1327
+ *
1328
+ * @param reportId - Report ID
1329
+ * @returns CSV file data
1330
+ *
1331
+ * @example
1332
+ * ```typescript
1333
+ * const csv = await client.exportTaxReport("report_123");
1334
+ * // Save or download the CSV
1335
+ * ```
1336
+ */
1337
+ async exportTaxReport(reportId: string): Promise<string> {
1338
+ return this.get(`/api/marketplace/merchant/tax-reports/${reportId}/export`);
1339
+ }
1340
+ }
1341
+