@basedone/core 0.2.8 → 0.3.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-NKSQEISP.mjs → chunk-35WGIB5F.mjs} +149 -1
- package/dist/{client-DMVXX1Gw.d.mts → client-BQzYwHDY.d.mts} +2 -2
- package/dist/{client-DMVXX1Gw.d.ts → client-BQzYwHDY.d.ts} +2 -2
- package/dist/ecommerce.d.mts +122 -2
- package/dist/ecommerce.d.ts +122 -2
- package/dist/ecommerce.js +158 -0
- package/dist/ecommerce.mjs +1 -1
- package/dist/index.d.mts +113 -3
- package/dist/index.d.ts +113 -3
- package/dist/index.js +299 -0
- package/dist/index.mjs +134 -2
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/index.ts +3 -0
- package/lib/abstraction/api.ts +106 -0
- package/lib/abstraction/index.ts +3 -0
- package/lib/abstraction/ratio.ts +61 -0
- package/lib/abstraction/types.ts +73 -0
- package/lib/constants/admin.ts +30 -0
- package/lib/ecommerce/client/customer.ts +42 -0
- package/lib/ecommerce/index.ts +14 -0
- package/lib/ecommerce/types/entities.ts +14 -0
- package/lib/ecommerce/types/enums.ts +5 -1
- package/lib/ecommerce/types/responses.ts +28 -0
- package/lib/ecommerce/utils/orderStateMachine.ts +197 -0
- package/lib/types.ts +29 -0
- package/package.json +1 -1
|
@@ -1220,6 +1220,38 @@ var CustomerEcommerceClient = class extends BaseEcommerceClient {
|
|
|
1220
1220
|
async getDeliveryAddress() {
|
|
1221
1221
|
return this.get("/api/basedpay/delivery-address");
|
|
1222
1222
|
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Get user's Hyperliquid USDC balance (perp withdrawable)
|
|
1225
|
+
*
|
|
1226
|
+
* Returns the USDC balance available for escrow deposits via usdSend.
|
|
1227
|
+
*
|
|
1228
|
+
* @returns Balance response with amount and currency
|
|
1229
|
+
*/
|
|
1230
|
+
async getUsdcBalance() {
|
|
1231
|
+
return this.get("/api/marketplace/usdc-balance");
|
|
1232
|
+
}
|
|
1233
|
+
// ============================================================================
|
|
1234
|
+
// Notifications API
|
|
1235
|
+
// ============================================================================
|
|
1236
|
+
/**
|
|
1237
|
+
* List notifications for the authenticated customer
|
|
1238
|
+
*
|
|
1239
|
+
* @param params - Query parameters for filtering and pagination
|
|
1240
|
+
* @returns Paginated list of notifications with unread count
|
|
1241
|
+
*/
|
|
1242
|
+
async listNotifications(params) {
|
|
1243
|
+
const queryString = params ? buildQueryString(params) : "";
|
|
1244
|
+
return this.get(`/api/marketplace/notifications${queryString}`);
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Mark notifications as read
|
|
1248
|
+
*
|
|
1249
|
+
* @param ids - Specific notification IDs to mark as read. If omitted, marks all as read.
|
|
1250
|
+
* @returns Count of updated notifications
|
|
1251
|
+
*/
|
|
1252
|
+
async markNotificationsAsRead(ids) {
|
|
1253
|
+
return this.patch("/api/marketplace/notifications/read", { ids });
|
|
1254
|
+
}
|
|
1223
1255
|
};
|
|
1224
1256
|
|
|
1225
1257
|
// lib/ecommerce/client/merchant.ts
|
|
@@ -2765,6 +2797,7 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
|
|
|
2765
2797
|
OrderStatus2["SHIPPED"] = "SHIPPED";
|
|
2766
2798
|
OrderStatus2["DELIVERED"] = "DELIVERED";
|
|
2767
2799
|
OrderStatus2["CANCELLED"] = "CANCELLED";
|
|
2800
|
+
OrderStatus2["SETTLED"] = "SETTLED";
|
|
2768
2801
|
OrderStatus2["CONFIRMED"] = "CONFIRMED";
|
|
2769
2802
|
OrderStatus2["COMPLETED"] = "COMPLETED";
|
|
2770
2803
|
return OrderStatus2;
|
|
@@ -2898,6 +2931,7 @@ var ProductSortBy = /* @__PURE__ */ ((ProductSortBy2) => {
|
|
|
2898
2931
|
ProductSortBy2["PRICE_ASC"] = "price_asc";
|
|
2899
2932
|
ProductSortBy2["PRICE_DESC"] = "price_desc";
|
|
2900
2933
|
ProductSortBy2["POPULAR"] = "popular";
|
|
2934
|
+
ProductSortBy2["BEST_SELLING"] = "best_selling";
|
|
2901
2935
|
ProductSortBy2["FEATURED"] = "featured";
|
|
2902
2936
|
ProductSortBy2["NEARBY"] = "nearby";
|
|
2903
2937
|
return ProductSortBy2;
|
|
@@ -2909,4 +2943,118 @@ var ReviewSortBy = /* @__PURE__ */ ((ReviewSortBy2) => {
|
|
|
2909
2943
|
return ReviewSortBy2;
|
|
2910
2944
|
})(ReviewSortBy || {});
|
|
2911
2945
|
|
|
2912
|
-
|
|
2946
|
+
// lib/ecommerce/utils/orderStateMachine.ts
|
|
2947
|
+
function isPickupOrder(shippingMethod, shippingRateId) {
|
|
2948
|
+
if (shippingRateId && shippingRateId.trim().toUpperCase() === "PICKUP") {
|
|
2949
|
+
return true;
|
|
2950
|
+
}
|
|
2951
|
+
if (!shippingMethod) return false;
|
|
2952
|
+
const normalized = shippingMethod.trim().toLowerCase().replace(/[\s-]+/g, " ");
|
|
2953
|
+
return normalized === "pickup" || normalized === "on site collection" || normalized === "onsite collection";
|
|
2954
|
+
}
|
|
2955
|
+
var ORDER_STATUS_TRANSITIONS = {
|
|
2956
|
+
["CREATED" /* CREATED */]: [
|
|
2957
|
+
"PAYMENT_RESERVED" /* PAYMENT_RESERVED */,
|
|
2958
|
+
"MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */,
|
|
2959
|
+
"CANCELLED" /* CANCELLED */
|
|
2960
|
+
],
|
|
2961
|
+
["PAYMENT_RESERVED" /* PAYMENT_RESERVED */]: [
|
|
2962
|
+
"MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */,
|
|
2963
|
+
"CANCELLED" /* CANCELLED */
|
|
2964
|
+
],
|
|
2965
|
+
["MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */]: [
|
|
2966
|
+
"SHIPPED" /* SHIPPED */,
|
|
2967
|
+
"CANCELLED" /* CANCELLED */
|
|
2968
|
+
],
|
|
2969
|
+
// Backward compat for existing SETTLED orders created before escrow change
|
|
2970
|
+
// Note: CANCELLED removed — settled orders have funds paid out, no clawback mechanism
|
|
2971
|
+
["SETTLED" /* SETTLED */]: ["SHIPPED" /* SHIPPED */],
|
|
2972
|
+
["SHIPPED" /* SHIPPED */]: ["DELIVERED" /* DELIVERED */, "CANCELLED" /* CANCELLED */],
|
|
2973
|
+
// Settlement triggered on delivery (buyer-protected escrow)
|
|
2974
|
+
["DELIVERED" /* DELIVERED */]: ["SETTLED" /* SETTLED */],
|
|
2975
|
+
// Terminal states
|
|
2976
|
+
["CANCELLED" /* CANCELLED */]: []
|
|
2977
|
+
};
|
|
2978
|
+
function validateStatusTransition(currentStatus, newStatus, options) {
|
|
2979
|
+
if (isPickupOrder(options?.shippingMethod, options?.shippingRateId) && (currentStatus === "MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */ || currentStatus === "SETTLED" /* SETTLED */) && newStatus === "DELIVERED" /* DELIVERED */) {
|
|
2980
|
+
return { valid: true };
|
|
2981
|
+
}
|
|
2982
|
+
const allowed = ORDER_STATUS_TRANSITIONS[currentStatus] ?? [];
|
|
2983
|
+
if (!allowed.includes(newStatus)) {
|
|
2984
|
+
if (allowed.length === 0) {
|
|
2985
|
+
return {
|
|
2986
|
+
valid: false,
|
|
2987
|
+
error: `Cannot change status from ${currentStatus} \u2014 this is a final state`
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
return {
|
|
2991
|
+
valid: false,
|
|
2992
|
+
error: `Cannot transition from ${currentStatus} to ${newStatus}. Allowed: ${allowed.join(", ")}`
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
return { valid: true };
|
|
2996
|
+
}
|
|
2997
|
+
function getNextStatuses(currentStatus, options) {
|
|
2998
|
+
const base = [
|
|
2999
|
+
...ORDER_STATUS_TRANSITIONS[currentStatus] ?? []
|
|
3000
|
+
];
|
|
3001
|
+
if (isPickupOrder(options?.shippingMethod, options?.shippingRateId) && (currentStatus === "MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */ || currentStatus === "SETTLED" /* SETTLED */) && !base.includes("DELIVERED" /* DELIVERED */)) {
|
|
3002
|
+
base.push("DELIVERED" /* DELIVERED */);
|
|
3003
|
+
}
|
|
3004
|
+
return base;
|
|
3005
|
+
}
|
|
3006
|
+
function getStatusLabel(status) {
|
|
3007
|
+
const labels = {
|
|
3008
|
+
CREATED: "Created",
|
|
3009
|
+
PAYMENT_RESERVED: "Payment Reserved",
|
|
3010
|
+
MERCHANT_ACCEPTED: "Accepted",
|
|
3011
|
+
SETTLED: "Completed (Paid)",
|
|
3012
|
+
SHIPPED: "Shipped",
|
|
3013
|
+
DELIVERED: "Delivered",
|
|
3014
|
+
CANCELLED: "Cancelled"
|
|
3015
|
+
};
|
|
3016
|
+
return labels[status] || status;
|
|
3017
|
+
}
|
|
3018
|
+
function getStatusColor(status) {
|
|
3019
|
+
const colors = {
|
|
3020
|
+
CREATED: "gray",
|
|
3021
|
+
PAYMENT_RESERVED: "blue",
|
|
3022
|
+
MERCHANT_ACCEPTED: "purple",
|
|
3023
|
+
SETTLED: "indigo",
|
|
3024
|
+
SHIPPED: "yellow",
|
|
3025
|
+
DELIVERED: "green",
|
|
3026
|
+
CANCELLED: "red"
|
|
3027
|
+
};
|
|
3028
|
+
return colors[status] || "gray";
|
|
3029
|
+
}
|
|
3030
|
+
function canCancelOrder(currentStatus) {
|
|
3031
|
+
return ORDER_STATUS_TRANSITIONS[currentStatus]?.includes(
|
|
3032
|
+
"CANCELLED" /* CANCELLED */
|
|
3033
|
+
) ?? false;
|
|
3034
|
+
}
|
|
3035
|
+
function requiresTrackingInfo(newStatus, options) {
|
|
3036
|
+
if (newStatus !== "SHIPPED" /* SHIPPED */) return false;
|
|
3037
|
+
return !isPickupOrder(options?.shippingMethod, options?.shippingRateId);
|
|
3038
|
+
}
|
|
3039
|
+
function shouldNotifyCustomer(newStatus) {
|
|
3040
|
+
return [
|
|
3041
|
+
"MERCHANT_ACCEPTED" /* MERCHANT_ACCEPTED */,
|
|
3042
|
+
"SHIPPED" /* SHIPPED */,
|
|
3043
|
+
"DELIVERED" /* DELIVERED */,
|
|
3044
|
+
"CANCELLED" /* CANCELLED */
|
|
3045
|
+
].includes(newStatus);
|
|
3046
|
+
}
|
|
3047
|
+
function getStatusProgress(status) {
|
|
3048
|
+
const progressMap = {
|
|
3049
|
+
CREATED: 10,
|
|
3050
|
+
PAYMENT_RESERVED: 25,
|
|
3051
|
+
MERCHANT_ACCEPTED: 40,
|
|
3052
|
+
SETTLED: 50,
|
|
3053
|
+
SHIPPED: 75,
|
|
3054
|
+
DELIVERED: 100,
|
|
3055
|
+
CANCELLED: 0
|
|
3056
|
+
};
|
|
3057
|
+
return progressMap[status] || 0;
|
|
3058
|
+
}
|
|
3059
|
+
|
|
3060
|
+
export { BannerType, BaseEcommerceClient, CustomerEcommerceClient, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, InventoryAuditAction, MerchantBusinessType, MerchantEcommerceClient, MerchantReturnPolicyType, MerchantStatus, ORDER_STATUS_TRANSITIONS, OrderStatus, PaymentMethod, PaymentStatus, ProductSortBy, ReturnStatus, ReviewSortBy, ReviewStatus, ShipmentStatus, SortOrder, TaxBehavior, TaxReportPeriodType, TaxReportStatus, TaxType, buildQueryString, calculateDiscountAmount, calculateFinalPrice, canCancelOrder, formatPrice, getBackoffDelay, getNextStatuses, getStatusColor, getStatusLabel, getStatusProgress, isPickupOrder, isRetryableError, isValidAddress, isValidEmail, parseError, requiresTrackingInfo, retryWithBackoff, shouldNotifyCustomer, sleep, truncateAddress, validateStatusTransition };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarginTables,
|
|
1
|
+
import { MarginTables, PerpDex as PerpDex$1, PerpsAssetCtx, InfoClient, SpotMeta, SpotToken } from '@nktkas/hyperliquid';
|
|
2
2
|
|
|
3
3
|
interface PerpsMeta {
|
|
4
4
|
collateralToken: number;
|
|
@@ -179,4 +179,4 @@ declare class InstrumentClient {
|
|
|
179
179
|
private extractDexNameFromMeta;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
export { type AllPerpsMeta as A, type BaseInstrument as B, InstrumentClient as I, type MarketInstrument as M, type
|
|
182
|
+
export { type AllPerpsMeta as A, type BaseInstrument as B, InstrumentClient as I, type MarketInstrument as M, type PerpDex as P, type SpotInstrument as S, AssetIdUtils as a, type PerpsInstrument as b, type PerpsMeta as c, type PerpsMetaAndAssetCtxs as d, type PerpsUniverse as e, getAllPerpsMeta as g };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarginTables,
|
|
1
|
+
import { MarginTables, PerpDex as PerpDex$1, PerpsAssetCtx, InfoClient, SpotMeta, SpotToken } from '@nktkas/hyperliquid';
|
|
2
2
|
|
|
3
3
|
interface PerpsMeta {
|
|
4
4
|
collateralToken: number;
|
|
@@ -179,4 +179,4 @@ declare class InstrumentClient {
|
|
|
179
179
|
private extractDexNameFromMeta;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
export { type AllPerpsMeta as A, type BaseInstrument as B, InstrumentClient as I, type MarketInstrument as M, type
|
|
182
|
+
export { type AllPerpsMeta as A, type BaseInstrument as B, InstrumentClient as I, type MarketInstrument as M, type PerpDex as P, type SpotInstrument as S, AssetIdUtils as a, type PerpsInstrument as b, type PerpsMeta as c, type PerpsMetaAndAssetCtxs as d, type PerpsUniverse as e, getAllPerpsMeta as g };
|
package/dist/ecommerce.d.mts
CHANGED
|
@@ -192,6 +192,8 @@ declare enum OrderStatus {
|
|
|
192
192
|
DELIVERED = "DELIVERED",
|
|
193
193
|
/** Order has been cancelled */
|
|
194
194
|
CANCELLED = "CANCELLED",
|
|
195
|
+
/** Payment settled / escrow released to merchant */
|
|
196
|
+
SETTLED = "SETTLED",
|
|
195
197
|
/** Order is confirmed (legacy status) */
|
|
196
198
|
CONFIRMED = "CONFIRMED",
|
|
197
199
|
/** Order is completed (legacy status) */
|
|
@@ -437,8 +439,10 @@ declare enum ProductSortBy {
|
|
|
437
439
|
PRICE_ASC = "price_asc",
|
|
438
440
|
/** Sort by price (high to low) */
|
|
439
441
|
PRICE_DESC = "price_desc",
|
|
440
|
-
/** Sort by popularity */
|
|
442
|
+
/** Sort by popularity (views) */
|
|
441
443
|
POPULAR = "popular",
|
|
444
|
+
/** Sort by best selling (sold quantity) */
|
|
445
|
+
BEST_SELLING = "best_selling",
|
|
442
446
|
/** Sort by featured status */
|
|
443
447
|
FEATURED = "featured",
|
|
444
448
|
/** Sort by proximity to user location (requires lat/lng) */
|
|
@@ -770,6 +774,20 @@ interface Order extends BaseEntity {
|
|
|
770
774
|
};
|
|
771
775
|
/** Order events */
|
|
772
776
|
events?: OrderEvent[];
|
|
777
|
+
/** Expected ship date */
|
|
778
|
+
expectedShipDate?: string | null;
|
|
779
|
+
/** Estimated delivery date */
|
|
780
|
+
estimatedDeliveryDate?: string | null;
|
|
781
|
+
/** Estimated delivery days */
|
|
782
|
+
estimatedDeliveryDays?: number | null;
|
|
783
|
+
/** Auto-complete deadline */
|
|
784
|
+
autoCompleteDeadline?: string | null;
|
|
785
|
+
/** Customer confirmed receipt timestamp */
|
|
786
|
+
customerConfirmedAt?: string | null;
|
|
787
|
+
/** Auto-completed timestamp */
|
|
788
|
+
autoCompletedAt?: string | null;
|
|
789
|
+
/** Status transition timestamps */
|
|
790
|
+
statusTransitions?: Record<string, string> | null;
|
|
773
791
|
}
|
|
774
792
|
/**
|
|
775
793
|
* Order event entity
|
|
@@ -2288,6 +2306,10 @@ interface ValidateDiscountResponse {
|
|
|
2288
2306
|
/** Discount amount */
|
|
2289
2307
|
discountAmount: number;
|
|
2290
2308
|
};
|
|
2309
|
+
/** Merchant ID the discount belongs to */
|
|
2310
|
+
merchantId?: string;
|
|
2311
|
+
/** Merchant name the discount belongs to */
|
|
2312
|
+
merchantName?: string | null;
|
|
2291
2313
|
/** Subtotal */
|
|
2292
2314
|
subtotal?: number;
|
|
2293
2315
|
/** Total */
|
|
@@ -3207,6 +3229,30 @@ interface CashAccountBalanceResponse {
|
|
|
3207
3229
|
/** Currency code (e.g., "USD") */
|
|
3208
3230
|
currency: string;
|
|
3209
3231
|
}
|
|
3232
|
+
interface CustomerNotification {
|
|
3233
|
+
id: string;
|
|
3234
|
+
type: string;
|
|
3235
|
+
title: string;
|
|
3236
|
+
message: string;
|
|
3237
|
+
metadata: Record<string, any> | null;
|
|
3238
|
+
isRead: boolean;
|
|
3239
|
+
createdAt: string;
|
|
3240
|
+
}
|
|
3241
|
+
interface CustomerNotificationsResponse {
|
|
3242
|
+
notifications: CustomerNotification[];
|
|
3243
|
+
stats: {
|
|
3244
|
+
unread: number;
|
|
3245
|
+
};
|
|
3246
|
+
pagination: {
|
|
3247
|
+
total: number;
|
|
3248
|
+
limit: number;
|
|
3249
|
+
offset: number;
|
|
3250
|
+
hasMore: boolean;
|
|
3251
|
+
};
|
|
3252
|
+
}
|
|
3253
|
+
interface MarkNotificationsReadResponse {
|
|
3254
|
+
updated: number;
|
|
3255
|
+
}
|
|
3210
3256
|
interface DeliveryAddressResponse {
|
|
3211
3257
|
name: string;
|
|
3212
3258
|
phoneNumber: string;
|
|
@@ -4013,6 +4059,32 @@ declare class CustomerEcommerceClient extends BaseEcommerceClient {
|
|
|
4013
4059
|
* ```
|
|
4014
4060
|
*/
|
|
4015
4061
|
getDeliveryAddress(): Promise<DeliveryAddressResponse>;
|
|
4062
|
+
/**
|
|
4063
|
+
* Get user's Hyperliquid USDC balance (perp withdrawable)
|
|
4064
|
+
*
|
|
4065
|
+
* Returns the USDC balance available for escrow deposits via usdSend.
|
|
4066
|
+
*
|
|
4067
|
+
* @returns Balance response with amount and currency
|
|
4068
|
+
*/
|
|
4069
|
+
getUsdcBalance(): Promise<CashAccountBalanceResponse>;
|
|
4070
|
+
/**
|
|
4071
|
+
* List notifications for the authenticated customer
|
|
4072
|
+
*
|
|
4073
|
+
* @param params - Query parameters for filtering and pagination
|
|
4074
|
+
* @returns Paginated list of notifications with unread count
|
|
4075
|
+
*/
|
|
4076
|
+
listNotifications(params?: {
|
|
4077
|
+
limit?: number;
|
|
4078
|
+
offset?: number;
|
|
4079
|
+
unreadOnly?: boolean;
|
|
4080
|
+
}): Promise<CustomerNotificationsResponse>;
|
|
4081
|
+
/**
|
|
4082
|
+
* Mark notifications as read
|
|
4083
|
+
*
|
|
4084
|
+
* @param ids - Specific notification IDs to mark as read. If omitted, marks all as read.
|
|
4085
|
+
* @returns Count of updated notifications
|
|
4086
|
+
*/
|
|
4087
|
+
markNotificationsAsRead(ids?: string[]): Promise<MarkNotificationsReadResponse>;
|
|
4016
4088
|
}
|
|
4017
4089
|
|
|
4018
4090
|
/**
|
|
@@ -5727,4 +5799,52 @@ declare function calculateDiscountAmount(price: number, discountType: "PERCENTAG
|
|
|
5727
5799
|
*/
|
|
5728
5800
|
declare function calculateFinalPrice(price: number, discountType: "PERCENTAGE" | "FIXED_AMOUNT", discountValue: number): number;
|
|
5729
5801
|
|
|
5730
|
-
|
|
5802
|
+
/** Detect pickup / on-site-collection shipping methods (normalised matching) */
|
|
5803
|
+
declare function isPickupOrder(shippingMethod?: string | null, shippingRateId?: string | null): boolean;
|
|
5804
|
+
/**
|
|
5805
|
+
* Canonical order status transitions.
|
|
5806
|
+
*
|
|
5807
|
+
* Buyer-protected escrow flow:
|
|
5808
|
+
* CREATED → PAYMENT_RESERVED → MERCHANT_ACCEPTED → SHIPPED → DELIVERED → SETTLED
|
|
5809
|
+
*
|
|
5810
|
+
* Cancellation is allowed from any non-terminal state except DELIVERED (already in settlement).
|
|
5811
|
+
*/
|
|
5812
|
+
declare const ORDER_STATUS_TRANSITIONS: Partial<Record<OrderStatus, OrderStatus[]>>;
|
|
5813
|
+
/**
|
|
5814
|
+
* Validate whether transitioning from `currentStatus` to `newStatus` is allowed.
|
|
5815
|
+
*
|
|
5816
|
+
* For pickup / on-site-collection orders, MERCHANT_ACCEPTED → DELIVERED and
|
|
5817
|
+
* SETTLED → DELIVERED are permitted (skipping SHIPPED).
|
|
5818
|
+
*/
|
|
5819
|
+
declare function validateStatusTransition(currentStatus: string, newStatus: string, options?: {
|
|
5820
|
+
shippingMethod?: string | null;
|
|
5821
|
+
shippingRateId?: string | null;
|
|
5822
|
+
}): {
|
|
5823
|
+
valid: boolean;
|
|
5824
|
+
error?: string;
|
|
5825
|
+
};
|
|
5826
|
+
/**
|
|
5827
|
+
* Return the list of statuses reachable from `currentStatus`.
|
|
5828
|
+
* For pickup orders, DELIVERED is added when on MERCHANT_ACCEPTED or SETTLED.
|
|
5829
|
+
*/
|
|
5830
|
+
declare function getNextStatuses(currentStatus: string, options?: {
|
|
5831
|
+
shippingMethod?: string | null;
|
|
5832
|
+
shippingRateId?: string | null;
|
|
5833
|
+
}): string[];
|
|
5834
|
+
/** Human-readable label for a status. */
|
|
5835
|
+
declare function getStatusLabel(status: string): string;
|
|
5836
|
+
/** UI colour key for a status. */
|
|
5837
|
+
declare function getStatusColor(status: string): string;
|
|
5838
|
+
/** Whether the order can be cancelled from its current status. */
|
|
5839
|
+
declare function canCancelOrder(currentStatus: string): boolean;
|
|
5840
|
+
/** Whether tracking info is required for a status change. */
|
|
5841
|
+
declare function requiresTrackingInfo(newStatus: string, options?: {
|
|
5842
|
+
shippingMethod?: string | null;
|
|
5843
|
+
shippingRateId?: string | null;
|
|
5844
|
+
}): boolean;
|
|
5845
|
+
/** Whether a status change should trigger customer notification. */
|
|
5846
|
+
declare function shouldNotifyCustomer(newStatus: string): boolean;
|
|
5847
|
+
/** Status progression percentage (for progress bars). */
|
|
5848
|
+
declare function getStatusProgress(status: string): number;
|
|
5849
|
+
|
|
5850
|
+
export { type ActiveFlashSalesResponse, type AnalyticsOverview, type ApiResponse, type AppliedDiscount, type Banner, type BannerResponse, BannerType, BaseEcommerceClient, type BaseEntity, type BrowsingLocation, type CalculateCartDiscountsRequest, type CalculateCartDiscountsResponse, type CalculateShippingRequest, type CalculateShippingResponse, type CalculateTaxRequest, type CalculateTaxResponse, type CartItem, type CashAccountBalanceResponse, 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 CreateShippingRateRequest, type CreateShippingZoneRequest, type CreateTaxNexusRequest, type CreateTaxRuleRequest, CustomerEcommerceClient, type CustomerMessagesResponse, type CustomerNotification, type CustomerNotificationsResponse, type CustomerSummary, type DeleteBrowsingLocationResponse, type DeliveryAddressResponse, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, type EcommerceClientConfig, type ExpiringGemBatch, type FlashSale, type FlashSaleAllowanceInfo, type FlashSaleItem, type FlashSaleItemInput, type FollowActionResponse, type FollowStatusResponse, type FollowedMerchantSummary, type GemHistoryItem, type GemHistoryType, type GemHistoryTypeFilter, type GemSource, type GenerateTaxReportRequest, type GetAnalyticsParams, type GetAnalyticsResponse, type GetBrowsingLocationResponse, type GetCouponResponse, type GetExpiringGemsParams, type GetExpiringGemsResponse, type GetFlashSaleAllowanceParams, type GetFlashSaleAllowanceResponse, type GetGemBalanceResponse, type GetGemHistoryParams, type GetGemHistoryResponse, type GetOrderResponse, type GetPaymentMethodsResponse, type GetProductMetricsResponse, type GetProductResponse, type GetTaxReportResponse, InventoryAuditAction, type InventoryAuditEntry, type ListActiveBannersParams, type ListActiveFlashSalesParams, type ListBannersResponse, type ListCouponsResponse, type ListCustomersParams, type ListCustomersResponse, type ListFollowingParams, type ListFollowingResponse, type ListInventoryAuditResponse, type ListMediaAssetsResponse, type ListMerchantProductsParams, 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 ListShippingRatesResponse, type ListShippingZonesResponse, type ListTaxNexusResponse, type ListTaxReportsParams, type ListTaxReportsResponse, type ListTaxRulesResponse, type MarkNotificationsReadResponse, type MediaAsset, type MediaAssetResponse, type Merchant, MerchantBusinessType, MerchantEcommerceClient, type MerchantProductsResponse, type MerchantProfileRequest, type MerchantProfileResponse, MerchantReturnPolicyType, type MerchantShippingSettings, type MerchantSocialLinks, MerchantStatus, type Message, type MessageResponse, type MessageStatsResponse, ORDER_STATUS_TRANSITIONS, type Order, type OrderEvent, type OrderItem, type OrderReceiptResponse, OrderStatus, type OrdersByStatus, type PaginatedResponse, type PaginationParams, type Payment, PaymentMethod, type PaymentMethodInfo, PaymentStatus, type ProcessPaymentRequest, type ProcessPaymentResponse, type Product, type ProductDimensions, type ProductDiscountsResponse, type ProductMetrics, type ProductResponse, type ProductReview, ProductSortBy, type ProductVariant, type ProductVariantResponse, type PublicMerchantProfile, type PublicMerchantProfileResponse, type RecentOrderSummary, type RespondToReviewRequest, type Return, type ReturnItem, type ReturnResponse, ReturnStatus, type RevenueByDay, type ReviewResponse, ReviewSortBy, ReviewStatus, type SaveBrowsingLocationRequest, type SaveBrowsingLocationResponse, type SendMessageRequest, type Settlement, type Shipment, type ShipmentResponse, ShipmentStatus, type ShippingAddress$1 as ShippingAddress, type ShippingAddressRequest, type ShippingAddressResponse, type ShippingMethod, type ShippingMethodResponse, type ShippingOption, type ShippingRate, type ShippingRateResponse, type ShippingSettingsResponse, type ShippingZone, type ShippingZoneResponse, 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 UpdateShippingRateRequest, type UpdateShippingSettingsRequest, type UpdateShippingZoneRequest, type UpdateTaxNexusRequest, type UpdateTaxReportStatusRequest, type UpdateTaxRuleRequest, type UpdateTaxSettingsRequest, type UserShippingAddress, type ValidateDiscountRequest, type ValidateDiscountResponse, buildQueryString, calculateDiscountAmount, calculateFinalPrice, canCancelOrder, formatPrice, getBackoffDelay, getNextStatuses, getStatusColor, getStatusLabel, getStatusProgress, isPickupOrder, isRetryableError, isValidAddress, isValidEmail, parseError, requiresTrackingInfo, retryWithBackoff, shouldNotifyCustomer, sleep, truncateAddress, validateStatusTransition };
|
package/dist/ecommerce.d.ts
CHANGED
|
@@ -192,6 +192,8 @@ declare enum OrderStatus {
|
|
|
192
192
|
DELIVERED = "DELIVERED",
|
|
193
193
|
/** Order has been cancelled */
|
|
194
194
|
CANCELLED = "CANCELLED",
|
|
195
|
+
/** Payment settled / escrow released to merchant */
|
|
196
|
+
SETTLED = "SETTLED",
|
|
195
197
|
/** Order is confirmed (legacy status) */
|
|
196
198
|
CONFIRMED = "CONFIRMED",
|
|
197
199
|
/** Order is completed (legacy status) */
|
|
@@ -437,8 +439,10 @@ declare enum ProductSortBy {
|
|
|
437
439
|
PRICE_ASC = "price_asc",
|
|
438
440
|
/** Sort by price (high to low) */
|
|
439
441
|
PRICE_DESC = "price_desc",
|
|
440
|
-
/** Sort by popularity */
|
|
442
|
+
/** Sort by popularity (views) */
|
|
441
443
|
POPULAR = "popular",
|
|
444
|
+
/** Sort by best selling (sold quantity) */
|
|
445
|
+
BEST_SELLING = "best_selling",
|
|
442
446
|
/** Sort by featured status */
|
|
443
447
|
FEATURED = "featured",
|
|
444
448
|
/** Sort by proximity to user location (requires lat/lng) */
|
|
@@ -770,6 +774,20 @@ interface Order extends BaseEntity {
|
|
|
770
774
|
};
|
|
771
775
|
/** Order events */
|
|
772
776
|
events?: OrderEvent[];
|
|
777
|
+
/** Expected ship date */
|
|
778
|
+
expectedShipDate?: string | null;
|
|
779
|
+
/** Estimated delivery date */
|
|
780
|
+
estimatedDeliveryDate?: string | null;
|
|
781
|
+
/** Estimated delivery days */
|
|
782
|
+
estimatedDeliveryDays?: number | null;
|
|
783
|
+
/** Auto-complete deadline */
|
|
784
|
+
autoCompleteDeadline?: string | null;
|
|
785
|
+
/** Customer confirmed receipt timestamp */
|
|
786
|
+
customerConfirmedAt?: string | null;
|
|
787
|
+
/** Auto-completed timestamp */
|
|
788
|
+
autoCompletedAt?: string | null;
|
|
789
|
+
/** Status transition timestamps */
|
|
790
|
+
statusTransitions?: Record<string, string> | null;
|
|
773
791
|
}
|
|
774
792
|
/**
|
|
775
793
|
* Order event entity
|
|
@@ -2288,6 +2306,10 @@ interface ValidateDiscountResponse {
|
|
|
2288
2306
|
/** Discount amount */
|
|
2289
2307
|
discountAmount: number;
|
|
2290
2308
|
};
|
|
2309
|
+
/** Merchant ID the discount belongs to */
|
|
2310
|
+
merchantId?: string;
|
|
2311
|
+
/** Merchant name the discount belongs to */
|
|
2312
|
+
merchantName?: string | null;
|
|
2291
2313
|
/** Subtotal */
|
|
2292
2314
|
subtotal?: number;
|
|
2293
2315
|
/** Total */
|
|
@@ -3207,6 +3229,30 @@ interface CashAccountBalanceResponse {
|
|
|
3207
3229
|
/** Currency code (e.g., "USD") */
|
|
3208
3230
|
currency: string;
|
|
3209
3231
|
}
|
|
3232
|
+
interface CustomerNotification {
|
|
3233
|
+
id: string;
|
|
3234
|
+
type: string;
|
|
3235
|
+
title: string;
|
|
3236
|
+
message: string;
|
|
3237
|
+
metadata: Record<string, any> | null;
|
|
3238
|
+
isRead: boolean;
|
|
3239
|
+
createdAt: string;
|
|
3240
|
+
}
|
|
3241
|
+
interface CustomerNotificationsResponse {
|
|
3242
|
+
notifications: CustomerNotification[];
|
|
3243
|
+
stats: {
|
|
3244
|
+
unread: number;
|
|
3245
|
+
};
|
|
3246
|
+
pagination: {
|
|
3247
|
+
total: number;
|
|
3248
|
+
limit: number;
|
|
3249
|
+
offset: number;
|
|
3250
|
+
hasMore: boolean;
|
|
3251
|
+
};
|
|
3252
|
+
}
|
|
3253
|
+
interface MarkNotificationsReadResponse {
|
|
3254
|
+
updated: number;
|
|
3255
|
+
}
|
|
3210
3256
|
interface DeliveryAddressResponse {
|
|
3211
3257
|
name: string;
|
|
3212
3258
|
phoneNumber: string;
|
|
@@ -4013,6 +4059,32 @@ declare class CustomerEcommerceClient extends BaseEcommerceClient {
|
|
|
4013
4059
|
* ```
|
|
4014
4060
|
*/
|
|
4015
4061
|
getDeliveryAddress(): Promise<DeliveryAddressResponse>;
|
|
4062
|
+
/**
|
|
4063
|
+
* Get user's Hyperliquid USDC balance (perp withdrawable)
|
|
4064
|
+
*
|
|
4065
|
+
* Returns the USDC balance available for escrow deposits via usdSend.
|
|
4066
|
+
*
|
|
4067
|
+
* @returns Balance response with amount and currency
|
|
4068
|
+
*/
|
|
4069
|
+
getUsdcBalance(): Promise<CashAccountBalanceResponse>;
|
|
4070
|
+
/**
|
|
4071
|
+
* List notifications for the authenticated customer
|
|
4072
|
+
*
|
|
4073
|
+
* @param params - Query parameters for filtering and pagination
|
|
4074
|
+
* @returns Paginated list of notifications with unread count
|
|
4075
|
+
*/
|
|
4076
|
+
listNotifications(params?: {
|
|
4077
|
+
limit?: number;
|
|
4078
|
+
offset?: number;
|
|
4079
|
+
unreadOnly?: boolean;
|
|
4080
|
+
}): Promise<CustomerNotificationsResponse>;
|
|
4081
|
+
/**
|
|
4082
|
+
* Mark notifications as read
|
|
4083
|
+
*
|
|
4084
|
+
* @param ids - Specific notification IDs to mark as read. If omitted, marks all as read.
|
|
4085
|
+
* @returns Count of updated notifications
|
|
4086
|
+
*/
|
|
4087
|
+
markNotificationsAsRead(ids?: string[]): Promise<MarkNotificationsReadResponse>;
|
|
4016
4088
|
}
|
|
4017
4089
|
|
|
4018
4090
|
/**
|
|
@@ -5727,4 +5799,52 @@ declare function calculateDiscountAmount(price: number, discountType: "PERCENTAG
|
|
|
5727
5799
|
*/
|
|
5728
5800
|
declare function calculateFinalPrice(price: number, discountType: "PERCENTAGE" | "FIXED_AMOUNT", discountValue: number): number;
|
|
5729
5801
|
|
|
5730
|
-
|
|
5802
|
+
/** Detect pickup / on-site-collection shipping methods (normalised matching) */
|
|
5803
|
+
declare function isPickupOrder(shippingMethod?: string | null, shippingRateId?: string | null): boolean;
|
|
5804
|
+
/**
|
|
5805
|
+
* Canonical order status transitions.
|
|
5806
|
+
*
|
|
5807
|
+
* Buyer-protected escrow flow:
|
|
5808
|
+
* CREATED → PAYMENT_RESERVED → MERCHANT_ACCEPTED → SHIPPED → DELIVERED → SETTLED
|
|
5809
|
+
*
|
|
5810
|
+
* Cancellation is allowed from any non-terminal state except DELIVERED (already in settlement).
|
|
5811
|
+
*/
|
|
5812
|
+
declare const ORDER_STATUS_TRANSITIONS: Partial<Record<OrderStatus, OrderStatus[]>>;
|
|
5813
|
+
/**
|
|
5814
|
+
* Validate whether transitioning from `currentStatus` to `newStatus` is allowed.
|
|
5815
|
+
*
|
|
5816
|
+
* For pickup / on-site-collection orders, MERCHANT_ACCEPTED → DELIVERED and
|
|
5817
|
+
* SETTLED → DELIVERED are permitted (skipping SHIPPED).
|
|
5818
|
+
*/
|
|
5819
|
+
declare function validateStatusTransition(currentStatus: string, newStatus: string, options?: {
|
|
5820
|
+
shippingMethod?: string | null;
|
|
5821
|
+
shippingRateId?: string | null;
|
|
5822
|
+
}): {
|
|
5823
|
+
valid: boolean;
|
|
5824
|
+
error?: string;
|
|
5825
|
+
};
|
|
5826
|
+
/**
|
|
5827
|
+
* Return the list of statuses reachable from `currentStatus`.
|
|
5828
|
+
* For pickup orders, DELIVERED is added when on MERCHANT_ACCEPTED or SETTLED.
|
|
5829
|
+
*/
|
|
5830
|
+
declare function getNextStatuses(currentStatus: string, options?: {
|
|
5831
|
+
shippingMethod?: string | null;
|
|
5832
|
+
shippingRateId?: string | null;
|
|
5833
|
+
}): string[];
|
|
5834
|
+
/** Human-readable label for a status. */
|
|
5835
|
+
declare function getStatusLabel(status: string): string;
|
|
5836
|
+
/** UI colour key for a status. */
|
|
5837
|
+
declare function getStatusColor(status: string): string;
|
|
5838
|
+
/** Whether the order can be cancelled from its current status. */
|
|
5839
|
+
declare function canCancelOrder(currentStatus: string): boolean;
|
|
5840
|
+
/** Whether tracking info is required for a status change. */
|
|
5841
|
+
declare function requiresTrackingInfo(newStatus: string, options?: {
|
|
5842
|
+
shippingMethod?: string | null;
|
|
5843
|
+
shippingRateId?: string | null;
|
|
5844
|
+
}): boolean;
|
|
5845
|
+
/** Whether a status change should trigger customer notification. */
|
|
5846
|
+
declare function shouldNotifyCustomer(newStatus: string): boolean;
|
|
5847
|
+
/** Status progression percentage (for progress bars). */
|
|
5848
|
+
declare function getStatusProgress(status: string): number;
|
|
5849
|
+
|
|
5850
|
+
export { type ActiveFlashSalesResponse, type AnalyticsOverview, type ApiResponse, type AppliedDiscount, type Banner, type BannerResponse, BannerType, BaseEcommerceClient, type BaseEntity, type BrowsingLocation, type CalculateCartDiscountsRequest, type CalculateCartDiscountsResponse, type CalculateShippingRequest, type CalculateShippingResponse, type CalculateTaxRequest, type CalculateTaxResponse, type CartItem, type CashAccountBalanceResponse, 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 CreateShippingRateRequest, type CreateShippingZoneRequest, type CreateTaxNexusRequest, type CreateTaxRuleRequest, CustomerEcommerceClient, type CustomerMessagesResponse, type CustomerNotification, type CustomerNotificationsResponse, type CustomerSummary, type DeleteBrowsingLocationResponse, type DeliveryAddressResponse, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, type EcommerceClientConfig, type ExpiringGemBatch, type FlashSale, type FlashSaleAllowanceInfo, type FlashSaleItem, type FlashSaleItemInput, type FollowActionResponse, type FollowStatusResponse, type FollowedMerchantSummary, type GemHistoryItem, type GemHistoryType, type GemHistoryTypeFilter, type GemSource, type GenerateTaxReportRequest, type GetAnalyticsParams, type GetAnalyticsResponse, type GetBrowsingLocationResponse, type GetCouponResponse, type GetExpiringGemsParams, type GetExpiringGemsResponse, type GetFlashSaleAllowanceParams, type GetFlashSaleAllowanceResponse, type GetGemBalanceResponse, type GetGemHistoryParams, type GetGemHistoryResponse, type GetOrderResponse, type GetPaymentMethodsResponse, type GetProductMetricsResponse, type GetProductResponse, type GetTaxReportResponse, InventoryAuditAction, type InventoryAuditEntry, type ListActiveBannersParams, type ListActiveFlashSalesParams, type ListBannersResponse, type ListCouponsResponse, type ListCustomersParams, type ListCustomersResponse, type ListFollowingParams, type ListFollowingResponse, type ListInventoryAuditResponse, type ListMediaAssetsResponse, type ListMerchantProductsParams, 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 ListShippingRatesResponse, type ListShippingZonesResponse, type ListTaxNexusResponse, type ListTaxReportsParams, type ListTaxReportsResponse, type ListTaxRulesResponse, type MarkNotificationsReadResponse, type MediaAsset, type MediaAssetResponse, type Merchant, MerchantBusinessType, MerchantEcommerceClient, type MerchantProductsResponse, type MerchantProfileRequest, type MerchantProfileResponse, MerchantReturnPolicyType, type MerchantShippingSettings, type MerchantSocialLinks, MerchantStatus, type Message, type MessageResponse, type MessageStatsResponse, ORDER_STATUS_TRANSITIONS, type Order, type OrderEvent, type OrderItem, type OrderReceiptResponse, OrderStatus, type OrdersByStatus, type PaginatedResponse, type PaginationParams, type Payment, PaymentMethod, type PaymentMethodInfo, PaymentStatus, type ProcessPaymentRequest, type ProcessPaymentResponse, type Product, type ProductDimensions, type ProductDiscountsResponse, type ProductMetrics, type ProductResponse, type ProductReview, ProductSortBy, type ProductVariant, type ProductVariantResponse, type PublicMerchantProfile, type PublicMerchantProfileResponse, type RecentOrderSummary, type RespondToReviewRequest, type Return, type ReturnItem, type ReturnResponse, ReturnStatus, type RevenueByDay, type ReviewResponse, ReviewSortBy, ReviewStatus, type SaveBrowsingLocationRequest, type SaveBrowsingLocationResponse, type SendMessageRequest, type Settlement, type Shipment, type ShipmentResponse, ShipmentStatus, type ShippingAddress$1 as ShippingAddress, type ShippingAddressRequest, type ShippingAddressResponse, type ShippingMethod, type ShippingMethodResponse, type ShippingOption, type ShippingRate, type ShippingRateResponse, type ShippingSettingsResponse, type ShippingZone, type ShippingZoneResponse, 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 UpdateShippingRateRequest, type UpdateShippingSettingsRequest, type UpdateShippingZoneRequest, type UpdateTaxNexusRequest, type UpdateTaxReportStatusRequest, type UpdateTaxRuleRequest, type UpdateTaxSettingsRequest, type UserShippingAddress, type ValidateDiscountRequest, type ValidateDiscountResponse, buildQueryString, calculateDiscountAmount, calculateFinalPrice, canCancelOrder, formatPrice, getBackoffDelay, getNextStatuses, getStatusColor, getStatusLabel, getStatusProgress, isPickupOrder, isRetryableError, isValidAddress, isValidEmail, parseError, requiresTrackingInfo, retryWithBackoff, shouldNotifyCustomer, sleep, truncateAddress, validateStatusTransition };
|