@gymspace/sdk 1.7.5 → 1.8.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.
@@ -0,0 +1,203 @@
1
+ import { BaseResource } from './base';
2
+ import { RequestOptions } from '../types';
3
+ import {
4
+ CreditAccount,
5
+ CreditAccountWithOrgName,
6
+ CreditTransaction,
7
+ CreditAdjustment,
8
+ CreditAdjustmentResponse,
9
+ CreditUsageReport,
10
+ CreditUsageReportQuery,
11
+ CreditStats,
12
+ } from '../models/credits';
13
+
14
+ export class CreditsResource extends BaseResource {
15
+ // Admin endpoints for specific organization
16
+ private adminOrgCreditsPath = (organizationId: string) =>
17
+ `admin/organizations/${organizationId}/credits`;
18
+
19
+ // Organization endpoints (non-admin)
20
+ private orgCreditsPath = (organizationId: string) => `organizations/${organizationId}/credits`;
21
+
22
+ // Global admin endpoints
23
+ private adminCreditsPath = 'admin/credits';
24
+
25
+ /**
26
+ * Get credit account for own organization (non-admin)
27
+ */
28
+ async getCreditAccount(organizationId: string, options?: RequestOptions): Promise<CreditAccount> {
29
+ return this.client.get<CreditAccount>(this.orgCreditsPath(organizationId), undefined, options);
30
+ }
31
+
32
+ /**
33
+ * Get credit account for a specific organization (admin only)
34
+ */
35
+ async getAdminCreditAccount(
36
+ organizationId: string,
37
+ options?: RequestOptions,
38
+ ): Promise<CreditAccount> {
39
+ return this.client.get<CreditAccount>(
40
+ this.adminOrgCreditsPath(organizationId),
41
+ undefined,
42
+ options,
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Get credit transaction history for own organization (non-admin)
48
+ */
49
+ async getCreditTransactions(
50
+ organizationId: string,
51
+ limit?: number,
52
+ options?: RequestOptions,
53
+ ): Promise<CreditTransaction[]> {
54
+ const params = limit ? { limit } : undefined;
55
+ return this.client.get<CreditTransaction[]>(
56
+ `${this.orgCreditsPath(organizationId)}/transactions`,
57
+ params,
58
+ options,
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Get credit transaction history for a specific organization (admin only)
64
+ */
65
+ async getAdminCreditTransactions(
66
+ organizationId: string,
67
+ limit?: number,
68
+ options?: RequestOptions,
69
+ ): Promise<CreditTransaction[]> {
70
+ const params = limit ? { limit } : undefined;
71
+ return this.client.get<CreditTransaction[]>(
72
+ `${this.adminOrgCreditsPath(organizationId)}/transactions`,
73
+ params,
74
+ options,
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Adjust credits for a specific organization (admin only)
80
+ */
81
+ async adjustCredits(
82
+ organizationId: string,
83
+ adjustment: CreditAdjustment,
84
+ options?: RequestOptions,
85
+ ): Promise<CreditAdjustmentResponse> {
86
+ return this.client.post<CreditAdjustmentResponse>(
87
+ `${this.adminOrgCreditsPath(organizationId)}/adjust`,
88
+ adjustment,
89
+ options,
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Get credit usage report for own organization (non-admin)
95
+ */
96
+ async getUsageReport(
97
+ organizationId: string,
98
+ query?: CreditUsageReportQuery,
99
+ options?: RequestOptions,
100
+ ): Promise<CreditUsageReport> {
101
+ return this.client.get<CreditUsageReport>(
102
+ `${this.orgCreditsPath(organizationId)}/usage-report`,
103
+ query,
104
+ options,
105
+ );
106
+ }
107
+
108
+ /**
109
+ * Get credit usage report for a specific organization (admin only)
110
+ */
111
+ async getAdminUsageReport(
112
+ organizationId: string,
113
+ query?: CreditUsageReportQuery,
114
+ options?: RequestOptions,
115
+ ): Promise<CreditUsageReport> {
116
+ return this.client.get<CreditUsageReport>(
117
+ `${this.adminOrgCreditsPath(organizationId)}/usage-report`,
118
+ query,
119
+ options,
120
+ );
121
+ }
122
+
123
+ /**
124
+ * Get all organizations with credit accounts (Super Admin only)
125
+ */
126
+ async getAllCreditAccounts(
127
+ limit?: number,
128
+ offset?: number,
129
+ options?: RequestOptions,
130
+ ): Promise<CreditAccountWithOrgName[]> {
131
+ const params = {
132
+ limit: limit || 50,
133
+ offset: offset || 0,
134
+ };
135
+ return this.client.get<CreditAccountWithOrgName[]>(
136
+ `${this.adminCreditsPath}/organizations`,
137
+ params,
138
+ options,
139
+ );
140
+ }
141
+
142
+ /**
143
+ * Get credit stats for current organization (existing endpoint)
144
+ */
145
+ async getCreditStats(organizationId: string, options?: RequestOptions): Promise<CreditStats> {
146
+ // This is the existing endpoint from bulk messaging controller
147
+ return this.client.get<CreditStats>(
148
+ `whatsapp/bulk-messaging/ai-usage-stats`,
149
+ undefined,
150
+ options,
151
+ );
152
+ }
153
+
154
+ /**
155
+ * Search credit transactions with filters
156
+ */
157
+ async searchTransactions(
158
+ organizationId: string,
159
+ filters: {
160
+ featureType?: string;
161
+ startDate?: string;
162
+ endDate?: string;
163
+ minAmount?: number;
164
+ maxAmount?: number;
165
+ },
166
+ limit?: number,
167
+ options?: RequestOptions,
168
+ ): Promise<CreditTransaction[]> {
169
+ const params = {
170
+ ...filters,
171
+ limit: limit || 50,
172
+ };
173
+ return this.client.get<CreditTransaction[]>(
174
+ `${this.orgCreditsPath(organizationId)}/transactions/search`,
175
+ params,
176
+ options,
177
+ );
178
+ }
179
+
180
+ /**
181
+ * Get credit summary for multiple organizations
182
+ */
183
+ async getOrganizationsCreditSummary(
184
+ organizationIds: string[],
185
+ options?: RequestOptions,
186
+ ): Promise<
187
+ Array<{
188
+ organizationId: string;
189
+ balance: number;
190
+ monthlyAllowance: number;
191
+ usedThisMonth: number;
192
+ }>
193
+ > {
194
+ return this.client.post<
195
+ Array<{
196
+ organizationId: string;
197
+ balance: number;
198
+ monthlyAllowance: number;
199
+ usedThisMonth: number;
200
+ }>
201
+ >(`${this.adminCreditsPath}/summary`, { organizationIds }, options);
202
+ }
203
+ }
@@ -34,3 +34,6 @@ export * from './commission-calculations';
34
34
  export * from './commission-reports';
35
35
  export * from './commission-promotions';
36
36
  export * from './messages';
37
+ export * from './credits';
38
+ export * from './pricing-packages';
39
+ export * from './promo-codes';
@@ -0,0 +1,72 @@
1
+ import { BaseResource } from './base';
2
+ import {
3
+ PricingPackage,
4
+ CreatePricingPackageDto,
5
+ UpdatePricingPackageDto,
6
+ SearchPricingPackagesParams,
7
+ } from '../models/pricing-packages';
8
+ import { RequestOptions, PaginatedResponseDto } from '../types';
9
+
10
+ export class PricingPackagesResource extends BaseResource {
11
+ private basePath = 'pricing-packages';
12
+
13
+ // CREATE - POST /pricing-packages/plans/:planId/packages
14
+ async createPricingPackage(
15
+ planId: string,
16
+ data: CreatePricingPackageDto,
17
+ options?: RequestOptions,
18
+ ): Promise<PricingPackage> {
19
+ return this.client.post<PricingPackage>(
20
+ `${this.basePath}/plans/${planId}/packages`,
21
+ data,
22
+ options,
23
+ );
24
+ }
25
+
26
+ // GET ONE - GET /pricing-packages/:id
27
+ async getPricingPackage(id: string, options?: RequestOptions): Promise<PricingPackage> {
28
+ return this.client.get<PricingPackage>(`${this.basePath}/${id}`, undefined, options);
29
+ }
30
+
31
+ // UPDATE - PUT /pricing-packages/:id
32
+ async updatePricingPackage(
33
+ id: string,
34
+ data: UpdatePricingPackageDto,
35
+ options?: RequestOptions,
36
+ ): Promise<PricingPackage> {
37
+ return this.client.put<PricingPackage>(`${this.basePath}/${id}`, data, options);
38
+ }
39
+
40
+ // SEARCH - GET /pricing-packages
41
+ async searchPricingPackages(
42
+ params?: SearchPricingPackagesParams,
43
+ options?: RequestOptions,
44
+ ): Promise<PaginatedResponseDto<PricingPackage>> {
45
+ return this.paginate<PricingPackage>(
46
+ this.basePath,
47
+ {
48
+ page: params?.page || 1,
49
+ limit: params?.limit || 20,
50
+ ...params,
51
+ },
52
+ options,
53
+ );
54
+ }
55
+
56
+ // GET BY PLAN - GET /pricing-packages/plans/:planId/packages
57
+ async getPricingPackagesByPlan(
58
+ planId: string,
59
+ options?: RequestOptions,
60
+ ): Promise<PricingPackage[]> {
61
+ return this.client.get<PricingPackage[]>(
62
+ `${this.basePath}/plans/${planId}/packages`,
63
+ undefined,
64
+ options,
65
+ );
66
+ }
67
+
68
+ // DELETE - DELETE /pricing-packages/:id
69
+ async deletePricingPackage(id: string, options?: RequestOptions): Promise<void> {
70
+ return this.client.delete<void>(`${this.basePath}/${id}`, options);
71
+ }
72
+ }
@@ -0,0 +1,76 @@
1
+ import { BaseResource } from './base';
2
+ import {
3
+ PromoCode,
4
+ CreatePromoCodeDto,
5
+ UpdatePromoCodeDto,
6
+ SearchPromoCodesParams,
7
+ ValidatePromoCodeDto,
8
+ ValidatePromoCodeResponseDto,
9
+ PromoCodeAnalytics,
10
+ } from '../models/promo-codes';
11
+ import { RequestOptions, PaginatedResponseDto } from '../types';
12
+
13
+ export class PromoCodesResource extends BaseResource {
14
+ private basePath = 'promo-codes';
15
+
16
+ // CREATE - POST /promo-codes
17
+ async createPromoCode(data: CreatePromoCodeDto, options?: RequestOptions): Promise<PromoCode> {
18
+ return this.client.post<PromoCode>(this.basePath, data, options);
19
+ }
20
+
21
+ // VALIDATE - POST /promo-codes/validate
22
+ async validatePromoCode(
23
+ data: ValidatePromoCodeDto,
24
+ options?: RequestOptions,
25
+ ): Promise<ValidatePromoCodeResponseDto> {
26
+ return this.client.post<ValidatePromoCodeResponseDto>(
27
+ `${this.basePath}/validate`,
28
+ data,
29
+ options,
30
+ );
31
+ }
32
+
33
+ // SEARCH - GET /promo-codes
34
+ async searchPromoCodes(
35
+ params?: SearchPromoCodesParams,
36
+ options?: RequestOptions,
37
+ ): Promise<PaginatedResponseDto<PromoCode>> {
38
+ return this.paginate<PromoCode>(
39
+ this.basePath,
40
+ {
41
+ page: params?.page || 1,
42
+ limit: params?.limit || 20,
43
+ ...params,
44
+ },
45
+ options,
46
+ );
47
+ }
48
+
49
+ // GET ANALYTICS - GET /promo-codes/analytics/:id
50
+ async getPromoCodeAnalytics(id: string, options?: RequestOptions): Promise<PromoCodeAnalytics> {
51
+ return this.client.get<PromoCodeAnalytics>(
52
+ `${this.basePath}/analytics/${id}`,
53
+ undefined,
54
+ options,
55
+ );
56
+ }
57
+
58
+ // GET ONE - GET /promo-codes/:id
59
+ async getPromoCode(id: string, options?: RequestOptions): Promise<PromoCode> {
60
+ return this.client.get<PromoCode>(`${this.basePath}/${id}`, undefined, options);
61
+ }
62
+
63
+ // UPDATE - PUT /promo-codes/:id
64
+ async updatePromoCode(
65
+ id: string,
66
+ data: UpdatePromoCodeDto,
67
+ options?: RequestOptions,
68
+ ): Promise<PromoCode> {
69
+ return this.client.put<PromoCode>(`${this.basePath}/${id}`, data, options);
70
+ }
71
+
72
+ // DELETE - DELETE /promo-codes/:id
73
+ async deletePromoCode(id: string, options?: RequestOptions): Promise<void> {
74
+ return this.client.delete<void>(`${this.basePath}/${id}`, options);
75
+ }
76
+ }
package/src/sdk.ts CHANGED
@@ -38,6 +38,9 @@ import {
38
38
  CommissionReportsResource,
39
39
  CommissionPromotionsResource,
40
40
  MessagesResource,
41
+ CreditsResource,
42
+ PricingPackagesResource,
43
+ PromoCodesResource,
41
44
  } from './resources';
42
45
 
43
46
  export class GymSpaceSdk {
@@ -81,6 +84,9 @@ export class GymSpaceSdk {
81
84
  public commissionReports: CommissionReportsResource;
82
85
  public commissionPromotions: CommissionPromotionsResource;
83
86
  public messages: MessagesResource;
87
+ public credits: CreditsResource;
88
+ public pricingPackages: PricingPackagesResource;
89
+ public promoCodes: PromoCodesResource;
84
90
 
85
91
  constructor(config: GymSpaceConfig) {
86
92
  this.client = new ApiClient(config);
@@ -122,6 +128,9 @@ export class GymSpaceSdk {
122
128
  this.commissionReports = new CommissionReportsResource(this.client);
123
129
  this.commissionPromotions = new CommissionPromotionsResource(this.client);
124
130
  this.messages = new MessagesResource(this.client);
131
+ this.credits = new CreditsResource(this.client);
132
+ this.pricingPackages = new PricingPackagesResource(this.client);
133
+ this.promoCodes = new PromoCodesResource(this.client);
125
134
  }
126
135
 
127
136
  /**