@gymspace/sdk 1.2.9 → 1.2.11

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 CHANGED
@@ -74,7 +74,7 @@ var ApiClient = class {
74
74
  if (this.config.apiKey && config.headers) {
75
75
  config.headers["Authorization"] = `Bearer ${this.config.apiKey}`;
76
76
  }
77
- if (this.refreshToken && config.url?.includes("current-session") && config.headers) {
77
+ if (this.refreshToken && this.config.apiKey && config.headers) {
78
78
  config.headers["X-Refresh-Token"] = this.refreshToken;
79
79
  }
80
80
  return config;
@@ -85,6 +85,18 @@ var ApiClient = class {
85
85
  );
86
86
  this.axiosInstance.interceptors.response.use(
87
87
  (response) => {
88
+ const newAccessToken = response.headers["x-new-access-token"];
89
+ const newRefreshToken = response.headers["x-new-refresh-token"];
90
+ if (newAccessToken) {
91
+ console.log("Tokens refreshed by backend, updating SDK...");
92
+ this.setAuthToken(newAccessToken);
93
+ if (newRefreshToken) {
94
+ this.setRefreshToken(newRefreshToken);
95
+ }
96
+ if (this.onTokenRefreshed) {
97
+ this.onTokenRefreshed(newAccessToken, newRefreshToken);
98
+ }
99
+ }
88
100
  return response;
89
101
  },
90
102
  async (error) => {
@@ -180,6 +192,18 @@ var ApiClient = class {
180
192
  getRefreshToken() {
181
193
  return this.refreshToken;
182
194
  }
195
+ /**
196
+ * Set callback for when tokens are refreshed by backend
197
+ */
198
+ setOnTokenRefreshed(callback) {
199
+ this.onTokenRefreshed = callback;
200
+ }
201
+ /**
202
+ * Get the token refresh callback
203
+ */
204
+ getOnTokenRefreshed() {
205
+ return this.onTokenRefreshed;
206
+ }
183
207
  setGymId(gymId) {
184
208
  this.axiosInstance.defaults.headers.common["X-Gym-Id"] = gymId;
185
209
  }
@@ -629,43 +653,6 @@ var DashboardResource = class extends BaseResource {
629
653
  }
630
654
  };
631
655
 
632
- // src/resources/evaluations.ts
633
- var EvaluationsResource = class extends BaseResource {
634
- constructor() {
635
- super(...arguments);
636
- this.basePath = "evaluations";
637
- }
638
- async createEvaluation(data, options) {
639
- return this.client.post(this.basePath, data, options);
640
- }
641
- async getEvaluation(id, options) {
642
- return this.client.get(`${this.basePath}/${id}`, void 0, options);
643
- }
644
- async updateEvaluation(id, data, options) {
645
- return this.client.put(`${this.basePath}/${id}`, data, options);
646
- }
647
- async deleteEvaluation(id, options) {
648
- return this.client.delete(`${this.basePath}/${id}`, options);
649
- }
650
- async getClientEvaluations(clientId, params, options) {
651
- return this.paginate(
652
- `${this.basePath}/client/${clientId}`,
653
- params,
654
- options
655
- );
656
- }
657
- async getGymEvaluationStats(options) {
658
- return this.client.get(`${this.basePath}/gym/stats`, void 0, options);
659
- }
660
- async generateEvaluationReport(id, options) {
661
- return this.client.get(
662
- `${this.basePath}/${id}/report`,
663
- void 0,
664
- options
665
- );
666
- }
667
- };
668
-
669
656
  // src/resources/check-ins.ts
670
657
  var CheckInsResource = class extends BaseResource {
671
658
  constructor() {
@@ -726,36 +713,6 @@ var InvitationsResource = class extends BaseResource {
726
713
  }
727
714
  };
728
715
 
729
- // src/resources/leads.ts
730
- var LeadsResource = class extends BaseResource {
731
- constructor() {
732
- super(...arguments);
733
- this.basePath = "leads";
734
- }
735
- async createLead(data, options) {
736
- return this.client.post(this.basePath, data, options);
737
- }
738
- async searchLeads(params, options) {
739
- return this.paginate(this.basePath, params, options);
740
- }
741
- async getLead(id, options) {
742
- return this.client.get(`${this.basePath}/${id}`, void 0, options);
743
- }
744
- async updateLead(id, data, options) {
745
- return this.client.put(`${this.basePath}/${id}`, data, options);
746
- }
747
- async getLeadStats(options) {
748
- return this.client.get(`${this.basePath}/stats/gym`, void 0, options);
749
- }
750
- async convertLead(id, options) {
751
- return this.client.post(
752
- `${this.basePath}/${id}/convert`,
753
- void 0,
754
- options
755
- );
756
- }
757
- };
758
-
759
716
  // src/resources/assets.ts
760
717
  var AssetsResource = class extends BaseResource {
761
718
  /**
@@ -1017,7 +974,7 @@ var ProductsResource = class extends BaseResource {
1017
974
  return this.client.post(`${this.basePath}/services`, data, options);
1018
975
  }
1019
976
  async searchProducts(params, options) {
1020
- return this.paginate(this.basePath, params, options);
977
+ return this.client.get(this.basePath, params, options);
1021
978
  }
1022
979
  async getProduct(id, options) {
1023
980
  return this.client.get(`${this.basePath}/${id}`, void 0, options);
@@ -1035,15 +992,15 @@ var ProductsResource = class extends BaseResource {
1035
992
  return this.client.patch(`${this.basePath}/${id}/stock`, data, options);
1036
993
  }
1037
994
  async getLowStockProducts(threshold = 10, options) {
995
+ return this.client.get(`${this.basePath}/low-stock`, { threshold }, options);
996
+ }
997
+ async getProductStockMovements(id, options) {
1038
998
  return this.client.get(
1039
- `${this.basePath}/low-stock`,
1040
- { threshold },
999
+ `${this.basePath}/${id}/stock-movements`,
1000
+ void 0,
1041
1001
  options
1042
1002
  );
1043
1003
  }
1044
- async getProductStockMovements(id, options) {
1045
- return this.client.get(`${this.basePath}/${id}/stock-movements`, void 0, options);
1046
- }
1047
1004
  };
1048
1005
 
1049
1006
  // src/resources/sales.ts
@@ -1301,7 +1258,7 @@ var PaymentMethodsResource = class extends BaseResource {
1301
1258
  return this.client.post(this.basePath, data, options);
1302
1259
  }
1303
1260
  async searchPaymentMethods(params, options) {
1304
- return this.paginate(this.basePath, params, options);
1261
+ return this.client.get(this.basePath, params, options);
1305
1262
  }
1306
1263
  async getPaymentMethod(id, options) {
1307
1264
  return this.client.get(`${this.basePath}/${id}`, void 0, options);
@@ -1456,10 +1413,8 @@ var GymSpaceSdk = class {
1456
1413
  this.membershipPlans = new MembershipPlansResource(this.client);
1457
1414
  this.contracts = new ContractsResource(this.client);
1458
1415
  this.dashboard = new DashboardResource(this.client);
1459
- this.evaluations = new EvaluationsResource(this.client);
1460
1416
  this.checkIns = new CheckInsResource(this.client);
1461
1417
  this.invitations = new InvitationsResource(this.client);
1462
- this.leads = new LeadsResource(this.client);
1463
1418
  this.assets = new AssetsResource(this.client);
1464
1419
  this.files = new FilesResource(this.client);
1465
1420
  this.publicCatalog = new PublicCatalogResource(this.client);
@@ -1521,6 +1476,12 @@ var GymSpaceSdk = class {
1521
1476
  createAgentFetch() {
1522
1477
  return createAgentFetch(this.client, this.expoFetch);
1523
1478
  }
1479
+ /**
1480
+ * Set callback for when tokens are refreshed by backend
1481
+ */
1482
+ setOnTokenRefreshed(callback) {
1483
+ this.client.setOnTokenRefreshed(callback);
1484
+ }
1524
1485
  /**
1525
1486
  * Get the underlying API client
1526
1487
  */
@@ -1928,7 +1889,6 @@ exports.EvaluationAssetCategory = EvaluationAssetCategory;
1928
1889
  exports.EvaluationAssetStage = EvaluationAssetStage;
1929
1890
  exports.EvaluationStatus = EvaluationStatus;
1930
1891
  exports.EvaluationType = EvaluationType;
1931
- exports.EvaluationsResource = EvaluationsResource;
1932
1892
  exports.FILE_LIMITS = FILE_LIMITS;
1933
1893
  exports.FilesResource = FilesResource;
1934
1894
  exports.GymSpaceError = GymSpaceError;
@@ -1939,7 +1899,6 @@ exports.HealthResource = HealthResource;
1939
1899
  exports.InvitationStatus = InvitationStatus;
1940
1900
  exports.InvitationsResource = InvitationsResource;
1941
1901
  exports.LeadStatus = LeadStatus;
1942
- exports.LeadsResource = LeadsResource;
1943
1902
  exports.MembershipPlansResource = MembershipPlansResource;
1944
1903
  exports.NetworkError = NetworkError;
1945
1904
  exports.NotFoundError = NotFoundError;