@gymspace/sdk 1.1.0 → 1.1.2
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 +30 -3
- package/dist/index.d.ts +30 -3
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +19 -1
- package/src/models/auth.ts +1 -0
- package/src/models/clients.ts +8 -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 +14 -1
package/src/client.ts
CHANGED
|
@@ -18,6 +18,11 @@ import {
|
|
|
18
18
|
export class ApiClient {
|
|
19
19
|
private axiosInstance: AxiosInstance;
|
|
20
20
|
private config: GymSpaceConfig;
|
|
21
|
+
private refreshToken: string | null = null;
|
|
22
|
+
|
|
23
|
+
public getAccessToken(): string | null {
|
|
24
|
+
return this.config.apiKey || null;
|
|
25
|
+
}
|
|
21
26
|
|
|
22
27
|
constructor(config: GymSpaceConfig) {
|
|
23
28
|
this.config = config;
|
|
@@ -43,6 +48,11 @@ export class ApiClient {
|
|
|
43
48
|
config.headers['Authorization'] = `Bearer ${this.config.apiKey}`;
|
|
44
49
|
}
|
|
45
50
|
|
|
51
|
+
// Add refresh token header for current-session endpoint
|
|
52
|
+
if (this.refreshToken && config.url?.includes('current-session') && config.headers) {
|
|
53
|
+
config.headers['X-Refresh-Token'] = this.refreshToken;
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
return config;
|
|
47
57
|
},
|
|
48
58
|
(error) => {
|
|
@@ -62,7 +72,6 @@ export class ApiClient {
|
|
|
62
72
|
);
|
|
63
73
|
}
|
|
64
74
|
|
|
65
|
-
|
|
66
75
|
private handleError(error: AxiosError): GymSpaceError {
|
|
67
76
|
const requestPath = error.config?.url || 'unknown';
|
|
68
77
|
const method = error.config?.method?.toUpperCase() || 'unknown';
|
|
@@ -168,12 +177,21 @@ export class ApiClient {
|
|
|
168
177
|
this.config.apiKey = token;
|
|
169
178
|
}
|
|
170
179
|
|
|
180
|
+
setRefreshToken(token: string | null): void {
|
|
181
|
+
this.refreshToken = token;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
getRefreshToken(): string | null {
|
|
185
|
+
return this.refreshToken;
|
|
186
|
+
}
|
|
187
|
+
|
|
171
188
|
setGymId(gymId: string): void {
|
|
172
189
|
this.axiosInstance.defaults.headers.common['X-Gym-Id'] = gymId;
|
|
173
190
|
}
|
|
174
191
|
|
|
175
192
|
clearAuth(): void {
|
|
176
193
|
delete this.config.apiKey;
|
|
194
|
+
this.refreshToken = null;
|
|
177
195
|
delete this.axiosInstance.defaults.headers.common['Authorization'];
|
|
178
196
|
delete this.axiosInstance.defaults.headers.common['X-Gym-Id'];
|
|
179
197
|
}
|
package/src/models/auth.ts
CHANGED
package/src/models/clients.ts
CHANGED
|
@@ -78,6 +78,12 @@ export interface Client {
|
|
|
78
78
|
evaluations: number;
|
|
79
79
|
checkIns: number;
|
|
80
80
|
};
|
|
81
|
+
hasCheckedInToday?: boolean;
|
|
82
|
+
lastCheckIn?: {
|
|
83
|
+
id: string;
|
|
84
|
+
timestamp: string;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
};
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
export interface ClientStat {
|
|
@@ -124,6 +130,8 @@ export interface SearchClientsParams extends PaginationQueryDto {
|
|
|
124
130
|
clientNumber?: string;
|
|
125
131
|
documentId?: string;
|
|
126
132
|
includeContractStatus?: boolean;
|
|
133
|
+
notCheckedInToday?: boolean;
|
|
134
|
+
checkedInToday?: boolean;
|
|
127
135
|
}
|
|
128
136
|
|
|
129
137
|
export interface ClientSearchForCheckInResponse {
|
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
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
} from './resources';
|
|
27
27
|
|
|
28
28
|
export class GymSpaceSdk {
|
|
29
|
-
|
|
29
|
+
public client: ApiClient;
|
|
30
30
|
|
|
31
31
|
// Resources
|
|
32
32
|
public auth: AuthResource;
|
|
@@ -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
|