@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.mjs CHANGED
@@ -68,7 +68,7 @@ var ApiClient = class {
68
68
  if (this.config.apiKey && config.headers) {
69
69
  config.headers["Authorization"] = `Bearer ${this.config.apiKey}`;
70
70
  }
71
- if (this.refreshToken && config.url?.includes("current-session") && config.headers) {
71
+ if (this.refreshToken && this.config.apiKey && config.headers) {
72
72
  config.headers["X-Refresh-Token"] = this.refreshToken;
73
73
  }
74
74
  return config;
@@ -79,6 +79,18 @@ var ApiClient = class {
79
79
  );
80
80
  this.axiosInstance.interceptors.response.use(
81
81
  (response) => {
82
+ const newAccessToken = response.headers["x-new-access-token"];
83
+ const newRefreshToken = response.headers["x-new-refresh-token"];
84
+ if (newAccessToken) {
85
+ console.log("Tokens refreshed by backend, updating SDK...");
86
+ this.setAuthToken(newAccessToken);
87
+ if (newRefreshToken) {
88
+ this.setRefreshToken(newRefreshToken);
89
+ }
90
+ if (this.onTokenRefreshed) {
91
+ this.onTokenRefreshed(newAccessToken, newRefreshToken);
92
+ }
93
+ }
82
94
  return response;
83
95
  },
84
96
  async (error) => {
@@ -174,6 +186,18 @@ var ApiClient = class {
174
186
  getRefreshToken() {
175
187
  return this.refreshToken;
176
188
  }
189
+ /**
190
+ * Set callback for when tokens are refreshed by backend
191
+ */
192
+ setOnTokenRefreshed(callback) {
193
+ this.onTokenRefreshed = callback;
194
+ }
195
+ /**
196
+ * Get the token refresh callback
197
+ */
198
+ getOnTokenRefreshed() {
199
+ return this.onTokenRefreshed;
200
+ }
177
201
  setGymId(gymId) {
178
202
  this.axiosInstance.defaults.headers.common["X-Gym-Id"] = gymId;
179
203
  }
@@ -623,43 +647,6 @@ var DashboardResource = class extends BaseResource {
623
647
  }
624
648
  };
625
649
 
626
- // src/resources/evaluations.ts
627
- var EvaluationsResource = class extends BaseResource {
628
- constructor() {
629
- super(...arguments);
630
- this.basePath = "evaluations";
631
- }
632
- async createEvaluation(data, options) {
633
- return this.client.post(this.basePath, data, options);
634
- }
635
- async getEvaluation(id, options) {
636
- return this.client.get(`${this.basePath}/${id}`, void 0, options);
637
- }
638
- async updateEvaluation(id, data, options) {
639
- return this.client.put(`${this.basePath}/${id}`, data, options);
640
- }
641
- async deleteEvaluation(id, options) {
642
- return this.client.delete(`${this.basePath}/${id}`, options);
643
- }
644
- async getClientEvaluations(clientId, params, options) {
645
- return this.paginate(
646
- `${this.basePath}/client/${clientId}`,
647
- params,
648
- options
649
- );
650
- }
651
- async getGymEvaluationStats(options) {
652
- return this.client.get(`${this.basePath}/gym/stats`, void 0, options);
653
- }
654
- async generateEvaluationReport(id, options) {
655
- return this.client.get(
656
- `${this.basePath}/${id}/report`,
657
- void 0,
658
- options
659
- );
660
- }
661
- };
662
-
663
650
  // src/resources/check-ins.ts
664
651
  var CheckInsResource = class extends BaseResource {
665
652
  constructor() {
@@ -720,36 +707,6 @@ var InvitationsResource = class extends BaseResource {
720
707
  }
721
708
  };
722
709
 
723
- // src/resources/leads.ts
724
- var LeadsResource = class extends BaseResource {
725
- constructor() {
726
- super(...arguments);
727
- this.basePath = "leads";
728
- }
729
- async createLead(data, options) {
730
- return this.client.post(this.basePath, data, options);
731
- }
732
- async searchLeads(params, options) {
733
- return this.paginate(this.basePath, params, options);
734
- }
735
- async getLead(id, options) {
736
- return this.client.get(`${this.basePath}/${id}`, void 0, options);
737
- }
738
- async updateLead(id, data, options) {
739
- return this.client.put(`${this.basePath}/${id}`, data, options);
740
- }
741
- async getLeadStats(options) {
742
- return this.client.get(`${this.basePath}/stats/gym`, void 0, options);
743
- }
744
- async convertLead(id, options) {
745
- return this.client.post(
746
- `${this.basePath}/${id}/convert`,
747
- void 0,
748
- options
749
- );
750
- }
751
- };
752
-
753
710
  // src/resources/assets.ts
754
711
  var AssetsResource = class extends BaseResource {
755
712
  /**
@@ -1011,7 +968,7 @@ var ProductsResource = class extends BaseResource {
1011
968
  return this.client.post(`${this.basePath}/services`, data, options);
1012
969
  }
1013
970
  async searchProducts(params, options) {
1014
- return this.paginate(this.basePath, params, options);
971
+ return this.client.get(this.basePath, params, options);
1015
972
  }
1016
973
  async getProduct(id, options) {
1017
974
  return this.client.get(`${this.basePath}/${id}`, void 0, options);
@@ -1029,15 +986,15 @@ var ProductsResource = class extends BaseResource {
1029
986
  return this.client.patch(`${this.basePath}/${id}/stock`, data, options);
1030
987
  }
1031
988
  async getLowStockProducts(threshold = 10, options) {
989
+ return this.client.get(`${this.basePath}/low-stock`, { threshold }, options);
990
+ }
991
+ async getProductStockMovements(id, options) {
1032
992
  return this.client.get(
1033
- `${this.basePath}/low-stock`,
1034
- { threshold },
993
+ `${this.basePath}/${id}/stock-movements`,
994
+ void 0,
1035
995
  options
1036
996
  );
1037
997
  }
1038
- async getProductStockMovements(id, options) {
1039
- return this.client.get(`${this.basePath}/${id}/stock-movements`, void 0, options);
1040
- }
1041
998
  };
1042
999
 
1043
1000
  // src/resources/sales.ts
@@ -1295,7 +1252,7 @@ var PaymentMethodsResource = class extends BaseResource {
1295
1252
  return this.client.post(this.basePath, data, options);
1296
1253
  }
1297
1254
  async searchPaymentMethods(params, options) {
1298
- return this.paginate(this.basePath, params, options);
1255
+ return this.client.get(this.basePath, params, options);
1299
1256
  }
1300
1257
  async getPaymentMethod(id, options) {
1301
1258
  return this.client.get(`${this.basePath}/${id}`, void 0, options);
@@ -1450,10 +1407,8 @@ var GymSpaceSdk = class {
1450
1407
  this.membershipPlans = new MembershipPlansResource(this.client);
1451
1408
  this.contracts = new ContractsResource(this.client);
1452
1409
  this.dashboard = new DashboardResource(this.client);
1453
- this.evaluations = new EvaluationsResource(this.client);
1454
1410
  this.checkIns = new CheckInsResource(this.client);
1455
1411
  this.invitations = new InvitationsResource(this.client);
1456
- this.leads = new LeadsResource(this.client);
1457
1412
  this.assets = new AssetsResource(this.client);
1458
1413
  this.files = new FilesResource(this.client);
1459
1414
  this.publicCatalog = new PublicCatalogResource(this.client);
@@ -1515,6 +1470,12 @@ var GymSpaceSdk = class {
1515
1470
  createAgentFetch() {
1516
1471
  return createAgentFetch(this.client, this.expoFetch);
1517
1472
  }
1473
+ /**
1474
+ * Set callback for when tokens are refreshed by backend
1475
+ */
1476
+ setOnTokenRefreshed(callback) {
1477
+ this.client.setOnTokenRefreshed(callback);
1478
+ }
1518
1479
  /**
1519
1480
  * Get the underlying API client
1520
1481
  */
@@ -1898,6 +1859,6 @@ var OnboardingStep = /* @__PURE__ */ ((OnboardingStep2) => {
1898
1859
  return OnboardingStep2;
1899
1860
  })(OnboardingStep || {});
1900
1861
 
1901
- export { AdminSubscriptionManagementResource, ApiClient, AssetCategory, AssetStatus, AssetsResource, AuthResource, AuthenticationError, AuthorizationError, CACHE_TTL, CheckInsResource, ClientStatus, ClientsResource, CollaboratorStatus, CollaboratorsResource, CommentType, ContractAssetType, ContractStatus, ContractsResource, DATE_FORMATS, DashboardResource, EvaluationAssetCategory, EvaluationAssetStage, EvaluationStatus, EvaluationType, EvaluationsResource, FILE_LIMITS, FilesResource, GymSpaceError, GymSpaceSdk, GymsResource, HEADERS, HealthResource, InvitationStatus, InvitationsResource, LeadStatus, LeadsResource, MembershipPlansResource, NetworkError, NotFoundError, OnboardingResource, OnboardingStep, OrganizationsResource, PAGINATION_DEFAULTS, PERMISSIONS, PaymentFrequency, PaymentMethodsResource, PlanStatus, ProductsResource, PublicCatalogResource, ROLE_NAMES, ROLE_PERMISSIONS, RoleNames, RolesResource, SalesResource, SubscriptionPlansResource, SubscriptionStatus, SubscriptionsResource, SuppliersResource, UserType, UsersResource, ValidationError, WhatsAppResource, WhatsAppTemplatesResource, canAccessFeature, getRoleCapabilities, getRoleDescription, getRoleDisplayName, isAdminRole, isEncargadoRole };
1862
+ export { AdminSubscriptionManagementResource, ApiClient, AssetCategory, AssetStatus, AssetsResource, AuthResource, AuthenticationError, AuthorizationError, CACHE_TTL, CheckInsResource, ClientStatus, ClientsResource, CollaboratorStatus, CollaboratorsResource, CommentType, ContractAssetType, ContractStatus, ContractsResource, DATE_FORMATS, DashboardResource, EvaluationAssetCategory, EvaluationAssetStage, EvaluationStatus, EvaluationType, FILE_LIMITS, FilesResource, GymSpaceError, GymSpaceSdk, GymsResource, HEADERS, HealthResource, InvitationStatus, InvitationsResource, LeadStatus, MembershipPlansResource, NetworkError, NotFoundError, OnboardingResource, OnboardingStep, OrganizationsResource, PAGINATION_DEFAULTS, PERMISSIONS, PaymentFrequency, PaymentMethodsResource, PlanStatus, ProductsResource, PublicCatalogResource, ROLE_NAMES, ROLE_PERMISSIONS, RoleNames, RolesResource, SalesResource, SubscriptionPlansResource, SubscriptionStatus, SubscriptionsResource, SuppliersResource, UserType, UsersResource, ValidationError, WhatsAppResource, WhatsAppTemplatesResource, canAccessFeature, getRoleCapabilities, getRoleDescription, getRoleDisplayName, isAdminRole, isEncargadoRole };
1902
1863
  //# sourceMappingURL=index.mjs.map
1903
1864
  //# sourceMappingURL=index.mjs.map