@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.js CHANGED
@@ -194,6 +194,26 @@ var ApiClient = class {
194
194
  }
195
195
  };
196
196
 
197
+ // src/utils/agent-fetch.ts
198
+ function createAgentFetch(apiClient, customFetch) {
199
+ const fetchFn = customFetch || fetch;
200
+ return async (path, options) => {
201
+ const fullUrl = `${apiClient.getBaseUrl()}/agent${path}`;
202
+ const axiosInstance = apiClient.axiosInstance;
203
+ const gymId = axiosInstance?.defaults?.headers?.common?.["X-Gym-Id"];
204
+ const headers = {
205
+ "Content-Type": "application/json",
206
+ ...apiClient.getAccessToken() && { Authorization: `Bearer ${apiClient.getAccessToken()}` },
207
+ ...gymId && { "X-Gym-Id": gymId },
208
+ ...options?.headers || {}
209
+ };
210
+ return fetchFn(fullUrl, {
211
+ ...options,
212
+ headers
213
+ });
214
+ };
215
+ }
216
+
197
217
  // src/resources/base.ts
198
218
  var BaseResource = class {
199
219
  constructor(client) {
@@ -386,11 +406,11 @@ var CollaboratorsResource = class extends BaseResource {
386
406
  async update(id, data, options) {
387
407
  return this.client.patch(`${this.basePath}/${id}`, data, options);
388
408
  }
389
- async updateRole(id, roleId, options) {
390
- return this.client.patch(`${this.basePath}/${id}/role`, { roleId }, options);
409
+ async updateRole(id, data, options) {
410
+ return this.client.patch(`${this.basePath}/${id}/role`, data, options);
391
411
  }
392
- async updateStatus(id, status, options) {
393
- return this.client.patch(`${this.basePath}/${id}/status`, { status }, options);
412
+ async updateStatus(id, data, options) {
413
+ return this.client.patch(`${this.basePath}/${id}/status`, data, options);
394
414
  }
395
415
  async getActivity(id, params, options) {
396
416
  return this.client.get(`${this.basePath}/${id}/activity`, params, options);
@@ -436,7 +456,7 @@ var ClientsResource = class extends BaseResource {
436
456
  return this.client.post(this.basePath, data, options);
437
457
  }
438
458
  async searchClients(params, options) {
439
- return this.paginate(this.basePath, params, options);
459
+ return this.client.get(this.basePath, params, options);
440
460
  }
441
461
  async getClient(id, options) {
442
462
  return this.client.get(`${this.basePath}/${id}`, void 0, options);
@@ -451,20 +471,24 @@ var ClientsResource = class extends BaseResource {
451
471
  return this.client.get(`${this.basePath}/${id}/stats`, void 0, options);
452
472
  }
453
473
  async getClientStat(id, statKey, options) {
454
- return this.client.get(`${this.basePath}/${id}/stats/${statKey}`, void 0, options);
474
+ return this.client.get(
475
+ `${this.basePath}/${id}/stats/${statKey}`,
476
+ void 0,
477
+ options
478
+ );
455
479
  }
456
480
  async getClientStatsByCategory(id, category, options) {
457
- return this.client.get(`${this.basePath}/${id}/stats/category/${category}`, void 0, options);
481
+ return this.client.get(
482
+ `${this.basePath}/${id}/stats/category/${category}`,
483
+ void 0,
484
+ options
485
+ );
458
486
  }
459
487
  async getAvailableStats(options) {
460
488
  return this.client.get(`${this.basePath}/stats/available`, void 0, options);
461
489
  }
462
490
  async searchClientsForCheckIn(params, options) {
463
- return this.client.get(
464
- `${this.basePath}/search/check-in`,
465
- params,
466
- options
467
- );
491
+ return this.client.get(`${this.basePath}/search/check-in`, params, options);
468
492
  }
469
493
  };
470
494
 
@@ -514,11 +538,7 @@ var ContractsResource = class extends BaseResource {
514
538
  return this.client.get(`${this.basePath}/${id}`, void 0, options);
515
539
  }
516
540
  async getClientContracts(clientId, options) {
517
- return this.client.get(
518
- `${this.basePath}/client/${clientId}`,
519
- void 0,
520
- options
521
- );
541
+ return this.client.get(`${this.basePath}/client/${clientId}`, void 0, options);
522
542
  }
523
543
  async renewContract(id, data, options) {
524
544
  return this.client.post(`${this.basePath}/${id}/renew`, data, options);
@@ -529,6 +549,13 @@ var ContractsResource = class extends BaseResource {
529
549
  async cancelContract(id, data, options) {
530
550
  return this.client.put(`${this.basePath}/${id}/cancel`, data, options);
531
551
  }
552
+ async resendWhatsAppNotification(contractId, options) {
553
+ return this.client.post(
554
+ `${this.basePath}/${contractId}/resend-whatsapp`,
555
+ {},
556
+ options
557
+ );
558
+ }
532
559
  };
533
560
 
534
561
  // src/resources/dashboard.ts
@@ -1030,7 +1057,11 @@ var SalesResource = class extends BaseResource {
1030
1057
  return this.client.put(`${this.basePath}/${id}`, data, options);
1031
1058
  }
1032
1059
  async updatePaymentStatus(id, paymentStatus, options) {
1033
- return this.client.put(`${this.basePath}/${id}/payment-status`, { paymentStatus }, options);
1060
+ return this.client.put(
1061
+ `${this.basePath}/${id}/payment-status`,
1062
+ { paymentStatus },
1063
+ options
1064
+ );
1034
1065
  }
1035
1066
  async paySale(id, data, options) {
1036
1067
  return this.client.post(`${this.basePath}/${id}/payment`, data, options);
@@ -1052,11 +1083,7 @@ var SalesResource = class extends BaseResource {
1052
1083
  const params = { limit };
1053
1084
  if (startDate) params.startDate = startDate;
1054
1085
  if (endDate) params.endDate = endDate;
1055
- return this.client.get(
1056
- `${this.basePath}/top-products`,
1057
- params,
1058
- options
1059
- );
1086
+ return this.client.get(`${this.basePath}/top-products`, params, options);
1060
1087
  }
1061
1088
  async getSalesByCustomer(startDate, endDate, options) {
1062
1089
  const params = {};
@@ -1068,6 +1095,13 @@ var SalesResource = class extends BaseResource {
1068
1095
  options
1069
1096
  );
1070
1097
  }
1098
+ async resendWhatsAppNotification(saleId, options) {
1099
+ return this.client.post(
1100
+ `${this.basePath}/${saleId}/resend-whatsapp`,
1101
+ {},
1102
+ options
1103
+ );
1104
+ }
1071
1105
  };
1072
1106
 
1073
1107
  // src/resources/suppliers.ts
@@ -1278,6 +1312,129 @@ var PaymentMethodsResource = class extends BaseResource {
1278
1312
  }
1279
1313
  };
1280
1314
 
1315
+ // src/resources/whatsapp.ts
1316
+ var WhatsAppResource = class extends BaseResource {
1317
+ constructor() {
1318
+ super(...arguments);
1319
+ this.basePath = "whatsapp";
1320
+ }
1321
+ /**
1322
+ * Get WhatsApp configuration for the current gym
1323
+ */
1324
+ async getConfig(options) {
1325
+ return this.client.get(`${this.basePath}/config`, void 0, options);
1326
+ }
1327
+ /**
1328
+ * Initialize WhatsApp connection
1329
+ * Returns QR code if needed
1330
+ */
1331
+ async initializeConnection(options) {
1332
+ return this.client.post(
1333
+ `${this.basePath}/initialize`,
1334
+ {},
1335
+ options
1336
+ );
1337
+ }
1338
+ /**
1339
+ * Update WhatsApp configuration
1340
+ */
1341
+ async updateConfig(data, options) {
1342
+ return this.client.put(`${this.basePath}/config`, data, options);
1343
+ }
1344
+ /**
1345
+ * Get WhatsApp connection status
1346
+ */
1347
+ async getConnectionStatus(options) {
1348
+ return this.client.get(
1349
+ `${this.basePath}/connection-status`,
1350
+ void 0,
1351
+ options
1352
+ );
1353
+ }
1354
+ /**
1355
+ * Send a WhatsApp message
1356
+ */
1357
+ async sendMessage(data, options) {
1358
+ return this.client.post(`${this.basePath}/send-message`, data, options);
1359
+ }
1360
+ /**
1361
+ * Get WhatsApp messages with pagination and filters
1362
+ */
1363
+ async getMessages(params, options) {
1364
+ return this.paginate(`${this.basePath}/messages`, params, options);
1365
+ }
1366
+ /**
1367
+ * Get a specific WhatsApp message by ID
1368
+ */
1369
+ async getMessage(id, options) {
1370
+ return this.client.get(`${this.basePath}/messages/${id}`, void 0, options);
1371
+ }
1372
+ async listContacts(options) {
1373
+ return this.client.get(`${this.basePath}/contacts`, void 0, options);
1374
+ }
1375
+ /**
1376
+ * Disconnect WhatsApp instance
1377
+ * Logs out from WhatsApp without deleting the instance
1378
+ */
1379
+ async disconnect(options) {
1380
+ return this.client.post(`${this.basePath}/disconnect`, {}, options);
1381
+ }
1382
+ };
1383
+
1384
+ // src/resources/whatsapp-templates.ts
1385
+ var WhatsAppTemplatesResource = class extends BaseResource {
1386
+ constructor() {
1387
+ super(...arguments);
1388
+ this.basePath = "whatsapp/templates";
1389
+ }
1390
+ /**
1391
+ * Create a new WhatsApp template
1392
+ */
1393
+ async create(data, options) {
1394
+ return this.client.post(this.basePath, data, options);
1395
+ }
1396
+ /**
1397
+ * Get all WhatsApp templates with pagination and filters
1398
+ */
1399
+ async findAll(params, options) {
1400
+ return this.paginate(this.basePath, params, options);
1401
+ }
1402
+ /**
1403
+ * Get a specific WhatsApp template by ID
1404
+ */
1405
+ async findOne(id, options) {
1406
+ return this.client.get(`${this.basePath}/${id}`, void 0, options);
1407
+ }
1408
+ /**
1409
+ * Get a WhatsApp template by code
1410
+ */
1411
+ async findByCode(code, options) {
1412
+ return this.client.get(`${this.basePath}/code/${code}`, void 0, options);
1413
+ }
1414
+ /**
1415
+ * Update a WhatsApp template
1416
+ */
1417
+ async update(id, data, options) {
1418
+ return this.client.put(`${this.basePath}/${id}`, data, options);
1419
+ }
1420
+ /**
1421
+ * Delete a WhatsApp template
1422
+ */
1423
+ async remove(id, options) {
1424
+ return this.client.delete(`${this.basePath}/${id}`, options);
1425
+ }
1426
+ /**
1427
+ * Preview a template with variables
1428
+ */
1429
+ async preview(id, variables, options) {
1430
+ return this.client.post(
1431
+ `${this.basePath}/${id}/preview`,
1432
+ variables,
1433
+ options
1434
+ );
1435
+ }
1436
+ };
1437
+
1281
1438
  // src/sdk.ts
1282
1439
  var GymSpaceSdk = class {
1283
1440
  constructor(config) {
@@ -1308,6 +1465,8 @@ var GymSpaceSdk = class {
1308
1465
  this.subscriptionPlans = new SubscriptionPlansResource(this.client);
1309
1466
  this.adminSubscriptionManagement = new AdminSubscriptionManagementResource(this.client);
1310
1467
  this.paymentMethods = new PaymentMethodsResource(this.client);
1468
+ this.whatsapp = new WhatsAppResource(this.client);
1469
+ this.whatsappTemplates = new WhatsAppTemplatesResource(this.client);
1311
1470
  }
1312
1471
  /**
1313
1472
  * Set the authentication token
@@ -1339,6 +1498,21 @@ var GymSpaceSdk = class {
1339
1498
  clearAuth() {
1340
1499
  this.client.clearAuth();
1341
1500
  }
1501
+ /**
1502
+ * Set Expo fetch for React Native environments
1503
+ * Should be called once during app initialization
1504
+ */
1505
+ setExpoFetch(fetchFn) {
1506
+ this.expoFetch = fetchFn;
1507
+ }
1508
+ /**
1509
+ * Create a fetch function for agent endpoints
1510
+ * Uses the /agent/* proxy that includes request context
1511
+ * Automatically uses Expo fetch if set
1512
+ */
1513
+ createAgentFetch() {
1514
+ return createAgentFetch(this.client, this.expoFetch);
1515
+ }
1342
1516
  /**
1343
1517
  * Get the underlying API client
1344
1518
  */
@@ -1370,6 +1544,7 @@ var CollaboratorStatus = /* @__PURE__ */ ((CollaboratorStatus2) => {
1370
1544
  var InvitationStatus = /* @__PURE__ */ ((InvitationStatus2) => {
1371
1545
  InvitationStatus2["PENDING"] = "pending";
1372
1546
  InvitationStatus2["ACCEPTED"] = "accepted";
1547
+ InvitationStatus2["CANCELLED"] = "cancelled";
1373
1548
  InvitationStatus2["EXPIRED"] = "expired";
1374
1549
  return InvitationStatus2;
1375
1550
  })(InvitationStatus || {});
@@ -1539,10 +1714,14 @@ var PERMISSIONS = {
1539
1714
  PAYMENT_METHODS_CREATE: "PAYMENT_METHODS_CREATE",
1540
1715
  PAYMENT_METHODS_READ: "PAYMENT_METHODS_READ",
1541
1716
  PAYMENT_METHODS_UPDATE: "PAYMENT_METHODS_UPDATE",
1542
- PAYMENT_METHODS_DELETE: "PAYMENT_METHODS_DELETE"
1717
+ PAYMENT_METHODS_DELETE: "PAYMENT_METHODS_DELETE",
1718
+ // Special permissions
1719
+ SUPER_ADMIN: "SUPER_ADMIN",
1720
+ OWNER: "OWNER",
1721
+ All: "ALL"
1543
1722
  };
1544
1723
  var ROLE_PERMISSIONS = {
1545
- OWNER: Object.values(PERMISSIONS),
1724
+ ADMIN: Object.values(PERMISSIONS),
1546
1725
  MANAGER: [
1547
1726
  PERMISSIONS.GYMS_READ,
1548
1727
  PERMISSIONS.COLLABORATORS_READ,
@@ -1582,26 +1761,6 @@ var ROLE_PERMISSIONS = {
1582
1761
  PERMISSIONS.PAYMENT_METHODS_READ,
1583
1762
  PERMISSIONS.PAYMENT_METHODS_UPDATE,
1584
1763
  PERMISSIONS.PAYMENT_METHODS_DELETE
1585
- ],
1586
- STAFF: [
1587
- PERMISSIONS.CLIENTS_READ,
1588
- PERMISSIONS.CHECKINS_CREATE,
1589
- PERMISSIONS.CHECKINS_READ,
1590
- PERMISSIONS.PRODUCTS_READ,
1591
- PERMISSIONS.PRODUCT_CATEGORIES_READ,
1592
- PERMISSIONS.SALES_CREATE,
1593
- PERMISSIONS.SALES_READ,
1594
- PERMISSIONS.PAYMENT_METHODS_READ
1595
- ],
1596
- ADVISOR: [
1597
- PERMISSIONS.CLIENTS_READ,
1598
- PERMISSIONS.EVALUATIONS_CREATE,
1599
- PERMISSIONS.EVALUATIONS_READ,
1600
- PERMISSIONS.EVALUATIONS_UPDATE,
1601
- PERMISSIONS.ASSETS_CREATE,
1602
- PERMISSIONS.ASSETS_READ,
1603
- PERMISSIONS.FILES_CREATE,
1604
- PERMISSIONS.FILES_READ
1605
1764
  ]
1606
1765
  };
1607
1766
  var CACHE_TTL = {
@@ -1638,6 +1797,95 @@ var HEADERS = {
1638
1797
  GYM_ID: "X-Gym-Id",
1639
1798
  REQUEST_ID: "X-Request-Id"
1640
1799
  };
1800
+ var RoleNames = /* @__PURE__ */ ((RoleNames2) => {
1801
+ RoleNames2["ADMIN"] = "Admin";
1802
+ RoleNames2["ENCARGADO"] = "Encargado";
1803
+ RoleNames2["OWNER"] = "OWNER";
1804
+ return RoleNames2;
1805
+ })(RoleNames || {});
1806
+ var ROLE_NAMES = RoleNames;
1807
+ function isAdminRole(roleName) {
1808
+ return roleName === "Admin";
1809
+ }
1810
+ function isEncargadoRole(roleName) {
1811
+ return roleName === "Encargado";
1812
+ }
1813
+ function canAccessFeature(userRole, allowedRoles) {
1814
+ if (!userRole) return false;
1815
+ if (userRole === "OWNER") return true;
1816
+ return allowedRoles.includes(userRole);
1817
+ }
1818
+ function getRoleDisplayName(roleName) {
1819
+ if (!roleName) return "";
1820
+ switch (roleName) {
1821
+ case "Admin":
1822
+ return "Administrador";
1823
+ case "Encargado":
1824
+ return "Encargado";
1825
+ case "OWNER":
1826
+ return "Propietario";
1827
+ default:
1828
+ return roleName;
1829
+ }
1830
+ }
1831
+ function getRoleDescription(roleName) {
1832
+ if (!roleName) return "";
1833
+ switch (roleName) {
1834
+ case "Admin":
1835
+ return "Acceso completo a todas las funcionalidades del gimnasio, gesti\xF3n de colaboradores y configuraci\xF3n";
1836
+ case "Encargado":
1837
+ return "Gesti\xF3n diaria del gimnasio: clientes, contratos, check-ins y reportes";
1838
+ case "OWNER":
1839
+ return "Acceso completo a todas las funcionalidades, organizaci\xF3n y suscripci\xF3n";
1840
+ default:
1841
+ return "";
1842
+ }
1843
+ }
1844
+ function getRoleCapabilities(roleName) {
1845
+ if (!roleName) return [];
1846
+ switch (roleName) {
1847
+ case "OWNER":
1848
+ return [
1849
+ "Acceso completo a todas las funcionalidades",
1850
+ "Gesti\xF3n de organizaci\xF3n",
1851
+ "Gesti\xF3n de suscripci\xF3n y facturaci\xF3n",
1852
+ "Gesti\xF3n completa de clientes",
1853
+ "Gesti\xF3n completa de contratos",
1854
+ "Gesti\xF3n de colaboradores",
1855
+ "Configuraci\xF3n del gimnasio",
1856
+ "Gesti\xF3n de planes",
1857
+ "Gesti\xF3n de proveedores",
1858
+ "Gesti\xF3n de m\xE9todos de pago",
1859
+ "Reportes y estad\xEDsticas",
1860
+ "Gesti\xF3n de inventario",
1861
+ "Check-ins"
1862
+ ];
1863
+ case "Admin":
1864
+ return [
1865
+ "Gesti\xF3n completa de clientes",
1866
+ "Gesti\xF3n completa de contratos",
1867
+ "Gesti\xF3n de colaboradores",
1868
+ "Configuraci\xF3n del gimnasio",
1869
+ "Gesti\xF3n de planes",
1870
+ "Gesti\xF3n de proveedores",
1871
+ "Gesti\xF3n de m\xE9todos de pago",
1872
+ "Reportes y estad\xEDsticas",
1873
+ "Gesti\xF3n de inventario",
1874
+ "Check-ins"
1875
+ ];
1876
+ case "Encargado":
1877
+ return [
1878
+ "Gesti\xF3n de clientes (ver, crear, editar)",
1879
+ "Creaci\xF3n y renovaci\xF3n de contratos",
1880
+ "Check-ins",
1881
+ "Ver reportes",
1882
+ "Gesti\xF3n de inventario",
1883
+ "Ventas"
1884
+ ];
1885
+ default:
1886
+ return [];
1887
+ }
1888
+ }
1641
1889
 
1642
1890
  // src/models/onboarding.ts
1643
1891
  var OnboardingStep = /* @__PURE__ */ ((OnboardingStep2) => {
@@ -1697,7 +1945,9 @@ exports.PaymentMethodsResource = PaymentMethodsResource;
1697
1945
  exports.PlanStatus = PlanStatus;
1698
1946
  exports.ProductsResource = ProductsResource;
1699
1947
  exports.PublicCatalogResource = PublicCatalogResource;
1948
+ exports.ROLE_NAMES = ROLE_NAMES;
1700
1949
  exports.ROLE_PERMISSIONS = ROLE_PERMISSIONS;
1950
+ exports.RoleNames = RoleNames;
1701
1951
  exports.RolesResource = RolesResource;
1702
1952
  exports.SalesResource = SalesResource;
1703
1953
  exports.SubscriptionPlansResource = SubscriptionPlansResource;
@@ -1707,5 +1957,13 @@ exports.SuppliersResource = SuppliersResource;
1707
1957
  exports.UserType = UserType;
1708
1958
  exports.UsersResource = UsersResource;
1709
1959
  exports.ValidationError = ValidationError;
1960
+ exports.WhatsAppResource = WhatsAppResource;
1961
+ exports.WhatsAppTemplatesResource = WhatsAppTemplatesResource;
1962
+ exports.canAccessFeature = canAccessFeature;
1963
+ exports.getRoleCapabilities = getRoleCapabilities;
1964
+ exports.getRoleDescription = getRoleDescription;
1965
+ exports.getRoleDisplayName = getRoleDisplayName;
1966
+ exports.isAdminRole = isAdminRole;
1967
+ exports.isEncargadoRole = isEncargadoRole;
1710
1968
  //# sourceMappingURL=index.js.map
1711
1969
  //# sourceMappingURL=index.js.map