@pear-protocol/hyperliquid-sdk 0.0.73-beta.5 → 0.0.73-beta.6

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.
@@ -1,4 +1,4 @@
1
- import type { ApiResponse, GetEIP712MessageResponse, AuthenticateRequest, AuthenticateResponse, RefreshTokenResponse, LogoutResponse } from '../types';
1
+ import type { ApiResponse, GetEIP712MessageResponse, AuthenticateRequest, AuthenticateResponse, RefreshTokenResponse, LogoutResponse } from "../types";
2
2
  export declare function getEIP712Message(baseUrl: string, address: string, clientId: string): Promise<ApiResponse<GetEIP712MessageResponse>>;
3
3
  export declare function authenticate(baseUrl: string, body: AuthenticateRequest): Promise<ApiResponse<AuthenticateResponse>>;
4
4
  /**
package/dist/index.js CHANGED
@@ -5910,10 +5910,10 @@ function toApiError(error) {
5910
5910
  var _a;
5911
5911
  const axiosError = error;
5912
5912
  const payload = (axiosError && axiosError.response ? axiosError.response.data : undefined);
5913
- const message = typeof payload === 'object' && payload && 'message' in payload
5913
+ const message = typeof payload === "object" && payload && "message" in payload
5914
5914
  ? String(payload.message)
5915
- : (axiosError === null || axiosError === void 0 ? void 0 : axiosError.message) || 'Request failed';
5916
- const errField = typeof payload === 'object' && payload && 'error' in payload
5915
+ : (axiosError === null || axiosError === void 0 ? void 0 : axiosError.message) || "Request failed";
5916
+ const errField = typeof payload === "object" && payload && "error" in payload
5917
5917
  ? String(payload.error)
5918
5918
  : undefined;
5919
5919
  return {
@@ -5923,8 +5923,8 @@ function toApiError(error) {
5923
5923
  };
5924
5924
  }
5925
5925
  function joinUrl(baseUrl, path) {
5926
- const cleanBase = baseUrl.replace(/\/$/, '');
5927
- const cleanPath = path.startsWith('/') ? path : `/${path}`;
5926
+ const cleanBase = baseUrl.replace(/\/$/, "");
5927
+ const cleanPath = path.startsWith("/") ? path : `/${path}`;
5928
5928
  return `${cleanBase}${cleanPath}`;
5929
5929
  }
5930
5930
  /**
@@ -5953,7 +5953,7 @@ function addAuthInterceptors(params) {
5953
5953
  pendingRequests = [];
5954
5954
  }
5955
5955
  const isOurApiUrl = (url) => Boolean(url && url.startsWith(apiBaseUrl));
5956
- const isRefreshUrl = (url) => Boolean(url && url.startsWith(joinUrl(apiBaseUrl, '/auth/refresh')));
5956
+ const isRefreshUrl = (url) => Boolean(url && url.startsWith(joinUrl(apiBaseUrl, "/auth/refresh")));
5957
5957
  const reqId = apiClient.interceptors.request.use((config) => {
5958
5958
  var _a;
5959
5959
  try {
@@ -5961,11 +5961,12 @@ function addAuthInterceptors(params) {
5961
5961
  const token = getAccessToken();
5962
5962
  if (token) {
5963
5963
  config.headers = (_a = config.headers) !== null && _a !== void 0 ? _a : {};
5964
- (config.headers)['Authorization'] = `Bearer ${token}`;
5964
+ config.headers["Authorization"] = `Bearer ${token}`;
5965
5965
  }
5966
5966
  }
5967
5967
  }
5968
- catch (_b) {
5968
+ catch (err) {
5969
+ console.error("[Auth Interceptor] Request interceptor error:", err);
5969
5970
  }
5970
5971
  return config;
5971
5972
  });
@@ -5976,22 +5977,36 @@ function addAuthInterceptors(params) {
5976
5977
  const url = originalRequest === null || originalRequest === void 0 ? void 0 : originalRequest.url;
5977
5978
  // If not our API or not 401, just reject
5978
5979
  if (!status || status !== 401 || !isOurApiUrl(url)) {
5980
+ if (status === 401) {
5981
+ console.warn("[Auth Interceptor] 401 received but URL check failed:", {
5982
+ url,
5983
+ apiBaseUrl,
5984
+ isOurApiUrl: isOurApiUrl(url),
5985
+ });
5986
+ }
5979
5987
  return Promise.reject(error);
5980
5988
  }
5989
+ console.log("[Auth Interceptor] 401 detected, attempting token refresh for URL:", url);
5981
5990
  // If the 401 is from refresh endpoint itself -> force logout
5982
5991
  if (isRefreshUrl(url)) {
5992
+ console.warn("[Auth Interceptor] Refresh endpoint returned 401, logging out");
5983
5993
  try {
5984
5994
  await logout();
5985
5995
  }
5986
- catch (_d) { }
5996
+ catch (err) {
5997
+ console.error("[Auth Interceptor] Logout failed:", err);
5998
+ }
5987
5999
  return Promise.reject(error);
5988
6000
  }
5989
6001
  // Prevent infinite loop
5990
6002
  if (originalRequest && originalRequest._retry) {
6003
+ console.warn("[Auth Interceptor] Request already retried, logging out");
5991
6004
  try {
5992
6005
  await logout();
5993
6006
  }
5994
- catch (_e) { }
6007
+ catch (err) {
6008
+ console.error("[Auth Interceptor] Logout failed:", err);
6009
+ }
5995
6010
  return Promise.reject(error);
5996
6011
  }
5997
6012
  // Mark so we don't retry twice
@@ -6005,31 +6020,45 @@ function addAuthInterceptors(params) {
6005
6020
  if (!newToken || !originalRequest)
6006
6021
  return reject(error);
6007
6022
  originalRequest.headers = (_a = originalRequest.headers) !== null && _a !== void 0 ? _a : {};
6008
- originalRequest.headers['Authorization'] = `Bearer ${newToken}`;
6023
+ originalRequest.headers["Authorization"] =
6024
+ `Bearer ${newToken}`;
6009
6025
  resolve(apiClient.request(originalRequest));
6010
6026
  });
6011
6027
  });
6012
6028
  }
6013
6029
  isRefreshing = true;
6014
6030
  try {
6031
+ console.log("[Auth Interceptor] Refreshing tokens...");
6015
6032
  const refreshed = await refreshTokens();
6016
- const newAccessToken = (_b = (refreshed && (refreshed.accessToken || ((_a = refreshed.data) === null || _a === void 0 ? void 0 : _a.accessToken)))) !== null && _b !== void 0 ? _b : null;
6033
+ const newAccessToken = (_b = (refreshed &&
6034
+ (refreshed.accessToken || ((_a = refreshed.data) === null || _a === void 0 ? void 0 : _a.accessToken)))) !== null && _b !== void 0 ? _b : null;
6035
+ if (!newAccessToken) {
6036
+ console.error("[Auth Interceptor] Token refresh succeeded but no access token in response:", refreshed);
6037
+ }
6038
+ else {
6039
+ console.log("[Auth Interceptor] Token refresh successful");
6040
+ }
6017
6041
  resolvePendingRequests(newAccessToken);
6018
6042
  if (originalRequest) {
6019
6043
  originalRequest.headers = (_c = originalRequest.headers) !== null && _c !== void 0 ? _c : {};
6020
6044
  if (newAccessToken)
6021
- (originalRequest.headers)['Authorization'] = `Bearer ${newAccessToken}`;
6045
+ originalRequest.headers["Authorization"] =
6046
+ `Bearer ${newAccessToken}`;
6047
+ console.log("[Auth Interceptor] Retrying original request with new token");
6022
6048
  const resp = await apiClient.request(originalRequest);
6023
6049
  return resp;
6024
6050
  }
6025
6051
  return Promise.reject(error);
6026
6052
  }
6027
6053
  catch (refreshErr) {
6054
+ console.error("[Auth Interceptor] Token refresh failed:", refreshErr);
6028
6055
  resolvePendingRequests(null);
6029
6056
  try {
6030
6057
  await logout();
6031
6058
  }
6032
- catch (_f) { }
6059
+ catch (err) {
6060
+ console.error("[Auth Interceptor] Logout failed:", err);
6061
+ }
6033
6062
  return Promise.reject(refreshErr);
6034
6063
  }
6035
6064
  finally {
@@ -6040,11 +6069,15 @@ function addAuthInterceptors(params) {
6040
6069
  try {
6041
6070
  apiClient.interceptors.request.eject(reqId);
6042
6071
  }
6043
- catch (_a) { }
6072
+ catch (err) {
6073
+ console.error("[Auth Interceptor] Failed to eject request interceptor:", err);
6074
+ }
6044
6075
  try {
6045
6076
  apiClient.interceptors.response.eject(resId);
6046
6077
  }
6047
- catch (_b) { }
6078
+ catch (err) {
6079
+ console.error("[Auth Interceptor] Failed to eject response interceptor:", err);
6080
+ }
6048
6081
  };
6049
6082
  }
6050
6083
 
@@ -8046,20 +8079,34 @@ function usePortfolio() {
8046
8079
  }
8047
8080
 
8048
8081
  async function getEIP712Message(baseUrl, address, clientId) {
8049
- const url = joinUrl(baseUrl, '/auth/eip712-message');
8082
+ const url = joinUrl(baseUrl, "/auth/eip712-message");
8050
8083
  try {
8051
- const resp = await axios$1.get(url, { params: { address, clientId }, timeout: 30000 });
8052
- return { data: resp.data, status: resp.status, headers: resp.headers };
8084
+ const resp = await apiClient.get(url, {
8085
+ params: { address, clientId },
8086
+ timeout: 30000,
8087
+ });
8088
+ return {
8089
+ data: resp.data,
8090
+ status: resp.status,
8091
+ headers: resp.headers,
8092
+ };
8053
8093
  }
8054
8094
  catch (error) {
8055
8095
  throw toApiError(error);
8056
8096
  }
8057
8097
  }
8058
8098
  async function authenticate(baseUrl, body) {
8059
- const url = joinUrl(baseUrl, '/auth/login');
8099
+ const url = joinUrl(baseUrl, "/auth/login");
8060
8100
  try {
8061
- const resp = await axios$1.post(url, body, { headers: { 'Content-Type': 'application/json' }, timeout: 30000 });
8062
- return { data: resp.data, status: resp.status, headers: resp.headers };
8101
+ const resp = await apiClient.post(url, body, {
8102
+ headers: { "Content-Type": "application/json" },
8103
+ timeout: 30000,
8104
+ });
8105
+ return {
8106
+ data: resp.data,
8107
+ status: resp.status,
8108
+ headers: resp.headers,
8109
+ };
8063
8110
  }
8064
8111
  catch (error) {
8065
8112
  throw toApiError(error);
@@ -8070,7 +8117,7 @@ async function authenticate(baseUrl, body) {
8070
8117
  */
8071
8118
  async function authenticateWithPrivy(baseUrl, params) {
8072
8119
  const body = {
8073
- method: 'privy_access_token',
8120
+ method: "privy_access_token",
8074
8121
  address: params.address,
8075
8122
  clientId: params.clientId,
8076
8123
  details: { appId: params.appId, accessToken: params.accessToken },
@@ -8078,20 +8125,28 @@ async function authenticateWithPrivy(baseUrl, params) {
8078
8125
  return authenticate(baseUrl, body);
8079
8126
  }
8080
8127
  async function refreshToken(baseUrl, refreshTokenVal) {
8081
- const url = joinUrl(baseUrl, '/auth/refresh');
8128
+ const url = joinUrl(baseUrl, "/auth/refresh");
8082
8129
  try {
8083
- const resp = await axios$1.post(url, { refreshToken: refreshTokenVal }, { headers: { 'Content-Type': 'application/json' }, timeout: 30000 });
8084
- return { data: resp.data, status: resp.status, headers: resp.headers };
8130
+ const resp = await apiClient.post(url, { refreshToken: refreshTokenVal }, { headers: { "Content-Type": "application/json" }, timeout: 30000 });
8131
+ return {
8132
+ data: resp.data,
8133
+ status: resp.status,
8134
+ headers: resp.headers,
8135
+ };
8085
8136
  }
8086
8137
  catch (error) {
8087
8138
  throw toApiError(error);
8088
8139
  }
8089
8140
  }
8090
8141
  async function logout(baseUrl, refreshTokenVal) {
8091
- const url = joinUrl(baseUrl, '/auth/logout');
8142
+ const url = joinUrl(baseUrl, "/auth/logout");
8092
8143
  try {
8093
- const resp = await axios$1.post(url, { refreshToken: refreshTokenVal }, { headers: { 'Content-Type': 'application/json' }, timeout: 30000 });
8094
- return { data: resp.data, status: resp.status, headers: resp.headers };
8144
+ const resp = await apiClient.post(url, { refreshToken: refreshTokenVal }, { headers: { "Content-Type": "application/json" }, timeout: 30000 });
8145
+ return {
8146
+ data: resp.data,
8147
+ status: resp.status,
8148
+ headers: resp.headers,
8149
+ };
8095
8150
  }
8096
8151
  catch (error) {
8097
8152
  throw toApiError(error);
@@ -1,5 +1,5 @@
1
- import type { AxiosInstance } from 'axios';
2
- import { ApiErrorResponse } from '../types';
1
+ import type { AxiosInstance } from "axios";
2
+ import { ApiErrorResponse } from "../types";
3
3
  export declare function toApiError(error: unknown): ApiErrorResponse;
4
4
  export declare function joinUrl(baseUrl: string, path: string): string;
5
5
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.73-beta.5",
3
+ "version": "0.0.73-beta.6",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",