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
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid dns — DNS Management (BYO: conecta tu zona + CRUD de records). Ver docs/DNS.md.
3
+ // koigrid dns — DNS Management (BYO: conecta tu zona + CRUD de records). Ver docs/products/DNS.md.
4
4
  export async function dns(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'zones';
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid errors — error tracking (Sentry-lite). Ver docs/ERRORS.md.
3
+ // koigrid errors — error tracking (Sentry-lite). Ver docs/products/ERRORS.md.
4
4
  export async function errors(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'ls';
@@ -1,11 +1,23 @@
1
1
  import { api } from '../api.js';
2
2
  import { output } from '../output.js';
3
+ // Filtros del feed (ficha 3e317f95): --type (repetible), --severity, --entity-type, --entity, --since/--until (ISO con
4
+ // zona), --hours, --limit, --cursor. Imprime el nextCursor para pedir la página siguiente.
3
5
  export async function events(a) {
4
6
  const json = !!a.flags.json, sub = a.sub || 'ls';
5
7
  if (sub === 'ls' || sub === 'list') {
6
- const r = await api('/events');
7
- const list = r.events || r || [];
8
- output(list, json, { rows: list.map((x) => ({ time: String(x.createdAt || '').slice(0, 16), type: x.type, message: (x.message || '').slice(0, 50) })), columns: ['time', 'type', 'message'] });
8
+ const q = new URLSearchParams();
9
+ const tipos = a.flags.type;
10
+ for (const t of Array.isArray(tipos) ? tipos : tipos != null ? [tipos] : [])
11
+ q.append('type', String(t));
12
+ const par = [['severity', 'severity'], ['entity-type', 'entityType'], ['entity', 'entityId'], ['hours', 'sinceHours'], ['since', 'since'], ['until', 'until'], ['limit', 'limit'], ['cursor', 'cursor']];
13
+ for (const [f, k] of par)
14
+ if (a.flags[f] != null && a.flags[f] !== true)
15
+ q.set(k, String(a.flags[f]));
16
+ const r = await api(`/events${q.size ? `?${q}` : ''}`);
17
+ const list = r.events || [];
18
+ output(json ? r : list, json, { rows: list.map((x) => ({ time: String(x.createdAt || '').slice(0, 19), type: x.type, message: (x.message || '').slice(0, 60) })), columns: ['time', 'type', 'message'] });
19
+ if (!json && r.nextCursor)
20
+ console.log(`\nmore: --cursor ${r.nextCursor}`);
9
21
  return;
10
22
  }
11
23
  if (sub === 'metrics') {
@@ -0,0 +1,105 @@
1
+ import { api } from '../api.js';
2
+ import { output, green } from '../output.js';
3
+ // koigrid experiments — experimentos A/B sobre flags multivariantes (ficha cdb42b0e, docs/products/FLAGS.md §Experimentos).
4
+ // Todo se fija ANTES de arrancar: hipótesis, métrica principal, métricas de seguridad y muestra por variante.
5
+ export async function experiments(a) {
6
+ const json = !!a.flags.json;
7
+ const sub = a.sub || 'ls';
8
+ const key = a.positionals[0];
9
+ const exigir = (uso) => { if (!key)
10
+ throw new Error(`usage: koigrid experiments ${uso}`); };
11
+ if (sub === 'ls' || sub === 'list') {
12
+ const r = await api('/experiments');
13
+ const l = r.experiments || [];
14
+ return output(l, json, {
15
+ rows: l.map((x) => ({ key: x.key, flag: x.flagKey, status: x.status, metric: x.primaryMetric, sample: x.minSamplePerVariant, winner: x.winner ?? '' })),
16
+ columns: ['key', 'flag', 'status', 'metric', 'sample', 'winner'],
17
+ });
18
+ }
19
+ if (sub === 'create') {
20
+ exigir('create <key> --flag <flagKey> --hypothesis "…" --metric <primary> [--guardrails a,b] (--sample N | --baseline 0.024 --mde 0.5)');
21
+ const body = { key, flagKey: a.flags.flag, hypothesis: a.flags.hypothesis, primaryMetric: a.flags.metric };
22
+ if (a.flags.guardrails)
23
+ body.guardrailMetrics = String(a.flags.guardrails).split(',').map((s) => s.trim()).filter(Boolean);
24
+ if (a.flags.sample !== undefined)
25
+ body.minSamplePerVariant = Number(a.flags.sample);
26
+ if (a.flags.baseline !== undefined)
27
+ body.baselineRate = Number(a.flags.baseline);
28
+ if (a.flags.mde !== undefined)
29
+ body.minDetectableEffect = Number(a.flags.mde);
30
+ const r = await api('/experiments', { method: 'POST', body });
31
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Experiment "${key}" created (draft) · ${r.experiment?.minSamplePerVariant} units per variant`));
32
+ }
33
+ if (sub === 'show' || sub === 'get') {
34
+ exigir('show <key>');
35
+ const r = await api(`/experiments/${encodeURIComponent(key)}`);
36
+ return console.log(JSON.stringify(r.experiment, null, 2));
37
+ }
38
+ if (sub === 'edit') {
39
+ exigir('edit <key> [--hypothesis "…"] [--guardrails a,b] [--sample N] (only while draft)');
40
+ const body = {};
41
+ if (a.flags.hypothesis)
42
+ body.hypothesis = String(a.flags.hypothesis);
43
+ if (a.flags.guardrails)
44
+ body.guardrailMetrics = String(a.flags.guardrails).split(',').map((s) => s.trim()).filter(Boolean);
45
+ if (a.flags.sample !== undefined)
46
+ body.minSamplePerVariant = Number(a.flags.sample);
47
+ await api(`/experiments/${encodeURIComponent(key)}`, { method: 'PATCH', body });
48
+ return console.log(green(`✓ ${key} updated`));
49
+ }
50
+ if (sub === 'start' || sub === 'stop') {
51
+ exigir(`${sub} <key>`);
52
+ const r = await api(`/experiments/${encodeURIComponent(key)}/${sub}`, { method: 'POST' });
53
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${key}: ${r.experiment?.status}`));
54
+ }
55
+ if (sub === 'decide') {
56
+ exigir('decide <key> --winner <variant|none> --note "why"');
57
+ const w = a.flags.winner === undefined || String(a.flags.winner) === 'none' ? null : String(a.flags.winner);
58
+ const r = await api(`/experiments/${encodeURIComponent(key)}/decide`, { method: 'POST', body: { winner: w, note: a.flags.note } });
59
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${key} decided: ${w ?? 'no difference'}`));
60
+ }
61
+ if (sub === 'expose') {
62
+ exigir('expose <key> <unit>');
63
+ const r = await api(`/experiments/${encodeURIComponent(key)}/exposures`, { method: 'POST', body: { unit: a.positionals[1] } });
64
+ return console.log(json ? JSON.stringify(r, null, 2) : `${a.positionals[1]} → ${r.variant ?? 'not in the test'}${r.recorded ? '' : ' (already recorded)'}`);
65
+ }
66
+ if (sub === 'convert') {
67
+ exigir('convert <key> <unit> <metric>');
68
+ const r = await api(`/experiments/${encodeURIComponent(key)}/conversions`, { method: 'POST', body: { unit: a.positionals[1], metric: a.positionals[2] } });
69
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${a.positionals[2]} ${r.recorded ? 'recorded' : 'already recorded'}`));
70
+ }
71
+ if (sub === 'results') {
72
+ exigir('results <key>');
73
+ const r = await api(`/experiments/${encodeURIComponent(key)}/results`);
74
+ if (json)
75
+ return console.log(JSON.stringify(r, null, 2));
76
+ const m = r.experiment?.primaryMetric;
77
+ const rows = (r.variants || []).map((v) => ({ variant: v.variant, exposed: v.exposed, [m]: v.conversions?.[m] ?? 0, rate: v.exposed ? `${(((v.conversions?.[m] ?? 0) / v.exposed) * 100).toFixed(2)}%` : '—' }));
78
+ console.log(`${key} · ${r.experiment?.status} · target ${r.experiment?.minSamplePerVariant} per variant`);
79
+ output(rows, false, { rows, columns: ['variant', 'exposed', m, 'rate'] });
80
+ const an = r.analysis;
81
+ if (!an)
82
+ return;
83
+ const pc = (x) => `${(x * 100).toFixed(1)}%`;
84
+ const cmp = (an.primary || []).map((c) => ({
85
+ variant: c.variant,
86
+ 'vs control': c.relativeLift == null ? '—' : `${c.relativeLift >= 0 ? '+' : ''}${pc(c.relativeLift)}`,
87
+ interval: c.relativeInterval ? `${pc(c.relativeInterval[0])} … ${pc(c.relativeInterval[1])}` : '—',
88
+ p: c.alwaysValidPValue == null ? '—' : c.alwaysValidPValue.toFixed(3),
89
+ verdict: c.verdict,
90
+ }));
91
+ if (cmp.length) {
92
+ console.log('');
93
+ output(cmp, false, { rows: cmp, columns: ['variant', 'vs control', 'interval', 'p', 'verdict'] });
94
+ }
95
+ if (an.srm?.measured)
96
+ console.log(`\nsample ratio: p=${an.srm.pValue < 0.001 ? an.srm.pValue.toExponential(1) : an.srm.pValue.toFixed(3)}${an.srm.mismatch ? ' ⚠️ MISMATCH' : ' ok'}`);
97
+ return console.log(`\n${an.verdict}: ${an.summary}`);
98
+ }
99
+ if (sub === 'rm' || sub === 'delete') {
100
+ exigir('rm <key> (only while draft)');
101
+ await api(`/experiments/${encodeURIComponent(key)}`, { method: 'DELETE' });
102
+ return console.log(green(`✓ Deleted ${key}`));
103
+ }
104
+ throw new Error(`unknown: experiments ${sub}`);
105
+ }
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid flags — feature flags (activar/desactivar + rollout gradual). Ver docs/FLAGS.md.
3
+ // koigrid flags — feature flags (activar/desactivar + rollout gradual). Ver docs/products/FLAGS.md.
4
4
  export async function flags(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'ls';
@@ -62,6 +62,24 @@ export async function flags(a) {
62
62
  await api(`/flags/${encodeURIComponent(key)}`, { method: 'PATCH', body: { rules: [{ attribute, op, values }] } });
63
63
  return console.log(green(`✓ ${key}: ${attribute} ${op} [${values.join(', ')}]`));
64
64
  }
65
+ if (sub === 'variants') {
66
+ // Flag multivariante para un experimento A/B: koigrid flags variants <key> control=50,home=50 (o --clear)
67
+ const key = a.positionals[0];
68
+ if (!key)
69
+ throw new Error('usage: koigrid flags variants <key> <variant=weight,…> (o --clear)');
70
+ if (a.flags.clear) {
71
+ await api(`/flags/${encodeURIComponent(key)}`, { method: 'PATCH', body: { variants: null } });
72
+ return console.log(green(`✓ ${key}: variants cleared (on/off flag again)`));
73
+ }
74
+ const variants = String(a.positionals[1] || '').split(',').map((p) => p.trim()).filter(Boolean).map((p) => {
75
+ const [k, w] = p.split('=');
76
+ return { key: (k || '').trim(), weight: Number(w) };
77
+ });
78
+ if (variants.length < 2 || variants.some((v) => !v.key || !Number.isFinite(v.weight)))
79
+ throw new Error('usage: koigrid flags variants <key> control=50,home=50');
80
+ await api(`/flags/${encodeURIComponent(key)}`, { method: 'PATCH', body: { variants } });
81
+ return console.log(green(`✓ ${key}: ${variants.map((v) => `${v.key} ${v.weight}`).join(' · ')}`));
82
+ }
65
83
  if (sub === 'eval' || sub === 'evaluate') {
66
84
  const context = a.flags.context ? String(a.flags.context) : '';
67
85
  const attributes = {};
@@ -78,8 +96,9 @@ export async function flags(a) {
78
96
  if (json)
79
97
  return console.log(JSON.stringify(r, null, 2));
80
98
  const f = r.flags || {};
81
- const rows = Object.keys(f).map((k) => ({ key: k, value: f[k] ? 'true' : 'false' }));
82
- return output(rows, false, { rows, columns: ['key', 'value'] });
99
+ const v = r.variants || {};
100
+ const rows = Object.keys(f).map((k) => ({ key: k, value: f[k] ? 'true' : 'false', variant: k in v ? (v[k] ?? '—') : '' }));
101
+ return output(rows, false, { rows, columns: ['key', 'value', 'variant'] });
83
102
  }
84
103
  throw new Error(`unknown: flags ${sub}`);
85
104
  }
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid heartbeats — cron monitoring (dead-man's switch). Ver docs/HEARTBEATS.md.
3
+ // koigrid heartbeats — cron monitoring (dead-man's switch). Ver docs/products/HEARTBEATS.md.
4
4
  export async function heartbeats(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'ls';
@@ -15,7 +15,7 @@ export async function heartbeats(a) {
15
15
  if (sub === 'create') {
16
16
  const name = a.positionals[0];
17
17
  if (!name)
18
- throw new Error('usage: koigrid heartbeats create "<name>" [--period 3600] [--grace 300] [--webhook URL]');
18
+ throw new Error('usage: koigrid heartbeats create "<name>" [--period 3600] [--grace 300] [--webhook URL] (grace ≤ max(86400, period))');
19
19
  const body = { name };
20
20
  if (a.flags.period !== undefined)
21
21
  body.periodSeconds = Number(a.flags.period);
@@ -36,7 +36,7 @@ export async function heartbeats(a) {
36
36
  if (sub === 'update') {
37
37
  const id = a.positionals[0];
38
38
  if (!id)
39
- throw new Error("usage: koigrid heartbeats update <id> [--period N] [--grace N] [--webhook URL] [--json '{…}']");
39
+ throw new Error("usage: koigrid heartbeats update <id> [--period N] [--grace N] [--webhook URL] [--json '{…}'] (grace ≤ max(86400, period))");
40
40
  const body = a.flags.json && a.flags.json !== true ? JSON.parse(String(a.flags.json)) : {};
41
41
  if (a.flags.period !== undefined)
42
42
  body.periodSeconds = Number(a.flags.period);
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { green } from '../output.js';
3
- // koigrid images — optimización de imágenes (allowlist anti-SSRF + token). Ver docs/IMAGES.md.
3
+ // koigrid images — optimización de imágenes (allowlist anti-SSRF + token). Ver docs/products/IMAGES.md.
4
4
  export async function images(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'config';
@@ -1,5 +1,36 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
+ import { credencialRegistryDeFlags, AYUDA_REGISTRY } from '../registry-flags.js';
4
+ import { proyectoDeFlags } from '../proyecto.js';
5
+ /** Opciones de recursos y entorno de un job (create y update). Lo que traen las tareas programadas de ECS. */
6
+ function opcionesComunes(a) {
7
+ const b = {};
8
+ if (a.flags.timezone)
9
+ b.timezone = String(a.flags.timezone);
10
+ if (a.flags.memory !== undefined)
11
+ b.memoryMb = Number(a.flags.memory);
12
+ if (a.flags.cpus !== undefined)
13
+ b.cpus = Number(a.flags.cpus);
14
+ if (a.flags.timeout !== undefined)
15
+ b.timeoutSec = Number(a.flags.timeout);
16
+ if (a.flags['max-retries'] !== undefined)
17
+ b.maxRetries = Number(a.flags['max-retries']);
18
+ Object.assign(b, proyectoDeFlags(a));
19
+ if (a.flags.enabled !== undefined)
20
+ b.enabled = a.flags.enabled === 'true' || a.flags.enabled === true;
21
+ const envs = [].concat(a.flags.env ?? []);
22
+ if (envs.length) {
23
+ const env = {};
24
+ for (const kv of envs) {
25
+ const i = kv.indexOf('=');
26
+ if (i <= 0)
27
+ throw new Error(`--env needs K=V (got "${kv}")`);
28
+ env[kv.slice(0, i)] = kv.slice(i + 1);
29
+ }
30
+ b.env = env;
31
+ }
32
+ return b;
33
+ }
3
34
  export async function jobs(a) {
4
35
  const json = !!a.flags.json, sub = a.sub || 'ls';
5
36
  if (sub === 'ls' || sub === 'list') {
@@ -14,7 +45,7 @@ export async function jobs(a) {
14
45
  const image = a.flags.image;
15
46
  const url = a.flags.url;
16
47
  if (!name || !schedule || (!image && !url))
17
- throw new Error('usage: koigrid jobs create <name> --schedule "<cron>" (--image <img> [--command "..."] | --url <url> [--method POST] [--header "K: V"])');
48
+ throw new Error(`usage: koigrid jobs create <name> --schedule "<cron>" (--image <img> [--command "..."] ${AYUDA_REGISTRY} | --url <url> [--method POST] [--header "K: V"]) [--timezone Europe/Madrid] [--memory MB] [--cpus N] [--timeout s] [--max-retries N] [--env K=V]… [--project <id>] [--enabled false]`);
18
49
  const body = { name, schedule };
19
50
  if (url) {
20
51
  // Job HTTP: pega a una URL según el cron (no un contenedor). --header repetible ("K: V").
@@ -36,7 +67,9 @@ export async function jobs(a) {
36
67
  body.image = image;
37
68
  if (a.flags.command)
38
69
  body.command = a.flags.command;
70
+ Object.assign(body, credencialRegistryDeFlags(a)); // imagen privada (ECR/GHCR/…)
39
71
  }
72
+ Object.assign(body, opcionesComunes(a));
40
73
  const r = await api('/jobs', { method: 'POST', body });
41
74
  if (json)
42
75
  console.log(JSON.stringify(r, null, 2));
@@ -72,7 +105,7 @@ export async function jobs(a) {
72
105
  if (sub === 'update') {
73
106
  const id = a.positionals[0];
74
107
  if (!id)
75
- throw new Error('usage: koigrid jobs update <id> [--schedule ..] [--image ..] [--enabled true|false]');
108
+ throw new Error(`usage: koigrid jobs update <id> [--schedule ..] [--image ..] [--command ..] ${AYUDA_REGISTRY} [--registry-clear] [--timezone ..] [--memory MB] [--cpus N] [--timeout s] [--max-retries N] [--env K=V]… [--enabled true|false]`);
76
109
  const body = {};
77
110
  if (a.flags.schedule)
78
111
  body.schedule = a.flags.schedule;
@@ -80,8 +113,10 @@ export async function jobs(a) {
80
113
  body.image = a.flags.image;
81
114
  if (a.flags.command)
82
115
  body.command = a.flags.command;
83
- if (a.flags.enabled !== undefined)
84
- body.enabled = a.flags.enabled === 'true' || a.flags.enabled === true;
116
+ Object.assign(body, credencialRegistryDeFlags(a), opcionesComunes(a));
117
+ if (a.flags['registry-clear'])
118
+ body.registryClear = true;
119
+ delete body.projectId;
85
120
  const r = await api(`/jobs/${encodeURIComponent(id)}`, { method: 'PATCH', body });
86
121
  console.log(json ? JSON.stringify(r, null, 2) : green('✓ Job updated'));
87
122
  return;
@@ -0,0 +1,59 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { api } from '../api.js';
3
+ import { output, green } from '../output.js';
4
+ export async function links(a) {
5
+ const json = !!a.flags.json, sub = a.sub || 'ls';
6
+ if (sub === 'ls' || sub === 'list') {
7
+ const r = await api('/links');
8
+ const l = r.links || [];
9
+ return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), slug: x.slug, url: String(x.url).slice(0, 60), clicks: String(x.clicks ?? 0) })), columns: ['id', 'slug', 'url', 'clicks'] });
10
+ }
11
+ if (sub === 'create' || sub === 'add') {
12
+ const url = a.positionals[0];
13
+ if (!url)
14
+ throw new Error('usage: koigrid links create <url>');
15
+ const r = await api('/links', { method: 'POST', body: { url } });
16
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${r.link?.shortUrl || ''}`));
17
+ }
18
+ if (sub === 'update' || sub === 'set') {
19
+ const id = a.positionals[0], url = a.positionals[1] || a.flags.url;
20
+ if (!id || !url)
21
+ throw new Error('usage: koigrid links update <id> <new-url>');
22
+ await api(`/links/${encodeURIComponent(id)}`, { method: 'PATCH', body: { url } });
23
+ return console.log(green(`✓ Updated ${id}`));
24
+ }
25
+ if (sub === 'rm' || sub === 'delete') {
26
+ const id = a.positionals[0];
27
+ if (!id)
28
+ throw new Error('usage: koigrid links rm <id>');
29
+ await api(`/links/${encodeURIComponent(id)}`, { method: 'DELETE' });
30
+ return console.log(green(`✓ Deleted ${id}`));
31
+ }
32
+ throw new Error(`unknown: links ${sub}`);
33
+ }
34
+ export async function share(a) {
35
+ const json = !!a.flags.json, sub = a.sub || 'ls';
36
+ if (sub === 'ls' || sub === 'list') {
37
+ const r = await api('/share');
38
+ const l = r.shares || [];
39
+ return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), filename: x.filename, size: String(x.size ?? ''), downloads: String(x.downloads ?? 0) })), columns: ['id', 'filename', 'size', 'downloads'] });
40
+ }
41
+ if (sub === 'upload' || sub === 'up') {
42
+ const ruta = a.positionals[0];
43
+ if (!ruta)
44
+ throw new Error('usage: koigrid share upload <file>');
45
+ // Cuerpo en crudo con `x-filename`: la otra forma que acepta la API (la de multipart la usa el navegador).
46
+ const bytes = readFileSync(ruta);
47
+ const nombre = ruta.split('/').pop() || 'file';
48
+ const r = await api('/share', { method: 'POST', rawBody: new Uint8Array(bytes), headers: { 'x-filename': nombre, 'content-type': 'application/octet-stream' } });
49
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${r.share?.url || ''}`));
50
+ }
51
+ if (sub === 'rm' || sub === 'delete') {
52
+ const id = a.positionals[0];
53
+ if (!id)
54
+ throw new Error('usage: koigrid share rm <id>');
55
+ await api(`/share/${encodeURIComponent(id)}`, { method: 'DELETE' });
56
+ return console.log(green(`✓ Deleted ${id}`));
57
+ }
58
+ throw new Error(`unknown: share ${sub}`);
59
+ }
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid logs — Log Drains (reenvío de logs a un sink) + ingesta/query del buffer. Ver docs/LOG-DRAINS.md.
3
+ // koigrid logs — Log Drains (reenvío de logs a un sink) + ingesta/query del buffer. Ver docs/products/LOG-DRAINS.md.
4
4
  export async function logs(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'tail';
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid members — gestión del equipo (miembros + invitaciones). Ver docs/MEMBERS.md.
3
+ // koigrid members — gestión del equipo (miembros + invitaciones). Ver docs/products/MEMBERS.md.
4
4
  export async function members(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'ls';
@@ -43,6 +43,31 @@ export async function members(a) {
43
43
  await api(`/members/${encodeURIComponent(userId)}`, { method: 'DELETE' });
44
44
  return console.log(green(`✓ Removed ${userId}`));
45
45
  }
46
+ if (sub === '2fa') {
47
+ // COMP-2FA-ORG: exigir 2FA a todo el equipo (con periodo de gracia y aviso por correo a quien no lo tenga).
48
+ const act = a.positionals[0];
49
+ if (!act || act === 'show') {
50
+ const r = await api('/members/two-factor');
51
+ const p = r.policy || r;
52
+ if (json)
53
+ return console.log(JSON.stringify(p, null, 2));
54
+ console.log(`2FA obligatorio: ${p.required ? 'SÍ' : 'no'}${p.required ? ` (gracia ${p.graceDays} días desde ${String(p.requiredAt ?? '—').slice(0, 10)})` : ''}`);
55
+ return console.log(`miembros: ${p.members} · sin 2FA configurado: ${p.withoutTwoFactor}`);
56
+ }
57
+ if (act === 'require' || act === 'off') {
58
+ const body = { required: act === 'require' };
59
+ if (a.flags.grace !== undefined)
60
+ body.graceDays = Number(a.flags.grace);
61
+ const r = await api('/members/two-factor', { method: 'PUT', body });
62
+ if (json)
63
+ return console.log(JSON.stringify(r, null, 2));
64
+ console.log(green(act === 'require' ? `✓ 2FA obligatorio (gracia hasta ${String(r.deadline ?? '').slice(0, 10)})` : '✓ 2FA obligatorio desactivado'));
65
+ if (r.warning)
66
+ console.log(` ⚠️ ${r.warning}`);
67
+ return;
68
+ }
69
+ throw new Error('usage: koigrid members 2fa show | require [--grace <días>] | off');
70
+ }
46
71
  if (sub === 'revoke') {
47
72
  const id = a.positionals[0];
48
73
  if (!id)
@@ -0,0 +1,28 @@
1
+ import { api } from '../api.js';
2
+ import { green } from '../output.js';
3
+ /**
4
+ * Quién puede conectarse a una base o caché (ficha 5120dcde): `<cmd> network <id>` muestra · `--allow ip,cidr,…` la
5
+ * restringe a esas IPs (más la flota de koigrid) · `--only-koigrid` sólo desde koigrid · `--public` la abre a todos.
6
+ */
7
+ export async function network(base, cmd, id, a, json) {
8
+ const ruta = `/${base}/${encodeURIComponent(id)}/network`;
9
+ let body = null;
10
+ if (a.flags.public)
11
+ body = { allowedIps: null };
12
+ else if (a.flags['only-koigrid'])
13
+ body = { allowedIps: [] };
14
+ else if (a.flags.allow)
15
+ body = { allowedIps: String(a.flags.allow).split(',').map((s) => s.trim()).filter(Boolean) };
16
+ const r = body ? await api(ruta, { method: 'PUT', body }) : await api(ruta);
17
+ if (json)
18
+ return console.log(JSON.stringify(r, null, 2));
19
+ const n = r.network ?? {};
20
+ const linea = n.access === 'public' ? 'public: any IP (password + TLS)' : `restricted: ${n.allowedIps?.length ? n.allowedIps.join(', ') : '(none)'} + the koigrid fleet`;
21
+ if (!body)
22
+ return console.log(`${linea}\n change: koigrid ${cmd} network ${id} --allow 1.2.3.4,10.0.0.0/24 | --only-koigrid | --public`);
23
+ console.log(green(`✓ ${linea}`));
24
+ if (n.applied === false)
25
+ console.log(' ⚠️ not applied on every machine yet: retried automatically within 10 minutes');
26
+ for (const w of n.warnings ?? [])
27
+ console.log(` ⚠️ ${w}`);
28
+ }
@@ -0,0 +1,24 @@
1
+ import { api } from '../api.js';
2
+ import { output, green } from '../output.js';
3
+ // koigrid notices — los avisos de la campana del panel (aprobado en la beta, despliegue fallido, pago enviado…) y
4
+ // cuántas conversaciones de soporte tienen respuesta sin leer.
5
+ // koigrid notices [ls] [--lang es]
6
+ // koigrid notices read [<id>...] (sin ids: todos)
7
+ export async function notices(a) {
8
+ const json = !!a.flags.json, sub = a.sub || 'ls';
9
+ if (sub === 'ls' || sub === 'list') {
10
+ const lang = typeof a.flags.lang === 'string' ? `?lang=${encodeURIComponent(String(a.flags.lang))}` : '';
11
+ const r = await api(`/notices${lang}`);
12
+ if (json)
13
+ return console.log(JSON.stringify(r, null, 2));
14
+ console.log(green(`${r.unread} unread notice(s) · ${r.supportUnread} support conversation(s) with an unread reply`));
15
+ const l = r.notices || [];
16
+ return output(l, false, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), new: x.read ? '' : '●', notice: x.title, when: String(x.createdAt).slice(0, 16).replace('T', ' ') })), columns: ['id', 'new', 'notice', 'when'] });
17
+ }
18
+ if (sub === 'read') {
19
+ const ids = a.positionals.filter(Boolean);
20
+ const r = await api('/notices/read', { method: 'POST', body: ids.length ? { ids } : {} });
21
+ return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${r.marked} notice(s) marked as read`));
22
+ }
23
+ throw new Error(`unknown: notices ${sub}`);
24
+ }
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid notifications — preferencias de aviso por email (por categoría: alarms/anomalies/spend).
3
+ // koigrid notifications — preferencias de aviso por email (por categoría: alarms/anomalies/spend/jobs/heartbeats/checks/deploys/maintenance).
4
4
  // koigrid notifications ls
5
5
  // koigrid notifications set spend off (o on)
6
6
  export async function notifications(a) {
@@ -13,7 +13,7 @@ export async function notifications(a) {
13
13
  if (sub === 'set') {
14
14
  const category = a.positionals[0], state = a.positionals[1];
15
15
  if (!category || (state !== 'on' && state !== 'off'))
16
- throw new Error('usage: koigrid notifications set <alarms|anomalies|spend> <on|off>');
16
+ throw new Error('usage: koigrid notifications set <alarms|anomalies|spend|jobs|heartbeats|checks|deploys|maintenance> <on|off>');
17
17
  const r = await api('/notifications/preferences', { method: 'PUT', body: { category, emailEnabled: state === 'on' } });
18
18
  return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${category} email notifications ${state}`));
19
19
  }
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { green } from '../output.js';
3
- // koigrid otel — OpenTelemetry export (endpoint OTLP de métricas). Ver docs/OTEL.md.
3
+ // koigrid otel — OpenTelemetry export (endpoint OTLP de métricas). Ver docs/products/OTEL.md.
4
4
  export async function otel(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'show';
@@ -0,0 +1,37 @@
1
+ import { api } from '../api.js';
2
+ import { output } from '../output.js';
3
+ // koigrid pricing — la tarifa (precio por recurso reservado) y el presupuesto de lo que costaría algo ANTES de
4
+ // crearlo. Sin credenciales: el precio es público (lib/billing/tarifa.ts).
5
+ // koigrid pricing → la tarifa
6
+ // koigrid pricing quote --memory 1024 --cpus 1 [--disk 10] [--copies 2] [--storage 50]
7
+ // koigrid pricing quote --json '{"resources":[…]}'
8
+ export async function pricing(a) {
9
+ const json = !!a.flags.json && a.flags.json === true;
10
+ const sub = a.positionals[0];
11
+ if (sub === 'quote') {
12
+ let body;
13
+ if (typeof a.flags.json === 'string')
14
+ body = JSON.parse(a.flags.json);
15
+ else {
16
+ const n = (k) => (a.flags[k] !== undefined ? Number(a.flags[k]) : undefined);
17
+ body = {
18
+ resources: [{ memoryMb: n('memory') ?? 0, cpus: n('cpus') ?? 0, diskGb: n('disk'), copies: n('copies') }],
19
+ objectStorageGb: n('storage'),
20
+ };
21
+ }
22
+ const r = await api('/pricing/quote', { method: 'POST', body, anon: true });
23
+ if (json)
24
+ return console.log(JSON.stringify(r, null, 2));
25
+ output(r.lines ?? [], false, {
26
+ rows: (r.lines ?? []).map((l) => ({ name: l.name ?? '—', copies: l.desglose?.copias, ram: l.desglose?.ramUsd, vcpu: l.desglose?.vcpuUsd, disk: l.desglose?.discoUsd, monthly: l.mensualUsd })),
27
+ columns: ['name', 'copies', 'ram', 'vcpu', 'disk', 'monthly'],
28
+ });
29
+ return console.log(`\nTotal: $${r.monthlyUsd}/month ($${r.hourlyUsd}/hour)${r.objectStorageUsd ? ` · object storage $${r.objectStorageUsd}` : ''}`);
30
+ }
31
+ const r = await api('/pricing', { anon: true });
32
+ if (json)
33
+ return console.log(JSON.stringify(r, null, 2));
34
+ const p = r.prices ?? {};
35
+ console.log(`RAM $${p.ramGbMonth}/GB·month${p.vcpuMonth ? ` · vCPU $${p.vcpuMonth}/month` : ' (shared vCPU included)'} · disk $${p.diskGbMonth}/GB·month · object storage $${p.objectStorageGbMonth}/GB·month · egress included`);
36
+ console.log(`Billed per hour (${r.hoursPerMonth} h/month), only while a resource exists.`);
37
+ }
@@ -1,6 +1,6 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid projects — agrupación de recursos dentro de la org (ver docs/PROJECTS.md).
3
+ // koigrid projects — agrupación de recursos dentro de la org (ver docs/products/PROJECTS.md).
4
4
  export async function projects(a) {
5
5
  const json = !!a.flags.json;
6
6
  const sub = a.sub || 'ls';
@@ -1,6 +1,7 @@
1
1
  import { api } from '../api.js';
2
2
  import { output, green } from '../output.js';
3
- // koigrid queues — cola durable (sustituto de AWS SQS): send/receive/ack + dead-letter. Ver docs/QUEUES.md.
3
+ import { proyectoDeFlags } from '../proyecto.js';
4
+ // koigrid queues — cola durable (sustituto de AWS SQS): send/receive/ack + dead-letter. Ver docs/products/QUEUES.md.
4
5
  export async function queues(a) {
5
6
  const json = !!a.flags.json;
6
7
  const sub = a.sub || 'ls';
@@ -13,8 +14,8 @@ export async function queues(a) {
13
14
  if (sub === 'create') {
14
15
  const name = a.positionals[0];
15
16
  if (!name)
16
- throw new Error('usage: koigrid queues create <name> [--visibility 30] [--max-receives 5]');
17
- const body = { name };
17
+ throw new Error('usage: koigrid queues create <name> [--visibility 30] [--max-receives 5] [--project <id>]');
18
+ const body = { name, ...proyectoDeFlags(a) };
18
19
  if (a.flags.visibility)
19
20
  body.visibilityTimeoutSec = Number(a.flags.visibility);
20
21
  if (a.flags['max-receives'])