@gymspace/sdk 1.2.5 → 1.2.8

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
@@ -188,6 +188,26 @@ var ApiClient = class {
188
188
  }
189
189
  };
190
190
 
191
+ // src/utils/agent-fetch.ts
192
+ function createAgentFetch(apiClient, customFetch) {
193
+ const fetchFn = customFetch || fetch;
194
+ return async (path, options) => {
195
+ const fullUrl = `${apiClient.getBaseUrl()}/agent${path}`;
196
+ const axiosInstance = apiClient.axiosInstance;
197
+ const gymId = axiosInstance?.defaults?.headers?.common?.["X-Gym-Id"];
198
+ const headers = {
199
+ "Content-Type": "application/json",
200
+ ...apiClient.getAccessToken() && { Authorization: `Bearer ${apiClient.getAccessToken()}` },
201
+ ...gymId && { "X-Gym-Id": gymId },
202
+ ...options?.headers || {}
203
+ };
204
+ return fetchFn(fullUrl, {
205
+ ...options,
206
+ headers
207
+ });
208
+ };
209
+ }
210
+
191
211
  // src/resources/base.ts
192
212
  var BaseResource = class {
193
213
  constructor(client) {
@@ -380,11 +400,11 @@ var CollaboratorsResource = class extends BaseResource {
380
400
  async update(id, data, options) {
381
401
  return this.client.patch(`${this.basePath}/${id}`, data, options);
382
402
  }
383
- async updateRole(id, roleId, options) {
384
- return this.client.patch(`${this.basePath}/${id}/role`, { roleId }, options);
403
+ async updateRole(id, data, options) {
404
+ return this.client.patch(`${this.basePath}/${id}/role`, data, options);
385
405
  }
386
- async updateStatus(id, status, options) {
387
- return this.client.patch(`${this.basePath}/${id}/status`, { status }, options);
406
+ async updateStatus(id, data, options) {
407
+ return this.client.patch(`${this.basePath}/${id}/status`, data, options);
388
408
  }
389
409
  async getActivity(id, params, options) {
390
410
  return this.client.get(`${this.basePath}/${id}/activity`, params, options);
@@ -430,7 +450,7 @@ var ClientsResource = class extends BaseResource {
430
450
  return this.client.post(this.basePath, data, options);
431
451
  }
432
452
  async searchClients(params, options) {
433
- return this.paginate(this.basePath, params, options);
453
+ return this.client.get(this.basePath, params, options);
434
454
  }
435
455
  async getClient(id, options) {
436
456
  return this.client.get(`${this.basePath}/${id}`, void 0, options);
@@ -445,20 +465,24 @@ var ClientsResource = class extends BaseResource {
445
465
  return this.client.get(`${this.basePath}/${id}/stats`, void 0, options);
446
466
  }
447
467
  async getClientStat(id, statKey, options) {
448
- return this.client.get(`${this.basePath}/${id}/stats/${statKey}`, void 0, options);
468
+ return this.client.get(
469
+ `${this.basePath}/${id}/stats/${statKey}`,
470
+ void 0,
471
+ options
472
+ );
449
473
  }
450
474
  async getClientStatsByCategory(id, category, options) {
451
- return this.client.get(`${this.basePath}/${id}/stats/category/${category}`, void 0, options);
475
+ return this.client.get(
476
+ `${this.basePath}/${id}/stats/category/${category}`,
477
+ void 0,
478
+ options
479
+ );
452
480
  }
453
481
  async getAvailableStats(options) {
454
482
  return this.client.get(`${this.basePath}/stats/available`, void 0, options);
455
483
  }
456
484
  async searchClientsForCheckIn(params, options) {
457
- return this.client.get(
458
- `${this.basePath}/search/check-in`,
459
- params,
460
- options
461
- );
485
+ return this.client.get(`${this.basePath}/search/check-in`, params, options);
462
486
  }
463
487
  };
464
488
 
@@ -508,11 +532,7 @@ var ContractsResource = class extends BaseResource {
508
532
  return this.client.get(`${this.basePath}/${id}`, void 0, options);
509
533
  }
510
534
  async getClientContracts(clientId, options) {
511
- return this.client.get(
512
- `${this.basePath}/client/${clientId}`,
513
- void 0,
514
- options
515
- );
535
+ return this.client.get(`${this.basePath}/client/${clientId}`, void 0, options);
516
536
  }
517
537
  async renewContract(id, data, options) {
518
538
  return this.client.post(`${this.basePath}/${id}/renew`, data, options);
@@ -523,6 +543,13 @@ var ContractsResource = class extends BaseResource {
523
543
  async cancelContract(id, data, options) {
524
544
  return this.client.put(`${this.basePath}/${id}/cancel`, data, options);
525
545
  }
546
+ async resendWhatsAppNotification(contractId, options) {
547
+ return this.client.post(
548
+ `${this.basePath}/${contractId}/resend-whatsapp`,
549
+ {},
550
+ options
551
+ );
552
+ }
526
553
  };
527
554
 
528
555
  // src/resources/dashboard.ts
@@ -1024,7 +1051,11 @@ var SalesResource = class extends BaseResource {
1024
1051
  return this.client.put(`${this.basePath}/${id}`, data, options);
1025
1052
  }
1026
1053
  async updatePaymentStatus(id, paymentStatus, options) {
1027
- return this.client.put(`${this.basePath}/${id}/payment-status`, { paymentStatus }, options);
1054
+ return this.client.put(
1055
+ `${this.basePath}/${id}/payment-status`,
1056
+ { paymentStatus },
1057
+ options
1058
+ );
1028
1059
  }
1029
1060
  async paySale(id, data, options) {
1030
1061
  return this.client.post(`${this.basePath}/${id}/payment`, data, options);
@@ -1046,11 +1077,7 @@ var SalesResource = class extends BaseResource {
1046
1077
  const params = { limit };
1047
1078
  if (startDate) params.startDate = startDate;
1048
1079
  if (endDate) params.endDate = endDate;
1049
- return this.client.get(
1050
- `${this.basePath}/top-products`,
1051
- params,
1052
- options
1053
- );
1080
+ return this.client.get(`${this.basePath}/top-products`, params, options);
1054
1081
  }
1055
1082
  async getSalesByCustomer(startDate, endDate, options) {
1056
1083
  const params = {};
@@ -1062,6 +1089,13 @@ var SalesResource = class extends BaseResource {
1062
1089
  options
1063
1090
  );
1064
1091
  }
1092
+ async resendWhatsAppNotification(saleId, options) {
1093
+ return this.client.post(
1094
+ `${this.basePath}/${saleId}/resend-whatsapp`,
1095
+ {},
1096
+ options
1097
+ );
1098
+ }
1065
1099
  };
1066
1100
 
1067
1101
  // src/resources/suppliers.ts
@@ -1272,6 +1306,129 @@ var PaymentMethodsResource = class extends BaseResource {
1272
1306
  }
1273
1307
  };
1274
1308
 
1309
+ // src/resources/whatsapp.ts
1310
+ var WhatsAppResource = class extends BaseResource {
1311
+ constructor() {
1312
+ super(...arguments);
1313
+ this.basePath = "whatsapp";
1314
+ }
1315
+ /**
1316
+ * Get WhatsApp configuration for the current gym
1317
+ */
1318
+ async getConfig(options) {
1319
+ return this.client.get(`${this.basePath}/config`, void 0, options);
1320
+ }
1321
+ /**
1322
+ * Initialize WhatsApp connection
1323
+ * Returns QR code if needed
1324
+ */
1325
+ async initializeConnection(options) {
1326
+ return this.client.post(
1327
+ `${this.basePath}/initialize`,
1328
+ {},
1329
+ options
1330
+ );
1331
+ }
1332
+ /**
1333
+ * Update WhatsApp configuration
1334
+ */
1335
+ async updateConfig(data, options) {
1336
+ return this.client.put(`${this.basePath}/config`, data, options);
1337
+ }
1338
+ /**
1339
+ * Get WhatsApp connection status
1340
+ */
1341
+ async getConnectionStatus(options) {
1342
+ return this.client.get(
1343
+ `${this.basePath}/connection-status`,
1344
+ void 0,
1345
+ options
1346
+ );
1347
+ }
1348
+ /**
1349
+ * Send a WhatsApp message
1350
+ */
1351
+ async sendMessage(data, options) {
1352
+ return this.client.post(`${this.basePath}/send-message`, data, options);
1353
+ }
1354
+ /**
1355
+ * Get WhatsApp messages with pagination and filters
1356
+ */
1357
+ async getMessages(params, options) {
1358
+ return this.paginate(`${this.basePath}/messages`, params, options);
1359
+ }
1360
+ /**
1361
+ * Get a specific WhatsApp message by ID
1362
+ */
1363
+ async getMessage(id, options) {
1364
+ return this.client.get(`${this.basePath}/messages/${id}`, void 0, options);
1365
+ }
1366
+ async listContacts(options) {
1367
+ return this.client.get(`${this.basePath}/contacts`, void 0, options);
1368
+ }
1369
+ /**
1370
+ * Disconnect WhatsApp instance
1371
+ * Logs out from WhatsApp without deleting the instance
1372
+ */
1373
+ async disconnect(options) {
1374
+ return this.client.post(`${this.basePath}/disconnect`, {}, options);
1375
+ }
1376
+ };
1377
+
1378
+ // src/resources/whatsapp-templates.ts
1379
+ var WhatsAppTemplatesResource = class extends BaseResource {
1380
+ constructor() {
1381
+ super(...arguments);
1382
+ this.basePath = "whatsapp/templates";
1383
+ }
1384
+ /**
1385
+ * Create a new WhatsApp template
1386
+ */
1387
+ async create(data, options) {
1388
+ return this.client.post(this.basePath, data, options);
1389
+ }
1390
+ /**
1391
+ * Get all WhatsApp templates with pagination and filters
1392
+ */
1393
+ async findAll(params, options) {
1394
+ return this.paginate(this.basePath, params, options);
1395
+ }
1396
+ /**
1397
+ * Get a specific WhatsApp template by ID
1398
+ */
1399
+ async findOne(id, options) {
1400
+ return this.client.get(`${this.basePath}/${id}`, void 0, options);
1401
+ }
1402
+ /**
1403
+ * Get a WhatsApp template by code
1404
+ */
1405
+ async findByCode(code, options) {
1406
+ return this.client.get(`${this.basePath}/code/${code}`, void 0, options);
1407
+ }
1408
+ /**
1409
+ * Update a WhatsApp template
1410
+ */
1411
+ async update(id, data, options) {
1412
+ return this.client.put(`${this.basePath}/${id}`, data, options);
1413
+ }
1414
+ /**
1415
+ * Delete a WhatsApp template
1416
+ */
1417
+ async remove(id, options) {
1418
+ return this.client.delete(`${this.basePath}/${id}`, options);
1419
+ }
1420
+ /**
1421
+ * Preview a template with variables
1422
+ */
1423
+ async preview(id, variables, options) {
1424
+ return this.client.post(
1425
+ `${this.basePath}/${id}/preview`,
1426
+ variables,
1427
+ options
1428
+ );
1429
+ }
1430
+ };
1431
+
1275
1432
  // src/sdk.ts
1276
1433
  var GymSpaceSdk = class {
1277
1434
  constructor(config) {
@@ -1302,6 +1459,8 @@ var GymSpaceSdk = class {
1302
1459
  this.subscriptionPlans = new SubscriptionPlansResource(this.client);
1303
1460
  this.adminSubscriptionManagement = new AdminSubscriptionManagementResource(this.client);
1304
1461
  this.paymentMethods = new PaymentMethodsResource(this.client);
1462
+ this.whatsapp = new WhatsAppResource(this.client);
1463
+ this.whatsappTemplates = new WhatsAppTemplatesResource(this.client);
1305
1464
  }
1306
1465
  /**
1307
1466
  * Set the authentication token
@@ -1333,6 +1492,21 @@ var GymSpaceSdk = class {
1333
1492
  clearAuth() {
1334
1493
  this.client.clearAuth();
1335
1494
  }
1495
+ /**
1496
+ * Set Expo fetch for React Native environments
1497
+ * Should be called once during app initialization
1498
+ */
1499
+ setExpoFetch(fetchFn) {
1500
+ this.expoFetch = fetchFn;
1501
+ }
1502
+ /**
1503
+ * Create a fetch function for agent endpoints
1504
+ * Uses the /agent/* proxy that includes request context
1505
+ * Automatically uses Expo fetch if set
1506
+ */
1507
+ createAgentFetch() {
1508
+ return createAgentFetch(this.client, this.expoFetch);
1509
+ }
1336
1510
  /**
1337
1511
  * Get the underlying API client
1338
1512
  */
@@ -1364,6 +1538,7 @@ var CollaboratorStatus = /* @__PURE__ */ ((CollaboratorStatus2) => {
1364
1538
  var InvitationStatus = /* @__PURE__ */ ((InvitationStatus2) => {
1365
1539
  InvitationStatus2["PENDING"] = "pending";
1366
1540
  InvitationStatus2["ACCEPTED"] = "accepted";
1541
+ InvitationStatus2["CANCELLED"] = "cancelled";
1367
1542
  InvitationStatus2["EXPIRED"] = "expired";
1368
1543
  return InvitationStatus2;
1369
1544
  })(InvitationStatus || {});
@@ -1533,10 +1708,14 @@ var PERMISSIONS = {
1533
1708
  PAYMENT_METHODS_CREATE: "PAYMENT_METHODS_CREATE",
1534
1709
  PAYMENT_METHODS_READ: "PAYMENT_METHODS_READ",
1535
1710
  PAYMENT_METHODS_UPDATE: "PAYMENT_METHODS_UPDATE",
1536
- PAYMENT_METHODS_DELETE: "PAYMENT_METHODS_DELETE"
1711
+ PAYMENT_METHODS_DELETE: "PAYMENT_METHODS_DELETE",
1712
+ // Special permissions
1713
+ SUPER_ADMIN: "SUPER_ADMIN",
1714
+ OWNER: "OWNER",
1715
+ All: "ALL"
1537
1716
  };
1538
1717
  var ROLE_PERMISSIONS = {
1539
- OWNER: Object.values(PERMISSIONS),
1718
+ ADMIN: Object.values(PERMISSIONS),
1540
1719
  MANAGER: [
1541
1720
  PERMISSIONS.GYMS_READ,
1542
1721
  PERMISSIONS.COLLABORATORS_READ,
@@ -1576,26 +1755,6 @@ var ROLE_PERMISSIONS = {
1576
1755
  PERMISSIONS.PAYMENT_METHODS_READ,
1577
1756
  PERMISSIONS.PAYMENT_METHODS_UPDATE,
1578
1757
  PERMISSIONS.PAYMENT_METHODS_DELETE
1579
- ],
1580
- STAFF: [
1581
- PERMISSIONS.CLIENTS_READ,
1582
- PERMISSIONS.CHECKINS_CREATE,
1583
- PERMISSIONS.CHECKINS_READ,
1584
- PERMISSIONS.PRODUCTS_READ,
1585
- PERMISSIONS.PRODUCT_CATEGORIES_READ,
1586
- PERMISSIONS.SALES_CREATE,
1587
- PERMISSIONS.SALES_READ,
1588
- PERMISSIONS.PAYMENT_METHODS_READ
1589
- ],
1590
- ADVISOR: [
1591
- PERMISSIONS.CLIENTS_READ,
1592
- PERMISSIONS.EVALUATIONS_CREATE,
1593
- PERMISSIONS.EVALUATIONS_READ,
1594
- PERMISSIONS.EVALUATIONS_UPDATE,
1595
- PERMISSIONS.ASSETS_CREATE,
1596
- PERMISSIONS.ASSETS_READ,
1597
- PERMISSIONS.FILES_CREATE,
1598
- PERMISSIONS.FILES_READ
1599
1758
  ]
1600
1759
  };
1601
1760
  var CACHE_TTL = {
@@ -1632,6 +1791,95 @@ var HEADERS = {
1632
1791
  GYM_ID: "X-Gym-Id",
1633
1792
  REQUEST_ID: "X-Request-Id"
1634
1793
  };
1794
+ var RoleNames = /* @__PURE__ */ ((RoleNames2) => {
1795
+ RoleNames2["ADMIN"] = "Admin";
1796
+ RoleNames2["ENCARGADO"] = "Encargado";
1797
+ RoleNames2["OWNER"] = "OWNER";
1798
+ return RoleNames2;
1799
+ })(RoleNames || {});
1800
+ var ROLE_NAMES = RoleNames;
1801
+ function isAdminRole(roleName) {
1802
+ return roleName === "Admin";
1803
+ }
1804
+ function isEncargadoRole(roleName) {
1805
+ return roleName === "Encargado";
1806
+ }
1807
+ function canAccessFeature(userRole, allowedRoles) {
1808
+ if (!userRole) return false;
1809
+ if (userRole === "OWNER") return true;
1810
+ return allowedRoles.includes(userRole);
1811
+ }
1812
+ function getRoleDisplayName(roleName) {
1813
+ if (!roleName) return "";
1814
+ switch (roleName) {
1815
+ case "Admin":
1816
+ return "Administrador";
1817
+ case "Encargado":
1818
+ return "Encargado";
1819
+ case "OWNER":
1820
+ return "Propietario";
1821
+ default:
1822
+ return roleName;
1823
+ }
1824
+ }
1825
+ function getRoleDescription(roleName) {
1826
+ if (!roleName) return "";
1827
+ switch (roleName) {
1828
+ case "Admin":
1829
+ return "Acceso completo a todas las funcionalidades del gimnasio, gesti\xF3n de colaboradores y configuraci\xF3n";
1830
+ case "Encargado":
1831
+ return "Gesti\xF3n diaria del gimnasio: clientes, contratos, check-ins y reportes";
1832
+ case "OWNER":
1833
+ return "Acceso completo a todas las funcionalidades, organizaci\xF3n y suscripci\xF3n";
1834
+ default:
1835
+ return "";
1836
+ }
1837
+ }
1838
+ function getRoleCapabilities(roleName) {
1839
+ if (!roleName) return [];
1840
+ switch (roleName) {
1841
+ case "OWNER":
1842
+ return [
1843
+ "Acceso completo a todas las funcionalidades",
1844
+ "Gesti\xF3n de organizaci\xF3n",
1845
+ "Gesti\xF3n de suscripci\xF3n y facturaci\xF3n",
1846
+ "Gesti\xF3n completa de clientes",
1847
+ "Gesti\xF3n completa de contratos",
1848
+ "Gesti\xF3n de colaboradores",
1849
+ "Configuraci\xF3n del gimnasio",
1850
+ "Gesti\xF3n de planes",
1851
+ "Gesti\xF3n de proveedores",
1852
+ "Gesti\xF3n de m\xE9todos de pago",
1853
+ "Reportes y estad\xEDsticas",
1854
+ "Gesti\xF3n de inventario",
1855
+ "Check-ins"
1856
+ ];
1857
+ case "Admin":
1858
+ return [
1859
+ "Gesti\xF3n completa de clientes",
1860
+ "Gesti\xF3n completa de contratos",
1861
+ "Gesti\xF3n de colaboradores",
1862
+ "Configuraci\xF3n del gimnasio",
1863
+ "Gesti\xF3n de planes",
1864
+ "Gesti\xF3n de proveedores",
1865
+ "Gesti\xF3n de m\xE9todos de pago",
1866
+ "Reportes y estad\xEDsticas",
1867
+ "Gesti\xF3n de inventario",
1868
+ "Check-ins"
1869
+ ];
1870
+ case "Encargado":
1871
+ return [
1872
+ "Gesti\xF3n de clientes (ver, crear, editar)",
1873
+ "Creaci\xF3n y renovaci\xF3n de contratos",
1874
+ "Check-ins",
1875
+ "Ver reportes",
1876
+ "Gesti\xF3n de inventario",
1877
+ "Ventas"
1878
+ ];
1879
+ default:
1880
+ return [];
1881
+ }
1882
+ }
1635
1883
 
1636
1884
  // src/models/onboarding.ts
1637
1885
  var OnboardingStep = /* @__PURE__ */ ((OnboardingStep2) => {
@@ -1642,6 +1890,6 @@ var OnboardingStep = /* @__PURE__ */ ((OnboardingStep2) => {
1642
1890
  return OnboardingStep2;
1643
1891
  })(OnboardingStep || {});
1644
1892
 
1645
- 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_PERMISSIONS, RolesResource, SalesResource, SubscriptionPlansResource, SubscriptionStatus, SubscriptionsResource, SuppliersResource, UserType, UsersResource, ValidationError };
1893
+ 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 };
1646
1894
  //# sourceMappingURL=index.mjs.map
1647
1895
  //# sourceMappingURL=index.mjs.map