@gymspace/sdk 1.1.0 → 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 +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +15 -0
- package/src/models/auth.ts +1 -0
- package/src/models/contracts.ts +1 -1
- package/src/models/sales.ts +6 -0
- package/src/resources/sales.ts +11 -2
- package/src/sdk.ts +13 -0
package/src/client.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
export class ApiClient {
|
|
19
19
|
private axiosInstance: AxiosInstance;
|
|
20
20
|
private config: GymSpaceConfig;
|
|
21
|
+
private refreshToken: string | null = null;
|
|
21
22
|
|
|
22
23
|
constructor(config: GymSpaceConfig) {
|
|
23
24
|
this.config = config;
|
|
@@ -43,6 +44,11 @@ export class ApiClient {
|
|
|
43
44
|
config.headers['Authorization'] = `Bearer ${this.config.apiKey}`;
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
// Add refresh token header for current-session endpoint
|
|
48
|
+
if (this.refreshToken && config.url?.includes('current-session') && config.headers) {
|
|
49
|
+
config.headers['X-Refresh-Token'] = this.refreshToken;
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
return config;
|
|
47
53
|
},
|
|
48
54
|
(error) => {
|
|
@@ -168,12 +174,21 @@ export class ApiClient {
|
|
|
168
174
|
this.config.apiKey = token;
|
|
169
175
|
}
|
|
170
176
|
|
|
177
|
+
setRefreshToken(token: string | null): void {
|
|
178
|
+
this.refreshToken = token;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
getRefreshToken(): string | null {
|
|
182
|
+
return this.refreshToken;
|
|
183
|
+
}
|
|
184
|
+
|
|
171
185
|
setGymId(gymId: string): void {
|
|
172
186
|
this.axiosInstance.defaults.headers.common['X-Gym-Id'] = gymId;
|
|
173
187
|
}
|
|
174
188
|
|
|
175
189
|
clearAuth(): void {
|
|
176
190
|
delete this.config.apiKey;
|
|
191
|
+
this.refreshToken = null;
|
|
177
192
|
delete this.axiosInstance.defaults.headers.common['Authorization'];
|
|
178
193
|
delete this.axiosInstance.defaults.headers.common['X-Gym-Id'];
|
|
179
194
|
}
|
package/src/models/auth.ts
CHANGED
package/src/models/contracts.ts
CHANGED
package/src/models/sales.ts
CHANGED
|
@@ -52,6 +52,12 @@ export interface UpdatePaymentStatusDto {
|
|
|
52
52
|
paymentStatus: 'paid' | 'unpaid';
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
export interface PaySaleDto {
|
|
56
|
+
paymentMethodId: string;
|
|
57
|
+
notes?: string;
|
|
58
|
+
fileIds?: string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
export interface Sale {
|
|
56
62
|
id: string;
|
|
57
63
|
gymId: string;
|
package/src/resources/sales.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BaseResource } from './base';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
3
|
Sale,
|
|
4
|
-
CreateSaleDto,
|
|
4
|
+
CreateSaleDto,
|
|
5
5
|
UpdateSaleDto,
|
|
6
6
|
UpdatePaymentStatusDto,
|
|
7
|
+
PaySaleDto,
|
|
7
8
|
SearchSalesParams,
|
|
8
9
|
SalesStats,
|
|
9
10
|
TopSellingProduct,
|
|
@@ -45,6 +46,14 @@ export class SalesResource extends BaseResource {
|
|
|
45
46
|
return this.client.put<Sale>(`${this.basePath}/${id}/payment-status`, { paymentStatus }, options);
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
async paySale(
|
|
50
|
+
id: string,
|
|
51
|
+
data: PaySaleDto,
|
|
52
|
+
options?: RequestOptions
|
|
53
|
+
): Promise<Sale> {
|
|
54
|
+
return this.client.post<Sale>(`${this.basePath}/${id}/payment`, data, options);
|
|
55
|
+
}
|
|
56
|
+
|
|
48
57
|
async deleteSale(id: string, options?: RequestOptions): Promise<void> {
|
|
49
58
|
return this.client.delete<void>(`${this.basePath}/${id}`, options);
|
|
50
59
|
}
|
package/src/sdk.ts
CHANGED
|
@@ -87,6 +87,19 @@ export class GymSpaceSdk {
|
|
|
87
87
|
this.client.setAuthToken(token);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Set the refresh token
|
|
92
|
+
*/
|
|
93
|
+
setRefreshToken(token: string | null): void {
|
|
94
|
+
this.client.setRefreshToken(token);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get the current refresh token
|
|
99
|
+
*/
|
|
100
|
+
getRefreshToken(): string | null {
|
|
101
|
+
return this.client.getRefreshToken();
|
|
102
|
+
}
|
|
90
103
|
|
|
91
104
|
/**
|
|
92
105
|
* Set the current gym context
|