@pear-protocol/hyperliquid-sdk 0.0.73-beta.4 → 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.
- package/dist/clients/auth.d.ts +1 -1
- package/dist/index.js +87 -36
- package/dist/store/userDataStore.d.ts +3 -1
- package/dist/utils/http.d.ts +2 -2
- package/package.json +1 -1
package/dist/clients/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiResponse, GetEIP712MessageResponse, AuthenticateRequest, AuthenticateResponse, RefreshTokenResponse, LogoutResponse } from
|
|
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
|
@@ -64,18 +64,12 @@ const useUserData = create((set) => ({
|
|
|
64
64
|
twapDetails: null,
|
|
65
65
|
notifications: null,
|
|
66
66
|
userExtraAgents: null,
|
|
67
|
+
spotState: null,
|
|
67
68
|
setAccessToken: (token) => set({ accessToken: token }),
|
|
68
69
|
setRefreshToken: (token) => set({ refreshToken: token }),
|
|
69
70
|
setIsAuthenticated: (value) => set({ isAuthenticated: value }),
|
|
70
71
|
setIsReady: (value) => set({ isReady: value }),
|
|
71
72
|
setAddress: (address) => {
|
|
72
|
-
// if (typeof window !== "undefined") {
|
|
73
|
-
// if (address) {
|
|
74
|
-
// window.localStorage.setItem("address", address);
|
|
75
|
-
// } else {
|
|
76
|
-
// window.localStorage.removeItem("address");
|
|
77
|
-
// }
|
|
78
|
-
// }
|
|
79
73
|
set({ address });
|
|
80
74
|
},
|
|
81
75
|
setTradeHistories: (value) => set({ tradeHistories: value }),
|
|
@@ -84,6 +78,7 @@ const useUserData = create((set) => ({
|
|
|
84
78
|
setAccountSummary: (value) => set({ accountSummary: value }),
|
|
85
79
|
setTwapDetails: (value) => set({ twapDetails: value }),
|
|
86
80
|
setNotifications: (value) => set({ notifications: value }),
|
|
81
|
+
setSpotState: (value) => set({ spotState: value }),
|
|
87
82
|
clean: () => set({
|
|
88
83
|
// accessToken: null,
|
|
89
84
|
// refreshToken: null,
|
|
@@ -96,6 +91,7 @@ const useUserData = create((set) => ({
|
|
|
96
91
|
accountSummary: null,
|
|
97
92
|
twapDetails: null,
|
|
98
93
|
notifications: null,
|
|
94
|
+
spotState: null,
|
|
99
95
|
}),
|
|
100
96
|
setUserExtraAgents: (value) => set({ userExtraAgents: value }),
|
|
101
97
|
}));
|
|
@@ -5914,10 +5910,10 @@ function toApiError(error) {
|
|
|
5914
5910
|
var _a;
|
|
5915
5911
|
const axiosError = error;
|
|
5916
5912
|
const payload = (axiosError && axiosError.response ? axiosError.response.data : undefined);
|
|
5917
|
-
const message = typeof payload ===
|
|
5913
|
+
const message = typeof payload === "object" && payload && "message" in payload
|
|
5918
5914
|
? String(payload.message)
|
|
5919
|
-
: (axiosError === null || axiosError === void 0 ? void 0 : axiosError.message) ||
|
|
5920
|
-
const errField = typeof payload ===
|
|
5915
|
+
: (axiosError === null || axiosError === void 0 ? void 0 : axiosError.message) || "Request failed";
|
|
5916
|
+
const errField = typeof payload === "object" && payload && "error" in payload
|
|
5921
5917
|
? String(payload.error)
|
|
5922
5918
|
: undefined;
|
|
5923
5919
|
return {
|
|
@@ -5927,8 +5923,8 @@ function toApiError(error) {
|
|
|
5927
5923
|
};
|
|
5928
5924
|
}
|
|
5929
5925
|
function joinUrl(baseUrl, path) {
|
|
5930
|
-
const cleanBase = baseUrl.replace(/\/$/,
|
|
5931
|
-
const cleanPath = path.startsWith(
|
|
5926
|
+
const cleanBase = baseUrl.replace(/\/$/, "");
|
|
5927
|
+
const cleanPath = path.startsWith("/") ? path : `/${path}`;
|
|
5932
5928
|
return `${cleanBase}${cleanPath}`;
|
|
5933
5929
|
}
|
|
5934
5930
|
/**
|
|
@@ -5957,7 +5953,7 @@ function addAuthInterceptors(params) {
|
|
|
5957
5953
|
pendingRequests = [];
|
|
5958
5954
|
}
|
|
5959
5955
|
const isOurApiUrl = (url) => Boolean(url && url.startsWith(apiBaseUrl));
|
|
5960
|
-
const isRefreshUrl = (url) => Boolean(url && url.startsWith(joinUrl(apiBaseUrl,
|
|
5956
|
+
const isRefreshUrl = (url) => Boolean(url && url.startsWith(joinUrl(apiBaseUrl, "/auth/refresh")));
|
|
5961
5957
|
const reqId = apiClient.interceptors.request.use((config) => {
|
|
5962
5958
|
var _a;
|
|
5963
5959
|
try {
|
|
@@ -5965,11 +5961,12 @@ function addAuthInterceptors(params) {
|
|
|
5965
5961
|
const token = getAccessToken();
|
|
5966
5962
|
if (token) {
|
|
5967
5963
|
config.headers = (_a = config.headers) !== null && _a !== void 0 ? _a : {};
|
|
5968
|
-
|
|
5964
|
+
config.headers["Authorization"] = `Bearer ${token}`;
|
|
5969
5965
|
}
|
|
5970
5966
|
}
|
|
5971
5967
|
}
|
|
5972
|
-
catch (
|
|
5968
|
+
catch (err) {
|
|
5969
|
+
console.error("[Auth Interceptor] Request interceptor error:", err);
|
|
5973
5970
|
}
|
|
5974
5971
|
return config;
|
|
5975
5972
|
});
|
|
@@ -5980,22 +5977,36 @@ function addAuthInterceptors(params) {
|
|
|
5980
5977
|
const url = originalRequest === null || originalRequest === void 0 ? void 0 : originalRequest.url;
|
|
5981
5978
|
// If not our API or not 401, just reject
|
|
5982
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
|
+
}
|
|
5983
5987
|
return Promise.reject(error);
|
|
5984
5988
|
}
|
|
5989
|
+
console.log("[Auth Interceptor] 401 detected, attempting token refresh for URL:", url);
|
|
5985
5990
|
// If the 401 is from refresh endpoint itself -> force logout
|
|
5986
5991
|
if (isRefreshUrl(url)) {
|
|
5992
|
+
console.warn("[Auth Interceptor] Refresh endpoint returned 401, logging out");
|
|
5987
5993
|
try {
|
|
5988
5994
|
await logout();
|
|
5989
5995
|
}
|
|
5990
|
-
catch (
|
|
5996
|
+
catch (err) {
|
|
5997
|
+
console.error("[Auth Interceptor] Logout failed:", err);
|
|
5998
|
+
}
|
|
5991
5999
|
return Promise.reject(error);
|
|
5992
6000
|
}
|
|
5993
6001
|
// Prevent infinite loop
|
|
5994
6002
|
if (originalRequest && originalRequest._retry) {
|
|
6003
|
+
console.warn("[Auth Interceptor] Request already retried, logging out");
|
|
5995
6004
|
try {
|
|
5996
6005
|
await logout();
|
|
5997
6006
|
}
|
|
5998
|
-
catch (
|
|
6007
|
+
catch (err) {
|
|
6008
|
+
console.error("[Auth Interceptor] Logout failed:", err);
|
|
6009
|
+
}
|
|
5999
6010
|
return Promise.reject(error);
|
|
6000
6011
|
}
|
|
6001
6012
|
// Mark so we don't retry twice
|
|
@@ -6009,31 +6020,45 @@ function addAuthInterceptors(params) {
|
|
|
6009
6020
|
if (!newToken || !originalRequest)
|
|
6010
6021
|
return reject(error);
|
|
6011
6022
|
originalRequest.headers = (_a = originalRequest.headers) !== null && _a !== void 0 ? _a : {};
|
|
6012
|
-
originalRequest.headers[
|
|
6023
|
+
originalRequest.headers["Authorization"] =
|
|
6024
|
+
`Bearer ${newToken}`;
|
|
6013
6025
|
resolve(apiClient.request(originalRequest));
|
|
6014
6026
|
});
|
|
6015
6027
|
});
|
|
6016
6028
|
}
|
|
6017
6029
|
isRefreshing = true;
|
|
6018
6030
|
try {
|
|
6031
|
+
console.log("[Auth Interceptor] Refreshing tokens...");
|
|
6019
6032
|
const refreshed = await refreshTokens();
|
|
6020
|
-
const newAccessToken = (_b = (refreshed &&
|
|
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
|
+
}
|
|
6021
6041
|
resolvePendingRequests(newAccessToken);
|
|
6022
6042
|
if (originalRequest) {
|
|
6023
6043
|
originalRequest.headers = (_c = originalRequest.headers) !== null && _c !== void 0 ? _c : {};
|
|
6024
6044
|
if (newAccessToken)
|
|
6025
|
-
|
|
6045
|
+
originalRequest.headers["Authorization"] =
|
|
6046
|
+
`Bearer ${newAccessToken}`;
|
|
6047
|
+
console.log("[Auth Interceptor] Retrying original request with new token");
|
|
6026
6048
|
const resp = await apiClient.request(originalRequest);
|
|
6027
6049
|
return resp;
|
|
6028
6050
|
}
|
|
6029
6051
|
return Promise.reject(error);
|
|
6030
6052
|
}
|
|
6031
6053
|
catch (refreshErr) {
|
|
6054
|
+
console.error("[Auth Interceptor] Token refresh failed:", refreshErr);
|
|
6032
6055
|
resolvePendingRequests(null);
|
|
6033
6056
|
try {
|
|
6034
6057
|
await logout();
|
|
6035
6058
|
}
|
|
6036
|
-
catch (
|
|
6059
|
+
catch (err) {
|
|
6060
|
+
console.error("[Auth Interceptor] Logout failed:", err);
|
|
6061
|
+
}
|
|
6037
6062
|
return Promise.reject(refreshErr);
|
|
6038
6063
|
}
|
|
6039
6064
|
finally {
|
|
@@ -6044,11 +6069,15 @@ function addAuthInterceptors(params) {
|
|
|
6044
6069
|
try {
|
|
6045
6070
|
apiClient.interceptors.request.eject(reqId);
|
|
6046
6071
|
}
|
|
6047
|
-
catch (
|
|
6072
|
+
catch (err) {
|
|
6073
|
+
console.error("[Auth Interceptor] Failed to eject request interceptor:", err);
|
|
6074
|
+
}
|
|
6048
6075
|
try {
|
|
6049
6076
|
apiClient.interceptors.response.eject(resId);
|
|
6050
6077
|
}
|
|
6051
|
-
catch (
|
|
6078
|
+
catch (err) {
|
|
6079
|
+
console.error("[Auth Interceptor] Failed to eject response interceptor:", err);
|
|
6080
|
+
}
|
|
6052
6081
|
};
|
|
6053
6082
|
}
|
|
6054
6083
|
|
|
@@ -8050,20 +8079,34 @@ function usePortfolio() {
|
|
|
8050
8079
|
}
|
|
8051
8080
|
|
|
8052
8081
|
async function getEIP712Message(baseUrl, address, clientId) {
|
|
8053
|
-
const url = joinUrl(baseUrl,
|
|
8082
|
+
const url = joinUrl(baseUrl, "/auth/eip712-message");
|
|
8054
8083
|
try {
|
|
8055
|
-
const resp = await
|
|
8056
|
-
|
|
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
|
+
};
|
|
8057
8093
|
}
|
|
8058
8094
|
catch (error) {
|
|
8059
8095
|
throw toApiError(error);
|
|
8060
8096
|
}
|
|
8061
8097
|
}
|
|
8062
8098
|
async function authenticate(baseUrl, body) {
|
|
8063
|
-
const url = joinUrl(baseUrl,
|
|
8099
|
+
const url = joinUrl(baseUrl, "/auth/login");
|
|
8064
8100
|
try {
|
|
8065
|
-
const resp = await
|
|
8066
|
-
|
|
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
|
+
};
|
|
8067
8110
|
}
|
|
8068
8111
|
catch (error) {
|
|
8069
8112
|
throw toApiError(error);
|
|
@@ -8074,7 +8117,7 @@ async function authenticate(baseUrl, body) {
|
|
|
8074
8117
|
*/
|
|
8075
8118
|
async function authenticateWithPrivy(baseUrl, params) {
|
|
8076
8119
|
const body = {
|
|
8077
|
-
method:
|
|
8120
|
+
method: "privy_access_token",
|
|
8078
8121
|
address: params.address,
|
|
8079
8122
|
clientId: params.clientId,
|
|
8080
8123
|
details: { appId: params.appId, accessToken: params.accessToken },
|
|
@@ -8082,20 +8125,28 @@ async function authenticateWithPrivy(baseUrl, params) {
|
|
|
8082
8125
|
return authenticate(baseUrl, body);
|
|
8083
8126
|
}
|
|
8084
8127
|
async function refreshToken(baseUrl, refreshTokenVal) {
|
|
8085
|
-
const url = joinUrl(baseUrl,
|
|
8128
|
+
const url = joinUrl(baseUrl, "/auth/refresh");
|
|
8086
8129
|
try {
|
|
8087
|
-
const resp = await
|
|
8088
|
-
return {
|
|
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
|
+
};
|
|
8089
8136
|
}
|
|
8090
8137
|
catch (error) {
|
|
8091
8138
|
throw toApiError(error);
|
|
8092
8139
|
}
|
|
8093
8140
|
}
|
|
8094
8141
|
async function logout(baseUrl, refreshTokenVal) {
|
|
8095
|
-
const url = joinUrl(baseUrl,
|
|
8142
|
+
const url = joinUrl(baseUrl, "/auth/logout");
|
|
8096
8143
|
try {
|
|
8097
|
-
const resp = await
|
|
8098
|
-
return {
|
|
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
|
+
};
|
|
8099
8150
|
}
|
|
8100
8151
|
catch (error) {
|
|
8101
8152
|
throw toApiError(error);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlatformAccountSummaryResponseDto, OpenLimitOrderDto, RawPositionDto, TradeHistoryDataDto, TwapMonitoringDto, NotificationDto, ExtraAgent } from "../types";
|
|
1
|
+
import { PlatformAccountSummaryResponseDto, OpenLimitOrderDto, RawPositionDto, TradeHistoryDataDto, TwapMonitoringDto, NotificationDto, ExtraAgent, SpotState } from "../types";
|
|
2
2
|
interface UserDataState {
|
|
3
3
|
accessToken: string | null;
|
|
4
4
|
refreshToken: string | null;
|
|
@@ -12,6 +12,7 @@ interface UserDataState {
|
|
|
12
12
|
twapDetails: TwapMonitoringDto[] | null;
|
|
13
13
|
notifications: NotificationDto[] | null;
|
|
14
14
|
userExtraAgents: ExtraAgent[] | null;
|
|
15
|
+
spotState: SpotState | null;
|
|
15
16
|
setAccessToken: (token: string | null) => void;
|
|
16
17
|
setRefreshToken: (token: string | null) => void;
|
|
17
18
|
setIsAuthenticated: (value: boolean) => void;
|
|
@@ -24,6 +25,7 @@ interface UserDataState {
|
|
|
24
25
|
setUserExtraAgents: (value: ExtraAgent[] | null) => void;
|
|
25
26
|
setTwapDetails: (value: TwapMonitoringDto[] | null) => void;
|
|
26
27
|
setNotifications: (value: NotificationDto[] | null) => void;
|
|
28
|
+
setSpotState: (value: SpotState | null) => void;
|
|
27
29
|
clean: () => void;
|
|
28
30
|
}
|
|
29
31
|
export declare const useUserData: import("zustand").UseBoundStore<import("zustand").StoreApi<UserDataState>>;
|
package/dist/utils/http.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AxiosInstance } from
|
|
2
|
-
import { ApiErrorResponse } from
|
|
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
|
/**
|