@basedone/core 0.2.0 → 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.
@@ -717,6 +717,110 @@ var CustomerEcommerceClient = class extends BaseEcommerceClient {
717
717
  async trackBanner(bannerId, request) {
718
718
  return this.post(`/api/marketplace/banners/${bannerId}/track`, request);
719
719
  }
720
+ // ============================================================================
721
+ // Messages API
722
+ // ============================================================================
723
+ /**
724
+ * List messages for customer
725
+ *
726
+ * Returns all conversations grouped by order, where each order represents
727
+ * a conversation with a merchant.
728
+ *
729
+ * @returns List of conversations with messages and stats
730
+ *
731
+ * @example
732
+ * ```typescript
733
+ * const result = await client.listMessages();
734
+ * console.log("Unread:", result.stats.unread);
735
+ * result.conversations.forEach(conv => {
736
+ * console.log(`Order ${conv.orderNumber}: ${conv.unreadCount} unread`);
737
+ * });
738
+ * ```
739
+ */
740
+ async listMessages() {
741
+ return this.get("/api/marketplace/messages");
742
+ }
743
+ /**
744
+ * Get message stats (unread count)
745
+ *
746
+ * Lightweight endpoint for notification badges.
747
+ *
748
+ * @returns Unread message count
749
+ *
750
+ * @example
751
+ * ```typescript
752
+ * const stats = await client.getMessageStats();
753
+ * console.log("Unread messages:", stats.unread);
754
+ * ```
755
+ */
756
+ async getMessageStats() {
757
+ return this.get("/api/marketplace/messages/stats");
758
+ }
759
+ /**
760
+ * Send a message to a merchant about an order
761
+ *
762
+ * @param request - Message data including orderId, recipientId (merchant user ID), and message
763
+ * @returns Sent message
764
+ *
765
+ * @example
766
+ * ```typescript
767
+ * await client.sendMessage({
768
+ * orderId: "ord_123",
769
+ * recipientId: "user_merchant_456",
770
+ * message: "When will my order ship?"
771
+ * });
772
+ * ```
773
+ */
774
+ async sendMessage(request) {
775
+ return this.post("/api/marketplace/messages/send", request);
776
+ }
777
+ /**
778
+ * Mark a message as read
779
+ *
780
+ * @param messageId - Message ID
781
+ * @returns Updated message
782
+ *
783
+ * @example
784
+ * ```typescript
785
+ * await client.markMessageAsRead("msg_123");
786
+ * ```
787
+ */
788
+ async markMessageAsRead(messageId) {
789
+ return this.patch(`/api/marketplace/messages/${messageId}/read`, {});
790
+ }
791
+ // ============================================================================
792
+ // Flash Sales API
793
+ // ============================================================================
794
+ /**
795
+ * Get active flash sales
796
+ *
797
+ * Returns currently running flash sales with their discounted products.
798
+ * Includes countdown timer information for UI display.
799
+ *
800
+ * @param params - Query parameters
801
+ * @returns List of active flash sales with time remaining
802
+ *
803
+ * @example
804
+ * ```typescript
805
+ * const result = await client.getActiveFlashSales({ limit: 5 });
806
+ *
807
+ * result.flashSales.forEach(sale => {
808
+ * console.log(`${sale.name} - ends at ${sale.endsAt}`);
809
+ * sale.items.forEach(item => {
810
+ * console.log(` ${item.product.title}: $${item.salePrice} (${item.discountPercent}% off)`);
811
+ * });
812
+ * });
813
+ *
814
+ * // Use timeRemaining for countdown UI
815
+ * if (result.timeRemaining) {
816
+ * console.log(`Featured sale ends in ${result.timeRemaining.remainingSeconds} seconds`);
817
+ * }
818
+ * ```
819
+ */
820
+ async getActiveFlashSales(params) {
821
+ const queryString = params ? buildQueryString(params) : "";
822
+ return this.get(`/api/marketplace/flash-sales/active${queryString}`);
823
+ }
720
824
  };
721
825
 
722
826
  // lib/ecommerce/client/merchant.ts
@@ -1093,6 +1093,73 @@ interface CustomerSummary {
1093
1093
  /** First order date */
1094
1094
  firstOrderDate?: string;
1095
1095
  }
1096
+ /**
1097
+ * Flash sale item entity
1098
+ */
1099
+ interface FlashSaleItem {
1100
+ /** Item ID */
1101
+ id: string;
1102
+ /** Product ID */
1103
+ productId: string;
1104
+ /** Sale price in USDC */
1105
+ salePrice: string;
1106
+ /** Original price in USDC */
1107
+ originalPrice: string;
1108
+ /** Discount percentage */
1109
+ discountPercent: number;
1110
+ /** Maximum quantity available at this price */
1111
+ maxQuantity: number | null;
1112
+ /** Quantity sold at flash price */
1113
+ soldQuantity: number;
1114
+ /** Remaining quantity */
1115
+ remainingQuantity: number | null;
1116
+ /** Limit per customer */
1117
+ limitPerCustomer: number | null;
1118
+ /** Product details */
1119
+ product: {
1120
+ id: string;
1121
+ title: string;
1122
+ description?: string | null;
1123
+ images: string[];
1124
+ priceUSDC: string;
1125
+ inventory: number | null;
1126
+ soldCount: number;
1127
+ averageRating: number | null;
1128
+ reviewCount: number;
1129
+ merchant?: {
1130
+ id: string;
1131
+ name: string;
1132
+ };
1133
+ };
1134
+ }
1135
+ /**
1136
+ * Flash sale entity
1137
+ */
1138
+ interface FlashSale {
1139
+ /** Flash sale ID */
1140
+ id: string;
1141
+ /** Sale name */
1142
+ name: string;
1143
+ /** Description */
1144
+ description?: string | null;
1145
+ /** Start timestamp */
1146
+ startsAt: string;
1147
+ /** End timestamp */
1148
+ endsAt: string;
1149
+ /** Badge text (e.g., "Mall", "Hot Deal") */
1150
+ badgeText?: string | null;
1151
+ /** Badge color (hex) */
1152
+ badgeColor?: string | null;
1153
+ /** Priority (higher = shown first) */
1154
+ priority: number;
1155
+ /** Merchant information */
1156
+ merchant?: {
1157
+ id: string;
1158
+ name: string;
1159
+ } | null;
1160
+ /** Flash sale items */
1161
+ items: FlashSaleItem[];
1162
+ }
1096
1163
 
1097
1164
  /**
1098
1165
  * Ecommerce API Request Types
@@ -1570,6 +1637,58 @@ interface ListActiveBannersParams {
1570
1637
  /** Filter by merchant ID */
1571
1638
  merchantId?: string;
1572
1639
  }
1640
+ /**
1641
+ * List active flash sales params
1642
+ */
1643
+ interface ListActiveFlashSalesParams {
1644
+ /** Maximum number of flash sales to return */
1645
+ limit?: number;
1646
+ /** Filter by merchant ID */
1647
+ merchantId?: string;
1648
+ }
1649
+ /**
1650
+ * Flash sale item input
1651
+ */
1652
+ interface FlashSaleItemInput {
1653
+ /** Product ID */
1654
+ productId: string;
1655
+ /** Sale price in USDC */
1656
+ salePrice: number;
1657
+ /** Maximum quantity available */
1658
+ maxQuantity?: number | null;
1659
+ /** Limit per customer */
1660
+ limitPerCustomer?: number;
1661
+ /** Sort order */
1662
+ sortOrder?: number;
1663
+ }
1664
+ /**
1665
+ * Create flash sale request
1666
+ */
1667
+ interface CreateFlashSaleRequest {
1668
+ /** Sale name */
1669
+ name: string;
1670
+ /** Description */
1671
+ description?: string | null;
1672
+ /** Start timestamp */
1673
+ startsAt: string;
1674
+ /** End timestamp */
1675
+ endsAt: string;
1676
+ /** Badge text */
1677
+ badgeText?: string;
1678
+ /** Badge color (hex) */
1679
+ badgeColor?: string;
1680
+ /** Priority (higher = shown first) */
1681
+ priority?: number;
1682
+ /** Is active */
1683
+ isActive?: boolean;
1684
+ /** Flash sale items */
1685
+ items?: FlashSaleItemInput[];
1686
+ }
1687
+ /**
1688
+ * Update flash sale request
1689
+ */
1690
+ interface UpdateFlashSaleRequest extends Partial<CreateFlashSaleRequest> {
1691
+ }
1573
1692
 
1574
1693
  /**
1575
1694
  * Ecommerce API Response Types
@@ -2019,6 +2138,38 @@ interface MessageResponse {
2019
2138
  /** Message */
2020
2139
  message: Message;
2021
2140
  }
2141
+ /**
2142
+ * Customer messages response (for retail users)
2143
+ *
2144
+ * Groups messages by order, where each order represents a conversation with a merchant.
2145
+ */
2146
+ interface CustomerMessagesResponse {
2147
+ /** Conversations grouped by order */
2148
+ conversations: Array<{
2149
+ orderId: string;
2150
+ orderNumber: string;
2151
+ merchant: {
2152
+ id: string;
2153
+ name: string;
2154
+ ownerUserId: string;
2155
+ };
2156
+ lastMessage: Message;
2157
+ unreadCount: number;
2158
+ messages: Message[];
2159
+ }>;
2160
+ /** Stats */
2161
+ stats: {
2162
+ total: number;
2163
+ unread: number;
2164
+ };
2165
+ }
2166
+ /**
2167
+ * Message stats response (for notification badges)
2168
+ */
2169
+ interface MessageStatsResponse {
2170
+ /** Unread message count */
2171
+ unread: number;
2172
+ }
2022
2173
  /**
2023
2174
  * Analytics overview
2024
2175
  */
@@ -2297,6 +2448,22 @@ interface CreateOrderEventResponse {
2297
2448
  /** Event */
2298
2449
  event: any;
2299
2450
  }
2451
+ /**
2452
+ * Active flash sales response
2453
+ */
2454
+ interface ActiveFlashSalesResponse {
2455
+ /** Flash sales */
2456
+ flashSales: FlashSale[];
2457
+ /** Time remaining for the featured/first sale */
2458
+ timeRemaining: {
2459
+ /** End timestamp */
2460
+ endsAt: string;
2461
+ /** Remaining seconds */
2462
+ remainingSeconds: number;
2463
+ } | null;
2464
+ /** Server time (for client-side sync) */
2465
+ serverTime: string;
2466
+ }
2300
2467
 
2301
2468
  /**
2302
2469
  * Customer/End-User Ecommerce API Client
@@ -2675,6 +2842,93 @@ declare class CustomerEcommerceClient extends BaseEcommerceClient {
2675
2842
  * ```
2676
2843
  */
2677
2844
  trackBanner(bannerId: string, request: TrackBannerRequest): Promise<SuccessResponse>;
2845
+ /**
2846
+ * List messages for customer
2847
+ *
2848
+ * Returns all conversations grouped by order, where each order represents
2849
+ * a conversation with a merchant.
2850
+ *
2851
+ * @returns List of conversations with messages and stats
2852
+ *
2853
+ * @example
2854
+ * ```typescript
2855
+ * const result = await client.listMessages();
2856
+ * console.log("Unread:", result.stats.unread);
2857
+ * result.conversations.forEach(conv => {
2858
+ * console.log(`Order ${conv.orderNumber}: ${conv.unreadCount} unread`);
2859
+ * });
2860
+ * ```
2861
+ */
2862
+ listMessages(): Promise<CustomerMessagesResponse>;
2863
+ /**
2864
+ * Get message stats (unread count)
2865
+ *
2866
+ * Lightweight endpoint for notification badges.
2867
+ *
2868
+ * @returns Unread message count
2869
+ *
2870
+ * @example
2871
+ * ```typescript
2872
+ * const stats = await client.getMessageStats();
2873
+ * console.log("Unread messages:", stats.unread);
2874
+ * ```
2875
+ */
2876
+ getMessageStats(): Promise<MessageStatsResponse>;
2877
+ /**
2878
+ * Send a message to a merchant about an order
2879
+ *
2880
+ * @param request - Message data including orderId, recipientId (merchant user ID), and message
2881
+ * @returns Sent message
2882
+ *
2883
+ * @example
2884
+ * ```typescript
2885
+ * await client.sendMessage({
2886
+ * orderId: "ord_123",
2887
+ * recipientId: "user_merchant_456",
2888
+ * message: "When will my order ship?"
2889
+ * });
2890
+ * ```
2891
+ */
2892
+ sendMessage(request: SendMessageRequest): Promise<MessageResponse>;
2893
+ /**
2894
+ * Mark a message as read
2895
+ *
2896
+ * @param messageId - Message ID
2897
+ * @returns Updated message
2898
+ *
2899
+ * @example
2900
+ * ```typescript
2901
+ * await client.markMessageAsRead("msg_123");
2902
+ * ```
2903
+ */
2904
+ markMessageAsRead(messageId: string): Promise<MessageResponse>;
2905
+ /**
2906
+ * Get active flash sales
2907
+ *
2908
+ * Returns currently running flash sales with their discounted products.
2909
+ * Includes countdown timer information for UI display.
2910
+ *
2911
+ * @param params - Query parameters
2912
+ * @returns List of active flash sales with time remaining
2913
+ *
2914
+ * @example
2915
+ * ```typescript
2916
+ * const result = await client.getActiveFlashSales({ limit: 5 });
2917
+ *
2918
+ * result.flashSales.forEach(sale => {
2919
+ * console.log(`${sale.name} - ends at ${sale.endsAt}`);
2920
+ * sale.items.forEach(item => {
2921
+ * console.log(` ${item.product.title}: $${item.salePrice} (${item.discountPercent}% off)`);
2922
+ * });
2923
+ * });
2924
+ *
2925
+ * // Use timeRemaining for countdown UI
2926
+ * if (result.timeRemaining) {
2927
+ * console.log(`Featured sale ends in ${result.timeRemaining.remainingSeconds} seconds`);
2928
+ * }
2929
+ * ```
2930
+ */
2931
+ getActiveFlashSales(params?: ListActiveFlashSalesParams): Promise<ActiveFlashSalesResponse>;
2678
2932
  }
2679
2933
 
2680
2934
  /**
@@ -3729,4 +3983,4 @@ declare function calculateDiscountAmount(price: number, discountType: "PERCENTAG
3729
3983
  */
3730
3984
  declare function calculateFinalPrice(price: number, discountType: "PERCENTAGE" | "FIXED_AMOUNT", discountValue: number): number;
3731
3985
 
3732
- export { type AnalyticsOverview, type ApiResponse, type AppliedDiscount, type Banner, type BannerResponse, BannerType, BaseEcommerceClient, type BaseEntity, type CalculateCartDiscountsRequest, type CalculateCartDiscountsResponse, type CalculateTaxRequest, type CalculateTaxResponse, type CartItem, type ConfirmEscrowDepositResponse, type Coupon, type CouponResponse, type CouponUsage, type CreateBannerRequest, type CreateCouponRequest, type CreateOrderEventRequest, type CreateOrderEventResponse, type CreateOrderRequest, type CreateOrderResponse, type CreateProductRequest, type CreateProductVariantRequest, type CreateReviewRequest, type CreateShippingMethodRequest, type CreateTaxNexusRequest, type CreateTaxRuleRequest, CustomerEcommerceClient, type CustomerSummary, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, type EcommerceClientConfig, type GenerateTaxReportRequest, type GetAnalyticsParams, type GetAnalyticsResponse, type GetCouponResponse, type GetOrderResponse, type GetProductMetricsResponse, type GetProductResponse, type GetTaxReportResponse, InventoryAuditAction, type InventoryAuditEntry, type ListActiveBannersParams, type ListBannersResponse, type ListCouponsResponse, type ListCustomersParams, type ListCustomersResponse, type ListInventoryAuditResponse, type ListMediaAssetsResponse, type ListMessagesResponse, type ListOrdersParams, type ListOrdersResponse, type ListProductVariantsResponse, type ListProductsParams, type ListProductsResponse, type ListReturnsResponse, type ListReviewsParams, type ListReviewsResponse, type ListShipmentsResponse, type ListShippingAddressesResponse, type ListShippingMethodsResponse, type ListTaxNexusResponse, type ListTaxReportsParams, type ListTaxReportsResponse, type ListTaxRulesResponse, type MediaAsset, type MediaAssetResponse, type Merchant, MerchantEcommerceClient, type MerchantProfileRequest, type MerchantProfileResponse, MerchantStatus, type Message, type MessageResponse, type Order, type OrderEvent, type OrderItem, type OrderReceiptResponse, OrderStatus, type OrdersByStatus, type PaginatedResponse, type PaginationParams, type Payment, PaymentMethod, PaymentStatus, type Product, type ProductDimensions, type ProductDiscountsResponse, type ProductMetrics, type ProductResponse, type ProductReview, ProductSortBy, type ProductVariant, type ProductVariantResponse, type RecentOrderSummary, type RespondToReviewRequest, type Return, type ReturnItem, type ReturnResponse, ReturnStatus, type RevenueByDay, type ReviewResponse, ReviewSortBy, ReviewStatus, type SendMessageRequest, type Settlement, type Shipment, type ShipmentResponse, ShipmentStatus, type ShippingAddress, type ShippingAddressRequest, type ShippingAddressResponse, type ShippingMethod, type ShippingMethodResponse, SortOrder, type SuccessResponse, TaxBehavior, type TaxBreakdownItem, type TaxNexus, type TaxNexusResponse, type TaxReport, type TaxReportDetails, TaxReportPeriodType, type TaxReportResponse, TaxReportStatus, type TaxRule, type TaxRuleResponse, type TaxSettings, type TaxSettingsResponse, TaxType, type TopProduct, type TrackBannerRequest, type UpdateBannerRequest, type UpdateCouponRequest, type UpdateOrderResponse, type UpdateOrderStatusRequest, type UpdateProductRequest, type UpdateProductVariantRequest, type UpdateShipmentRequest, type UpdateShippingMethodRequest, type UpdateTaxNexusRequest, type UpdateTaxReportStatusRequest, type UpdateTaxRuleRequest, type UpdateTaxSettingsRequest, type UserShippingAddress, type ValidateDiscountRequest, type ValidateDiscountResponse, buildQueryString, calculateDiscountAmount, calculateFinalPrice, formatPrice, getBackoffDelay, isRetryableError, isValidAddress, isValidEmail, parseError, retryWithBackoff, sleep, truncateAddress };
3986
+ export { type ActiveFlashSalesResponse, type AnalyticsOverview, type ApiResponse, type AppliedDiscount, type Banner, type BannerResponse, BannerType, BaseEcommerceClient, type BaseEntity, type CalculateCartDiscountsRequest, type CalculateCartDiscountsResponse, type CalculateTaxRequest, type CalculateTaxResponse, type CartItem, type ConfirmEscrowDepositResponse, type Coupon, type CouponResponse, type CouponUsage, type CreateBannerRequest, type CreateCouponRequest, type CreateFlashSaleRequest, type CreateOrderEventRequest, type CreateOrderEventResponse, type CreateOrderRequest, type CreateOrderResponse, type CreateProductRequest, type CreateProductVariantRequest, type CreateReviewRequest, type CreateShippingMethodRequest, type CreateTaxNexusRequest, type CreateTaxRuleRequest, CustomerEcommerceClient, type CustomerMessagesResponse, type CustomerSummary, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, type EcommerceClientConfig, type FlashSale, type FlashSaleItem, type FlashSaleItemInput, type GenerateTaxReportRequest, type GetAnalyticsParams, type GetAnalyticsResponse, type GetCouponResponse, type GetOrderResponse, type GetProductMetricsResponse, type GetProductResponse, type GetTaxReportResponse, InventoryAuditAction, type InventoryAuditEntry, type ListActiveBannersParams, type ListActiveFlashSalesParams, type ListBannersResponse, type ListCouponsResponse, type ListCustomersParams, type ListCustomersResponse, type ListInventoryAuditResponse, type ListMediaAssetsResponse, type ListMessagesResponse, type ListOrdersParams, type ListOrdersResponse, type ListProductVariantsResponse, type ListProductsParams, type ListProductsResponse, type ListReturnsResponse, type ListReviewsParams, type ListReviewsResponse, type ListShipmentsResponse, type ListShippingAddressesResponse, type ListShippingMethodsResponse, type ListTaxNexusResponse, type ListTaxReportsParams, type ListTaxReportsResponse, type ListTaxRulesResponse, type MediaAsset, type MediaAssetResponse, type Merchant, MerchantEcommerceClient, type MerchantProfileRequest, type MerchantProfileResponse, MerchantStatus, type Message, type MessageResponse, type MessageStatsResponse, type Order, type OrderEvent, type OrderItem, type OrderReceiptResponse, OrderStatus, type OrdersByStatus, type PaginatedResponse, type PaginationParams, type Payment, PaymentMethod, PaymentStatus, type Product, type ProductDimensions, type ProductDiscountsResponse, type ProductMetrics, type ProductResponse, type ProductReview, ProductSortBy, type ProductVariant, type ProductVariantResponse, type RecentOrderSummary, type RespondToReviewRequest, type Return, type ReturnItem, type ReturnResponse, ReturnStatus, type RevenueByDay, type ReviewResponse, ReviewSortBy, ReviewStatus, type SendMessageRequest, type Settlement, type Shipment, type ShipmentResponse, ShipmentStatus, type ShippingAddress, type ShippingAddressRequest, type ShippingAddressResponse, type ShippingMethod, type ShippingMethodResponse, SortOrder, type SuccessResponse, TaxBehavior, type TaxBreakdownItem, type TaxNexus, type TaxNexusResponse, type TaxReport, type TaxReportDetails, TaxReportPeriodType, type TaxReportResponse, TaxReportStatus, type TaxRule, type TaxRuleResponse, type TaxSettings, type TaxSettingsResponse, TaxType, type TopProduct, type TrackBannerRequest, type UpdateBannerRequest, type UpdateCouponRequest, type UpdateFlashSaleRequest, type UpdateOrderResponse, type UpdateOrderStatusRequest, type UpdateProductRequest, type UpdateProductVariantRequest, type UpdateShipmentRequest, type UpdateShippingMethodRequest, type UpdateTaxNexusRequest, type UpdateTaxReportStatusRequest, type UpdateTaxRuleRequest, type UpdateTaxSettingsRequest, type UserShippingAddress, type ValidateDiscountRequest, type ValidateDiscountResponse, buildQueryString, calculateDiscountAmount, calculateFinalPrice, formatPrice, getBackoffDelay, isRetryableError, isValidAddress, isValidEmail, parseError, retryWithBackoff, sleep, truncateAddress };