@basedone/core 0.1.8 → 0.2.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.
Files changed (59) hide show
  1. package/dist/chunk-4GAKANLT.mjs +1987 -0
  2. package/dist/chunk-4UEJOM6W.mjs +1 -3
  3. package/dist/chunk-VBC6EQ7Q.mjs +235 -0
  4. package/dist/client-CgmiTuEX.d.mts +179 -0
  5. package/dist/client-CgmiTuEX.d.ts +179 -0
  6. package/dist/ecommerce.d.mts +3732 -0
  7. package/dist/ecommerce.d.ts +3732 -0
  8. package/dist/ecommerce.js +2031 -0
  9. package/dist/ecommerce.mjs +2 -0
  10. package/dist/index.d.mts +79 -4
  11. package/dist/index.d.ts +79 -4
  12. package/dist/index.js +3674 -331
  13. package/dist/index.mjs +107 -104
  14. package/dist/{meta-57AY44US.mjs → meta-JB5ITE27.mjs} +6 -14
  15. package/dist/{meta-RSZFFH63.mjs → meta-UOGUG3OW.mjs} +5 -11
  16. package/dist/{perpDexs-PBKWKKQU.mjs → perpDexs-3LRJ5ZHM.mjs} +100 -13
  17. package/dist/{perpDexs-XSB4Y2BP.mjs → perpDexs-4ISLD7NX.mjs} +798 -121
  18. package/dist/react.d.mts +39 -0
  19. package/dist/react.d.ts +39 -0
  20. package/dist/react.js +268 -0
  21. package/dist/react.mjs +31 -0
  22. package/dist/{spotMeta-WQ4PXRNY.mjs → spotMeta-GHXX7C5M.mjs} +85 -14
  23. package/dist/{spotMeta-Y7G2GI7B.mjs → spotMeta-IBBUP2SG.mjs} +249 -12
  24. package/dist/staticMeta-GM7T3OYL.mjs +3 -6
  25. package/dist/staticMeta-QV2KMX57.mjs +3 -6
  26. package/ecommerce.ts +15 -0
  27. package/index.ts +7 -0
  28. package/lib/cloid/cloid.ts +2 -0
  29. package/lib/ecommerce/QUICK_REFERENCE.md +211 -0
  30. package/lib/ecommerce/README.md +385 -0
  31. package/lib/ecommerce/USAGE_EXAMPLES.md +704 -0
  32. package/lib/ecommerce/client/base.ts +272 -0
  33. package/lib/ecommerce/client/customer.ts +522 -0
  34. package/lib/ecommerce/client/merchant.ts +1341 -0
  35. package/lib/ecommerce/index.ts +51 -0
  36. package/lib/ecommerce/types/entities.ts +722 -0
  37. package/lib/ecommerce/types/enums.ts +270 -0
  38. package/lib/ecommerce/types/index.ts +18 -0
  39. package/lib/ecommerce/types/requests.ts +525 -0
  40. package/lib/ecommerce/types/responses.ts +805 -0
  41. package/lib/ecommerce/utils/errors.ts +113 -0
  42. package/lib/ecommerce/utils/helpers.ts +131 -0
  43. package/lib/fee.ts +10 -10
  44. package/lib/hip3/market-info.ts +36 -8
  45. package/lib/hip3/utils.ts +15 -2
  46. package/lib/instrument/client.ts +351 -0
  47. package/lib/meta/data/mainnet/meta.json +2 -4
  48. package/lib/meta/data/mainnet/perpDexs.json +97 -9
  49. package/lib/meta/data/mainnet/spotMeta.json +82 -8
  50. package/lib/meta/data/testnet/meta.json +3 -7
  51. package/lib/meta/data/testnet/perpDexs.json +795 -117
  52. package/lib/meta/data/testnet/spotMeta.json +246 -6
  53. package/lib/meta/metadata.ts +8 -1
  54. package/lib/meta/types.ts +36 -0
  55. package/lib/react/InstrumentProvider.tsx +69 -0
  56. package/lib/utils/flooredDateTime.ts +55 -0
  57. package/lib/utils/time.ts +51 -0
  58. package/package.json +37 -11
  59. package/react.ts +1 -0
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Base Ecommerce API Client
3
+ *
4
+ * This module provides the base HTTP client for the ecommerce API with
5
+ * authentication, error handling, and retry logic.
6
+ */
7
+
8
+ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
9
+ import { parseError, isRetryableError, EcommerceApiError } from "../utils/errors";
10
+ import { retryWithBackoff } from "../utils/helpers";
11
+
12
+ /**
13
+ * Client configuration options
14
+ */
15
+ export interface EcommerceClientConfig {
16
+ /** Base API URL */
17
+ baseURL: string;
18
+
19
+ /** Authentication token (Bearer token) */
20
+ authToken?: string;
21
+
22
+ /** Request timeout in milliseconds */
23
+ timeout?: number;
24
+
25
+ /** Maximum number of retries for failed requests */
26
+ maxRetries?: number;
27
+
28
+ /** Base delay for exponential backoff (ms) */
29
+ retryBaseDelay?: number;
30
+
31
+ /** Custom headers */
32
+ headers?: Record<string, string>;
33
+
34
+ /** Enable automatic retry on retryable errors */
35
+ enableRetry?: boolean;
36
+ }
37
+
38
+ /**
39
+ * Base ecommerce API client class
40
+ *
41
+ * Provides HTTP methods with authentication, error handling, and retry logic.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const client = new BaseEcommerceClient({
46
+ * baseURL: "https://api.example.com",
47
+ * authToken: "your-auth-token",
48
+ * timeout: 30000,
49
+ * maxRetries: 3,
50
+ * });
51
+ *
52
+ * // Make authenticated request
53
+ * const products = await client.get("/api/marketplace/products");
54
+ * ```
55
+ */
56
+ export class BaseEcommerceClient {
57
+ private axiosInstance: AxiosInstance;
58
+ private config: Required<Omit<EcommerceClientConfig, "authToken" | "headers">> & {
59
+ authToken?: string;
60
+ headers?: Record<string, string>;
61
+ };
62
+
63
+ constructor(config: EcommerceClientConfig) {
64
+ this.config = {
65
+ baseURL: config.baseURL,
66
+ authToken: config.authToken,
67
+ timeout: config.timeout || 30000,
68
+ maxRetries: config.maxRetries || 3,
69
+ retryBaseDelay: config.retryBaseDelay || 1000,
70
+ headers: config.headers,
71
+ enableRetry: config.enableRetry !== false,
72
+ };
73
+
74
+ this.axiosInstance = axios.create({
75
+ baseURL: this.config.baseURL,
76
+ timeout: this.config.timeout,
77
+ headers: {
78
+ "Content-Type": "application/json",
79
+ ...this.config.headers,
80
+ },
81
+ });
82
+
83
+ // Request interceptor for authentication
84
+ this.axiosInstance.interceptors.request.use(
85
+ (config: any) => {
86
+ if (this.config.authToken) {
87
+ config.headers.Authorization = `Bearer ${this.config.authToken}`;
88
+ }
89
+ return config;
90
+ },
91
+ (error: any) => Promise.reject(error)
92
+ );
93
+
94
+ // Response interceptor for error handling
95
+ this.axiosInstance.interceptors.response.use(
96
+ (response: any) => response,
97
+ (error: any) => Promise.reject(parseError(error))
98
+ );
99
+ }
100
+
101
+ /**
102
+ * Update authentication token
103
+ *
104
+ * @param token - New authentication token
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * client.setAuthToken("new-auth-token");
109
+ * ```
110
+ */
111
+ public setAuthToken(token: string): void {
112
+ this.config.authToken = token;
113
+ }
114
+
115
+ /**
116
+ * Clear authentication token
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * client.clearAuthToken();
121
+ * ```
122
+ */
123
+ public clearAuthToken(): void {
124
+ this.config.authToken = undefined;
125
+ }
126
+
127
+ /**
128
+ * Make a GET request
129
+ *
130
+ * @param url - Request URL
131
+ * @param config - Axios request config
132
+ * @returns Response data
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const products = await client.get("/api/marketplace/products", {
137
+ * params: { limit: 20, offset: 0 }
138
+ * });
139
+ * ```
140
+ */
141
+ public async get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> {
142
+ return this.request<T>({ ...config, method: "GET", url });
143
+ }
144
+
145
+ /**
146
+ * Make a POST request
147
+ *
148
+ * @param url - Request URL
149
+ * @param data - Request body data
150
+ * @param config - Axios request config
151
+ * @returns Response data
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const order = await client.post("/api/marketplace/orders", {
156
+ * items: [{ productId: "123", quantity: 1 }],
157
+ * paymentMethod: "USDC_ESCROW"
158
+ * });
159
+ * ```
160
+ */
161
+ public async post<T = any>(
162
+ url: string,
163
+ data?: any,
164
+ config?: AxiosRequestConfig
165
+ ): Promise<T> {
166
+ return this.request<T>({ ...config, method: "POST", url, data });
167
+ }
168
+
169
+ /**
170
+ * Make a PUT request
171
+ *
172
+ * @param url - Request URL
173
+ * @param data - Request body data
174
+ * @param config - Axios request config
175
+ * @returns Response data
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const product = await client.put("/api/marketplace/products/123", {
180
+ * title: "Updated Product"
181
+ * });
182
+ * ```
183
+ */
184
+ public async put<T = any>(
185
+ url: string,
186
+ data?: any,
187
+ config?: AxiosRequestConfig
188
+ ): Promise<T> {
189
+ return this.request<T>({ ...config, method: "PUT", url, data });
190
+ }
191
+
192
+ /**
193
+ * Make a PATCH request
194
+ *
195
+ * @param url - Request URL
196
+ * @param data - Request body data
197
+ * @param config - Axios request config
198
+ * @returns Response data
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const order = await client.patch("/api/marketplace/merchant/orders/123", {
203
+ * status: "SHIPPED",
204
+ * tracking: { trackingNumber: "123456", carrier: "UPS" }
205
+ * });
206
+ * ```
207
+ */
208
+ public async patch<T = any>(
209
+ url: string,
210
+ data?: any,
211
+ config?: AxiosRequestConfig
212
+ ): Promise<T> {
213
+ return this.request<T>({ ...config, method: "PATCH", url, data });
214
+ }
215
+
216
+ /**
217
+ * Make a DELETE request
218
+ *
219
+ * @param url - Request URL
220
+ * @param config - Axios request config
221
+ * @returns Response data
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * await client.delete("/api/marketplace/products/123");
226
+ * ```
227
+ */
228
+ public async delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> {
229
+ return this.request<T>({ ...config, method: "DELETE", url });
230
+ }
231
+
232
+ /**
233
+ * Make a request with retry logic
234
+ *
235
+ * @param config - Axios request config
236
+ * @returns Response data
237
+ */
238
+ private async request<T = any>(config: AxiosRequestConfig): Promise<T> {
239
+ const makeRequest = async (): Promise<AxiosResponse<T>> => {
240
+ return this.axiosInstance.request<T>(config);
241
+ };
242
+
243
+ if (this.config.enableRetry) {
244
+ const response = await retryWithBackoff(
245
+ makeRequest,
246
+ this.config.maxRetries,
247
+ this.config.retryBaseDelay,
248
+ (error: EcommerceApiError) => isRetryableError(error)
249
+ );
250
+ return response.data;
251
+ } else {
252
+ const response = await makeRequest();
253
+ return response.data;
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Get the underlying axios instance
259
+ *
260
+ * @returns Axios instance
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * const axios = client.getAxiosInstance();
265
+ * // Use axios directly for advanced use cases
266
+ * ```
267
+ */
268
+ public getAxiosInstance(): AxiosInstance {
269
+ return this.axiosInstance;
270
+ }
271
+ }
272
+