@gymspace/sdk 1.0.3 → 1.1.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.
- package/dist/index.d.mts +1 -12
- package/dist/index.d.ts +1 -12
- package/dist/index.js +3 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +2 -89
- package/src/models/auth.ts +1 -0
- package/src/resources/onboarding.ts +2 -2
- package/src/sdk.ts +0 -6
package/dist/index.d.mts
CHANGED
|
@@ -35,15 +35,8 @@ type PaginationQueryDto = PaginationParams$1;
|
|
|
35
35
|
declare class ApiClient {
|
|
36
36
|
private axiosInstance;
|
|
37
37
|
private config;
|
|
38
|
-
private refreshPromise;
|
|
39
|
-
onTokensUpdated?: (accessToken: string, refreshToken: string) => void;
|
|
40
|
-
onAuthError?: (error: any) => void;
|
|
41
38
|
constructor(config: GymSpaceConfig);
|
|
42
39
|
private setupInterceptors;
|
|
43
|
-
/**
|
|
44
|
-
* Refresh the access token using the stored refresh token
|
|
45
|
-
*/
|
|
46
|
-
private refreshAccessToken;
|
|
47
40
|
private handleError;
|
|
48
41
|
private mergeOptions;
|
|
49
42
|
request<T>(method: string, path: string, data?: any, options?: RequestOptions & AxiosRequestConfig): Promise<T>;
|
|
@@ -53,7 +46,6 @@ declare class ApiClient {
|
|
|
53
46
|
patch<T>(path: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
54
47
|
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
55
48
|
setAuthToken(token: string): void;
|
|
56
|
-
setTokens(accessToken: string, refreshToken: string): void;
|
|
57
49
|
setGymId(gymId: string): void;
|
|
58
50
|
clearAuth(): void;
|
|
59
51
|
getBaseUrl(): string;
|
|
@@ -147,6 +139,7 @@ interface InvitationValidationResponse {
|
|
|
147
139
|
};
|
|
148
140
|
}
|
|
149
141
|
interface CurrentSessionResponse {
|
|
142
|
+
accessToken: string;
|
|
150
143
|
user: {
|
|
151
144
|
id: string;
|
|
152
145
|
email: string;
|
|
@@ -2028,10 +2021,6 @@ declare class GymSpaceSdk {
|
|
|
2028
2021
|
* Set the authentication token
|
|
2029
2022
|
*/
|
|
2030
2023
|
setAuthToken(token: string): void;
|
|
2031
|
-
/**
|
|
2032
|
-
* Set both access and refresh tokens
|
|
2033
|
-
*/
|
|
2034
|
-
setTokens(accessToken: string, refreshToken: string): void;
|
|
2035
2024
|
/**
|
|
2036
2025
|
* Set the current gym context
|
|
2037
2026
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -35,15 +35,8 @@ type PaginationQueryDto = PaginationParams$1;
|
|
|
35
35
|
declare class ApiClient {
|
|
36
36
|
private axiosInstance;
|
|
37
37
|
private config;
|
|
38
|
-
private refreshPromise;
|
|
39
|
-
onTokensUpdated?: (accessToken: string, refreshToken: string) => void;
|
|
40
|
-
onAuthError?: (error: any) => void;
|
|
41
38
|
constructor(config: GymSpaceConfig);
|
|
42
39
|
private setupInterceptors;
|
|
43
|
-
/**
|
|
44
|
-
* Refresh the access token using the stored refresh token
|
|
45
|
-
*/
|
|
46
|
-
private refreshAccessToken;
|
|
47
40
|
private handleError;
|
|
48
41
|
private mergeOptions;
|
|
49
42
|
request<T>(method: string, path: string, data?: any, options?: RequestOptions & AxiosRequestConfig): Promise<T>;
|
|
@@ -53,7 +46,6 @@ declare class ApiClient {
|
|
|
53
46
|
patch<T>(path: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
54
47
|
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
55
48
|
setAuthToken(token: string): void;
|
|
56
|
-
setTokens(accessToken: string, refreshToken: string): void;
|
|
57
49
|
setGymId(gymId: string): void;
|
|
58
50
|
clearAuth(): void;
|
|
59
51
|
getBaseUrl(): string;
|
|
@@ -147,6 +139,7 @@ interface InvitationValidationResponse {
|
|
|
147
139
|
};
|
|
148
140
|
}
|
|
149
141
|
interface CurrentSessionResponse {
|
|
142
|
+
accessToken: string;
|
|
150
143
|
user: {
|
|
151
144
|
id: string;
|
|
152
145
|
email: string;
|
|
@@ -2028,10 +2021,6 @@ declare class GymSpaceSdk {
|
|
|
2028
2021
|
* Set the authentication token
|
|
2029
2022
|
*/
|
|
2030
2023
|
setAuthToken(token: string): void;
|
|
2031
|
-
/**
|
|
2032
|
-
* Set both access and refresh tokens
|
|
2033
|
-
*/
|
|
2034
|
-
setTokens(accessToken: string, refreshToken: string): void;
|
|
2035
2024
|
/**
|
|
2036
2025
|
* Set the current gym context
|
|
2037
2026
|
*/
|
package/dist/index.js
CHANGED
|
@@ -53,7 +53,6 @@ var NetworkError = class extends GymSpaceError {
|
|
|
53
53
|
// src/client.ts
|
|
54
54
|
var ApiClient = class {
|
|
55
55
|
constructor(config) {
|
|
56
|
-
this.refreshPromise = null;
|
|
57
56
|
this.config = config;
|
|
58
57
|
this.axiosInstance = axios__default.default.create({
|
|
59
58
|
baseURL: config.baseURL,
|
|
@@ -71,9 +70,6 @@ var ApiClient = class {
|
|
|
71
70
|
if (this.config.apiKey && config.headers) {
|
|
72
71
|
config.headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
73
72
|
}
|
|
74
|
-
if (this.config.refreshToken && config.headers) {
|
|
75
|
-
config.headers["X-Refresh-Token"] = this.config.refreshToken;
|
|
76
|
-
}
|
|
77
73
|
return config;
|
|
78
74
|
},
|
|
79
75
|
(error) => {
|
|
@@ -82,66 +78,13 @@ var ApiClient = class {
|
|
|
82
78
|
);
|
|
83
79
|
this.axiosInstance.interceptors.response.use(
|
|
84
80
|
(response) => {
|
|
85
|
-
const newAccessToken = response.headers["x-new-access-token"];
|
|
86
|
-
const newRefreshToken = response.headers["x-new-refresh-token"];
|
|
87
|
-
if (newAccessToken && newRefreshToken) {
|
|
88
|
-
this.setTokens(newAccessToken, newRefreshToken);
|
|
89
|
-
this.onTokensUpdated?.(newAccessToken, newRefreshToken);
|
|
90
|
-
}
|
|
91
81
|
return response;
|
|
92
82
|
},
|
|
93
83
|
async (error) => {
|
|
94
|
-
const originalRequest = error.config;
|
|
95
|
-
if (error.response?.status === 401 && !originalRequest._retry && this.config.refreshToken) {
|
|
96
|
-
originalRequest._retry = true;
|
|
97
|
-
try {
|
|
98
|
-
if (!this.refreshPromise) {
|
|
99
|
-
this.refreshPromise = this.refreshAccessToken();
|
|
100
|
-
}
|
|
101
|
-
const newTokens = await this.refreshPromise;
|
|
102
|
-
this.refreshPromise = null;
|
|
103
|
-
if (newTokens) {
|
|
104
|
-
if (!originalRequest.headers) {
|
|
105
|
-
originalRequest.headers = {};
|
|
106
|
-
}
|
|
107
|
-
originalRequest.headers["Authorization"] = `Bearer ${newTokens.access_token}`;
|
|
108
|
-
return this.axiosInstance(originalRequest);
|
|
109
|
-
}
|
|
110
|
-
} catch (refreshError) {
|
|
111
|
-
this.refreshPromise = null;
|
|
112
|
-
this.clearAuth();
|
|
113
|
-
this.onAuthError?.(refreshError);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
84
|
throw this.handleError(error);
|
|
117
85
|
}
|
|
118
86
|
);
|
|
119
87
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Refresh the access token using the stored refresh token
|
|
122
|
-
*/
|
|
123
|
-
async refreshAccessToken() {
|
|
124
|
-
if (!this.config.refreshToken) {
|
|
125
|
-
throw new AuthenticationError("No refresh token available");
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
const response = await axios__default.default.post(
|
|
129
|
-
`${this.config.baseURL}/auth/refresh`,
|
|
130
|
-
{ refresh_token: this.config.refreshToken },
|
|
131
|
-
{
|
|
132
|
-
headers: {
|
|
133
|
-
"Content-Type": "application/json"
|
|
134
|
-
},
|
|
135
|
-
timeout: this.config.timeout || 3e4
|
|
136
|
-
}
|
|
137
|
-
);
|
|
138
|
-
const newTokens = response.data;
|
|
139
|
-
this.setTokens(newTokens.access_token, newTokens.refresh_token);
|
|
140
|
-
return newTokens;
|
|
141
|
-
} catch (error) {
|
|
142
|
-
throw new AuthenticationError("Failed to refresh token");
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
88
|
handleError(error) {
|
|
146
89
|
const requestPath = error.config?.url || "unknown";
|
|
147
90
|
const method = error.config?.method?.toUpperCase() || "unknown";
|
|
@@ -224,16 +167,11 @@ var ApiClient = class {
|
|
|
224
167
|
setAuthToken(token) {
|
|
225
168
|
this.config.apiKey = token;
|
|
226
169
|
}
|
|
227
|
-
setTokens(accessToken, refreshToken) {
|
|
228
|
-
this.config.apiKey = accessToken;
|
|
229
|
-
this.config.refreshToken = refreshToken;
|
|
230
|
-
}
|
|
231
170
|
setGymId(gymId) {
|
|
232
171
|
this.axiosInstance.defaults.headers.common["X-Gym-Id"] = gymId;
|
|
233
172
|
}
|
|
234
173
|
clearAuth() {
|
|
235
174
|
delete this.config.apiKey;
|
|
236
|
-
delete this.config.refreshToken;
|
|
237
175
|
delete this.axiosInstance.defaults.headers.common["Authorization"];
|
|
238
176
|
delete this.axiosInstance.defaults.headers.common["X-Gym-Id"];
|
|
239
177
|
}
|
|
@@ -908,8 +846,8 @@ var OnboardingResource = class extends BaseResource {
|
|
|
908
846
|
*/
|
|
909
847
|
async start(data) {
|
|
910
848
|
const response = await this.client.post("/onboarding/start", data);
|
|
911
|
-
if (response.access_token
|
|
912
|
-
this.client.
|
|
849
|
+
if (response.access_token) {
|
|
850
|
+
this.client.setAuthToken(response.access_token);
|
|
913
851
|
}
|
|
914
852
|
return response;
|
|
915
853
|
}
|
|
@@ -1209,12 +1147,6 @@ var GymSpaceSdk = class {
|
|
|
1209
1147
|
setAuthToken(token) {
|
|
1210
1148
|
this.client.setAuthToken(token);
|
|
1211
1149
|
}
|
|
1212
|
-
/**
|
|
1213
|
-
* Set both access and refresh tokens
|
|
1214
|
-
*/
|
|
1215
|
-
setTokens(accessToken, refreshToken) {
|
|
1216
|
-
this.client.setTokens(accessToken, refreshToken);
|
|
1217
|
-
}
|
|
1218
1150
|
/**
|
|
1219
1151
|
* Set the current gym context
|
|
1220
1152
|
*/
|
|
@@ -1235,7 +1167,7 @@ var GymSpaceSdk = class {
|
|
|
1235
1167
|
}
|
|
1236
1168
|
};
|
|
1237
1169
|
|
|
1238
|
-
// node_modules/@gymspace/shared/dist/index.mjs
|
|
1170
|
+
// ../../node_modules/@gymspace/shared/dist/index.mjs
|
|
1239
1171
|
var UserType = /* @__PURE__ */ ((UserType2) => {
|
|
1240
1172
|
UserType2["OWNER"] = "owner";
|
|
1241
1173
|
UserType2["COLLABORATOR"] = "collaborator";
|