@basedone/core 0.2.1 → 0.2.3
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-MVFO4WRF.mjs → chunk-SKX4VGEN.mjs} +573 -1
- package/dist/ecommerce.d.mts +1220 -7
- package/dist/ecommerce.d.ts +1220 -7
- package/dist/ecommerce.js +573 -1
- package/dist/ecommerce.mjs +1 -1
- package/dist/index.d.mts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +580 -1
- package/dist/index.mjs +8 -2
- package/lib/ecommerce/QUICK_REFERENCE.md +26 -0
- package/lib/ecommerce/README.md +26 -0
- package/lib/ecommerce/client/base.ts +7 -1
- package/lib/ecommerce/client/customer.ts +190 -0
- package/lib/ecommerce/client/merchant.ts +783 -0
- package/lib/ecommerce/types/entities.ts +94 -0
- package/lib/ecommerce/types/enums.ts +5 -1
- package/lib/ecommerce/types/requests.ts +122 -0
- package/lib/ecommerce/types/responses.ts +244 -0
- package/lib/utils/formatter.ts +1 -1
- package/lib/utils/time.ts +24 -0
- package/package.json +3 -2
|
@@ -789,3 +789,97 @@ export interface FlashSale {
|
|
|
789
789
|
items: FlashSaleItem[];
|
|
790
790
|
}
|
|
791
791
|
|
|
792
|
+
// ============================================
|
|
793
|
+
// SHIPPING ENTITIES
|
|
794
|
+
// ============================================
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Merchant shipping settings entity
|
|
798
|
+
*/
|
|
799
|
+
export interface MerchantShippingSettings extends BaseEntity {
|
|
800
|
+
/** Merchant ID */
|
|
801
|
+
merchantId: string;
|
|
802
|
+
/** Default handling fee in USDC */
|
|
803
|
+
defaultHandlingFee: number;
|
|
804
|
+
/** Default processing time in days */
|
|
805
|
+
defaultProcessingDays: number;
|
|
806
|
+
/** Default product weight in kg */
|
|
807
|
+
defaultWeightKg: number;
|
|
808
|
+
/** Free shipping enabled globally */
|
|
809
|
+
freeShippingEnabled: boolean;
|
|
810
|
+
/** Free shipping threshold in USDC */
|
|
811
|
+
freeShippingThreshold: number | null;
|
|
812
|
+
/** Show estimated delivery to customers */
|
|
813
|
+
showEstimatedDelivery: boolean;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Shipping zone entity
|
|
818
|
+
*/
|
|
819
|
+
export interface ShippingZone extends BaseEntity {
|
|
820
|
+
/** Merchant ID */
|
|
821
|
+
merchantId: string;
|
|
822
|
+
/** Zone name */
|
|
823
|
+
name: string;
|
|
824
|
+
/** Country codes (ISO 2-letter codes) */
|
|
825
|
+
countries: string[];
|
|
826
|
+
/** Is default zone for unlisted countries */
|
|
827
|
+
isDefault: boolean;
|
|
828
|
+
/** Is zone active */
|
|
829
|
+
isActive: boolean;
|
|
830
|
+
/** Priority (higher = checked first) */
|
|
831
|
+
priority: number;
|
|
832
|
+
/** Number of rates in this zone */
|
|
833
|
+
rateCount?: number;
|
|
834
|
+
/** Associated shipping rates */
|
|
835
|
+
rates?: ShippingRate[];
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Shipping rate entity
|
|
840
|
+
*/
|
|
841
|
+
export interface ShippingRate extends BaseEntity {
|
|
842
|
+
/** Zone ID */
|
|
843
|
+
zoneId: string;
|
|
844
|
+
/** Zone name (for display) */
|
|
845
|
+
zoneName?: string;
|
|
846
|
+
/** Merchant ID */
|
|
847
|
+
merchantId: string;
|
|
848
|
+
/** Rate name (e.g., "Standard", "Express") */
|
|
849
|
+
name: string;
|
|
850
|
+
/** Base shipping rate in USDC */
|
|
851
|
+
baseRate: number;
|
|
852
|
+
/** Per kg rate in USDC */
|
|
853
|
+
perKgRate: number;
|
|
854
|
+
/** Minimum weight in kg */
|
|
855
|
+
minWeightKg: number | null;
|
|
856
|
+
/** Maximum weight in kg */
|
|
857
|
+
maxWeightKg: number | null;
|
|
858
|
+
/** Minimum delivery days */
|
|
859
|
+
minDeliveryDays: number | null;
|
|
860
|
+
/** Maximum delivery days */
|
|
861
|
+
maxDeliveryDays: number | null;
|
|
862
|
+
/** Free shipping above this amount */
|
|
863
|
+
freeAboveAmount: number | null;
|
|
864
|
+
/** Is rate active */
|
|
865
|
+
isActive: boolean;
|
|
866
|
+
/** Sort order */
|
|
867
|
+
sortOrder: number;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Shipping option (calculated for checkout)
|
|
872
|
+
*/
|
|
873
|
+
export interface ShippingOption {
|
|
874
|
+
/** Rate ID */
|
|
875
|
+
id: string;
|
|
876
|
+
/** Rate name */
|
|
877
|
+
name: string;
|
|
878
|
+
/** Calculated cost in USDC */
|
|
879
|
+
cost: number;
|
|
880
|
+
/** Estimated delivery string */
|
|
881
|
+
estimatedDelivery: string;
|
|
882
|
+
/** Zone name */
|
|
883
|
+
zoneName: string;
|
|
884
|
+
}
|
|
885
|
+
|
|
@@ -32,8 +32,12 @@ export enum OrderStatus {
|
|
|
32
32
|
* Payment method enum
|
|
33
33
|
*/
|
|
34
34
|
export enum PaymentMethod {
|
|
35
|
-
/** USDC payment via Hyperliquid
|
|
35
|
+
/** USDC payment via Hyperliquid SpotTransfer */
|
|
36
36
|
USDC_ESCROW = "USDC_ESCROW",
|
|
37
|
+
/** BasedPay external ledger payment */
|
|
38
|
+
BASEDPAY = "BASEDPAY",
|
|
39
|
+
/** Stripe card payment */
|
|
40
|
+
STRIPE = "STRIPE",
|
|
37
41
|
/** Points-based payment */
|
|
38
42
|
POINTS = "POINTS",
|
|
39
43
|
}
|
|
@@ -144,6 +144,14 @@ export interface CreateOrderRequest {
|
|
|
144
144
|
couponCode?: string;
|
|
145
145
|
/** Idempotency key */
|
|
146
146
|
idempotencyKey?: string;
|
|
147
|
+
/** Selected shipping method name (e.g., "Standard", "Express") */
|
|
148
|
+
shippingMethod?: string;
|
|
149
|
+
/** Calculated shipping cost in USDC */
|
|
150
|
+
shippingCost?: number;
|
|
151
|
+
/** Shipping zone name for reference */
|
|
152
|
+
shippingZone?: string;
|
|
153
|
+
/** Estimated delivery time (e.g., "5-7 business days") */
|
|
154
|
+
estimatedDelivery?: string;
|
|
147
155
|
}
|
|
148
156
|
|
|
149
157
|
/**
|
|
@@ -578,3 +586,117 @@ export interface CreateFlashSaleRequest {
|
|
|
578
586
|
*/
|
|
579
587
|
export interface UpdateFlashSaleRequest extends Partial<CreateFlashSaleRequest> {}
|
|
580
588
|
|
|
589
|
+
/**
|
|
590
|
+
* List merchant products params
|
|
591
|
+
*/
|
|
592
|
+
export interface ListMerchantProductsParams extends PaginationParams {
|
|
593
|
+
/** Search query */
|
|
594
|
+
search?: string;
|
|
595
|
+
/** Filter by category slug */
|
|
596
|
+
category?: string;
|
|
597
|
+
/** Minimum price */
|
|
598
|
+
minPrice?: number;
|
|
599
|
+
/** Maximum price */
|
|
600
|
+
maxPrice?: number;
|
|
601
|
+
/** Sort by: popular, latest, top_sales, price_asc, price_desc, rating */
|
|
602
|
+
sortBy?: "popular" | "latest" | "top_sales" | "price_asc" | "price_desc" | "rating";
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* List followed merchants params
|
|
607
|
+
*/
|
|
608
|
+
export interface ListFollowingParams extends PaginationParams {
|
|
609
|
+
/** Sort by: recent (default) or name */
|
|
610
|
+
sortBy?: "recent" | "name";
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// ============================================
|
|
614
|
+
// SHIPPING REQUESTS
|
|
615
|
+
// ============================================
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Update shipping settings request
|
|
619
|
+
*/
|
|
620
|
+
export interface UpdateShippingSettingsRequest {
|
|
621
|
+
/** Default handling fee in USDC */
|
|
622
|
+
defaultHandlingFee?: number;
|
|
623
|
+
/** Default processing time in days */
|
|
624
|
+
defaultProcessingDays?: number;
|
|
625
|
+
/** Default product weight in kg */
|
|
626
|
+
defaultWeightKg?: number;
|
|
627
|
+
/** Free shipping enabled globally */
|
|
628
|
+
freeShippingEnabled?: boolean;
|
|
629
|
+
/** Free shipping threshold in USDC */
|
|
630
|
+
freeShippingThreshold?: number | null;
|
|
631
|
+
/** Show estimated delivery to customers */
|
|
632
|
+
showEstimatedDelivery?: boolean;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Create shipping zone request
|
|
637
|
+
*/
|
|
638
|
+
export interface CreateShippingZoneRequest {
|
|
639
|
+
/** Zone name */
|
|
640
|
+
name: string;
|
|
641
|
+
/** Country codes (ISO 2-letter codes) */
|
|
642
|
+
countries: string[];
|
|
643
|
+
/** Is default zone for unlisted countries */
|
|
644
|
+
isDefault?: boolean;
|
|
645
|
+
/** Is zone active */
|
|
646
|
+
isActive?: boolean;
|
|
647
|
+
/** Priority (higher = checked first) */
|
|
648
|
+
priority?: number;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Update shipping zone request
|
|
653
|
+
*/
|
|
654
|
+
export interface UpdateShippingZoneRequest extends Partial<CreateShippingZoneRequest> {}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Create shipping rate request
|
|
658
|
+
*/
|
|
659
|
+
export interface CreateShippingRateRequest {
|
|
660
|
+
/** Zone ID */
|
|
661
|
+
zoneId: string;
|
|
662
|
+
/** Rate name (e.g., "Standard", "Express") */
|
|
663
|
+
name: string;
|
|
664
|
+
/** Base shipping rate in USDC */
|
|
665
|
+
baseRate: number;
|
|
666
|
+
/** Per kg rate in USDC */
|
|
667
|
+
perKgRate?: number;
|
|
668
|
+
/** Minimum weight in kg */
|
|
669
|
+
minWeightKg?: number | null;
|
|
670
|
+
/** Maximum weight in kg */
|
|
671
|
+
maxWeightKg?: number | null;
|
|
672
|
+
/** Minimum delivery days */
|
|
673
|
+
minDeliveryDays?: number | null;
|
|
674
|
+
/** Maximum delivery days */
|
|
675
|
+
maxDeliveryDays?: number | null;
|
|
676
|
+
/** Free shipping above this amount */
|
|
677
|
+
freeAboveAmount?: number | null;
|
|
678
|
+
/** Is rate active */
|
|
679
|
+
isActive?: boolean;
|
|
680
|
+
/** Sort order */
|
|
681
|
+
sortOrder?: number;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Update shipping rate request
|
|
686
|
+
*/
|
|
687
|
+
export interface UpdateShippingRateRequest extends Partial<Omit<CreateShippingRateRequest, "zoneId">> {}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Calculate shipping options request
|
|
691
|
+
*/
|
|
692
|
+
export interface CalculateShippingRequest {
|
|
693
|
+
/** Merchant ID */
|
|
694
|
+
merchantId: string;
|
|
695
|
+
/** Cart items */
|
|
696
|
+
cartItems: CartItem[];
|
|
697
|
+
/** Destination country code (ISO 2-letter) */
|
|
698
|
+
destinationCountry: string;
|
|
699
|
+
/** Order subtotal in USDC */
|
|
700
|
+
orderSubtotal: number;
|
|
701
|
+
}
|
|
702
|
+
|
|
@@ -340,6 +340,102 @@ export interface MerchantProfileResponse {
|
|
|
340
340
|
merchant: Merchant;
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Public merchant profile (for storefront)
|
|
345
|
+
*/
|
|
346
|
+
export interface PublicMerchantProfile {
|
|
347
|
+
/** Merchant ID */
|
|
348
|
+
id: string;
|
|
349
|
+
/** Merchant name */
|
|
350
|
+
name: string;
|
|
351
|
+
/** Description */
|
|
352
|
+
description: string | null;
|
|
353
|
+
/** Created at */
|
|
354
|
+
createdAt: string;
|
|
355
|
+
/** Number of active products */
|
|
356
|
+
productCount: number;
|
|
357
|
+
/** Total orders */
|
|
358
|
+
orderCount: number;
|
|
359
|
+
/** Average rating */
|
|
360
|
+
averageRating: number | null;
|
|
361
|
+
/** Total sold count */
|
|
362
|
+
totalSold: number;
|
|
363
|
+
/** Total view count */
|
|
364
|
+
totalViews: number;
|
|
365
|
+
/** Review count */
|
|
366
|
+
reviewCount: number;
|
|
367
|
+
/** Follower count */
|
|
368
|
+
followerCount: number;
|
|
369
|
+
/** Categories the merchant sells in */
|
|
370
|
+
categories: string[];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Public merchant profile response
|
|
375
|
+
*/
|
|
376
|
+
export interface PublicMerchantProfileResponse {
|
|
377
|
+
/** Merchant */
|
|
378
|
+
merchant: PublicMerchantProfile;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Merchant products response
|
|
383
|
+
*/
|
|
384
|
+
export interface MerchantProductsResponse extends PaginatedResponse<Product> {
|
|
385
|
+
/** Merchant info */
|
|
386
|
+
merchant: {
|
|
387
|
+
id: string;
|
|
388
|
+
name: string;
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Follow status response
|
|
394
|
+
*/
|
|
395
|
+
export interface FollowStatusResponse {
|
|
396
|
+
/** Whether the user is following */
|
|
397
|
+
isFollowing: boolean;
|
|
398
|
+
/** When the user followed (null if not following) */
|
|
399
|
+
followedAt: string | null;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Follow action response
|
|
404
|
+
*/
|
|
405
|
+
export interface FollowActionResponse {
|
|
406
|
+
/** Success flag */
|
|
407
|
+
success: boolean;
|
|
408
|
+
/** Human-readable message */
|
|
409
|
+
message: string;
|
|
410
|
+
/** Whether the user is now following */
|
|
411
|
+
isFollowing: boolean;
|
|
412
|
+
/** When the user followed (only for follow action) */
|
|
413
|
+
followedAt?: string;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Followed merchant summary
|
|
418
|
+
*/
|
|
419
|
+
export interface FollowedMerchantSummary {
|
|
420
|
+
/** When the user followed */
|
|
421
|
+
followedAt: string;
|
|
422
|
+
/** Merchant info */
|
|
423
|
+
merchant: {
|
|
424
|
+
id: string;
|
|
425
|
+
name: string;
|
|
426
|
+
description: string | null;
|
|
427
|
+
createdAt: string;
|
|
428
|
+
productCount: number;
|
|
429
|
+
averageRating: number | null;
|
|
430
|
+
totalSold: number;
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* List followed merchants response
|
|
436
|
+
*/
|
|
437
|
+
export interface ListFollowingResponse extends PaginatedResponse<FollowedMerchantSummary> {}
|
|
438
|
+
|
|
343
439
|
/**
|
|
344
440
|
* List coupons response
|
|
345
441
|
*/
|
|
@@ -855,3 +951,151 @@ export interface ActiveFlashSalesResponse {
|
|
|
855
951
|
serverTime: string;
|
|
856
952
|
}
|
|
857
953
|
|
|
954
|
+
// ============================================
|
|
955
|
+
// SHIPPING RESPONSES
|
|
956
|
+
// ============================================
|
|
957
|
+
|
|
958
|
+
import type {
|
|
959
|
+
MerchantShippingSettings,
|
|
960
|
+
ShippingZone,
|
|
961
|
+
ShippingRate,
|
|
962
|
+
ShippingOption,
|
|
963
|
+
} from "./entities";
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Get shipping settings response
|
|
967
|
+
*/
|
|
968
|
+
export interface ShippingSettingsResponse {
|
|
969
|
+
/** Shipping settings */
|
|
970
|
+
settings: MerchantShippingSettings | {
|
|
971
|
+
defaultHandlingFee: number;
|
|
972
|
+
defaultProcessingDays: number;
|
|
973
|
+
freeShippingEnabled: boolean;
|
|
974
|
+
freeShippingThreshold: number | null;
|
|
975
|
+
defaultWeightKg: number;
|
|
976
|
+
showEstimatedDelivery: boolean;
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* List shipping zones response
|
|
982
|
+
*/
|
|
983
|
+
export interface ListShippingZonesResponse {
|
|
984
|
+
/** Shipping zones */
|
|
985
|
+
zones: ShippingZone[];
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* Shipping zone response
|
|
990
|
+
*/
|
|
991
|
+
export interface ShippingZoneResponse {
|
|
992
|
+
/** Shipping zone */
|
|
993
|
+
zone: ShippingZone;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* List shipping rates response
|
|
998
|
+
*/
|
|
999
|
+
export interface ListShippingRatesResponse {
|
|
1000
|
+
/** Shipping rates */
|
|
1001
|
+
rates: ShippingRate[];
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Shipping rate response
|
|
1006
|
+
*/
|
|
1007
|
+
export interface ShippingRateResponse {
|
|
1008
|
+
/** Shipping rate */
|
|
1009
|
+
rate: ShippingRate;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* Calculate shipping options response
|
|
1014
|
+
*/
|
|
1015
|
+
export interface CalculateShippingResponse {
|
|
1016
|
+
/** Available shipping options */
|
|
1017
|
+
shippingOptions: ShippingOption[];
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// ============================================================================
|
|
1021
|
+
// Payment Method Responses
|
|
1022
|
+
// ============================================================================
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Payment method info for display
|
|
1026
|
+
*/
|
|
1027
|
+
export interface PaymentMethodInfo {
|
|
1028
|
+
/** Payment method ID (e.g., "USDC_ESCROW") */
|
|
1029
|
+
id: string;
|
|
1030
|
+
/** Display name (e.g., "USDC (Hyperliquid)") */
|
|
1031
|
+
name: string;
|
|
1032
|
+
/** Description of the payment method */
|
|
1033
|
+
description: string;
|
|
1034
|
+
/** Icon identifier */
|
|
1035
|
+
icon?: string;
|
|
1036
|
+
/** Whether the payment requires user signature (e.g., blockchain) */
|
|
1037
|
+
requiresSignature?: boolean;
|
|
1038
|
+
/** Whether refunds are supported */
|
|
1039
|
+
supportsRefund?: boolean;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* Get payment methods response
|
|
1044
|
+
*/
|
|
1045
|
+
export interface GetPaymentMethodsResponse {
|
|
1046
|
+
/** Whether the request was successful */
|
|
1047
|
+
success: boolean;
|
|
1048
|
+
/** Whether payments are globally enabled */
|
|
1049
|
+
paymentsEnabled: boolean;
|
|
1050
|
+
/** List of enabled payment methods */
|
|
1051
|
+
methods: PaymentMethodInfo[];
|
|
1052
|
+
/** Optional message (e.g., when payments are disabled) */
|
|
1053
|
+
message?: string;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Process payment request
|
|
1058
|
+
*/
|
|
1059
|
+
export interface ProcessPaymentRequest {
|
|
1060
|
+
/** Order ID to pay for */
|
|
1061
|
+
orderId: string;
|
|
1062
|
+
/** Payment method to use */
|
|
1063
|
+
paymentMethod: string;
|
|
1064
|
+
/** Amount in USDC */
|
|
1065
|
+
amount: number;
|
|
1066
|
+
/** Pre-signed action for USDC_ESCROW */
|
|
1067
|
+
signedAction?: {
|
|
1068
|
+
action: unknown;
|
|
1069
|
+
nonce: number;
|
|
1070
|
+
signature: unknown;
|
|
1071
|
+
};
|
|
1072
|
+
/** Stripe payment method ID */
|
|
1073
|
+
stripePaymentMethodId?: string;
|
|
1074
|
+
/** BasedPay account ID */
|
|
1075
|
+
basedPayAccountId?: string;
|
|
1076
|
+
/** Points to spend */
|
|
1077
|
+
pointsAmount?: number;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Process payment response
|
|
1082
|
+
*/
|
|
1083
|
+
export interface ProcessPaymentResponse {
|
|
1084
|
+
/** Whether the payment was successful */
|
|
1085
|
+
success: boolean;
|
|
1086
|
+
/** Payment transaction ID */
|
|
1087
|
+
transactionId?: string;
|
|
1088
|
+
/** Blockchain transaction hash (for crypto payments) */
|
|
1089
|
+
transactionHash?: string;
|
|
1090
|
+
/** Payment status */
|
|
1091
|
+
status: "PENDING" | "PROCESSING" | "COMPLETED" | "FAILED" | "CANCELLED" | "REFUNDED";
|
|
1092
|
+
/** Amount charged */
|
|
1093
|
+
amount: number;
|
|
1094
|
+
/** Currency */
|
|
1095
|
+
currency: string;
|
|
1096
|
+
/** Error message if failed */
|
|
1097
|
+
error?: string;
|
|
1098
|
+
/** Error code */
|
|
1099
|
+
errorCode?: string;
|
|
1100
|
+
}
|
|
1101
|
+
|
package/lib/utils/formatter.ts
CHANGED
package/lib/utils/time.ts
CHANGED
|
@@ -49,3 +49,27 @@ export function getLatestCompletedWeek(
|
|
|
49
49
|
return { weekNumber, startDate, endDate };
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Gets week information from a week number.
|
|
54
|
+
* This is the inverse of getLatestCompletedWeek - it converts a week number to start/end dates.
|
|
55
|
+
*
|
|
56
|
+
* @param weekNumber - The week number (1-based, where week 1 starts at WEEK1_START_DATE)
|
|
57
|
+
* @param weekStartsOn - Day of week the week should start on. Defaults to Thursday.
|
|
58
|
+
* @returns WeekInfo with weekNumber, startDate, and endDate
|
|
59
|
+
*/
|
|
60
|
+
export function getWeekInfoFromNumber(
|
|
61
|
+
weekNumber: number,
|
|
62
|
+
weekStartsOn: DayOfWeek = DayOfWeek.Thursday
|
|
63
|
+
): WeekInfo {
|
|
64
|
+
// Using a fixed point in time for week 1 calculation for consistency
|
|
65
|
+
const week1StartDate = new Date(process.env.WEEK1_START_DATE || "2025-12-04T00:00:00Z");
|
|
66
|
+
|
|
67
|
+
// Calculate start date: week 1 starts at week1StartDate, week N starts at week1StartDate + (N-1) weeks
|
|
68
|
+
const startDate = new Date(week1StartDate.getTime() + (weekNumber - 1) * WEEK_IN_MS);
|
|
69
|
+
|
|
70
|
+
// End date is 7 days after start date
|
|
71
|
+
const endDate = new Date(startDate.getTime() + WEEK_IN_MS);
|
|
72
|
+
|
|
73
|
+
return { weekNumber, startDate, endDate };
|
|
74
|
+
}
|
|
75
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basedone/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Core utilities for Based One",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -36,17 +36,18 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^20.0.0",
|
|
38
38
|
"@types/react": "^18.0.0",
|
|
39
|
+
"axios": "^1.6.0",
|
|
39
40
|
"tsup": "^8.5.0",
|
|
40
41
|
"tsx": "^4.19.2",
|
|
41
42
|
"typescript": "^5.0.0",
|
|
42
43
|
"vitest": "^3.2.4"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
45
|
-
"axios": "^1.6.0",
|
|
46
46
|
"decimal.js": "^10.6.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@nktkas/hyperliquid": "^0.24.3",
|
|
50
|
+
"axios": "^1.6.0",
|
|
50
51
|
"react": "^18.0.0 || ^19.0.0"
|
|
51
52
|
},
|
|
52
53
|
"peerDependenciesMeta": {
|