koigrid 0.7.0 → 0.9.0

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +19 -2
  2. package/dist/api.js +78 -6
  3. package/dist/args.js +19 -0
  4. package/dist/commands/analytics.js +1 -1
  5. package/dist/commands/apps.js +369 -27
  6. package/dist/commands/audit.js +1 -1
  7. package/dist/commands/billing.js +87 -0
  8. package/dist/commands/bots.js +1 -1
  9. package/dist/commands/changelog.js +19 -0
  10. package/dist/commands/checks.js +4 -3
  11. package/dist/commands/config.js +9 -6
  12. package/dist/commands/connect.js +2 -2
  13. package/dist/commands/db.js +761 -17
  14. package/dist/commands/dns.js +1 -1
  15. package/dist/commands/errors.js +1 -1
  16. package/dist/commands/events.js +15 -3
  17. package/dist/commands/experiments.js +105 -0
  18. package/dist/commands/flags.js +22 -3
  19. package/dist/commands/heartbeats.js +3 -3
  20. package/dist/commands/images.js +1 -1
  21. package/dist/commands/jobs.js +39 -4
  22. package/dist/commands/links.js +59 -0
  23. package/dist/commands/logs.js +1 -1
  24. package/dist/commands/members.js +26 -1
  25. package/dist/commands/network.js +28 -0
  26. package/dist/commands/notices.js +24 -0
  27. package/dist/commands/notifications.js +2 -2
  28. package/dist/commands/otel.js +1 -1
  29. package/dist/commands/pricing.js +37 -0
  30. package/dist/commands/projects.js +1 -1
  31. package/dist/commands/queues.js +4 -3
  32. package/dist/commands/redis.js +80 -2
  33. package/dist/commands/registry.js +58 -3
  34. package/dist/commands/rewards.js +92 -14
  35. package/dist/commands/sandboxes.js +507 -2
  36. package/dist/commands/speed.js +1 -1
  37. package/dist/commands/spend.js +1 -1
  38. package/dist/commands/status.js +1 -1
  39. package/dist/commands/storage.js +51 -3
  40. package/dist/commands/support.js +47 -0
  41. package/dist/commands/tokens.js +7 -3
  42. package/dist/commands/up.js +6 -2
  43. package/dist/commands/waf.js +1 -1
  44. package/dist/commands/webhooks.js +1 -1
  45. package/dist/commands/wordpress.js +4 -3
  46. package/dist/commands/workflows.js +4 -3
  47. package/dist/esperar.js +41 -0
  48. package/dist/help.js +14 -1
  49. package/dist/index.js +26 -6
  50. package/dist/manifest.js +29 -12
  51. package/dist/output.js +1 -0
  52. package/dist/proyecto.js +6 -0
  53. package/dist/registry-flags.js +17 -0
  54. package/dist/registry.js +8 -2
  55. package/package.json +1 -1
  56. package/dist/commands/ai.js +0 -56
package/CHANGELOG.md CHANGED
@@ -2,10 +2,27 @@
2
2
 
3
3
  All notable changes to the koigrid CLI are documented here. Format: [Keep a Changelog](https://keepachangelog.com). Versions follow [SemVer](https://semver.org).
4
4
 
5
+ ## [Unreleased]
6
+
7
+ ## [0.9.0] — 2026-11-25
8
+
9
+ ### Changed
10
+ - **Default port comes from the image** (ficha 4d8b02da): without `--port`, the app listens on the image's single
11
+ `EXPOSE` port (an nginx `--dir` app goes live on 80), else 3000. A warning is shown if it clashes with one you chose.
12
+ - **A missing image is reported as such** (ficha 51987655): the deploy fails with `image_pull_failed` ("could not pull
13
+ the image") instead of a timeout, and internal timestamps no longer leak into your log.
14
+ - **`koigrid apps deploy` waits for the outcome** (ficha f76082de): shows each state change and ends with the URL, or with
15
+ the error and the last lines of the build/deploy log (exit code 1). `--no-wait` / `--detach` return at once,
16
+ `--timeout <min>` (default 20). With `--json` it still returns at once unless you pass `--wait` (scripts don't change).
17
+
18
+ ### Added
19
+ - **`koigrid apps port <id> <n>`** — change an app's port after creating it (redeploys).
20
+ - **Help per command and subcommand**: `koigrid apps deploy --help` lists its flags (it used to print the global help).
21
+
5
22
  ## [0.7.0] — 2026-07-24
6
23
 
7
24
  ### Added
8
- - **`koigrid apps loadtest <id>`** — reporte de capacidad: martillea la URL de tu app (concurrencia/duración acotadas) → req/s + p50/p95/p99 + señal de saturación + guía de dimensionado. `--duration <s>` `--concurrency <n>` `--path </>`. Ver docs/CAPACITY.md.
25
+ - **`koigrid apps loadtest <id>`** — reporte de capacidad: martillea la URL de tu app (concurrencia/duración acotadas) → req/s + p50/p95/p99 + señal de saturación + guía de dimensionado. `--duration <s>` `--concurrency <n>` `--path </>`. Ver docs/platform/CAPACITY.md.
9
26
 
10
27
  ## [0.6.0] — 2026-07-24
11
28
 
@@ -13,7 +30,7 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
13
30
  - **`koigrid up` / `koigrid plan`** — cutover multi-servicio: lee un `koigrid.yaml` (o `.json`) que declara el
14
31
  STACK entero (project + databases + redis + apps cableados por `${{...}}`) y lo levanta en un comando,
15
32
  idempotente (como `docker-compose up` / `terraform apply`). `plan` = dry-run. `up -f <fichero>` para otro
16
- manifiesto. Ver docs/CUTOVER.md. (dep nueva: `yaml` para parsear el manifiesto).
33
+ manifiesto. Ver docs/runbooks/CUTOVER.md. (dep nueva: `yaml` para parsear el manifiesto).
17
34
 
18
35
  ## [0.5.0] — 2026-07-24
19
36
 
package/dist/api.js CHANGED
@@ -1,25 +1,46 @@
1
1
  // Cliente HTTP de la API de koigrid. Añade el Bearer token + maneja errores JSON de forma uniforme.
2
2
  import { loadConfig, DEFAULT_API } from './config.js';
3
+ import { createRequire } from 'node:module';
4
+ // El CLI se IDENTIFICA con su versión: sin esto la API no puede distinguir un CLI viejo (que descartaba flags en
5
+ // silencio) de una petición a mano, ni avisar a quien siga en una versión con fallos conocidos.
6
+ const VERSION = (() => { try {
7
+ return String(createRequire(import.meta.url)('../package.json').version);
8
+ }
9
+ catch {
10
+ return '0';
11
+ } })();
12
+ export const USER_AGENT = `koigrid-cli/${VERSION}`;
3
13
  export class ApiError extends Error {
4
14
  status;
5
15
  detail;
6
- constructor(status, message, detail) {
16
+ body;
17
+ /** `body`: el JSON de error entero, para los campos que no son `error`/`detail` (p. ej. `checkoutUrl`). */
18
+ constructor(status, message, detail, body) {
7
19
  super(message);
8
20
  this.status = status;
9
21
  this.detail = detail;
22
+ this.body = body;
10
23
  this.name = 'ApiError';
11
24
  }
12
25
  }
26
+ /**
27
+ * `rawBody`: cuerpo en BYTES en vez de JSON (subir un fichero). Va aquí y no en el comando porque lo que hay
28
+ * que no repetir es la resolución del token y de la URL base, no el `fetch`.
29
+ */
13
30
  export async function api(path, opts = {}) {
14
31
  const cfg = loadConfig();
15
32
  const token = opts.token || cfg.token;
16
33
  const base = opts.api || cfg.api || DEFAULT_API;
17
- if (!token)
34
+ // `anon`: endpoints PÚBLICOS a propósito. Exigir credenciales para consultarlos sería una contradicción — el
35
+ // historial de cambios existe para que puedas averiguar si tu problema está arreglado, y quien todavía no ha
36
+ // conseguido autenticarse es justo quien más lo necesita. Si hay token se manda igual (así el consumo se
37
+ // atribuye a quien es); si no lo hay, se pregunta sin él en vez de negarse.
38
+ if (!token && !opts.anon)
18
39
  throw new ApiError(401, 'Not logged in. Run `koigrid login` (or set KOIGRID_TOKEN).');
19
40
  const res = await fetch(`${base}${path}`, {
20
41
  method: opts.method || 'GET',
21
- headers: { Authorization: `Bearer ${token}`, ...(opts.body ? { 'content-type': 'application/json' } : {}) },
22
- body: opts.body ? JSON.stringify(opts.body) : undefined,
42
+ headers: { 'user-agent': USER_AGENT, ...(token ? { Authorization: `Bearer ${token}` } : {}), ...(opts.body ? { 'content-type': 'application/json' } : {}), ...(opts.headers || {}) },
43
+ body: opts.rawBody ? opts.rawBody : opts.body ? JSON.stringify(opts.body) : undefined,
23
44
  signal: AbortSignal.timeout(30_000),
24
45
  }).catch((e) => { throw new ApiError(0, `network error: ${e?.message || e}`); });
25
46
  const text = await res.text();
@@ -32,7 +53,7 @@ export async function api(path, opts = {}) {
32
53
  }
33
54
  catch { }
34
55
  ;
35
- throw new ApiError(res.status, j?.error || `HTTP ${res.status}`, j?.detail);
56
+ throw new ApiError(res.status, j?.error || `HTTP ${res.status}`, j?.detail, j ?? { requestId: res.headers.get('x-request-id') ?? undefined });
36
57
  }
37
58
  return text;
38
59
  }
@@ -42,6 +63,57 @@ export async function api(path, opts = {}) {
42
63
  }
43
64
  catch { /* non-json */ }
44
65
  if (!res.ok)
45
- throw new ApiError(res.status, json?.error || `HTTP ${res.status}`, json?.detail);
66
+ throw new ApiError(res.status, json?.error || `HTTP ${res.status}`, json?.detail, json);
46
67
  return json;
47
68
  }
69
+ /**
70
+ * Una respuesta NDJSON (application/x-ndjson) de la API, evento a evento según llega: la salida en directo de una orden
71
+ * de una VM. Sin el plazo de 30 s de `api` (un enganche dura hasta 10 min por diseño): el servidor manda un latido
72
+ * cada 15 s, así que 60 s sin nada es una conexión muerta. Un error HTTP antes del primer evento se lanza como en `api`.
73
+ */
74
+ export async function apiNdjson(path, opts, alEvento) {
75
+ const cfg = loadConfig();
76
+ if (!cfg.token)
77
+ throw new ApiError(401, 'Not logged in. Run `koigrid login` (or set KOIGRID_TOKEN).');
78
+ const ctrl = new AbortController();
79
+ let vigia = setTimeout(() => ctrl.abort(), 60_000);
80
+ const res = await fetch(`${cfg.api || DEFAULT_API}${path}`, {
81
+ method: opts.method || 'GET',
82
+ headers: { 'user-agent': USER_AGENT, Authorization: `Bearer ${cfg.token}`, accept: 'application/x-ndjson', ...(opts.body ? { 'content-type': 'application/json' } : {}) },
83
+ body: opts.body ? JSON.stringify(opts.body) : undefined,
84
+ signal: ctrl.signal,
85
+ }).catch((e) => { throw new ApiError(0, `network error: ${e?.message || e}`); });
86
+ if (!res.ok || !res.body) {
87
+ clearTimeout(vigia);
88
+ const text = await res.text();
89
+ let j = null;
90
+ try {
91
+ j = JSON.parse(text);
92
+ }
93
+ catch { }
94
+ throw new ApiError(res.status, j?.error || `HTTP ${res.status}`, j?.detail, j);
95
+ }
96
+ const dec = new TextDecoder();
97
+ let resto = '';
98
+ try {
99
+ for await (const trozo of res.body) {
100
+ clearTimeout(vigia);
101
+ vigia = setTimeout(() => ctrl.abort(), 60_000);
102
+ const partes = (resto + dec.decode(trozo, { stream: true })).split('\n');
103
+ resto = partes.pop() ?? '';
104
+ for (const l of partes)
105
+ if (l.trim())
106
+ alEvento(JSON.parse(l));
107
+ }
108
+ if (resto.trim())
109
+ alEvento(JSON.parse(resto));
110
+ }
111
+ catch (e) {
112
+ if (ctrl.signal.aborted)
113
+ throw new ApiError(0, 'the live output stopped arriving (no heartbeat in 60 s)');
114
+ throw e;
115
+ }
116
+ finally {
117
+ clearTimeout(vigia);
118
+ }
119
+ }
package/dist/args.js CHANGED
@@ -49,3 +49,22 @@ export function parseArgs(argv) {
49
49
  const sub = positionals.shift();
50
50
  return { cmd, sub, positionals, flags, ...(passthrough ? { passthrough } : {}) };
51
51
  }
52
+ /**
53
+ * Vigila qué flags LEE de verdad el comando, para decir cuáles se ignoraron.
54
+ *
55
+ * ⛔ POR QUÉ (2026-10-08, cuenta real de un cliente). Con el CLI de npm, `koigrid apps deploy … --env KEY=VAL` creó
56
+ * la app SIN variables y no dijo nada: esa versión no conocía `--env` al crear y el parser acepta cualquier flag. La
57
+ * app arrancó sin `DATABASE_URL` y su API devolvía 500. Un flag que no se usa es una instrucción que se pierde, así
58
+ * que se dice. Se mide por LECTURA, no con una lista por comando: una lista se queda atrás al añadir un flag, y lo
59
+ * que importa es si ESTA ejecución lo usó.
60
+ */
61
+ export function vigilarFlags(flags) {
62
+ const leidos = new Set();
63
+ const proxy = new Proxy(flags, {
64
+ get(t, k) { if (typeof k === 'string')
65
+ leidos.add(k); return Reflect.get(t, k); },
66
+ has(t, k) { if (typeof k === 'string')
67
+ leidos.add(k); return Reflect.has(t, k); },
68
+ });
69
+ return { flags: proxy, sinLeer: () => Object.keys(flags).filter((k) => !leidos.has(k)) };
70
+ }
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid analytics — web analytics privacy-first. Ver docs/ANALYTICS.md.
3
+ // koigrid analytics — web analytics privacy-first. Ver docs/products/ANALYTICS.md.
4
4
  export async function analytics(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'sites';