gufi-cli 0.1.13 β†’ 0.1.16

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/CLAUDE.md CHANGED
@@ -45,6 +45,105 @@ Ejemplo:
45
45
 
46
46
  ---
47
47
 
48
+ ## πŸ’œ Core Database - Relaciones Importantes
49
+
50
+ ### Diagrama de Relaciones
51
+
52
+ ```
53
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
54
+ β”‚ SCHEMA: core β”‚
55
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
56
+ β”‚ β”‚
57
+ β”‚ companies (1) β”‚
58
+ β”‚ β”œβ”€β”€ id: 116 β”‚
59
+ β”‚ β”œβ”€β”€ name: "Fitvending" β”‚
60
+ β”‚ └── schema: "company_116" β”‚
61
+ β”‚ β”‚ β”‚
62
+ β”‚ β”‚ 1:N β”‚
63
+ β”‚ β–Ό β”‚
64
+ β”‚ modules (N) users (N) β”‚
65
+ β”‚ β”œβ”€β”€ id: 308 β”œβ”€β”€ id: 16 β”‚
66
+ β”‚ β”œβ”€β”€ company_id: 116 ◄────────── β”œβ”€β”€ email: "juan@gufi.es" β”‚
67
+ β”‚ β”œβ”€β”€ name: "nayax" └── platform_role: "admin" β”‚
68
+ β”‚ └── json_definition: {...} β”‚ β”‚
69
+ β”‚ β”‚ β”‚ N:M β”‚
70
+ β”‚ β”‚ 1:N β–Ό β”‚
71
+ β”‚ β–Ό company_users β”‚
72
+ β”‚ entities (N) β”œβ”€β”€ user_id: 16 β”‚
73
+ β”‚ β”œβ”€β”€ id: 4136 β”œβ”€β”€ company_id: 116 β”‚
74
+ β”‚ β”œβ”€β”€ module_id: 308 ◄─────────── └── roles: ["Admin"] β”‚
75
+ β”‚ β”œβ”€β”€ company_id: 116 β”‚
76
+ β”‚ β”œβ”€β”€ name: "machines" β”‚
77
+ β”‚ β”œβ”€β”€ permissions: {"Admin": "*"} ◄── Permisos por rol β”‚
78
+ β”‚ └── automations: [{...}] ◄── JSONB array de triggers β”‚
79
+ β”‚ β”‚ β”‚
80
+ β”‚ β”‚ N:1 (via script_id en automations) β”‚
81
+ β”‚ β–Ό β”‚
82
+ β”‚ automation_scripts (N) β”‚
83
+ β”‚ β”œβ”€β”€ id: 15 β”‚
84
+ β”‚ β”œβ”€β”€ company_id: 116 β”‚
85
+ β”‚ β”œβ”€β”€ name: "sync_machines" β”‚
86
+ β”‚ └── code: "async function..." ◄── El JavaScript β”‚
87
+ β”‚ β”‚ β”‚
88
+ β”‚ β”‚ (sync automΓ‘tico) β”‚
89
+ β”‚ β–Ό β”‚
90
+ β”‚ automation_meta (Γ­ndice para worker) β”‚
91
+ β”‚ automation_executions (historial) β”‚
92
+ β”‚ β”‚
93
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
94
+
95
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
96
+ β”‚ SCHEMA: company_116 β”‚
97
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
98
+ β”‚ β”‚
99
+ β”‚ m308_t4136 (machines) m308_t4137 (products) m308_t4140 (sales) β”‚
100
+ β”‚ β”œβ”€β”€ id β”œβ”€β”€ id β”œβ”€β”€ id β”‚
101
+ β”‚ β”œβ”€β”€ name β”œβ”€β”€ name β”œβ”€β”€ machine_id (FK) β”‚
102
+ β”‚ └── ... └── ... └── ... β”‚
103
+ β”‚ β”‚
104
+ β”‚ __audit_log__ (historial de cambios) β”‚
105
+ β”‚ β”‚
106
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
107
+ ```
108
+
109
+ ### Tablas Core Principales
110
+
111
+ | Tabla | DescripciΓ³n | Relaciones |
112
+ |-------|-------------|------------|
113
+ | `companies` | Empresas/tenants | 1 company β†’ N modules, N users |
114
+ | `users` | Usuarios globales | N:M con companies via company_users |
115
+ | `company_users` | MembresΓ­a usuario-empresa | Contiene roles[] del usuario en esa company |
116
+ | `modules` | DefiniciΓ³n JSON de mΓ³dulos | 1 module β†’ N entities |
117
+ | `entities` | Metadatos de tablas | Contiene permissions, automations, config |
118
+ | `automation_scripts` | CΓ³digo JavaScript | 1 script β†’ N entities pueden usarlo |
119
+ | `automation_meta` | Índice para worker | Generado auto desde entities.automations |
120
+
121
+ ### Flujo de Datos
122
+
123
+ ```
124
+ Usuario hace login
125
+ β”‚
126
+ β–Ό
127
+ JWT contiene: { user_id, company_id, roles[], platform_role }
128
+ β”‚
129
+ β–Ό
130
+ Backend: SET search_path TO company_116, core;
131
+ β”‚
132
+ β–Ό
133
+ Queries van automΓ‘ticamente al schema correcto
134
+ ```
135
+
136
+ ### IDs Importantes para CLI
137
+
138
+ | Quiero trabajar con... | Necesito el ID de... | CΓ³mo obtenerlo |
139
+ |------------------------|---------------------|----------------|
140
+ | Datos de una tabla | entity (tabla fΓ­sica: m308_t4136) | `gufi schema -c 116` |
141
+ | Estructura de mΓ³dulo | module_id | `gufi modules 116` |
142
+ | CΓ³digo de automation | script_id | `gufi automations -c 116` |
143
+ | Triggers de una entity | entity_id | `gufi schema -c 116` |
144
+
145
+ ---
146
+
48
147
  ## Estructura de un MΓ³dulo (JSON)
49
148
 
50
149
  Un mΓ³dulo es un JSON que define **toda la estructura de datos** de una funcionalidad. Gufi lee este JSON y automΓ‘ticamente:
@@ -245,11 +344,11 @@ Un mΓ³dulo es un JSON que define **toda la estructura de datos** de una funciona
245
344
  ],
246
345
  "automations": [
247
346
  {
248
- "trigger": "on_insert",
347
+ "trigger": "insert",
249
348
  "function_name": "notificar_nuevo_pedido"
250
349
  },
251
350
  {
252
- "trigger": "on_update",
351
+ "trigger": "update",
253
352
  "condition": "estado = 'confirmado'",
254
353
  "function_name": "procesar_pedido"
255
354
  },
@@ -426,10 +525,10 @@ SELECT * FROM core.automation_meta WHERE company_id = 116;
426
525
 
427
526
  | Trigger | CuΓ‘ndo se ejecuta |
428
527
  |---------|-------------------|
429
- | `on_insert` | Al crear un registro |
430
- | `on_update` | Al modificar un registro |
431
- | `on_delete` | Al eliminar un registro |
432
- | `on_click` / `click` | BotΓ³n manual en la UI |
528
+ | `insert` | Al crear un registro |
529
+ | `update` | Al modificar un registro |
530
+ | `delete` | Al eliminar un registro |
531
+ | `click` / `click` | BotΓ³n manual en la UI |
433
532
  | `scheduled` | Cron job (ej: "0 9 * * *") |
434
533
 
435
534
  ### Formato de entities.automations
@@ -437,13 +536,13 @@ SELECT * FROM core.automation_meta WHERE company_id = 116;
437
536
  ```json
438
537
  [
439
538
  {
440
- "trigger": "on_insert",
539
+ "trigger": "insert",
441
540
  "function_name": "procesar_pedido",
442
541
  "script_id": 42,
443
542
  "enabled": true
444
543
  },
445
544
  {
446
- "trigger": "on_click",
545
+ "trigger": "click",
447
546
  "function_name": "generar_factura",
448
547
  "label": "Generar Factura",
449
548
  "enabled": true
@@ -456,7 +555,7 @@ SELECT * FROM core.automation_meta WHERE company_id = 116;
456
555
  ```javascript
457
556
  /**
458
557
  * FunciΓ³n: procesar_pedido
459
- * Trigger: on_update cuando estado = 'confirmado'
558
+ * Trigger: update cuando estado = 'confirmado'
460
559
  *
461
560
  * @param {Object} context - Contexto de ejecuciΓ³n
462
561
  * @param {Object} api - API para interactuar con el sistema
@@ -472,7 +571,7 @@ async function procesar_pedido(context, api, logger) {
472
571
  entity_id, // ID de la entidad/tabla (ej: 4136)
473
572
  table, // Nombre fΓ­sico de tabla (ej: "m308_t4136")
474
573
  row, // Registro actual (despuΓ©s del cambio)
475
- old_row, // Registro anterior (solo en on_update)
574
+ old_row, // Registro anterior (solo en update)
476
575
  input, // Input del usuario (solo en click)
477
576
  env, // Variables de entorno de la company
478
577
  user // Usuario que disparΓ³ el evento
@@ -667,7 +766,13 @@ Cuando descargas una view con `gufi view:pull <id>`, obtienes:
667
766
 
668
767
  ### πŸ’œ dataSources - Declarar quΓ© Tablas Necesita la Vista
669
768
 
670
- El archivo `core/dataProvider.ts` define quΓ© tablas necesita la vista. El Developer Center lee esto y muestra UI para que el usuario asigne sus tablas.
769
+ El archivo `core/dataProvider.ts` define quΓ© tablas necesita la vista.
770
+
771
+ **Arquitectura:**
772
+ 1. Se declaran en cΓ³digo (`core/dataProvider.ts`)
773
+ 2. Se editan con CLI: `gufi pull` β†’ editar β†’ `gufi push`
774
+ 3. Developer Center los muestra como **solo lectura**
775
+ 4. Al instalar la vista, el sistema mapea nombres lΓ³gicos automΓ‘ticamente
671
776
 
672
777
  ```typescript
673
778
  // core/dataProvider.ts
@@ -734,9 +839,9 @@ export default function MiVista({ gufi }) { ... }
734
839
  export default function MiVista({ gufi }) {
735
840
  const viewSpec = gufi?.context?.viewSpec || {};
736
841
 
737
- // Keys de dataSources β†’ nombres de tabla fΓ­sicos
738
- const tareasTable = viewSpec.tareasTable; // "m360_t16194"
739
- const proyectosTable = viewSpec.proyectosTable; // "m360_t16200" o undefined
842
+ // Keys de dataSources β†’ NOMBRES LΓ“GICOS (nunca IDs fΓ­sicos)
843
+ const tareasTable = viewSpec.tareasTable; // "tareas.asignaciones"
844
+ const proyectosTable = viewSpec.proyectosTable; // "tareas.proyectos" o undefined
740
845
 
741
846
  // Usar para queries
742
847
  const res = await gufi.dataProvider.getList({
@@ -1117,7 +1222,7 @@ Las vistas pueden incluir automations que se ejecutan al hacer click.
1117
1222
  // automations/send_notification.js
1118
1223
  /**
1119
1224
  * πŸ’œ Automation: send_notification
1120
- * Trigger: ON_CLICK (desde la vista)
1225
+ * Trigger: CLICK (desde la vista)
1121
1226
  */
1122
1227
  async function send_notification(context, api, logger) {
1123
1228
  const { input, env } = context;
@@ -1594,6 +1699,31 @@ SELECT * FROM marketplace.package_modules WHERE package_id = 14;
1594
1699
 
1595
1700
  ## Comandos del CLI
1596
1701
 
1702
+ ### πŸ’œ Resumen RΓ‘pido para Claude
1703
+
1704
+ **El CLI gestiona companies, mΓ³dulos, automations y datos. Todo es dinΓ‘mico - detecta la company automΓ‘ticamente.**
1705
+
1706
+ | Quiero... | Comando |
1707
+ |-----------|---------|
1708
+ | Ver companies | `gufi companies` |
1709
+ | Ver mΓ³dulos de company | `gufi modules 146` |
1710
+ | Ver/editar mΓ³dulo | `gufi module 360` |
1711
+ | Ver registros | `gufi rows m308_t4136` |
1712
+ | Listar scripts | `gufi automations` |
1713
+ | Ver/editar script | `gufi automation 15` |
1714
+ | **Ver Γ­ndice del worker** | `gufi automations:meta` |
1715
+ | **Ver ejecuciones** | `gufi automations:executions` |
1716
+ | **Ver/editar triggers** | `gufi entity:automations 4136` |
1717
+ | **Ver mis packages** | `gufi packages` |
1718
+ | **Ver package** | `gufi package 14` |
1719
+ | **Crear package** | `gufi package:create "Nombre"` |
1720
+ | **Desarrollar view** | `gufi pull 13` β†’ `gufi watch` β†’ `gufi logs` |
1721
+
1722
+ **3 cosas que saber:**
1723
+ 1. **Auto-login**: `gufi login` guarda credenciales β†’ funciona para siempre (logout NO las borra)
1724
+ 2. **Auto-detecciΓ³n**: `module`, `automation`, `rows` detectan la company automΓ‘ticamente
1725
+ 3. **Sin prefijos**: `gufi pull/push/watch/logs` (no `view:pull`, etc.)
1726
+
1597
1727
  ### InstalaciΓ³n
1598
1728
 
1599
1729
  ```bash
@@ -1633,14 +1763,14 @@ gufi companies
1633
1763
  # Ver mΓ³dulos de una company
1634
1764
  gufi modules 146
1635
1765
 
1636
- # Ver JSON de un mΓ³dulo
1637
- gufi module 360 -c 146
1766
+ # Ver JSON de un mΓ³dulo (auto-detecta company)
1767
+ gufi module 360
1638
1768
 
1639
1769
  # Editar mΓ³dulo con tu editor
1640
- gufi module 360 -c 146 --edit
1770
+ gufi module 360 --edit
1641
1771
 
1642
1772
  # Guardar JSON a archivo
1643
- gufi module 360 -c 146 --file modulo.json
1773
+ gufi module 360 --file modulo.json
1644
1774
 
1645
1775
  # Actualizar mΓ³dulo desde archivo
1646
1776
  gufi module:update 360 modulo.json -c 146
@@ -1669,6 +1799,14 @@ gufi automation calcular_stock -c 116 --file script.js
1669
1799
 
1670
1800
  # Crear/actualizar automation desde archivo JS
1671
1801
  gufi automation:create calcular_stock script.js -c 116
1802
+
1803
+ # πŸ’œ Debugging - Ver Γ­ndice del worker (auto-synced desde entities.automations)
1804
+ gufi automations:meta -c 116
1805
+
1806
+ # πŸ’œ Ver historial de ejecuciones
1807
+ gufi automations:executions -c 116
1808
+ gufi automations:executions -c 116 --limit 50
1809
+ gufi automations:executions -c 116 --script sync_nayax
1672
1810
  ```
1673
1811
 
1674
1812
  ### Entity Automations (Automations por Entidad)
@@ -1676,29 +1814,29 @@ gufi automation:create calcular_stock script.js -c 116
1676
1814
  Las automations de entidad estΓ‘n vinculadas a una entidad especΓ­fica (tabla) y se almacenan en `core.entities.automations`.
1677
1815
 
1678
1816
  ```bash
1679
- # Ver automations de una entidad
1680
- gufi entity:automations 4589 -c 116
1817
+ # Ver automations de una entidad (auto-detecta company)
1818
+ gufi entity:automations 4589
1681
1819
 
1682
1820
  # Editar automations con tu editor ($EDITOR)
1683
- gufi entity:automations 4589 -c 116 --edit
1821
+ gufi entity:automations 4589 --edit
1684
1822
 
1685
1823
  # Guardar automations a archivo JSON
1686
- gufi entity:automations 4589 -c 116 --file automations.json
1824
+ gufi entity:automations 4589 --file automations.json
1687
1825
 
1688
1826
  # Actualizar automations desde archivo JSON
1689
- gufi entity:automations:update 4589 automations.json -c 116
1827
+ gufi entity:automations:update 4589 automations.json
1690
1828
  ```
1691
1829
 
1692
1830
  **Formato del JSON de automations:**
1693
1831
  ```json
1694
1832
  [
1695
1833
  {
1696
- "trigger": "on_insert",
1834
+ "trigger": "insert",
1697
1835
  "function_name": "notificar_nuevo",
1698
1836
  "enabled": true
1699
1837
  },
1700
1838
  {
1701
- "trigger": "on_click",
1839
+ "trigger": "click",
1702
1840
  "function_name": "generar_factura",
1703
1841
  "label": "Generar Factura",
1704
1842
  "enabled": true
@@ -1715,10 +1853,10 @@ gufi entity:automations:update 4589 automations.json -c 116
1715
1853
  **Triggers disponibles:**
1716
1854
  | Trigger | DescripciΓ³n |
1717
1855
  |---------|-------------|
1718
- | `on_insert` | Al crear registro |
1719
- | `on_update` | Al modificar registro |
1720
- | `on_delete` | Al eliminar registro |
1721
- | `on_click` | BotΓ³n manual en UI |
1856
+ | `insert` | Al crear registro |
1857
+ | `update` | Al modificar registro |
1858
+ | `delete` | Al eliminar registro |
1859
+ | `click` | BotΓ³n manual en UI |
1722
1860
  | `scheduled` | Intervalo programado |
1723
1861
 
1724
1862
  ### Environment Variables
@@ -1746,8 +1884,12 @@ gufi schema -m 360
1746
1884
 
1747
1885
  ### Row CRUD (Datos de Tablas)
1748
1886
 
1887
+ > πŸ’œ **Auto-detecciΓ³n de Company**: El CLI detecta automΓ‘ticamente a quΓ© company pertenece una tabla
1888
+ > analizando el nombre (ej: `m308_t4136` β†’ mΓ³dulo 308 β†’ busca en quΓ© company estΓ‘).
1889
+ > Ya no necesitas usar `-c` en la mayorΓ­a de casos.
1890
+
1749
1891
  ```bash
1750
- # Listar registros de una tabla
1892
+ # Listar registros de una tabla (auto-detecta company)
1751
1893
  gufi rows m360_t16192 # Últimos 20 registros
1752
1894
  gufi rows m360_t16192 -l 50 # Últimos 50 registros
1753
1895
  gufi rows m360_t16192 -f estado=activo # Filtrar por campo
@@ -1772,6 +1914,9 @@ gufi row:duplicate m360_t16192 123
1772
1914
  # Crear mΓΊltiples registros desde archivo JSON
1773
1915
  gufi rows:create m360_t16192 --file datos.json
1774
1916
  # datos.json debe ser un array: [{"nombre":"A"},{"nombre":"B"}]
1917
+
1918
+ # Si necesitas forzar una company especΓ­fica, usa -c
1919
+ gufi rows m360_t16192 -c 146
1775
1920
  ```
1776
1921
 
1777
1922
  ### Desarrollo de Views
@@ -1798,49 +1943,162 @@ gufi view:push
1798
1943
  gufi view:status
1799
1944
  ```
1800
1945
 
1946
+ ### Packages del Marketplace
1947
+
1948
+ ```bash
1949
+ # Ver mis packages
1950
+ gufi packages
1951
+
1952
+ # Ver detalles de un package (mΓ³dulos, views, estado)
1953
+ gufi package 14
1954
+
1955
+ # Crear nuevo package
1956
+ gufi package:create "Mi Package" --description "DescripciΓ³n opcional"
1957
+
1958
+ # AΓ±adir mΓ³dulo de una company al package
1959
+ gufi package:add-module 14 --company 146 --module 360
1960
+ # O interactivo (muestra companies disponibles)
1961
+ gufi package:add-module 14
1962
+
1963
+ # Ver cambios pendientes en mΓ³dulos
1964
+ gufi package:check 14
1965
+
1966
+ # Sincronizar versiΓ³n (actualiza snapshots de mΓ³dulos)
1967
+ gufi package:sync 14
1968
+
1969
+ # Publicar package al Marketplace
1970
+ gufi package:publish 14
1971
+
1972
+ # Despublicar
1973
+ gufi package:unpublish 14
1974
+
1975
+ # Gestionar views del package
1976
+ gufi package:views 14
1977
+ gufi package:add-view 14 <viewId>
1978
+ gufi package:remove-view 14 <packageViewId>
1979
+
1980
+ # Eliminar mΓ³dulo o package
1981
+ gufi package:remove-module 14 <moduleId>
1982
+ gufi package:delete 14
1983
+ ```
1984
+
1801
1985
  ### Opciones Globales
1802
1986
 
1803
1987
  | OpciΓ³n | DescripciΓ³n |
1804
1988
  |--------|-------------|
1805
- | `-c, --company <id>` | ID de company |
1989
+ | `-c, --company <id>` | ID de company (solo para `modules`, `automations`, `*:create`) |
1806
1990
  | `-e, --edit` | Abrir en editor ($EDITOR) |
1807
1991
  | `-f, --file <path>` | Guardar a archivo |
1808
1992
  | `--dry-run` | Validar sin aplicar |
1809
1993
  | `-h, --help` | Ayuda del comando |
1810
1994
 
1995
+ **Auto-detecciΓ³n:** `module`, `module:update`, `automation`, `entity:automations`, `rows` detectan company automΓ‘ticamente del ID.
1996
+
1811
1997
  ---
1812
1998
 
1813
1999
  ## Tips para Claude
1814
2000
 
2001
+ ### πŸ’œ Flujo de Trabajo Recomendado
2002
+
2003
+ ```bash
2004
+ # 1. Primero, oriΓ©ntate
2005
+ gufi companies # Ver companies disponibles
2006
+ gufi modules 146 # Ver mΓ³dulos de una company
2007
+
2008
+ # 2. Para ver/modificar datos (auto-detecta company)
2009
+ gufi rows m308_t4136 # Auto-detecta company del mΓ³dulo 308
2010
+ gufi row m308_t4136 123 # Ver registro especΓ­fico
2011
+ gufi row:update m308_t4136 123 --data '{"status":"done"}'
2012
+
2013
+ # 3. Para editar estructura (mΓ³dulos - auto-detecta company)
2014
+ gufi module 360 --edit # Abre JSON en tu $EDITOR
2015
+
2016
+ # 4. Para editar lΓ³gica (automations - auto-detecta company)
2017
+ gufi automation 15 # Busca por script_id
2018
+ gufi automation 15 --edit # Editar cΓ³digo JS
2019
+ ```
2020
+
1815
2021
  ### CuΓ‘ndo usar cada comando
1816
2022
 
1817
2023
  | El usuario quiere... | Comando |
1818
2024
  |---------------------|---------|
1819
- | Ver quΓ© companies tiene | `gufi companies` |
1820
- | Ver estructura de una company | `gufi modules <company_id>` |
1821
- | Ver/editar JSON de mΓ³dulo | `gufi module <id> -c <company>` |
1822
- | Ver/editar cΓ³digo de automation script | `gufi automation <nombre> -c <company>` |
1823
- | Ver/editar automations de una entidad | `gufi entity:automations <entity_id> -c <company>` |
1824
- | Desarrollar una vista | `gufi view:pull <id>`, `gufi view:watch`, `gufi view:logs` |
2025
+ | Ver companies | `gufi companies` |
2026
+ | Ver mΓ³dulos de company | `gufi modules 146` |
2027
+ | Ver/editar mΓ³dulo | `gufi module 360` |
2028
+ | Ver/editar automation | `gufi automation 15` |
2029
+ | Ver/editar datos | `gufi rows m308_t4136` |
2030
+ | Desarrollar vista | `gufi pull "Mi Vista"` β†’ `gufi watch` β†’ `gufi logs` |
2031
+
2032
+ ### Auto-detecciΓ³n
2033
+
2034
+ Todo automΓ‘tico:
2035
+ - `gufi module 360` β†’ detecta company del mΓ³dulo
2036
+ - `gufi automation 15` β†’ detecta company del script
2037
+ - `gufi rows m308_t4136` β†’ detecta company de la tabla
2038
+
2039
+ ### Automations: 4 tablas que trabajan juntas
2040
+
2041
+ ```
2042
+ automation_scripts (id=15) ← CΓ“DIGO JavaScript
2043
+ β”‚
2044
+ └── entities.automations ← CONFIGURACIΓ“N (quΓ© trigger, cuΓ‘ndo ejecutar)
2045
+ β”‚
2046
+ β–Ό (sync automΓ‘tico)
2047
+ automation_meta ← ÍNDICE para worker
2048
+ β”‚
2049
+ β–Ό
2050
+ automation_executions ← HISTORIAL de ejecuciones
2051
+ ```
2052
+
2053
+ | Tabla | QuΓ© guarda | CLI |
2054
+ |-------|------------|-----|
2055
+ | `automation_scripts` | CΓ³digo JS | `gufi automation 15` |
2056
+ | `entities.automations` | Triggers (on_insert, on_click...) | `gufi entity:automations 4136` |
2057
+ | `automation_meta` | Índice para worker (auto-sync) | `gufi automations:meta` |
2058
+ | `automation_executions` | Historial de ejecuciones | `gufi automations:executions` |
2059
+
2060
+ **Ejemplo:** Un script puede usarse en varias entities:
2061
+ ```
2062
+ script 15 "sync_nayax" β†’ machines (on_click), products (scheduled), sales (on_insert)
2063
+ ```
2064
+
2065
+ **Flujo tΓ­pico:**
2066
+ ```bash
2067
+ gufi automations # Ver scripts
2068
+ gufi automation 15 --edit # Editar cΓ³digo
2069
+ gufi entity:automations 4136 # Ver/editar triggers
2070
+ gufi automations:meta # Ver quΓ© tiene el worker indexado (debugging)
2071
+ gufi automations:executions # Ver historial de ejecuciones
2072
+ ```
1825
2073
 
1826
2074
  ### Errores comunes
1827
2075
 
1828
2076
  | Error | SoluciΓ³n |
1829
2077
  |-------|----------|
1830
2078
  | "No estΓ‘s logueado" | `gufi login` (guarda credenciales para auto-login) |
1831
- | "MΓ³dulo no encontrado" | Verificar `-c <company_id>` |
2079
+ | "MΓ³dulo no encontrado" | Verificar que el ID existe con `gufi modules <company>` |
1832
2080
  | "Token expirado" | AutomΓ‘tico: refresh o auto-login con credenciales guardadas |
1833
2081
  | "JSON invΓ‘lido" | Validar estructura del JSON |
2082
+ | "API Error 404" | Verificar nombre de tabla (formato: `m{moduleId}_t{entityId}`) |
1834
2083
 
1835
2084
  ### Conceptos clave
1836
2085
 
1837
2086
  - **Multi-tenant**: Cada company = schema aislado en PostgreSQL
1838
- - **Tablas fΓ­sicas**: `m{moduleId}_t{entityId}`
2087
+ - **Tablas fΓ­sicas**: `m{moduleId}_t{entityId}` (ej: `m308_t4136`)
1839
2088
  - **MΓ³dulos**: JSON que define estructura β†’ Gufi crea tablas/UI
1840
2089
  - **Automations**: JS en DB, ejecutado por worker (pg-boss)
1841
2090
  - **Views**: React/TS en DB, ejecutado en frontend dinΓ‘micamente
1842
2091
  - **Marketplace**: Sistema de distribuciΓ³n de packages
1843
2092
 
2093
+ ### Companies Importantes
2094
+
2095
+ | ID | Nombre | Uso |
2096
+ |----|--------|-----|
2097
+ | 101 | Demo | Pruebas generales |
2098
+ | 116 | Fitvending | ProducciΓ³n - cliente real |
2099
+ | 146 | Gufi | Desarrollo interno |
2100
+ | 147 | Apuestas Pro | Cliente real |
2101
+
1844
2102
  ---
1845
2103
 
1846
2104
  ## Links
@@ -22,7 +22,7 @@ export declare function automationsCommand(_moduleId?: string, // Ignored - kept
22
22
  options?: {
23
23
  company?: string;
24
24
  }): Promise<void>;
25
- export declare function automationCommand(automationName?: string, options?: {
25
+ export declare function automationCommand(automationId?: string, options?: {
26
26
  edit?: boolean;
27
27
  company?: string;
28
28
  file?: string;
@@ -44,3 +44,14 @@ export declare function entityAutomationsCommand(entityId?: string, options?: {
44
44
  export declare function entityAutomationsUpdateCommand(entityId?: string, jsonFile?: string, options?: {
45
45
  company?: string;
46
46
  }): Promise<void>;
47
+ /**
48
+ * Interactive editor for entity automations
49
+ */
50
+ export declare function automationsMetaCommand(options?: {
51
+ company?: string;
52
+ }): Promise<void>;
53
+ export declare function automationsExecutionsCommand(options?: {
54
+ company?: string;
55
+ limit?: string;
56
+ script?: string;
57
+ }): Promise<void>;