koigrid 0.9.0 → 0.10.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.
- package/CHANGELOG.md +9 -0
- package/dist/actualizacion.js +49 -0
- package/dist/agente.js +103 -0
- package/dist/api.js +27 -1
- package/dist/commands/apps.js +12 -3
- package/dist/commands/auth.js +10 -1
- package/dist/commands/storage.js +3 -0
- package/dist/config.js +4 -1
- package/dist/index.js +7 -0
- package/dist/manifest.js +3 -1
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.10.0] — 2026-11-26
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **Update notice**: once a day the CLI checks npm and, if a newer version exists, says so on stderr with the command
|
|
11
|
+
to update. Never in CI or with `--json`; turn it off with `KOIGRID_NO_UPDATE_CHECK=1`.
|
|
12
|
+
|
|
7
13
|
## [0.9.0] — 2026-11-25
|
|
8
14
|
|
|
9
15
|
### Changed
|
|
@@ -18,6 +24,9 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
|
|
|
18
24
|
### Added
|
|
19
25
|
- **`koigrid apps port <id> <n>`** — change an app's port after creating it (redeploys).
|
|
20
26
|
- **Help per command and subcommand**: `koigrid apps deploy --help` lists its flags (it used to print the global help).
|
|
27
|
+
- **`koigrid login --email <you>`** — no key to paste: agent registration (auth.md, like `fly` / `vercel login`). The CLI
|
|
28
|
+
shows a link and a 6-digit code, the person approves it in the browser with that account, and the CLI keeps a 24-hour
|
|
29
|
+
token that **renews by itself** for up to 30 days (and once more after a 401). `--name` names the agent in Tokens.
|
|
21
30
|
|
|
22
31
|
## [0.7.0] — 2026-07-24
|
|
23
32
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// ¿Hay una versión más nueva del CLI? (ficha dd72ac6f). Como update-notifier, gh o flyctl: pregunta a npm como mucho una
|
|
2
|
+
// vez al día, guarda la respuesta en ~/.koigrid/update-check.json y avisa por stderr (no ensucia una salida --json). La
|
|
3
|
+
// consulta va al FINAL del comando, con plazo de 1,5 s, y un fallo de red se calla: avisar de una versión nueva nunca puede
|
|
4
|
+
// romper ni frenar el comando que se pidió.
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
8
|
+
const FICHERO = join(homedir(), '.koigrid', 'update-check.json');
|
|
9
|
+
const UN_DIA_MS = 24 * 3600_000;
|
|
10
|
+
const REGISTRO = 'https://registry.npmjs.org/koigrid/latest';
|
|
11
|
+
/** ¿`a` es más nueva que `b`? Sólo x.y.z (una versión con sufijo no se anuncia). PURA. */
|
|
12
|
+
export function esMasNueva(a, b) {
|
|
13
|
+
const pa = a.match(/^(\d+)\.(\d+)\.(\d+)$/);
|
|
14
|
+
const pb = b.match(/^(\d+)\.(\d+)\.(\d+)$/);
|
|
15
|
+
if (!pa || !pb)
|
|
16
|
+
return false;
|
|
17
|
+
for (let i = 1; i <= 3; i++)
|
|
18
|
+
if (Number(pa[i]) !== Number(pb[i]))
|
|
19
|
+
return Number(pa[i]) > Number(pb[i]);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
/** ¿Se comprueba en esta ejecución? No en CI, ni con --json, ni si se pidió no hacerlo. PURA. */
|
|
23
|
+
export function debeComprobar(entorno, json) {
|
|
24
|
+
return !json && !entorno.CI && entorno.KOIGRID_NO_UPDATE_CHECK !== '1' && entorno.NO_UPDATE_NOTIFIER === undefined;
|
|
25
|
+
}
|
|
26
|
+
/** El aviso, si lo hay. PURA. */
|
|
27
|
+
export function avisoDeVersion(actual, ultima) {
|
|
28
|
+
return ultima && esMasNueva(ultima, actual) ? `A new koigrid CLI is available: ${actual} → ${ultima}. Update: npm i -g koigrid@latest` : null;
|
|
29
|
+
}
|
|
30
|
+
/** Lee la última versión conocida y, si la consulta tiene más de un día, pregunta a npm. Nunca lanza. */
|
|
31
|
+
export async function ultimaVersionConocida(ahora = Date.now()) {
|
|
32
|
+
let cache = {};
|
|
33
|
+
try {
|
|
34
|
+
cache = JSON.parse(readFileSync(FICHERO, 'utf8'));
|
|
35
|
+
}
|
|
36
|
+
catch { /* primera vez */ }
|
|
37
|
+
if (cache.comprobado && ahora - cache.comprobado < UN_DIA_MS)
|
|
38
|
+
return cache.ultima ?? null;
|
|
39
|
+
try {
|
|
40
|
+
const r = await fetch(REGISTRO, { signal: AbortSignal.timeout(1500) });
|
|
41
|
+
const ultima = r.ok ? String((await r.json()).version ?? '') || null : null;
|
|
42
|
+
mkdirSync(join(homedir(), '.koigrid'), { recursive: true, mode: 0o700 });
|
|
43
|
+
writeFileSync(FICHERO, JSON.stringify({ comprobado: ahora, ultima }));
|
|
44
|
+
return ultima;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return cache.ultima ?? null;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/agente.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// cli/src/agente.ts — `koigrid login --email`: el registro de agente de auth.md (ficha d6d481e3), como el `vercel login`
|
|
2
|
+
// por código de dispositivo. La CLI pide acceso para ese email, enseña el enlace y el código de 6 cifras, espera a que
|
|
3
|
+
// la persona lo apruebe en el navegador y guarda el token y su aserción; después `renovarSiHaceFalta` renueva el token
|
|
4
|
+
// antes de que caduque. El protocolo, en https://koigrid.com/auth.md.
|
|
5
|
+
import { saveConfig, loadConfig, DEFAULT_API } from './config.js';
|
|
6
|
+
const GRANT_CLAIM = 'urn:workos:agent-auth:grant-type:claim';
|
|
7
|
+
const GRANT_JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer';
|
|
8
|
+
/** Se renueva cuando quedan menos de 10 min de token. */
|
|
9
|
+
const MARGEN_RENOVACION_MS = 10 * 60_000;
|
|
10
|
+
function origenDe(api) {
|
|
11
|
+
return new URL(api).origin;
|
|
12
|
+
}
|
|
13
|
+
async function json(res) {
|
|
14
|
+
const t = await res.text();
|
|
15
|
+
try {
|
|
16
|
+
return t ? JSON.parse(t) : null;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function descubrir(origen) {
|
|
23
|
+
const m = await json(await fetch(`${origen}/.well-known/oauth-authorization-server`, { signal: AbortSignal.timeout(15_000) }));
|
|
24
|
+
if (!m?.token_endpoint || !m?.agent_auth?.identity_endpoint)
|
|
25
|
+
throw new Error('This koigrid server does not offer agent registration (no agent_auth in its OAuth metadata).');
|
|
26
|
+
return { tokenEndpoint: m.token_endpoint, identityEndpoint: m.agent_auth.identity_endpoint, claimEndpoint: m.agent_auth.claim_endpoint };
|
|
27
|
+
}
|
|
28
|
+
async function tokenEndpoint(url, form) {
|
|
29
|
+
const res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams(form).toString(), signal: AbortSignal.timeout(30_000) });
|
|
30
|
+
return { status: res.status, body: await json(res) };
|
|
31
|
+
}
|
|
32
|
+
function guardar(api, b) {
|
|
33
|
+
saveConfig({ token: b.access_token, api, assertion: b.identity_assertion, tokenExpiresAt: new Date(Date.now() + Number(b.expires_in) * 1000).toISOString() });
|
|
34
|
+
}
|
|
35
|
+
const dormir = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
36
|
+
/** La ceremonia entera. `avisar` imprime para la persona (el enlace y el código). Devuelve cuando hay token guardado. */
|
|
37
|
+
export async function loginComoAgente(email, opts) {
|
|
38
|
+
const api = opts.api || loadConfig().api || DEFAULT_API;
|
|
39
|
+
const ep = await descubrir(origenDe(api));
|
|
40
|
+
const alta = await fetch(ep.identityEndpoint, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: { 'content-type': 'application/json' },
|
|
43
|
+
body: JSON.stringify({ type: 'service_auth', login_hint: email, client_name: opts.clientName ?? 'koigrid CLI' }),
|
|
44
|
+
signal: AbortSignal.timeout(30_000),
|
|
45
|
+
});
|
|
46
|
+
const a = await json(alta);
|
|
47
|
+
if (!alta.ok)
|
|
48
|
+
throw new Error(`${a?.error ?? `HTTP ${alta.status}`}: ${a?.error_description ?? ''}`.trim());
|
|
49
|
+
let claim = a.claim;
|
|
50
|
+
const mostrar = () => opts.avisar(`Open ${claim.verification_uri_complete ?? claim.verification_uri}\nsign in as ${email} and enter the code: ${claim.user_code}`);
|
|
51
|
+
mostrar();
|
|
52
|
+
let intervalo = Number(claim.interval) || 5;
|
|
53
|
+
for (;;) {
|
|
54
|
+
await dormir(intervalo * 1000);
|
|
55
|
+
const r = await tokenEndpoint(ep.tokenEndpoint, { grant_type: GRANT_CLAIM, claim_token: a.claim_token });
|
|
56
|
+
if (r.status === 200 && r.body?.access_token)
|
|
57
|
+
return guardar(api, r.body);
|
|
58
|
+
const e = r.body?.error;
|
|
59
|
+
if (e === 'authorization_pending')
|
|
60
|
+
continue;
|
|
61
|
+
if (e === 'slow_down') {
|
|
62
|
+
intervalo += 5;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (e === 'expired_token') {
|
|
66
|
+
const n = await fetch(ep.claimEndpoint, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ claim_token: a.claim_token, email }), signal: AbortSignal.timeout(30_000) });
|
|
67
|
+
const nb = await json(n);
|
|
68
|
+
if (!n.ok)
|
|
69
|
+
throw new Error(`${nb?.error ?? `HTTP ${n.status}`}: the registration ended. Run the login again.`);
|
|
70
|
+
claim = nb.claim;
|
|
71
|
+
opts.avisar('The code expired. New code:');
|
|
72
|
+
mostrar();
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`${e ?? `HTTP ${r.status}`}: ${r.body?.error_description ?? 'the registration ended. Run the login again.'}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** ¿Hay que renovar? Sólo con aserción guardada y quedando menos del margen. PURA. */
|
|
79
|
+
export function tocaRenovar(c, ahora = Date.now()) {
|
|
80
|
+
if (!c.assertion || !c.tokenExpiresAt)
|
|
81
|
+
return false;
|
|
82
|
+
const exp = Date.parse(c.tokenExpiresAt);
|
|
83
|
+
return Number.isFinite(exp) && exp - ahora < MARGEN_RENOVACION_MS;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Renueva el token si va a caducar (o si `forzar`, tras un 401). Devuelve el token vigente. Si la renovación falla con
|
|
87
|
+
* `invalid_grant` (aserción caducada o la persona revocó al agente), lo dice: hay que volver a entrar.
|
|
88
|
+
*/
|
|
89
|
+
export async function renovarSiHaceFalta(forzar = false) {
|
|
90
|
+
const c = loadConfig();
|
|
91
|
+
if (!c.assertion || (!forzar && !tocaRenovar(c)))
|
|
92
|
+
return c.token;
|
|
93
|
+
const api = c.api || DEFAULT_API;
|
|
94
|
+
const ep = await descubrir(origenDe(api));
|
|
95
|
+
const r = await tokenEndpoint(ep.tokenEndpoint, { grant_type: GRANT_JWT_BEARER, assertion: c.assertion });
|
|
96
|
+
if (r.status === 200 && r.body?.access_token) {
|
|
97
|
+
guardar(api, r.body);
|
|
98
|
+
return r.body.access_token;
|
|
99
|
+
}
|
|
100
|
+
if (r.body?.error === 'invalid_grant')
|
|
101
|
+
throw new Error('Your agent access ended (expired, or revoked in Tokens). Run `koigrid login --email <your email>` again.');
|
|
102
|
+
return c.token; // rate_limited u otro fallo pasajero: se sigue con el token actual mientras valga
|
|
103
|
+
}
|
package/dist/api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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 { renovarSiHaceFalta } from './agente.js';
|
|
3
4
|
import { createRequire } from 'node:module';
|
|
4
5
|
// El CLI se IDENTIFICA con su versión: sin esto la API no puede distinguir un CLI viejo (que descartaba flags en
|
|
5
6
|
// silencio) de una petición a mano, ni avisar a quien siga en una versión con fallos conocidos.
|
|
@@ -29,7 +30,8 @@ export class ApiError extends Error {
|
|
|
29
30
|
*/
|
|
30
31
|
export async function api(path, opts = {}) {
|
|
31
32
|
const cfg = loadConfig();
|
|
32
|
-
|
|
33
|
+
// Entraste con `koigrid login --email` (registro de agente): el token se renueva solo antes de caducar.
|
|
34
|
+
const token = opts.token || (cfg.assertion ? await renovarSiHaceFalta() : cfg.token);
|
|
33
35
|
const base = opts.api || cfg.api || DEFAULT_API;
|
|
34
36
|
// `anon`: endpoints PÚBLICOS a propósito. Exigir credenciales para consultarlos sería una contradicción — el
|
|
35
37
|
// historial de cambios existe para que puedas averiguar si tu problema está arreglado, y quien todavía no ha
|
|
@@ -62,10 +64,32 @@ export async function api(path, opts = {}) {
|
|
|
62
64
|
json = text ? JSON.parse(text) : null;
|
|
63
65
|
}
|
|
64
66
|
catch { /* non-json */ }
|
|
67
|
+
// Un 401 con aserción guardada (el token se revocó o caducó antes de tiempo): se renueva UNA vez y se repite.
|
|
68
|
+
if (res.status === 401 && !opts.token && cfg.assertion && !opts.raw && !opts._renovado) {
|
|
69
|
+
const nuevo = await renovarSiHaceFalta(true);
|
|
70
|
+
if (nuevo && nuevo !== token)
|
|
71
|
+
return api(path, { ...opts, _renovado: true });
|
|
72
|
+
}
|
|
65
73
|
if (!res.ok)
|
|
66
74
|
throw new ApiError(res.status, json?.error || `HTTP ${res.status}`, json?.detail, json);
|
|
75
|
+
// ⛔ UN 2xx QUE NO ES JSON NO ES LA API (ficha 550d3360). Con KOIGRID_API=https://koigrid.com (sin /api/v1) la web
|
|
76
|
+
// responde 200 con su HTML; esto devolvía null y el comando reventaba con «Cannot read properties of null (reading
|
|
77
|
+
// 'app')», sin decir que la URL estaba mal. Como gh o el CLI de Stripe: qué URL se usó y cuál es la buena.
|
|
78
|
+
if (text && json === null)
|
|
79
|
+
throw new ApiError(res.status, noEsLaApi(base, path, res.headers.get('content-type')), pistaDeUrl(base));
|
|
67
80
|
return json;
|
|
68
81
|
}
|
|
82
|
+
/** El mensaje de una respuesta 2xx que no es JSON: la URL pedida y lo que llegó en su lugar. */
|
|
83
|
+
export function noEsLaApi(base, path, contentType) {
|
|
84
|
+
return `${base}${path} did not answer like the koigrid API (got ${contentType || 'a non-JSON body'} instead of JSON)`;
|
|
85
|
+
}
|
|
86
|
+
/** La pista para arreglarlo: casi siempre es la base sin /api/v1. */
|
|
87
|
+
export function pistaDeUrl(base) {
|
|
88
|
+
const limpia = base.replace(/\/+$/, '');
|
|
89
|
+
return limpia.endsWith('/api/v1')
|
|
90
|
+
? `Check KOIGRID_API (or "api" in your config): it is ${base}.`
|
|
91
|
+
: `Check KOIGRID_API (or "api" in your config): did you mean ${limpia}/api/v1 ? The default is ${DEFAULT_API}.`;
|
|
92
|
+
}
|
|
69
93
|
/**
|
|
70
94
|
* Una respuesta NDJSON (application/x-ndjson) de la API, evento a evento según llega: la salida en directo de una orden
|
|
71
95
|
* 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
|
|
@@ -73,6 +97,8 @@ export async function api(path, opts = {}) {
|
|
|
73
97
|
*/
|
|
74
98
|
export async function apiNdjson(path, opts, alEvento) {
|
|
75
99
|
const cfg = loadConfig();
|
|
100
|
+
if (cfg.assertion)
|
|
101
|
+
cfg.token = await renovarSiHaceFalta();
|
|
76
102
|
if (!cfg.token)
|
|
77
103
|
throw new ApiError(401, 'Not logged in. Run `koigrid login` (or set KOIGRID_TOKEN).');
|
|
78
104
|
const ctrl = new AbortController();
|
package/dist/commands/apps.js
CHANGED
|
@@ -18,7 +18,9 @@ async function esperarYContar(appId, depId, plazoMin, json) {
|
|
|
18
18
|
leer, dormir: (ms) => new Promise((ok) => setTimeout(ok, ms)), ahora: () => Date.now(), plazoMs: plazoMin * 60_000,
|
|
19
19
|
alCambiar: json ? undefined : (e) => console.log(dim(` · ${e}`)),
|
|
20
20
|
});
|
|
21
|
-
const
|
|
21
|
+
const final = r.final?.status === 'live' ? (await api(`/apps/${encodeURIComponent(appId)}`)).app : null;
|
|
22
|
+
const url = final?.url ?? null;
|
|
23
|
+
const worker = final?.kind === 'worker';
|
|
22
24
|
if (json) {
|
|
23
25
|
console.log(JSON.stringify({ deploymentId: r.final?.id ?? depId ?? null, appId, status: r.final?.status ?? 'unknown', url, error: r.final?.error ?? null, timedOut: r.agotado }, null, 2));
|
|
24
26
|
}
|
|
@@ -26,7 +28,8 @@ async function esperarYContar(appId, depId, plazoMin, json) {
|
|
|
26
28
|
console.log(yellow(`… still ${r.final?.status ?? 'starting'} after ${plazoMin} min — it keeps going. Follow it: koigrid apps deployments ${appId}`));
|
|
27
29
|
}
|
|
28
30
|
else if (r.final?.status === 'live') {
|
|
29
|
-
|
|
31
|
+
// Un worker no tiene URL a propósito (ficha 73b2fa7c): decirlo, no «todavía no».
|
|
32
|
+
console.log(green(worker ? `✓ Running as a background worker (no URL). Logs: koigrid apps logs ${appId}` : `✓ Live: ${url ?? '(no URL yet)'}`));
|
|
30
33
|
}
|
|
31
34
|
else {
|
|
32
35
|
console.log(red(`✗ Deployment ${r.final?.status}${r.final?.error ? `: ${r.final.error}` : ''}`));
|
|
@@ -88,8 +91,14 @@ export async function apps(a) {
|
|
|
88
91
|
const ing = a.flags.ingress === 'runner' ? { ingress: 'runner' } : {};
|
|
89
92
|
if (a.flags.ingress !== undefined && a.flags.ingress !== 'runner' && a.flags.ingress !== 'edge')
|
|
90
93
|
throw new Error("--ingress must be 'edge' (default) or 'runner'");
|
|
94
|
+
// --worker: proceso de fondo SIN puerto (consumidor de cola, bot), como un worker de Heroku o un Background Worker
|
|
95
|
+
// de Render (ficha 73b2fa7c). Sin URL ni dominio; vivo = el proceso se sostiene. --port no aplica.
|
|
96
|
+
if (a.flags.worker && a.flags.port)
|
|
97
|
+
throw new Error('--worker has no port: drop --port (a background worker receives no traffic)');
|
|
98
|
+
if (a.flags.worker)
|
|
99
|
+
ing.kind = 'worker';
|
|
91
100
|
if (!name || (!image && !repo && !dir))
|
|
92
|
-
throw new Error('usage: koigrid apps deploy <name> --dir <path>|--image <img>|--repo <git-url> [--branch B] [--repo-token <t>] [--port N] [--ingress edge|runner] [--build-cmd C] [--install-cmd C] [--start-cmd C] [--root-dir D] [--node-version V] [--dockerfile PATH] [--release-cmd C] [--memory <mb>] [--cpus <n>] [--project <id>] [--env KEY=VALUE ...] [--env-target all|production|preview]');
|
|
101
|
+
throw new Error('usage: koigrid apps deploy <name> --dir <path>|--image <img>|--repo <git-url> [--branch B] [--repo-token <t>] [--port N | --worker] [--ingress edge|runner] [--build-cmd C] [--install-cmd C] [--start-cmd C] [--root-dir D] [--node-version V] [--dockerfile PATH] [--release-cmd C] [--memory <mb>] [--cpus <n>] [--project <id>] [--env KEY=VALUE ...] [--env-target all|production|preview]');
|
|
93
102
|
const port = a.flags.port ? Number(a.flags.port) : 3000;
|
|
94
103
|
// Esperar al desenlace (ficha f76082de): por defecto sí (personas y agentes), --json sólo con --wait, --no-wait nunca.
|
|
95
104
|
const esperar = debeEsperar(a.flags, json);
|
package/dist/commands/auth.js
CHANGED
|
@@ -2,10 +2,19 @@ import { createInterface } from 'node:readline/promises';
|
|
|
2
2
|
import { api } from '../api.js';
|
|
3
3
|
import { saveConfig, clearConfig, loadConfig } from '../config.js';
|
|
4
4
|
import { green, dim } from '../output.js';
|
|
5
|
+
import { loginComoAgente } from '../agente.js';
|
|
5
6
|
export async function login(flags) {
|
|
7
|
+
// `--email <email>`: sin token que pegar. Registro de agente (auth.md): enlace + código de 6 cifras que la persona
|
|
8
|
+
// aprueba en el navegador; el token se renueva solo hasta 30 días. Ideal para un agente que trabaja para alguien.
|
|
9
|
+
if (typeof flags.email === 'string') {
|
|
10
|
+
await loginComoAgente(flags.email, { api: typeof flags.api === 'string' ? flags.api : undefined, clientName: typeof flags.name === 'string' ? flags.name : undefined, avisar: (s) => console.log(s) });
|
|
11
|
+
const me = await api('/me');
|
|
12
|
+
console.log(green(`✓ Logged in as ${me?.user?.email || me?.email || flags.email} (agent access, renews automatically)`));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
6
15
|
let token = typeof flags.token === 'string' ? flags.token : '';
|
|
7
16
|
if (!token) {
|
|
8
|
-
console.log(dim('Create an API key at https://koigrid.com/dashboard/keys and paste it here.'));
|
|
17
|
+
console.log(dim('Create an API key at https://koigrid.com/dashboard/keys and paste it here (or run `koigrid login --email <your email>`).'));
|
|
9
18
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
10
19
|
token = (await rl.question('Token (koi_…): ')).trim();
|
|
11
20
|
rl.close();
|
package/dist/commands/storage.js
CHANGED
|
@@ -110,6 +110,9 @@ export async function storage(a) {
|
|
|
110
110
|
console.log(` ${b.publicUrl}`);
|
|
111
111
|
if (r.warning)
|
|
112
112
|
console.log(`⚠️ ${r.warning}`);
|
|
113
|
+
// Lo servido por el nombre público en 24 h (ficha 2b384027): sólo lo trae el GET de estado.
|
|
114
|
+
if (r.traffic)
|
|
115
|
+
console.log(` últimas ${r.traffic.horas} h: ${r.traffic.requests} peticiones · ${(r.traffic.bytes / 1e6).toFixed(1)} MB · ${r.traffic.errors5xx} 5xx`);
|
|
113
116
|
return;
|
|
114
117
|
}
|
|
115
118
|
// Explorador de objetos: ls por prefijo, url de subida/descarga, borrar
|
package/dist/config.js
CHANGED
|
@@ -12,7 +12,10 @@ export function loadConfig() {
|
|
|
12
12
|
file = JSON.parse(readFileSync(FILE, 'utf8'));
|
|
13
13
|
}
|
|
14
14
|
catch { /* ignore */ }
|
|
15
|
-
|
|
15
|
+
// Con KOIGRID_TOKEN manda el entorno: no se renueva lo que la CLI no guardó.
|
|
16
|
+
if (process.env.KOIGRID_TOKEN)
|
|
17
|
+
return { token: process.env.KOIGRID_TOKEN, api: process.env.KOIGRID_API || file.api || DEFAULT_API };
|
|
18
|
+
return { token: file.token, api: process.env.KOIGRID_API || file.api || DEFAULT_API, assertion: file.assertion, tokenExpiresAt: file.tokenExpiresAt };
|
|
16
19
|
}
|
|
17
20
|
export function saveConfig(c) {
|
|
18
21
|
// El token es un secreto: crea el dir 0700 y ESCRIBE el fichero ya con modo 0600 (mode en writeFileSync) para
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { resolveCommand, CLI_COMMANDS } from './manifest.js';
|
|
|
8
8
|
import { HANDLERS } from './registry.js';
|
|
9
9
|
import { red, yellow } from './output.js';
|
|
10
10
|
import { createRequire } from 'node:module';
|
|
11
|
+
import { avisoDeVersion, debeComprobar, ultimaVersionConocida } from './actualizacion.js';
|
|
11
12
|
const version = (() => { try {
|
|
12
13
|
return createRequire(import.meta.url)('../package.json').version;
|
|
13
14
|
}
|
|
@@ -47,6 +48,12 @@ async function main() {
|
|
|
47
48
|
if (ignorados.length)
|
|
48
49
|
console.error(yellow(`⚠ ignored (this command doesn't use them): ${ignorados.map((f) => (f.length === 1 ? `-${f}` : `--${f}`)).join(' ')}`));
|
|
49
50
|
}
|
|
51
|
+
// ¿Hay versión nueva? Al final y por stderr, como gh o flyctl; nunca frena ni rompe el comando (ficha dd72ac6f).
|
|
52
|
+
if (debeComprobar(process.env, !!a.flags.json)) {
|
|
53
|
+
const aviso = avisoDeVersion(version, await ultimaVersionConocida());
|
|
54
|
+
if (aviso)
|
|
55
|
+
console.error(yellow(aviso));
|
|
56
|
+
}
|
|
50
57
|
}
|
|
51
58
|
main().catch((e) => {
|
|
52
59
|
if (e instanceof ApiError) {
|
package/dist/manifest.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const CLI_COMMANDS = [
|
|
2
|
-
{ name: 'login', summary: 'Authenticate (paste an API key
|
|
2
|
+
{ name: 'login', summary: 'Authenticate: --email <you> (link + 6-digit code you approve in the browser; renews by itself) or paste an API key (--token / KOIGRID_TOKEN)', subs: [], endpoints: [] },
|
|
3
3
|
{ name: 'logout', summary: 'Remove the stored credentials', subs: [], endpoints: [] },
|
|
4
4
|
{ name: 'whoami', summary: 'Show the authenticated account', subs: [], endpoints: ['me'] },
|
|
5
5
|
{ name: 'usage', summary: 'Show usage & cost', subs: [], endpoints: ['usage'] },
|
|
@@ -12,6 +12,8 @@ export const CLI_COMMANDS = [
|
|
|
12
12
|
deploy: `koigrid apps deploy <name> --dir <path> | --image <img> | --repo <git-url>
|
|
13
13
|
Source --dir <path> (your folder, no git/Docker needed) · --image <img> · --repo <git-url> [--branch B] [--repo-token T]
|
|
14
14
|
Runtime --port N (default: the image's single EXPOSE port, else 3000; PORT is injected; change later: apps port <id> <n>) · --health-path /health · --memory <MB> · --cpus <n> · --ingress edge|runner
|
|
15
|
+
Worker --worker: a background process with NO port (queue consumer, bot), like a Heroku worker or a Render
|
|
16
|
+
background worker. No URL or domain; alive = the process keeps running. Do not pass --port.
|
|
15
17
|
Build --build-cmd C · --install-cmd C · --start-cmd C · --root-dir D · --node-version V · --dockerfile PATH · --release-cmd C
|
|
16
18
|
Env --env KEY=VALUE (repeatable; references like 'DATABASE_URL=\${{db.<name>.DATABASE_URL}}') · --env-target all|production|preview
|
|
17
19
|
Waiting waits until live or failed and prints the URL or the error with the end of the log (default)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koigrid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "koigrid CLI — deploy apps, databases, redis, storage and more from your terminal (or your AI agent).",
|
|
5
5
|
"bin": {
|
|
6
6
|
"koigrid": "dist/index.js"
|
|
@@ -36,5 +36,9 @@
|
|
|
36
36
|
"author": "koigrid",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"yaml": "^2.9.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^20.19.43",
|
|
42
|
+
"typescript": "^5.9.3"
|
|
39
43
|
}
|
|
40
44
|
}
|