@basedone/core 0.2.2 → 0.2.4

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.
@@ -33,6 +33,9 @@ export interface EcommerceClientConfig {
33
33
 
34
34
  /** Enable automatic retry on retryable errors */
35
35
  enableRetry?: boolean;
36
+
37
+ /** Whether to send cookies with requests */
38
+ withCredentials?: boolean;
36
39
  }
37
40
 
38
41
  /**
@@ -55,9 +58,10 @@ export interface EcommerceClientConfig {
55
58
  */
56
59
  export class BaseEcommerceClient {
57
60
  private axiosInstance: AxiosInstance;
58
- private config: Required<Omit<EcommerceClientConfig, "authToken" | "headers">> & {
61
+ private config: Required<Omit<EcommerceClientConfig, "authToken" | "headers" | "withCredentials">> & {
59
62
  authToken?: string;
60
63
  headers?: Record<string, string>;
64
+ withCredentials?: boolean;
61
65
  };
62
66
 
63
67
  constructor(config: EcommerceClientConfig) {
@@ -69,11 +73,13 @@ export class BaseEcommerceClient {
69
73
  retryBaseDelay: config.retryBaseDelay || 1000,
70
74
  headers: config.headers,
71
75
  enableRetry: config.enableRetry !== false,
76
+ withCredentials: config.withCredentials || false,
72
77
  };
73
78
 
74
79
  this.axiosInstance = axios.create({
75
80
  baseURL: this.config.baseURL,
76
81
  timeout: this.config.timeout,
82
+ withCredentials: this.config.withCredentials,
77
83
  headers: {
78
84
  "Content-Type": "application/json",
79
85
  ...this.config.headers,
@@ -24,6 +24,10 @@ import type {
24
24
  ListActiveFlashSalesParams,
25
25
  ListMerchantProductsParams,
26
26
  ListFollowingParams,
27
+ CalculateShippingRequest,
28
+ GetGemHistoryParams,
29
+ GetExpiringGemsParams,
30
+ SaveBrowsingLocationRequest,
27
31
 
28
32
  // Response types
29
33
  ListProductsResponse,
@@ -47,11 +51,19 @@ import type {
47
51
  MessageStatsResponse,
48
52
  MessageResponse,
49
53
  ActiveFlashSalesResponse,
54
+ GetPaymentMethodsResponse,
50
55
  PublicMerchantProfileResponse,
51
56
  MerchantProductsResponse,
52
57
  FollowStatusResponse,
53
58
  FollowActionResponse,
54
59
  ListFollowingResponse,
60
+ CalculateShippingResponse,
61
+ GetGemBalanceResponse,
62
+ GetBrowsingLocationResponse,
63
+ SaveBrowsingLocationResponse,
64
+ DeleteBrowsingLocationResponse,
65
+ GetGemHistoryResponse,
66
+ GetExpiringGemsResponse,
55
67
  } from "../types";
56
68
 
57
69
  /**
@@ -488,6 +500,36 @@ export class CustomerEcommerceClient extends BaseEcommerceClient {
488
500
  async calculateTax(request: CalculateTaxRequest): Promise<CalculateTaxResponse> {
489
501
  return this.post("/api/marketplace/tax/calculate", request);
490
502
  }
503
+
504
+ // ============================================================================
505
+ // Shipping Calculation API
506
+ // ============================================================================
507
+
508
+ /**
509
+ * Calculate shipping options for cart items
510
+ *
511
+ * @param request - Cart items, merchant, and destination
512
+ * @returns Available shipping options with costs
513
+ *
514
+ * @example
515
+ * ```typescript
516
+ * const result = await client.calculateShippingOptions({
517
+ * merchantId: "merchant_123",
518
+ * cartItems: [
519
+ * { productId: "prod_123", quantity: 2 }
520
+ * ],
521
+ * destinationCountry: "US",
522
+ * orderSubtotal: 99.99
523
+ * });
524
+ *
525
+ * result.shippingOptions.forEach(opt => {
526
+ * console.log(opt.name, opt.cost, opt.estimatedDelivery);
527
+ * });
528
+ * ```
529
+ */
530
+ async calculateShippingOptions(request: CalculateShippingRequest): Promise<CalculateShippingResponse> {
531
+ return this.post("/api/marketplace/shipping/calculate", request);
532
+ }
491
533
 
492
534
  // ============================================================================
493
535
  // Banners API
@@ -767,5 +809,180 @@ export class CustomerEcommerceClient extends BaseEcommerceClient {
767
809
  const queryString = params ? buildQueryString(params) : "";
768
810
  return this.get(`/api/marketplace/following${queryString}`);
769
811
  }
812
+
813
+ // ============================================================================
814
+ // Payment Methods
815
+ // ============================================================================
816
+
817
+ /**
818
+ * Get available payment methods
819
+ *
820
+ * Returns the list of enabled payment methods that can be used during checkout.
821
+ *
822
+ * @returns List of available payment methods with display info
823
+ *
824
+ * @example
825
+ * ```typescript
826
+ * const result = await client.getPaymentMethods();
827
+ * if (result.paymentsEnabled) {
828
+ * result.methods.forEach(method => {
829
+ * console.log(`${method.name}: ${method.description}`);
830
+ * });
831
+ * }
832
+ * ```
833
+ */
834
+ async getPaymentMethods(): Promise<GetPaymentMethodsResponse> {
835
+ return this.get("/api/marketplace/payments/methods");
836
+ }
837
+
838
+ // ============================================================================
839
+ // GEM System API
840
+ // ============================================================================
841
+
842
+ /**
843
+ * Get user's gem balance
844
+ *
845
+ * Returns the current gem balance including total gems, available gems,
846
+ * and gems expiring soon. Gems are earned at 100 per $1 of revenue.
847
+ *
848
+ * @returns Current gem balance with USD equivalent
849
+ *
850
+ * @example
851
+ * ```typescript
852
+ * const balance = await client.getGemBalance();
853
+ * console.log(`You have ${balance.totalGems} gems (${balance.usdEquivalent} USD)`);
854
+ * console.log(`${balance.expiringSoon} gems expiring soon`);
855
+ * ```
856
+ */
857
+ async getGemBalance(): Promise<GetGemBalanceResponse> {
858
+ return this.get("/api/gems/balance");
859
+ }
860
+
861
+ /**
862
+ * Get gem transaction history
863
+ *
864
+ * Returns paginated history of gem transactions including earning,
865
+ * spending, and expiration events.
866
+ *
867
+ * @param params - Query parameters for filtering and pagination
868
+ * @returns Paginated gem history
869
+ *
870
+ * @example
871
+ * ```typescript
872
+ * // Get all history
873
+ * const history = await client.getGemHistory({ limit: 20, offset: 0 });
874
+ *
875
+ * // Get only earned gems
876
+ * const earned = await client.getGemHistory({ type: "earn", limit: 10 });
877
+ *
878
+ * // Get only spent gems
879
+ * const spent = await client.getGemHistory({ type: "spend", limit: 10 });
880
+ *
881
+ * history.items.forEach(item => {
882
+ * console.log(`${item.type}: ${item.amount} gems - ${item.createdAt}`);
883
+ * });
884
+ * ```
885
+ */
886
+ async getGemHistory(params?: GetGemHistoryParams): Promise<GetGemHistoryResponse> {
887
+ const queryString = params ? buildQueryString(params) : "";
888
+ return this.get(`/api/gems/history${queryString}`);
889
+ }
890
+
891
+ /**
892
+ * Get gems that are expiring soon
893
+ *
894
+ * Returns gem batches that will expire within the specified number of days.
895
+ * Useful for prompting users to spend gems before they expire.
896
+ *
897
+ * @param params - Query parameters (days: default 30, max 180)
898
+ * @returns Expiring gem batches with countdown info
899
+ *
900
+ * @example
901
+ * ```typescript
902
+ * // Get gems expiring in next 30 days (default)
903
+ * const expiring = await client.getExpiringGems();
904
+ *
905
+ * // Get gems expiring in next 7 days
906
+ * const urgent = await client.getExpiringGems({ days: 7 });
907
+ *
908
+ * if (expiring.totalExpiring > 0) {
909
+ * console.log(`${expiring.totalExpiring} gems expiring soon!`);
910
+ * expiring.batches.forEach(batch => {
911
+ * console.log(`${batch.amount} gems expire in ${batch.daysUntilExpiry} days`);
912
+ * });
913
+ * }
914
+ * ```
915
+ */
916
+ async getExpiringGems(params?: GetExpiringGemsParams): Promise<GetExpiringGemsResponse> {
917
+ const queryString = params ? buildQueryString(params) : "";
918
+ return this.get(`/api/gems/expiring${queryString}`);
919
+ }
920
+
921
+ // ============================================================================
922
+ // Browsing Location API
923
+ // ============================================================================
924
+
925
+ /**
926
+ * Get user's browsing location
927
+ *
928
+ * Returns the user's saved delivery location for geo-based product filtering.
929
+ * This location is used to show products from merchants that ship to the area.
930
+ *
931
+ * @returns Current browsing location or null if not set
932
+ *
933
+ * @example
934
+ * ```typescript
935
+ * const result = await client.getBrowsingLocation();
936
+ * if (result.location) {
937
+ * console.log(`Delivery to: ${result.location.city}, ${result.location.country}`);
938
+ * }
939
+ * ```
940
+ */
941
+ async getBrowsingLocation(): Promise<GetBrowsingLocationResponse> {
942
+ return this.get("/api/user/browsing-location");
943
+ }
944
+
945
+ /**
946
+ * Save user's browsing location
947
+ *
948
+ * Sets the user's delivery location for geo-based product filtering.
949
+ * Products will be filtered to show only items from merchants that ship to this location.
950
+ *
951
+ * @param request - Location data from Google Places or manual input
952
+ * @returns The saved location
953
+ *
954
+ * @example
955
+ * ```typescript
956
+ * const result = await client.saveBrowsingLocation({
957
+ * formattedAddress: "Singapore, Singapore",
958
+ * city: "Singapore",
959
+ * country: "SG",
960
+ * latitude: 1.3521,
961
+ * longitude: 103.8198
962
+ * });
963
+ * console.log(`Location saved: ${result.location.formattedAddress}`);
964
+ * ```
965
+ */
966
+ async saveBrowsingLocation(request: SaveBrowsingLocationRequest): Promise<SaveBrowsingLocationResponse> {
967
+ return this.post("/api/user/browsing-location", request);
968
+ }
969
+
970
+ /**
971
+ * Clear user's browsing location
972
+ *
973
+ * Removes the user's saved delivery location. Products will no longer
974
+ * be filtered by shipping destination.
975
+ *
976
+ * @returns Success response
977
+ *
978
+ * @example
979
+ * ```typescript
980
+ * await client.clearBrowsingLocation();
981
+ * console.log("Location cleared - showing all products");
982
+ * ```
983
+ */
984
+ async clearBrowsingLocation(): Promise<DeleteBrowsingLocationResponse> {
985
+ return this.delete("/api/user/browsing-location");
986
+ }
770
987
  }
771
988