@basedone/core 0.2.3 → 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.
package/dist/index.js CHANGED
@@ -43324,6 +43324,148 @@ var CustomerEcommerceClient = class extends BaseEcommerceClient {
43324
43324
  async getPaymentMethods() {
43325
43325
  return this.get("/api/marketplace/payments/methods");
43326
43326
  }
43327
+ // ============================================================================
43328
+ // GEM System API
43329
+ // ============================================================================
43330
+ /**
43331
+ * Get user's gem balance
43332
+ *
43333
+ * Returns the current gem balance including total gems, available gems,
43334
+ * and gems expiring soon. Gems are earned at 100 per $1 of revenue.
43335
+ *
43336
+ * @returns Current gem balance with USD equivalent
43337
+ *
43338
+ * @example
43339
+ * ```typescript
43340
+ * const balance = await client.getGemBalance();
43341
+ * console.log(`You have ${balance.totalGems} gems (${balance.usdEquivalent} USD)`);
43342
+ * console.log(`${balance.expiringSoon} gems expiring soon`);
43343
+ * ```
43344
+ */
43345
+ async getGemBalance() {
43346
+ return this.get("/api/gems/balance");
43347
+ }
43348
+ /**
43349
+ * Get gem transaction history
43350
+ *
43351
+ * Returns paginated history of gem transactions including earning,
43352
+ * spending, and expiration events.
43353
+ *
43354
+ * @param params - Query parameters for filtering and pagination
43355
+ * @returns Paginated gem history
43356
+ *
43357
+ * @example
43358
+ * ```typescript
43359
+ * // Get all history
43360
+ * const history = await client.getGemHistory({ limit: 20, offset: 0 });
43361
+ *
43362
+ * // Get only earned gems
43363
+ * const earned = await client.getGemHistory({ type: "earn", limit: 10 });
43364
+ *
43365
+ * // Get only spent gems
43366
+ * const spent = await client.getGemHistory({ type: "spend", limit: 10 });
43367
+ *
43368
+ * history.items.forEach(item => {
43369
+ * console.log(`${item.type}: ${item.amount} gems - ${item.createdAt}`);
43370
+ * });
43371
+ * ```
43372
+ */
43373
+ async getGemHistory(params) {
43374
+ const queryString = params ? buildQueryString(params) : "";
43375
+ return this.get(`/api/gems/history${queryString}`);
43376
+ }
43377
+ /**
43378
+ * Get gems that are expiring soon
43379
+ *
43380
+ * Returns gem batches that will expire within the specified number of days.
43381
+ * Useful for prompting users to spend gems before they expire.
43382
+ *
43383
+ * @param params - Query parameters (days: default 30, max 180)
43384
+ * @returns Expiring gem batches with countdown info
43385
+ *
43386
+ * @example
43387
+ * ```typescript
43388
+ * // Get gems expiring in next 30 days (default)
43389
+ * const expiring = await client.getExpiringGems();
43390
+ *
43391
+ * // Get gems expiring in next 7 days
43392
+ * const urgent = await client.getExpiringGems({ days: 7 });
43393
+ *
43394
+ * if (expiring.totalExpiring > 0) {
43395
+ * console.log(`${expiring.totalExpiring} gems expiring soon!`);
43396
+ * expiring.batches.forEach(batch => {
43397
+ * console.log(`${batch.amount} gems expire in ${batch.daysUntilExpiry} days`);
43398
+ * });
43399
+ * }
43400
+ * ```
43401
+ */
43402
+ async getExpiringGems(params) {
43403
+ const queryString = params ? buildQueryString(params) : "";
43404
+ return this.get(`/api/gems/expiring${queryString}`);
43405
+ }
43406
+ // ============================================================================
43407
+ // Browsing Location API
43408
+ // ============================================================================
43409
+ /**
43410
+ * Get user's browsing location
43411
+ *
43412
+ * Returns the user's saved delivery location for geo-based product filtering.
43413
+ * This location is used to show products from merchants that ship to the area.
43414
+ *
43415
+ * @returns Current browsing location or null if not set
43416
+ *
43417
+ * @example
43418
+ * ```typescript
43419
+ * const result = await client.getBrowsingLocation();
43420
+ * if (result.location) {
43421
+ * console.log(`Delivery to: ${result.location.city}, ${result.location.country}`);
43422
+ * }
43423
+ * ```
43424
+ */
43425
+ async getBrowsingLocation() {
43426
+ return this.get("/api/user/browsing-location");
43427
+ }
43428
+ /**
43429
+ * Save user's browsing location
43430
+ *
43431
+ * Sets the user's delivery location for geo-based product filtering.
43432
+ * Products will be filtered to show only items from merchants that ship to this location.
43433
+ *
43434
+ * @param request - Location data from Google Places or manual input
43435
+ * @returns The saved location
43436
+ *
43437
+ * @example
43438
+ * ```typescript
43439
+ * const result = await client.saveBrowsingLocation({
43440
+ * formattedAddress: "Singapore, Singapore",
43441
+ * city: "Singapore",
43442
+ * country: "SG",
43443
+ * latitude: 1.3521,
43444
+ * longitude: 103.8198
43445
+ * });
43446
+ * console.log(`Location saved: ${result.location.formattedAddress}`);
43447
+ * ```
43448
+ */
43449
+ async saveBrowsingLocation(request) {
43450
+ return this.post("/api/user/browsing-location", request);
43451
+ }
43452
+ /**
43453
+ * Clear user's browsing location
43454
+ *
43455
+ * Removes the user's saved delivery location. Products will no longer
43456
+ * be filtered by shipping destination.
43457
+ *
43458
+ * @returns Success response
43459
+ *
43460
+ * @example
43461
+ * ```typescript
43462
+ * await client.clearBrowsingLocation();
43463
+ * console.log("Location cleared - showing all products");
43464
+ * ```
43465
+ */
43466
+ async clearBrowsingLocation() {
43467
+ return this.delete("/api/user/browsing-location");
43468
+ }
43327
43469
  };
43328
43470
 
43329
43471
  // lib/ecommerce/client/merchant.ts
@@ -44987,6 +45129,7 @@ var ProductSortBy = /* @__PURE__ */ ((ProductSortBy2) => {
44987
45129
  ProductSortBy2["PRICE_DESC"] = "price_desc";
44988
45130
  ProductSortBy2["POPULAR"] = "popular";
44989
45131
  ProductSortBy2["FEATURED"] = "featured";
45132
+ ProductSortBy2["NEARBY"] = "nearby";
44990
45133
  return ProductSortBy2;
44991
45134
  })(ProductSortBy || {});
44992
45135
  var ReviewSortBy = /* @__PURE__ */ ((ReviewSortBy2) => {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { BannerType, BaseEcommerceClient, CustomerEcommerceClient, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, InventoryAuditAction, MerchantEcommerceClient, MerchantStatus, OrderStatus, PaymentMethod, PaymentStatus, ProductSortBy, ReturnStatus, ReviewSortBy, ReviewStatus, ShipmentStatus, SortOrder, TaxBehavior, TaxReportPeriodType, TaxReportStatus, TaxType, buildQueryString, calculateDiscountAmount, calculateFinalPrice, formatPrice, getBackoffDelay, isRetryableError, isValidAddress, isValidEmail, parseError, retryWithBackoff, sleep, truncateAddress } from './chunk-SKX4VGEN.mjs';
1
+ export { BannerType, BaseEcommerceClient, CustomerEcommerceClient, DiscountMethod, DiscountScope, DiscountType, EcommerceApiError, InventoryAuditAction, MerchantEcommerceClient, MerchantStatus, OrderStatus, PaymentMethod, PaymentStatus, ProductSortBy, ReturnStatus, ReviewSortBy, ReviewStatus, ShipmentStatus, SortOrder, TaxBehavior, TaxReportPeriodType, TaxReportStatus, TaxType, buildQueryString, calculateDiscountAmount, calculateFinalPrice, formatPrice, getBackoffDelay, isRetryableError, isValidAddress, isValidEmail, parseError, retryWithBackoff, sleep, truncateAddress } from './chunk-NVL2HX2H.mjs';
2
2
  export { AssetIdUtils, InstrumentClient } from './chunk-VBC6EQ7Q.mjs';
3
3
  import { __glob } from './chunk-4UEJOM6W.mjs';
4
4
  import Decimal, { Decimal as Decimal$1 } from 'decimal.js';
@@ -25,6 +25,9 @@ import type {
25
25
  ListMerchantProductsParams,
26
26
  ListFollowingParams,
27
27
  CalculateShippingRequest,
28
+ GetGemHistoryParams,
29
+ GetExpiringGemsParams,
30
+ SaveBrowsingLocationRequest,
28
31
 
29
32
  // Response types
30
33
  ListProductsResponse,
@@ -55,6 +58,12 @@ import type {
55
58
  FollowActionResponse,
56
59
  ListFollowingResponse,
57
60
  CalculateShippingResponse,
61
+ GetGemBalanceResponse,
62
+ GetBrowsingLocationResponse,
63
+ SaveBrowsingLocationResponse,
64
+ DeleteBrowsingLocationResponse,
65
+ GetGemHistoryResponse,
66
+ GetExpiringGemsResponse,
58
67
  } from "../types";
59
68
 
60
69
  /**
@@ -825,5 +834,155 @@ export class CustomerEcommerceClient extends BaseEcommerceClient {
825
834
  async getPaymentMethods(): Promise<GetPaymentMethodsResponse> {
826
835
  return this.get("/api/marketplace/payments/methods");
827
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
+ }
828
987
  }
829
988
 
@@ -258,6 +258,8 @@ export enum ProductSortBy {
258
258
  POPULAR = "popular",
259
259
  /** Sort by featured status */
260
260
  FEATURED = "featured",
261
+ /** Sort by proximity to user location (requires lat/lng) */
262
+ NEARBY = "nearby",
261
263
  }
262
264
 
263
265
  /**
@@ -54,6 +54,12 @@ export interface ListProductsParams extends PaginationParams {
54
54
  sortBy?: ProductSortBy;
55
55
  /** Filter by active status */
56
56
  isActive?: boolean;
57
+ /** Filter by destination country (ISO 2-letter code) - only show products from merchants that ship here */
58
+ country?: string;
59
+ /** User latitude for proximity sorting (used with sortBy=nearby) */
60
+ lat?: number;
61
+ /** User longitude for proximity sorting (used with sortBy=nearby) */
62
+ lng?: number;
57
63
  }
58
64
 
59
65
  /**
@@ -700,3 +706,50 @@ export interface CalculateShippingRequest {
700
706
  orderSubtotal: number;
701
707
  }
702
708
 
709
+ // ============================================================================
710
+ // GEM System Requests
711
+ // ============================================================================
712
+
713
+ /**
714
+ * Gem history type filter
715
+ */
716
+ export type GemHistoryTypeFilter = "earn" | "spend" | "all";
717
+
718
+ /**
719
+ * Get gem history parameters
720
+ */
721
+ export interface GetGemHistoryParams extends PaginationParams {
722
+ /** Filter by transaction type */
723
+ type?: GemHistoryTypeFilter;
724
+ }
725
+
726
+ /**
727
+ * Get expiring gems parameters
728
+ */
729
+ export interface GetExpiringGemsParams {
730
+ /** Number of days ahead to check (default: 30, max: 180) */
731
+ days?: number;
732
+ }
733
+
734
+ // ============================================================================
735
+ // Browsing Location Requests
736
+ // ============================================================================
737
+
738
+ /**
739
+ * Save browsing location request
740
+ */
741
+ export interface SaveBrowsingLocationRequest {
742
+ /** Full display address from Google Places */
743
+ formattedAddress: string;
744
+ /** City name */
745
+ city: string;
746
+ /** State/Province (optional) */
747
+ stateProvince?: string;
748
+ /** ISO 2-letter country code (e.g., "SG", "US") */
749
+ country: string;
750
+ /** Latitude coordinate */
751
+ latitude: number;
752
+ /** Longitude coordinate */
753
+ longitude: number;
754
+ }
755
+
@@ -1099,3 +1099,169 @@ export interface ProcessPaymentResponse {
1099
1099
  errorCode?: string;
1100
1100
  }
1101
1101
 
1102
+ // ============================================================================
1103
+ // GEM System Responses
1104
+ // ============================================================================
1105
+
1106
+ /**
1107
+ * Gem source type - how gems were earned
1108
+ */
1109
+ export type GemSource =
1110
+ | "BUILDER_CODE"
1111
+ | "PREDICTION"
1112
+ | "CARD_SPEND"
1113
+ | "MALL_SPEND"
1114
+ | "ADMIN"
1115
+ | "REFUND";
1116
+
1117
+ /**
1118
+ * Get gem balance response
1119
+ */
1120
+ export interface GetGemBalanceResponse {
1121
+ /** User ID */
1122
+ userId: string;
1123
+ /** Total gems owned */
1124
+ totalGems: number;
1125
+ /** Available gems (not reserved) */
1126
+ availableGems: number;
1127
+ /** Gems expiring within 30 days */
1128
+ expiringSoon: number;
1129
+ /** Last balance update timestamp */
1130
+ lastUpdated: string;
1131
+ /** USD equivalent (totalGems / 100) */
1132
+ usdEquivalent: number;
1133
+ /** Conversion rate (gems per $1) */
1134
+ conversionRate: number;
1135
+ }
1136
+
1137
+ /**
1138
+ * Gem history item type
1139
+ */
1140
+ export type GemHistoryType = "earn" | "spend" | "expire";
1141
+
1142
+ /**
1143
+ * Gem history item
1144
+ */
1145
+ export interface GemHistoryItem {
1146
+ /** Transaction ID */
1147
+ id: string;
1148
+ /** Type of transaction */
1149
+ type: GemHistoryType;
1150
+ /** Amount of gems (positive for earn, negative for spend) */
1151
+ amount: number;
1152
+ /** Source type (for earn transactions) */
1153
+ source?: GemSource;
1154
+ /** Reason description (for spend transactions) */
1155
+ reason?: string;
1156
+ /** When the transaction occurred */
1157
+ createdAt: string;
1158
+ /** When the gems expire (for earn transactions) */
1159
+ expiresAt?: string;
1160
+ }
1161
+
1162
+ /**
1163
+ * Get gem history response
1164
+ */
1165
+ export interface GetGemHistoryResponse {
1166
+ /** History items */
1167
+ items: GemHistoryItem[];
1168
+ /** Total count of items */
1169
+ total: number;
1170
+ /** Pagination info */
1171
+ pagination: {
1172
+ /** Items per page */
1173
+ limit: number;
1174
+ /** Current offset */
1175
+ offset: number;
1176
+ /** Whether more items exist */
1177
+ hasMore: boolean;
1178
+ };
1179
+ }
1180
+
1181
+ /**
1182
+ * Expiring gem batch
1183
+ */
1184
+ export interface ExpiringGemBatch {
1185
+ /** Batch ID */
1186
+ id: string;
1187
+ /** Remaining gems in batch */
1188
+ amount: number;
1189
+ /** How the gems were earned */
1190
+ source: GemSource;
1191
+ /** When the batch expires */
1192
+ expiresAt: string;
1193
+ /** When the batch was created */
1194
+ createdAt: string;
1195
+ /** Days until expiry */
1196
+ daysUntilExpiry: number;
1197
+ }
1198
+
1199
+ /**
1200
+ * Get expiring gems response
1201
+ */
1202
+ export interface GetExpiringGemsResponse {
1203
+ /** Total gems expiring within the query period */
1204
+ totalExpiring: number;
1205
+ /** Expiring batches */
1206
+ batches: ExpiringGemBatch[];
1207
+ /** Query parameters used */
1208
+ queryParams: {
1209
+ /** Days ahead that were queried */
1210
+ days: number;
1211
+ };
1212
+ }
1213
+
1214
+ // ============================================================================
1215
+ // Browsing Location Responses
1216
+ // ============================================================================
1217
+
1218
+ /**
1219
+ * User's browsing location for geo-based product filtering
1220
+ */
1221
+ export interface BrowsingLocation {
1222
+ /** Location ID */
1223
+ id: string;
1224
+ /** Full display address */
1225
+ formattedAddress: string;
1226
+ /** City name */
1227
+ city: string;
1228
+ /** State/Province (if applicable) */
1229
+ stateProvince?: string | null;
1230
+ /** ISO 2-letter country code */
1231
+ country: string;
1232
+ /** Latitude coordinate */
1233
+ latitude: number;
1234
+ /** Longitude coordinate */
1235
+ longitude: number;
1236
+ /** Last updated timestamp */
1237
+ updatedAt: string;
1238
+ }
1239
+
1240
+ /**
1241
+ * Get browsing location response
1242
+ */
1243
+ export interface GetBrowsingLocationResponse {
1244
+ /** User's saved browsing location (null if not set) */
1245
+ location: BrowsingLocation | null;
1246
+ }
1247
+
1248
+ /**
1249
+ * Save browsing location response
1250
+ */
1251
+ export interface SaveBrowsingLocationResponse {
1252
+ /** Whether the operation was successful */
1253
+ success: boolean;
1254
+ /** The saved location */
1255
+ location: BrowsingLocation;
1256
+ }
1257
+
1258
+ /**
1259
+ * Delete browsing location response
1260
+ */
1261
+ export interface DeleteBrowsingLocationResponse {
1262
+ /** Whether the operation was successful */
1263
+ success: boolean;
1264
+ /** Success message */
1265
+ message: string;
1266
+ }
1267
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basedone/core",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Core utilities for Based One",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",