@zyfai/sdk 0.1.11 → 0.1.12

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
@@ -76,7 +76,7 @@ var ENDPOINTS = {
76
76
  };
77
77
  var DATA_ENDPOINTS = {
78
78
  // User Initialization
79
- USER_INITIALIZE: "/earnings/initialize",
79
+ USER_INITIALIZE: "/api/earnings/initialize",
80
80
  // Earnings
81
81
  ONCHAIN_EARNINGS: (walletAddress) => `/usercheck/onchain-earnings?walletAddress=${walletAddress}`,
82
82
  CALCULATE_ONCHAIN_EARNINGS: "/usercheck/calculate-onchain-earnings",
@@ -110,6 +110,7 @@ var HttpClient = class {
110
110
  this.authToken = null;
111
111
  this.apiKey = apiKey;
112
112
  this.dataApiKey = dataApiKey || apiKey;
113
+ this.environment = environment;
113
114
  const endpoint = API_ENDPOINTS[environment];
114
115
  const parsedUrl = new URL(endpoint);
115
116
  this.origin = parsedUrl.origin;
@@ -214,6 +215,31 @@ var HttpClient = class {
214
215
  const response = await this.dataClient.post(url, data, config);
215
216
  return response.data;
216
217
  }
218
+ /**
219
+ * Make a POST request to Data API with a custom path (bypasses /api/v2 baseURL)
220
+ * Useful for endpoints that don't follow the /api/v2 pattern
221
+ *
222
+ * @param path - API path (e.g., "/api/earnings/initialize")
223
+ * @param data - Request body
224
+ * @param config - Additional axios config
225
+ */
226
+ async dataPostCustom(path, data, config) {
227
+ const fullUrl = `${DATA_API_ENDPOINTS[this.environment]}${path}`;
228
+ const headers = {
229
+ "Content-Type": "application/json",
230
+ "X-API-Key": this.dataApiKey,
231
+ ...config?.headers
232
+ };
233
+ if (this.authToken) {
234
+ headers["Authorization"] = `Bearer ${this.authToken}`;
235
+ }
236
+ const response = await import_axios.default.post(fullUrl, data, {
237
+ ...config,
238
+ headers,
239
+ timeout: config?.timeout || 3e4
240
+ });
241
+ return response.data;
242
+ }
217
243
  setupDataInterceptors() {
218
244
  this.dataClient.interceptors.request.use(
219
245
  (config) => {
@@ -762,18 +788,18 @@ var ZyfaiSDK = class {
762
788
  async initializeUser(smartWallet, chainId) {
763
789
  try {
764
790
  await this.authenticateUser();
765
- const response = await this.httpClient.dataPost(
791
+ const responseData = await this.httpClient.dataPostCustom(
766
792
  DATA_ENDPOINTS.USER_INITIALIZE,
767
793
  {
768
794
  walletAddress: smartWallet
769
795
  }
770
796
  );
771
797
  return {
772
- success: response.status === "success" || true,
773
- userId: response.userId || response.id,
774
- smartWallet: response.smartWallet || smartWallet,
775
- chainId: response.chainId || chainId,
776
- message: response.message || response.status || "User initialized successfully"
798
+ success: responseData.status === "success" || true,
799
+ userId: responseData.userId || responseData.id,
800
+ smartWallet: responseData.smartWallet || smartWallet,
801
+ chainId: responseData.chainId || chainId,
802
+ message: responseData.message || responseData.status || "User initialized successfully"
777
803
  };
778
804
  } catch (error) {
779
805
  throw new Error(`Failed to initialize user: ${error.message}`);
package/dist/index.mjs CHANGED
@@ -37,7 +37,7 @@ var ENDPOINTS = {
37
37
  };
38
38
  var DATA_ENDPOINTS = {
39
39
  // User Initialization
40
- USER_INITIALIZE: "/earnings/initialize",
40
+ USER_INITIALIZE: "/api/earnings/initialize",
41
41
  // Earnings
42
42
  ONCHAIN_EARNINGS: (walletAddress) => `/usercheck/onchain-earnings?walletAddress=${walletAddress}`,
43
43
  CALCULATE_ONCHAIN_EARNINGS: "/usercheck/calculate-onchain-earnings",
@@ -71,6 +71,7 @@ var HttpClient = class {
71
71
  this.authToken = null;
72
72
  this.apiKey = apiKey;
73
73
  this.dataApiKey = dataApiKey || apiKey;
74
+ this.environment = environment;
74
75
  const endpoint = API_ENDPOINTS[environment];
75
76
  const parsedUrl = new URL(endpoint);
76
77
  this.origin = parsedUrl.origin;
@@ -175,6 +176,31 @@ var HttpClient = class {
175
176
  const response = await this.dataClient.post(url, data, config);
176
177
  return response.data;
177
178
  }
179
+ /**
180
+ * Make a POST request to Data API with a custom path (bypasses /api/v2 baseURL)
181
+ * Useful for endpoints that don't follow the /api/v2 pattern
182
+ *
183
+ * @param path - API path (e.g., "/api/earnings/initialize")
184
+ * @param data - Request body
185
+ * @param config - Additional axios config
186
+ */
187
+ async dataPostCustom(path, data, config) {
188
+ const fullUrl = `${DATA_API_ENDPOINTS[this.environment]}${path}`;
189
+ const headers = {
190
+ "Content-Type": "application/json",
191
+ "X-API-Key": this.dataApiKey,
192
+ ...config?.headers
193
+ };
194
+ if (this.authToken) {
195
+ headers["Authorization"] = `Bearer ${this.authToken}`;
196
+ }
197
+ const response = await axios.post(fullUrl, data, {
198
+ ...config,
199
+ headers,
200
+ timeout: config?.timeout || 3e4
201
+ });
202
+ return response.data;
203
+ }
178
204
  setupDataInterceptors() {
179
205
  this.dataClient.interceptors.request.use(
180
206
  (config) => {
@@ -742,18 +768,18 @@ var ZyfaiSDK = class {
742
768
  async initializeUser(smartWallet, chainId) {
743
769
  try {
744
770
  await this.authenticateUser();
745
- const response = await this.httpClient.dataPost(
771
+ const responseData = await this.httpClient.dataPostCustom(
746
772
  DATA_ENDPOINTS.USER_INITIALIZE,
747
773
  {
748
774
  walletAddress: smartWallet
749
775
  }
750
776
  );
751
777
  return {
752
- success: response.status === "success" || true,
753
- userId: response.userId || response.id,
754
- smartWallet: response.smartWallet || smartWallet,
755
- chainId: response.chainId || chainId,
756
- message: response.message || response.status || "User initialized successfully"
778
+ success: responseData.status === "success" || true,
779
+ userId: responseData.userId || responseData.id,
780
+ smartWallet: responseData.smartWallet || smartWallet,
781
+ chainId: responseData.chainId || chainId,
782
+ message: responseData.message || responseData.status || "User initialized successfully"
757
783
  };
758
784
  } catch (error) {
759
785
  throw new Error(`Failed to initialize user: ${error.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "TypeScript SDK for ZyFAI Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",