@gymspace/sdk 1.0.0 → 1.0.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.js +221 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +220 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/client.ts +85 -17
- package/src/models/auth.ts +20 -0
- package/src/models/clients.ts +35 -7
- package/src/models/contracts.ts +23 -1
- package/src/models/dashboard.ts +42 -9
- package/src/models/index.ts +2 -0
- package/src/models/organizations.ts +1 -4
- package/src/models/payment-methods.ts +41 -0
- package/src/models/products.ts +48 -1
- package/src/models/sales.ts +47 -0
- package/src/models/subscriptions.ts +74 -0
- package/src/resources/auth.ts +2 -2
- package/src/resources/clients.ts +14 -0
- package/src/resources/dashboard.ts +64 -12
- package/src/resources/index.ts +3 -1
- package/src/resources/payment-methods.ts +48 -0
- package/src/resources/products.ts +13 -0
- package/src/resources/sales.ts +20 -3
- package/src/resources/subscriptions.ts +65 -0
- package/src/sdk.ts +13 -0
|
@@ -1,30 +1,82 @@
|
|
|
1
1
|
import { BaseResource } from './base';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DashboardStats,
|
|
4
|
+
ExpiringContract,
|
|
5
|
+
ContractsRevenue,
|
|
6
|
+
SalesRevenue,
|
|
7
|
+
Debts,
|
|
8
|
+
CheckIns,
|
|
9
|
+
NewClients,
|
|
10
|
+
DateRangeParams,
|
|
11
|
+
} from '../models/dashboard';
|
|
3
12
|
|
|
4
13
|
export class DashboardResource extends BaseResource {
|
|
5
14
|
/**
|
|
6
|
-
* Get dashboard statistics
|
|
7
|
-
* @returns Dashboard statistics including
|
|
15
|
+
* Get dashboard statistics (lightweight counts only)
|
|
16
|
+
* @returns Dashboard statistics including client and contract counts
|
|
8
17
|
*/
|
|
9
18
|
async getStats(): Promise<DashboardStats> {
|
|
10
19
|
return this.client.get<DashboardStats>('/dashboard/stats');
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
/**
|
|
14
|
-
* Get
|
|
15
|
-
* @param
|
|
16
|
-
* @returns
|
|
23
|
+
* Get contracts revenue within date range
|
|
24
|
+
* @param params Optional date range parameters
|
|
25
|
+
* @returns Contracts revenue data for the specified period
|
|
17
26
|
*/
|
|
18
|
-
async
|
|
19
|
-
return this.client.get<
|
|
27
|
+
async getContractsRevenue(params?: DateRangeParams): Promise<ContractsRevenue> {
|
|
28
|
+
return this.client.get<ContractsRevenue>('/dashboard/contracts-revenue', params);
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
/**
|
|
23
|
-
* Get
|
|
32
|
+
* Get sales revenue within date range
|
|
33
|
+
* @param params Optional date range parameters
|
|
34
|
+
* @returns Sales revenue data for the specified period
|
|
35
|
+
*/
|
|
36
|
+
async getSalesRevenue(params?: DateRangeParams): Promise<SalesRevenue> {
|
|
37
|
+
return this.client.get<SalesRevenue>('/dashboard/sales-revenue', params);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get total debts within date range
|
|
42
|
+
* @param params Optional date range parameters
|
|
43
|
+
* @returns Outstanding debts data for the specified period
|
|
44
|
+
*/
|
|
45
|
+
async getDebts(params?: DateRangeParams): Promise<Debts> {
|
|
46
|
+
return this.client.get<Debts>('/dashboard/debts', params);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get check-ins count within date range
|
|
51
|
+
* @param params Optional date range parameters
|
|
52
|
+
* @returns Check-ins data for the specified period
|
|
53
|
+
*/
|
|
54
|
+
async getCheckIns(params?: DateRangeParams): Promise<CheckIns> {
|
|
55
|
+
return this.client.get<CheckIns>('/dashboard/check-ins', params);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get new clients count within date range
|
|
60
|
+
* @param params Optional date range parameters
|
|
61
|
+
* @returns New clients data for the specified period
|
|
62
|
+
*/
|
|
63
|
+
async getNewClients(params?: DateRangeParams): Promise<NewClients> {
|
|
64
|
+
return this.client.get<NewClients>('/dashboard/new-clients', params);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get expiring contracts within date range
|
|
24
69
|
* @param limit Maximum number of contracts to return (default: 10)
|
|
25
|
-
* @
|
|
70
|
+
* @param params Optional date range parameters
|
|
71
|
+
* @returns List of contracts expiring in the specified period
|
|
26
72
|
*/
|
|
27
|
-
async getExpiringContracts(
|
|
28
|
-
|
|
73
|
+
async getExpiringContracts(
|
|
74
|
+
limit: number = 10,
|
|
75
|
+
params?: DateRangeParams,
|
|
76
|
+
): Promise<ExpiringContract[]> {
|
|
77
|
+
return this.client.get<ExpiringContract[]>('/dashboard/expiring-contracts', {
|
|
78
|
+
limit,
|
|
79
|
+
...params,
|
|
80
|
+
});
|
|
29
81
|
}
|
|
30
82
|
}
|
package/src/resources/index.ts
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BaseResource } from './base';
|
|
2
|
+
import {
|
|
3
|
+
PaymentMethod,
|
|
4
|
+
CreatePaymentMethodDto,
|
|
5
|
+
UpdatePaymentMethodDto,
|
|
6
|
+
SearchPaymentMethodsParams,
|
|
7
|
+
PaymentMethodStats
|
|
8
|
+
} from '../models/payment-methods';
|
|
9
|
+
import { RequestOptions, PaginatedResponseDto } from '../types';
|
|
10
|
+
|
|
11
|
+
export class PaymentMethodsResource extends BaseResource {
|
|
12
|
+
private basePath = 'payment-methods';
|
|
13
|
+
|
|
14
|
+
async createPaymentMethod(data: CreatePaymentMethodDto, options?: RequestOptions): Promise<PaymentMethod> {
|
|
15
|
+
return this.client.post<PaymentMethod>(this.basePath, data, options);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async searchPaymentMethods(
|
|
19
|
+
params?: SearchPaymentMethodsParams,
|
|
20
|
+
options?: RequestOptions
|
|
21
|
+
): Promise<PaginatedResponseDto<PaymentMethod>> {
|
|
22
|
+
return this.paginate<PaymentMethod>(this.basePath, params, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getPaymentMethod(id: string, options?: RequestOptions): Promise<PaymentMethod> {
|
|
26
|
+
return this.client.get<PaymentMethod>(`${this.basePath}/${id}`, undefined, options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async updatePaymentMethod(
|
|
30
|
+
id: string,
|
|
31
|
+
data: UpdatePaymentMethodDto,
|
|
32
|
+
options?: RequestOptions
|
|
33
|
+
): Promise<PaymentMethod> {
|
|
34
|
+
return this.client.put<PaymentMethod>(`${this.basePath}/${id}`, data, options);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async deletePaymentMethod(id: string, options?: RequestOptions): Promise<void> {
|
|
38
|
+
return this.client.delete<void>(`${this.basePath}/${id}`, options);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async togglePaymentMethod(id: string, options?: RequestOptions): Promise<PaymentMethod> {
|
|
42
|
+
return this.client.put<PaymentMethod>(`${this.basePath}/${id}/toggle`, undefined, options);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getPaymentMethodStats(options?: RequestOptions): Promise<PaymentMethodStats> {
|
|
46
|
+
return this.client.get<PaymentMethodStats>(`${this.basePath}/stats`, undefined, options);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -2,7 +2,9 @@ import { BaseResource } from './base';
|
|
|
2
2
|
import {
|
|
3
3
|
Product,
|
|
4
4
|
ProductCategory,
|
|
5
|
+
StockMovement,
|
|
5
6
|
CreateProductDto,
|
|
7
|
+
CreateServiceDto,
|
|
6
8
|
UpdateProductDto,
|
|
7
9
|
UpdateStockDto,
|
|
8
10
|
CreateProductCategoryDto,
|
|
@@ -43,6 +45,10 @@ export class ProductsResource extends BaseResource {
|
|
|
43
45
|
return this.client.post<Product>(this.basePath, data, options);
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
async createService(data: CreateServiceDto, options?: RequestOptions): Promise<Product> {
|
|
49
|
+
return this.client.post<Product>(`${this.basePath}/services`, data, options);
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
async searchProducts(
|
|
47
53
|
params?: SearchProductsParams,
|
|
48
54
|
options?: RequestOptions
|
|
@@ -88,4 +94,11 @@ export class ProductsResource extends BaseResource {
|
|
|
88
94
|
options
|
|
89
95
|
);
|
|
90
96
|
}
|
|
97
|
+
|
|
98
|
+
async getProductStockMovements(
|
|
99
|
+
id: string,
|
|
100
|
+
options?: RequestOptions
|
|
101
|
+
): Promise<StockMovement[]> {
|
|
102
|
+
return this.client.get<StockMovement[]>(`${this.basePath}/${id}/stock-movements`, undefined, options);
|
|
103
|
+
}
|
|
91
104
|
}
|
package/src/resources/sales.ts
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
UpdatePaymentStatusDto,
|
|
7
7
|
SearchSalesParams,
|
|
8
8
|
SalesStats,
|
|
9
|
-
TopSellingProduct
|
|
9
|
+
TopSellingProduct,
|
|
10
|
+
CustomerSalesReport
|
|
10
11
|
} from '../models/sales';
|
|
11
12
|
import { RequestOptions, PaginatedResponseDto } from '../types';
|
|
12
13
|
|
|
@@ -38,10 +39,10 @@ export class SalesResource extends BaseResource {
|
|
|
38
39
|
|
|
39
40
|
async updatePaymentStatus(
|
|
40
41
|
id: string,
|
|
41
|
-
|
|
42
|
+
paymentStatus: 'paid' | 'unpaid',
|
|
42
43
|
options?: RequestOptions
|
|
43
44
|
): Promise<Sale> {
|
|
44
|
-
return this.client.put<Sale>(`${this.basePath}/${id}/payment-status`,
|
|
45
|
+
return this.client.put<Sale>(`${this.basePath}/${id}/payment-status`, { paymentStatus }, options);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
async deleteSale(id: string, options?: RequestOptions): Promise<void> {
|
|
@@ -80,4 +81,20 @@ export class SalesResource extends BaseResource {
|
|
|
80
81
|
options
|
|
81
82
|
);
|
|
82
83
|
}
|
|
84
|
+
|
|
85
|
+
async getSalesByCustomer(
|
|
86
|
+
startDate?: string,
|
|
87
|
+
endDate?: string,
|
|
88
|
+
options?: RequestOptions
|
|
89
|
+
): Promise<CustomerSalesReport> {
|
|
90
|
+
const params: Record<string, string> = {};
|
|
91
|
+
if (startDate) params.startDate = startDate;
|
|
92
|
+
if (endDate) params.endDate = endDate;
|
|
93
|
+
|
|
94
|
+
return this.client.get<CustomerSalesReport>(
|
|
95
|
+
`${this.basePath}/reports/by-customer`,
|
|
96
|
+
Object.keys(params).length > 0 ? params : undefined,
|
|
97
|
+
options
|
|
98
|
+
);
|
|
99
|
+
}
|
|
83
100
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AvailablePlanDto,
|
|
3
|
+
SubscriptionStatusDto,
|
|
4
|
+
AffiliateOrganizationDto,
|
|
5
|
+
CheckLimitResponse,
|
|
6
|
+
} from '../models/subscriptions';
|
|
7
|
+
import { RequestOptions } from '../types';
|
|
8
|
+
import { BaseResource } from './base';
|
|
9
|
+
|
|
10
|
+
export class SubscriptionsResource extends BaseResource {
|
|
11
|
+
private basePath = 'subscriptions';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get available subscription plans (currently only free plans)
|
|
15
|
+
*/
|
|
16
|
+
async getAvailablePlans(options?: RequestOptions): Promise<AvailablePlanDto[]> {
|
|
17
|
+
return this.client.get<AvailablePlanDto[]>(`${this.basePath}/plans`, undefined, options);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get subscription status for an organization
|
|
22
|
+
*/
|
|
23
|
+
async getSubscriptionStatus(
|
|
24
|
+
organizationId: string,
|
|
25
|
+
options?: RequestOptions,
|
|
26
|
+
): Promise<SubscriptionStatusDto> {
|
|
27
|
+
return this.client.get<SubscriptionStatusDto>(
|
|
28
|
+
`${this.basePath}/organizations/${organizationId}/status`,
|
|
29
|
+
undefined,
|
|
30
|
+
options,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Affiliate organization to a subscription plan
|
|
36
|
+
*/
|
|
37
|
+
async affiliateOrganization(
|
|
38
|
+
organizationId: string,
|
|
39
|
+
data: AffiliateOrganizationDto,
|
|
40
|
+
options?: RequestOptions,
|
|
41
|
+
): Promise<SubscriptionStatusDto> {
|
|
42
|
+
return this.client.post<SubscriptionStatusDto>(
|
|
43
|
+
`${this.basePath}/organizations/${organizationId}/affiliate`,
|
|
44
|
+
data,
|
|
45
|
+
options,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Check subscription limits
|
|
51
|
+
* @param organizationId Organization ID
|
|
52
|
+
* @param limitType Type of limit to check: 'gyms', 'clients', or 'users'
|
|
53
|
+
*/
|
|
54
|
+
async checkSubscriptionLimit(
|
|
55
|
+
organizationId: string,
|
|
56
|
+
limitType: 'gyms' | 'clients' | 'users',
|
|
57
|
+
options?: RequestOptions,
|
|
58
|
+
): Promise<CheckLimitResponse> {
|
|
59
|
+
return this.client.get<CheckLimitResponse>(
|
|
60
|
+
`${this.basePath}/organizations/${organizationId}/limits/${limitType}`,
|
|
61
|
+
undefined,
|
|
62
|
+
options,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/sdk.ts
CHANGED
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
SalesResource,
|
|
22
22
|
SuppliersResource,
|
|
23
23
|
UsersResource,
|
|
24
|
+
SubscriptionsResource,
|
|
25
|
+
PaymentMethodsResource,
|
|
24
26
|
} from './resources';
|
|
25
27
|
|
|
26
28
|
export class GymSpaceSdk {
|
|
@@ -47,6 +49,8 @@ export class GymSpaceSdk {
|
|
|
47
49
|
public sales: SalesResource;
|
|
48
50
|
public suppliers: SuppliersResource;
|
|
49
51
|
public users: UsersResource;
|
|
52
|
+
public subscriptions: SubscriptionsResource;
|
|
53
|
+
public paymentMethods: PaymentMethodsResource;
|
|
50
54
|
|
|
51
55
|
constructor(config: GymSpaceConfig) {
|
|
52
56
|
this.client = new ApiClient(config);
|
|
@@ -72,6 +76,8 @@ export class GymSpaceSdk {
|
|
|
72
76
|
this.sales = new SalesResource(this.client);
|
|
73
77
|
this.suppliers = new SuppliersResource(this.client);
|
|
74
78
|
this.users = new UsersResource(this.client);
|
|
79
|
+
this.subscriptions = new SubscriptionsResource(this.client);
|
|
80
|
+
this.paymentMethods = new PaymentMethodsResource(this.client);
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
/**
|
|
@@ -81,6 +87,13 @@ export class GymSpaceSdk {
|
|
|
81
87
|
this.client.setAuthToken(token);
|
|
82
88
|
}
|
|
83
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Set both access and refresh tokens
|
|
92
|
+
*/
|
|
93
|
+
setTokens(accessToken: string, refreshToken: string): void {
|
|
94
|
+
this.client.setTokens(accessToken, refreshToken);
|
|
95
|
+
}
|
|
96
|
+
|
|
84
97
|
/**
|
|
85
98
|
* Set the current gym context
|
|
86
99
|
*/
|