@gymspace/sdk 1.0.3 → 1.1.1
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 +19 -12
- package/dist/index.d.ts +19 -12
- package/dist/index.js +24 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -66
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +13 -85
- package/src/models/auth.ts +2 -0
- package/src/models/contracts.ts +1 -1
- package/src/models/sales.ts +6 -0
- package/src/resources/onboarding.ts +2 -2
- package/src/resources/sales.ts +11 -2
- package/src/sdk.ts +10 -3
package/dist/index.mjs
CHANGED
|
@@ -47,7 +47,7 @@ var NetworkError = class extends GymSpaceError {
|
|
|
47
47
|
// src/client.ts
|
|
48
48
|
var ApiClient = class {
|
|
49
49
|
constructor(config) {
|
|
50
|
-
this.
|
|
50
|
+
this.refreshToken = null;
|
|
51
51
|
this.config = config;
|
|
52
52
|
this.axiosInstance = axios.create({
|
|
53
53
|
baseURL: config.baseURL,
|
|
@@ -65,8 +65,8 @@ var ApiClient = class {
|
|
|
65
65
|
if (this.config.apiKey && config.headers) {
|
|
66
66
|
config.headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
67
67
|
}
|
|
68
|
-
if (this.config.
|
|
69
|
-
config.headers["X-Refresh-Token"] = this.
|
|
68
|
+
if (this.refreshToken && config.url?.includes("current-session") && config.headers) {
|
|
69
|
+
config.headers["X-Refresh-Token"] = this.refreshToken;
|
|
70
70
|
}
|
|
71
71
|
return config;
|
|
72
72
|
},
|
|
@@ -76,66 +76,13 @@ var ApiClient = class {
|
|
|
76
76
|
);
|
|
77
77
|
this.axiosInstance.interceptors.response.use(
|
|
78
78
|
(response) => {
|
|
79
|
-
const newAccessToken = response.headers["x-new-access-token"];
|
|
80
|
-
const newRefreshToken = response.headers["x-new-refresh-token"];
|
|
81
|
-
if (newAccessToken && newRefreshToken) {
|
|
82
|
-
this.setTokens(newAccessToken, newRefreshToken);
|
|
83
|
-
this.onTokensUpdated?.(newAccessToken, newRefreshToken);
|
|
84
|
-
}
|
|
85
79
|
return response;
|
|
86
80
|
},
|
|
87
81
|
async (error) => {
|
|
88
|
-
const originalRequest = error.config;
|
|
89
|
-
if (error.response?.status === 401 && !originalRequest._retry && this.config.refreshToken) {
|
|
90
|
-
originalRequest._retry = true;
|
|
91
|
-
try {
|
|
92
|
-
if (!this.refreshPromise) {
|
|
93
|
-
this.refreshPromise = this.refreshAccessToken();
|
|
94
|
-
}
|
|
95
|
-
const newTokens = await this.refreshPromise;
|
|
96
|
-
this.refreshPromise = null;
|
|
97
|
-
if (newTokens) {
|
|
98
|
-
if (!originalRequest.headers) {
|
|
99
|
-
originalRequest.headers = {};
|
|
100
|
-
}
|
|
101
|
-
originalRequest.headers["Authorization"] = `Bearer ${newTokens.access_token}`;
|
|
102
|
-
return this.axiosInstance(originalRequest);
|
|
103
|
-
}
|
|
104
|
-
} catch (refreshError) {
|
|
105
|
-
this.refreshPromise = null;
|
|
106
|
-
this.clearAuth();
|
|
107
|
-
this.onAuthError?.(refreshError);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
82
|
throw this.handleError(error);
|
|
111
83
|
}
|
|
112
84
|
);
|
|
113
85
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Refresh the access token using the stored refresh token
|
|
116
|
-
*/
|
|
117
|
-
async refreshAccessToken() {
|
|
118
|
-
if (!this.config.refreshToken) {
|
|
119
|
-
throw new AuthenticationError("No refresh token available");
|
|
120
|
-
}
|
|
121
|
-
try {
|
|
122
|
-
const response = await axios.post(
|
|
123
|
-
`${this.config.baseURL}/auth/refresh`,
|
|
124
|
-
{ refresh_token: this.config.refreshToken },
|
|
125
|
-
{
|
|
126
|
-
headers: {
|
|
127
|
-
"Content-Type": "application/json"
|
|
128
|
-
},
|
|
129
|
-
timeout: this.config.timeout || 3e4
|
|
130
|
-
}
|
|
131
|
-
);
|
|
132
|
-
const newTokens = response.data;
|
|
133
|
-
this.setTokens(newTokens.access_token, newTokens.refresh_token);
|
|
134
|
-
return newTokens;
|
|
135
|
-
} catch (error) {
|
|
136
|
-
throw new AuthenticationError("Failed to refresh token");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
86
|
handleError(error) {
|
|
140
87
|
const requestPath = error.config?.url || "unknown";
|
|
141
88
|
const method = error.config?.method?.toUpperCase() || "unknown";
|
|
@@ -218,16 +165,18 @@ var ApiClient = class {
|
|
|
218
165
|
setAuthToken(token) {
|
|
219
166
|
this.config.apiKey = token;
|
|
220
167
|
}
|
|
221
|
-
|
|
222
|
-
this.
|
|
223
|
-
|
|
168
|
+
setRefreshToken(token) {
|
|
169
|
+
this.refreshToken = token;
|
|
170
|
+
}
|
|
171
|
+
getRefreshToken() {
|
|
172
|
+
return this.refreshToken;
|
|
224
173
|
}
|
|
225
174
|
setGymId(gymId) {
|
|
226
175
|
this.axiosInstance.defaults.headers.common["X-Gym-Id"] = gymId;
|
|
227
176
|
}
|
|
228
177
|
clearAuth() {
|
|
229
178
|
delete this.config.apiKey;
|
|
230
|
-
|
|
179
|
+
this.refreshToken = null;
|
|
231
180
|
delete this.axiosInstance.defaults.headers.common["Authorization"];
|
|
232
181
|
delete this.axiosInstance.defaults.headers.common["X-Gym-Id"];
|
|
233
182
|
}
|
|
@@ -902,8 +851,8 @@ var OnboardingResource = class extends BaseResource {
|
|
|
902
851
|
*/
|
|
903
852
|
async start(data) {
|
|
904
853
|
const response = await this.client.post("/onboarding/start", data);
|
|
905
|
-
if (response.access_token
|
|
906
|
-
this.client.
|
|
854
|
+
if (response.access_token) {
|
|
855
|
+
this.client.setAuthToken(response.access_token);
|
|
907
856
|
}
|
|
908
857
|
return response;
|
|
909
858
|
}
|
|
@@ -1013,6 +962,9 @@ var SalesResource = class extends BaseResource {
|
|
|
1013
962
|
async updatePaymentStatus(id, paymentStatus, options) {
|
|
1014
963
|
return this.client.put(`${this.basePath}/${id}/payment-status`, { paymentStatus }, options);
|
|
1015
964
|
}
|
|
965
|
+
async paySale(id, data, options) {
|
|
966
|
+
return this.client.post(`${this.basePath}/${id}/payment`, data, options);
|
|
967
|
+
}
|
|
1016
968
|
async deleteSale(id, options) {
|
|
1017
969
|
return this.client.delete(`${this.basePath}/${id}`, options);
|
|
1018
970
|
}
|
|
@@ -1204,10 +1156,16 @@ var GymSpaceSdk = class {
|
|
|
1204
1156
|
this.client.setAuthToken(token);
|
|
1205
1157
|
}
|
|
1206
1158
|
/**
|
|
1207
|
-
* Set
|
|
1159
|
+
* Set the refresh token
|
|
1160
|
+
*/
|
|
1161
|
+
setRefreshToken(token) {
|
|
1162
|
+
this.client.setRefreshToken(token);
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Get the current refresh token
|
|
1208
1166
|
*/
|
|
1209
|
-
|
|
1210
|
-
this.client.
|
|
1167
|
+
getRefreshToken() {
|
|
1168
|
+
return this.client.getRefreshToken();
|
|
1211
1169
|
}
|
|
1212
1170
|
/**
|
|
1213
1171
|
* Set the current gym context
|
|
@@ -1229,7 +1187,7 @@ var GymSpaceSdk = class {
|
|
|
1229
1187
|
}
|
|
1230
1188
|
};
|
|
1231
1189
|
|
|
1232
|
-
// node_modules/@gymspace/shared/dist/index.mjs
|
|
1190
|
+
// ../../node_modules/@gymspace/shared/dist/index.mjs
|
|
1233
1191
|
var UserType = /* @__PURE__ */ ((UserType2) => {
|
|
1234
1192
|
UserType2["OWNER"] = "owner";
|
|
1235
1193
|
UserType2["COLLABORATOR"] = "collaborator";
|