koigrid 0.4.0 → 0.6.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 +24 -0
- package/dist/api.js +13 -0
- package/dist/args.js +28 -5
- package/dist/commands/ai.js +56 -0
- package/dist/commands/analytics.js +52 -0
- package/dist/commands/anomalies.js +38 -0
- package/dist/commands/apps.js +215 -13
- package/dist/commands/audit.js +45 -0
- package/dist/commands/bots.js +47 -0
- package/dist/commands/checks.js +87 -0
- package/dist/commands/config.js +52 -0
- package/dist/commands/connect.js +86 -0
- package/dist/commands/db.js +240 -0
- package/dist/commands/dns.js +79 -0
- package/dist/commands/email.js +16 -2
- package/dist/commands/errors.js +34 -0
- package/dist/commands/flags.js +85 -0
- package/dist/commands/heartbeats.js +51 -0
- package/dist/commands/images.js +31 -0
- package/dist/commands/logs.js +69 -0
- package/dist/commands/members.js +54 -0
- package/dist/commands/notifications.js +21 -0
- package/dist/commands/otel.js +35 -0
- package/dist/commands/projects.js +38 -0
- package/dist/commands/queues.js +90 -0
- package/dist/commands/redis.js +18 -0
- package/dist/commands/registry.js +31 -0
- package/dist/commands/rewards.js +57 -0
- package/dist/commands/sandboxes.js +46 -0
- package/dist/commands/speed.js +33 -0
- package/dist/commands/spend.js +33 -0
- package/dist/commands/status.js +81 -0
- package/dist/commands/storage.js +53 -0
- package/dist/commands/tokens.js +42 -0
- package/dist/commands/up.js +44 -0
- package/dist/commands/waf.js +57 -0
- package/dist/commands/webhooks.js +54 -0
- package/dist/commands/wordpress.js +153 -0
- package/dist/commands/workflows.js +95 -0
- package/dist/config.js +4 -2
- package/dist/manifest.js +37 -5
- package/dist/registry.js +32 -1
- package/package.json +6 -3
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid sandboxes — compute efímero (docker run --rm una vez). Ver docs/SANDBOXES.md.
|
|
4
|
+
export async function sandboxes(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/sandboxes');
|
|
9
|
+
const l = r.sandboxes || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), image: x.image, status: x.status, exit: x.exitCode ?? '', ms: x.durationMs ?? '' })),
|
|
12
|
+
columns: ['id', 'image', 'status', 'exit', 'ms'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'run') {
|
|
16
|
+
const image = a.positionals[0];
|
|
17
|
+
if (!image)
|
|
18
|
+
throw new Error('usage: koigrid sandboxes run <image> [--cmd "…"] [--timeout N] [--memory MB]');
|
|
19
|
+
const body = { image };
|
|
20
|
+
if (a.flags.cmd)
|
|
21
|
+
body.command = String(a.flags.cmd);
|
|
22
|
+
if (a.flags.timeout)
|
|
23
|
+
body.timeoutSec = Number(a.flags.timeout);
|
|
24
|
+
if (a.flags.memory)
|
|
25
|
+
body.memoryMb = Number(a.flags.memory);
|
|
26
|
+
const r = await api('/sandboxes', { method: 'POST', body });
|
|
27
|
+
if (json)
|
|
28
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
29
|
+
const s = r.sandbox || {};
|
|
30
|
+
console.log(green(`✓ ${s.status} (exit ${s.exitCode ?? '—'}, ${s.durationMs ?? '?'}ms)`));
|
|
31
|
+
if (s.logs)
|
|
32
|
+
console.log(s.logs);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// get <id>
|
|
36
|
+
const id = sub === 'get' ? a.positionals[0] : sub;
|
|
37
|
+
if (!id)
|
|
38
|
+
throw new Error('usage: koigrid sandboxes get <id>');
|
|
39
|
+
const r = await api(`/sandboxes/${encodeURIComponent(id)}`);
|
|
40
|
+
if (json)
|
|
41
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
42
|
+
const s = r.sandbox || {};
|
|
43
|
+
console.log(`${s.image} — ${s.status} (exit ${s.exitCode ?? '—'}, ${s.durationMs ?? '?'}ms)`);
|
|
44
|
+
if (s.logs)
|
|
45
|
+
console.log(s.logs);
|
|
46
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output } from '../output.js';
|
|
3
|
+
// koigrid speed — Speed Insights (Core Web Vitals). Reutiliza el site de Web Analytics. Ver docs/SPEED-INSIGHTS.md.
|
|
4
|
+
export async function speed(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
const days = a.flags.days ? Number(a.flags.days) : 30;
|
|
8
|
+
if (sub === 'ls' || sub === 'list') {
|
|
9
|
+
const r = await api(`/speed-insights?days=${days}`);
|
|
10
|
+
const sites = r.sites || [];
|
|
11
|
+
if (json)
|
|
12
|
+
return console.log(JSON.stringify(sites, null, 2));
|
|
13
|
+
if (!sites.length)
|
|
14
|
+
return console.log('No sites yet. Create one with `koigrid analytics create` and add the /v.js beacon.');
|
|
15
|
+
for (const s of sites) {
|
|
16
|
+
console.log(`\n${s.name}`);
|
|
17
|
+
const rows = (s.metrics || []).map((m) => ({ metric: m.metric, p75: m.p75, rating: m.rating, samples: m.samples }));
|
|
18
|
+
output(rows, false, { rows, columns: ['metric', 'p75', 'rating', 'samples'] });
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// detalle de un site (el id llega como `sub`: `koigrid speed <siteId>`)
|
|
23
|
+
const id = sub === 'ls' || sub === 'list' ? a.positionals[0] : sub;
|
|
24
|
+
if (!id)
|
|
25
|
+
throw new Error('usage: koigrid speed <siteId> [--days 30]');
|
|
26
|
+
const r = await api(`/speed-insights/${encodeURIComponent(id)}?days=${days}`);
|
|
27
|
+
if (json)
|
|
28
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
29
|
+
const v = r.vitals || {};
|
|
30
|
+
console.log(`${v.name} — Core Web Vitals p75 (last ${days}d)`);
|
|
31
|
+
const rows = (v.metrics || []).map((m) => ({ metric: m.metric, p75: m.p75, rating: m.rating, samples: m.samples }));
|
|
32
|
+
output(rows, false, { rows, columns: ['metric', 'p75', 'rating', 'samples'] });
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { green } from '../output.js';
|
|
3
|
+
// koigrid spend — Spend Management (tope de gasto mensual + avisos + parada dura). Ver docs/SPEND.md.
|
|
4
|
+
export async function spend(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'show';
|
|
7
|
+
const usd = (c) => `$${(c / 100).toFixed(2)}`;
|
|
8
|
+
if (sub === 'show' || sub === 'status') {
|
|
9
|
+
const r = await api('/spend');
|
|
10
|
+
if (json)
|
|
11
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
12
|
+
if (!r.limit)
|
|
13
|
+
return console.log(`${usd(r.spendCents)} this month (${r.period}) · no limit set`);
|
|
14
|
+
return console.log(`${usd(r.spendCents)} / ${usd(r.limit.amountCents)} this month (${r.pct}%)${r.blocked ? ' · BLOCKED' : ''}`);
|
|
15
|
+
}
|
|
16
|
+
if (sub === 'set') {
|
|
17
|
+
const dollars = a.positionals[0] ?? a.flags.amount;
|
|
18
|
+
if (dollars == null)
|
|
19
|
+
throw new Error('usage: koigrid spend set <usd-per-month> [--thresholds 80,100] [--hard-stop]');
|
|
20
|
+
const body = { amountCents: Math.round(parseFloat(String(dollars)) * 100) };
|
|
21
|
+
if (a.flags.thresholds)
|
|
22
|
+
body.thresholds = String(a.flags.thresholds).split(',').map((s) => parseInt(s.trim(), 10)).filter((n) => n >= 1 && n <= 100);
|
|
23
|
+
if (a.flags['hard-stop'] || a.flags.hardStop)
|
|
24
|
+
body.hardStop = true;
|
|
25
|
+
const r = await api('/spend', { method: 'PUT', body });
|
|
26
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Spend limit set → ${usd(r.limit.amountCents)}/mo${r.limit.hardStop ? ' (hard stop)' : ''}`));
|
|
27
|
+
}
|
|
28
|
+
if (sub === 'rm' || sub === 'remove') {
|
|
29
|
+
await api('/spend', { method: 'DELETE' });
|
|
30
|
+
return console.log(green('✓ Spend limit removed'));
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`unknown: spend ${sub}`);
|
|
33
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid status — status pages públicas generadas de tus Checks. Ver docs/STATUS-PAGES.md.
|
|
4
|
+
export async function status(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/status-pages');
|
|
9
|
+
const l = r.statusPages || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), slug: x.slug, name: x.name, url: `koigrid.com/status/${x.slug}` })),
|
|
12
|
+
columns: ['id', 'slug', 'name', 'url'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'create') {
|
|
16
|
+
const slug = a.positionals[0];
|
|
17
|
+
const name = a.positionals[1] || slug;
|
|
18
|
+
if (!slug)
|
|
19
|
+
throw new Error('usage: koigrid status create <slug> "<name>" [--desc "…"]');
|
|
20
|
+
const body = { slug, name };
|
|
21
|
+
if (a.flags.desc)
|
|
22
|
+
body.description = String(a.flags.desc);
|
|
23
|
+
const r = await api('/status-pages', { method: 'POST', body });
|
|
24
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Status page → https://koigrid.com/status/${slug}`));
|
|
25
|
+
}
|
|
26
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
27
|
+
const id = a.positionals[0];
|
|
28
|
+
if (!id)
|
|
29
|
+
throw new Error('usage: koigrid status rm <id>');
|
|
30
|
+
await api(`/status-pages/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
31
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
32
|
+
}
|
|
33
|
+
// Incidentes / mantenimientos
|
|
34
|
+
if (sub === 'incidents') {
|
|
35
|
+
const pageId = a.positionals[0];
|
|
36
|
+
if (!pageId)
|
|
37
|
+
throw new Error('usage: koigrid status incidents <pageId>');
|
|
38
|
+
const r = await api(`/status-pages/${encodeURIComponent(pageId)}/incidents`);
|
|
39
|
+
const l = r.incidents || [];
|
|
40
|
+
return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), status: x.status, impact: x.impact, title: x.title })), columns: ['id', 'status', 'impact', 'title'] });
|
|
41
|
+
}
|
|
42
|
+
if (sub === 'incident') {
|
|
43
|
+
const pageId = a.positionals[0], title = a.positionals[1];
|
|
44
|
+
if (!pageId || !title)
|
|
45
|
+
throw new Error('usage: koigrid status incident <pageId> "<title>" [--impact minor|major|critical] [--status investigating|identified|monitoring|resolved] [--body "…"]');
|
|
46
|
+
const body = { title };
|
|
47
|
+
if (a.flags.impact)
|
|
48
|
+
body.impact = String(a.flags.impact);
|
|
49
|
+
if (a.flags.status)
|
|
50
|
+
body.status = String(a.flags.status);
|
|
51
|
+
if (a.flags.body)
|
|
52
|
+
body.body = String(a.flags.body);
|
|
53
|
+
const r = await api(`/status-pages/${encodeURIComponent(pageId)}/incidents`, { method: 'POST', body });
|
|
54
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Incident created (${r.incident?.id})`));
|
|
55
|
+
}
|
|
56
|
+
if (sub === 'resolve' || sub === 'incident-update') {
|
|
57
|
+
const pageId = a.positionals[0], incidentId = a.positionals[1];
|
|
58
|
+
if (!pageId || !incidentId)
|
|
59
|
+
throw new Error('usage: koigrid status resolve <pageId> <incidentId> [--status …] [--body "…"]');
|
|
60
|
+
const body = { status: a.flags.status ? String(a.flags.status) : 'resolved' };
|
|
61
|
+
if (a.flags.body)
|
|
62
|
+
body.body = String(a.flags.body);
|
|
63
|
+
const r = await api(`/status-pages/${encodeURIComponent(pageId)}/incidents/${encodeURIComponent(incidentId)}`, { method: 'PATCH', body });
|
|
64
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Incident → ${r.incident?.status}`));
|
|
65
|
+
}
|
|
66
|
+
if (sub === 'update') {
|
|
67
|
+
const id = a.positionals[0];
|
|
68
|
+
if (!id)
|
|
69
|
+
throw new Error("usage: koigrid status update <id> [--name \"…\"] [--slug s] [--desc \"…\"] [--json '{…}']");
|
|
70
|
+
const body = a.flags.json && a.flags.json !== true ? JSON.parse(String(a.flags.json)) : {};
|
|
71
|
+
if (a.flags.name)
|
|
72
|
+
body.name = String(a.flags.name);
|
|
73
|
+
if (a.flags.slug)
|
|
74
|
+
body.slug = String(a.flags.slug);
|
|
75
|
+
if (a.flags.desc)
|
|
76
|
+
body.description = String(a.flags.desc);
|
|
77
|
+
const r = await api(`/status-pages/${encodeURIComponent(id)}`, { method: 'PATCH', body });
|
|
78
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Status page ${id} updated`));
|
|
79
|
+
}
|
|
80
|
+
throw new Error(`unknown: status ${sub}`);
|
|
81
|
+
}
|
package/dist/commands/storage.js
CHANGED
|
@@ -46,5 +46,58 @@ export async function storage(a) {
|
|
|
46
46
|
console.log(green(`✓ Revoked ${kid}`));
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
+
if (sub === 'versions') {
|
|
50
|
+
const id = a.positionals[0];
|
|
51
|
+
if (!id)
|
|
52
|
+
throw new Error('usage: koigrid storage versions <bucketId> [prefix]');
|
|
53
|
+
const prefix = a.positionals[1] ? `?prefix=${encodeURIComponent(a.positionals[1])}` : '';
|
|
54
|
+
const r = await api(`/buckets/${encodeURIComponent(id)}/versions${prefix}`);
|
|
55
|
+
const l = r.versions || [];
|
|
56
|
+
output(l, json, { rows: l.map((x) => ({ key: x.key, deleted: x.deleted ? 'yes' : '', latest: x.latest ? 'yes' : '', version: String(x.versionId).slice(0, 12) })), columns: ['key', 'deleted', 'latest', 'version'] });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (sub === 'restore') {
|
|
60
|
+
const id = a.positionals[0], key = a.positionals[1];
|
|
61
|
+
if (!id || !key)
|
|
62
|
+
throw new Error('usage: koigrid storage restore <bucketId> <key>');
|
|
63
|
+
const r = await api(`/buckets/${encodeURIComponent(id)}/versions`, { method: 'POST', body: { key } });
|
|
64
|
+
console.log(json ? JSON.stringify(r, null, 2) : (r.restored ? green(`✓ Restored ${key}`) : `— ${key} no estaba borrado (nada que restaurar)`));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// Explorador de objetos: ls por prefijo, url de subida/descarga, borrar
|
|
68
|
+
if (sub === 'objects' || sub === 'ls-objects') {
|
|
69
|
+
const id = a.positionals[0];
|
|
70
|
+
if (!id)
|
|
71
|
+
throw new Error('usage: koigrid storage objects <bucketId> [prefix]');
|
|
72
|
+
const prefix = a.positionals[1] ? `?prefix=${encodeURIComponent(a.positionals[1])}` : '';
|
|
73
|
+
const r = await api(`/buckets/${encodeURIComponent(id)}/objects${prefix}`);
|
|
74
|
+
if (json)
|
|
75
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
76
|
+
for (const f of r.folders || [])
|
|
77
|
+
console.log(` 📁 ${f.name}/`);
|
|
78
|
+
output(r.objects || [], false, { rows: (r.objects || []).map((o) => ({ key: o.name, size: String(o.size), modified: o.lastModified || '' })), columns: ['key', 'size', 'modified'] });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (sub === 'upload-url') {
|
|
82
|
+
const id = a.positionals[0], key = a.positionals[1];
|
|
83
|
+
if (!id || !key)
|
|
84
|
+
throw new Error('usage: koigrid storage upload-url <bucketId> <key>');
|
|
85
|
+
const r = await api(`/buckets/${encodeURIComponent(id)}/objects/upload-url`, { method: 'POST', body: { key } });
|
|
86
|
+
return console.log(json ? JSON.stringify(r, null, 2) : r.url);
|
|
87
|
+
}
|
|
88
|
+
if (sub === 'download-url') {
|
|
89
|
+
const id = a.positionals[0], key = a.positionals[1];
|
|
90
|
+
if (!id || !key)
|
|
91
|
+
throw new Error('usage: koigrid storage download-url <bucketId> <key>');
|
|
92
|
+
const r = await api(`/buckets/${encodeURIComponent(id)}/objects/download-url?key=${encodeURIComponent(key)}`);
|
|
93
|
+
return console.log(json ? JSON.stringify(r, null, 2) : r.url);
|
|
94
|
+
}
|
|
95
|
+
if (sub === 'object-rm') {
|
|
96
|
+
const id = a.positionals[0], key = a.positionals[1];
|
|
97
|
+
if (!id || !key)
|
|
98
|
+
throw new Error('usage: koigrid storage object-rm <bucketId> <key>');
|
|
99
|
+
await api(`/buckets/${encodeURIComponent(id)}/objects?key=${encodeURIComponent(key)}`, { method: 'DELETE' });
|
|
100
|
+
return console.log(green(`✓ Deleted ${key}`));
|
|
101
|
+
}
|
|
49
102
|
throw new Error(`unknown: storage ${sub}`);
|
|
50
103
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid tokens — API tokens por API (AI-first): mintear tokens con scopes acotados + expiración + tope de coste.
|
|
4
|
+
// Anti-escalada: no puedes crear uno con más scopes que el tuyo.
|
|
5
|
+
// koigrid tokens ls
|
|
6
|
+
// koigrid tokens create "ci deploy" --scopes apps:read,apps:deploy --expires 3600 --max-cost 50
|
|
7
|
+
// koigrid tokens rm <id>
|
|
8
|
+
export async function tokens(a) {
|
|
9
|
+
const json = !!a.flags.json, sub = a.sub || 'ls';
|
|
10
|
+
if (sub === 'ls' || sub === 'list') {
|
|
11
|
+
const r = await api('/tokens');
|
|
12
|
+
const l = r.tokens || [];
|
|
13
|
+
return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), name: x.name, prefix: x.prefix, scopes: (x.scopes || []).join(',') || 'full', expires: x.expiresAt || '—' })), columns: ['id', 'name', 'prefix', 'scopes', 'expires'] });
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'create') {
|
|
16
|
+
const name = a.positionals[0];
|
|
17
|
+
if (!name)
|
|
18
|
+
throw new Error('usage: koigrid tokens create <name> [--scopes a:b,c:d] [--expires <seconds>] [--max-cost <cents>] [--project <id>]');
|
|
19
|
+
const body = { name };
|
|
20
|
+
if (a.flags.scopes)
|
|
21
|
+
body.scopes = String(a.flags.scopes).split(',').map((s) => s.trim()).filter(Boolean);
|
|
22
|
+
if (a.flags.expires !== undefined)
|
|
23
|
+
body.expiresInSeconds = Number(a.flags.expires);
|
|
24
|
+
if (a.flags['max-cost'] !== undefined)
|
|
25
|
+
body.maxCostCents = Number(a.flags['max-cost']);
|
|
26
|
+
if (a.flags.project)
|
|
27
|
+
body.projectId = String(a.flags.project);
|
|
28
|
+
const r = await api('/tokens', { method: 'POST', body });
|
|
29
|
+
if (json)
|
|
30
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
31
|
+
console.log(green(`✓ Token "${name}" created — copy it now, it won't be shown again:`));
|
|
32
|
+
return console.log(r.token?.token || '');
|
|
33
|
+
}
|
|
34
|
+
if (sub === 'rm' || sub === 'delete' || sub === 'revoke') {
|
|
35
|
+
const id = a.positionals[0];
|
|
36
|
+
if (!id)
|
|
37
|
+
throw new Error('usage: koigrid tokens rm <id>');
|
|
38
|
+
await api(`/tokens/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
39
|
+
return console.log(green(`✓ Revoked ${id}`));
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`unknown: tokens ${sub}`);
|
|
42
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { parse as parseYaml } from 'yaml';
|
|
3
|
+
import { api } from '../api.js';
|
|
4
|
+
import { output, green, dim } from '../output.js';
|
|
5
|
+
// koigrid up / koigrid plan — cutover multi-servicio. Lee un koigrid.yaml (o .json) que declara el STACK entero
|
|
6
|
+
// (project + databases + redis + apps cableados por ${{...}}) y lo levanta en un comando (idempotente). docs/CUTOVER.md
|
|
7
|
+
// koigrid up (aplica koigrid.yaml/koigrid.json del directorio actual)
|
|
8
|
+
// koigrid up -f stack.yaml
|
|
9
|
+
// koigrid plan (dry-run: qué crearía/actualizaría, sin tocar nada)
|
|
10
|
+
function loadManifest(a) {
|
|
11
|
+
const file = (a.flags.file || a.flags.f);
|
|
12
|
+
const candidates = file ? [file] : ['koigrid.yaml', 'koigrid.yml', 'koigrid.json'];
|
|
13
|
+
const path = candidates.find((p) => existsSync(p));
|
|
14
|
+
if (!path)
|
|
15
|
+
throw new Error('no encontré un manifiesto (koigrid.yaml / koigrid.json) en este directorio. Usa -f <fichero>.');
|
|
16
|
+
const raw = readFileSync(path, 'utf8');
|
|
17
|
+
try {
|
|
18
|
+
return (path.endsWith('.json') ? JSON.parse(raw) : parseYaml(raw));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
throw new Error(`no pude parsear ${path}: ${e.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function render(a, r, verb) {
|
|
25
|
+
if (a.flags.json)
|
|
26
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
27
|
+
console.log(green(`${verb}: proyecto '${r.project}' (${String(r.projectId).slice(0, 8)})`));
|
|
28
|
+
output(r.resources || [], false, {
|
|
29
|
+
rows: (r.resources || []).map((x) => ({
|
|
30
|
+
kind: x.kind, name: x.name, action: x.action, id: x.id ? String(x.id).slice(0, 8) : '—', deploy: x.deploymentId ? String(x.deploymentId).slice(0, 8) : '—',
|
|
31
|
+
})),
|
|
32
|
+
columns: ['kind', 'name', 'action', 'id', 'deploy'],
|
|
33
|
+
});
|
|
34
|
+
for (const w of r.warnings || [])
|
|
35
|
+
console.log(dim(`⚠ ${w}`));
|
|
36
|
+
}
|
|
37
|
+
export async function up(a) {
|
|
38
|
+
const r = await api('/manifest', { method: 'POST', body: loadManifest(a) });
|
|
39
|
+
render(a, r, 'Aplicado');
|
|
40
|
+
}
|
|
41
|
+
export async function plan(a) {
|
|
42
|
+
const r = await api('/manifest/plan', { method: 'POST', body: loadManifest(a) });
|
|
43
|
+
render(a, r, 'Plan (dry-run)');
|
|
44
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid waf — Firewall/WAF (reglas allow/block + evaluate). Ver docs/FIREWALL.md.
|
|
4
|
+
export async function waf(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'rules';
|
|
7
|
+
if (sub === 'rules' || sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/waf/rules');
|
|
9
|
+
const l = r.rules || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), pri: x.priority, action: x.action, match: `${x.matchType}=${x.matchValue}`, on: x.enabled ? 'yes' : '' })),
|
|
12
|
+
columns: ['id', 'pri', 'action', 'match', 'on'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'add') {
|
|
16
|
+
const [action, matchType, matchValue] = a.positionals;
|
|
17
|
+
if (!action || !matchType || !matchValue)
|
|
18
|
+
throw new Error('usage: koigrid waf add <block|allow|rate_limit> <all|ip|ip_cidr|country|path_prefix|method|ua_contains> <value> [--priority N] [rate_limit: --limit N --window S --key ip|ip_path|global]');
|
|
19
|
+
const body = { action, matchType, matchValue };
|
|
20
|
+
if (a.flags.priority)
|
|
21
|
+
body.priority = Number(a.flags.priority);
|
|
22
|
+
if (action === 'rate_limit') {
|
|
23
|
+
if (!a.flags.limit || !a.flags.window)
|
|
24
|
+
throw new Error('rate_limit needs --limit N --window S (e.g. --limit 100 --window 60)');
|
|
25
|
+
body.rateLimit = Number(a.flags.limit);
|
|
26
|
+
body.rateWindowSec = Number(a.flags.window);
|
|
27
|
+
if (a.flags.key)
|
|
28
|
+
body.rateKey = String(a.flags.key);
|
|
29
|
+
}
|
|
30
|
+
const r = await api('/waf/rules', { method: 'POST', body });
|
|
31
|
+
const rl = r.rule?.action === 'rate_limit' ? ` (${r.rule?.rateLimit}/${r.rule?.rateWindowSec}s per ${r.rule?.rateKey})` : '';
|
|
32
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Rule ${r.rule?.action} ${r.rule?.matchType}=${r.rule?.matchValue}${rl} (${String(r.rule?.id).slice(0, 8)})`));
|
|
33
|
+
}
|
|
34
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
35
|
+
const id = a.positionals[0];
|
|
36
|
+
if (!id)
|
|
37
|
+
throw new Error('usage: koigrid waf rm <id>');
|
|
38
|
+
await api(`/waf/rules/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
39
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
40
|
+
}
|
|
41
|
+
if (sub === 'disable' || sub === 'enable') {
|
|
42
|
+
const id = a.positionals[0];
|
|
43
|
+
if (!id)
|
|
44
|
+
throw new Error(`usage: koigrid waf ${sub} <id>`);
|
|
45
|
+
await api(`/waf/rules/${encodeURIComponent(id)}`, { method: 'PATCH', body: { enabled: sub === 'enable' } });
|
|
46
|
+
return console.log(green(`✓ ${id} ${sub}d`));
|
|
47
|
+
}
|
|
48
|
+
if (sub === 'evaluate' || sub === 'test') {
|
|
49
|
+
const body = {};
|
|
50
|
+
for (const k of ['ip', 'country', 'path', 'method', 'ua'])
|
|
51
|
+
if (a.flags[k])
|
|
52
|
+
body[k === 'ua' ? 'userAgent' : k] = String(a.flags[k]);
|
|
53
|
+
const r = await api('/waf/evaluate', { method: 'POST', body });
|
|
54
|
+
return console.log(json ? JSON.stringify(r, null, 2) : `${r.action}${r.ruleId ? ` (rule ${String(r.ruleId).slice(0, 8)})` : ''}`);
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`unknown: waf ${sub}`);
|
|
57
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green, bold } from '../output.js';
|
|
3
|
+
// koigrid webhooks — webhooks salientes (eventos → tu URL, firmados + reintentos). Ver docs/WEBHOOKS.md.
|
|
4
|
+
export async function webhooks(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/webhooks');
|
|
9
|
+
const l = r.webhooks || r || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), url: x.url, events: (x.events || []).join(','), enabled: x.enabled ? 'on' : 'off' })),
|
|
12
|
+
columns: ['id', 'url', 'events', 'enabled'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'create' || sub === 'add') {
|
|
16
|
+
const url = a.flags.url || a.positionals[0];
|
|
17
|
+
const events = (a.flags.events ? String(a.flags.events).split(',') : a.positionals.slice(1)).map((e) => e.trim()).filter(Boolean);
|
|
18
|
+
if (!url || !events.length)
|
|
19
|
+
throw new Error('usage: koigrid webhooks create <url> <event…> (or --url <url> --events "app.*,db.failover")');
|
|
20
|
+
const body = { url, events };
|
|
21
|
+
if (a.flags.description)
|
|
22
|
+
body.description = String(a.flags.description);
|
|
23
|
+
const r = await api('/webhooks', { method: 'POST', body });
|
|
24
|
+
if (json)
|
|
25
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
26
|
+
console.log(green(`✓ Webhook created → ${url}`));
|
|
27
|
+
if (r.webhook?.secret)
|
|
28
|
+
console.log(bold(` signing secret (shown once): ${r.webhook.secret}`));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (sub === 'enable' || sub === 'disable') {
|
|
32
|
+
const id = a.positionals[0];
|
|
33
|
+
if (!id)
|
|
34
|
+
throw new Error(`usage: koigrid webhooks ${sub} <id>`);
|
|
35
|
+
await api(`/webhooks/${encodeURIComponent(id)}`, { method: 'PATCH', body: { enabled: sub === 'enable' } });
|
|
36
|
+
return console.log(green(`✓ ${sub}d ${id}`));
|
|
37
|
+
}
|
|
38
|
+
if (sub === 'deliveries') {
|
|
39
|
+
const id = a.positionals[0];
|
|
40
|
+
if (!id)
|
|
41
|
+
throw new Error('usage: koigrid webhooks deliveries <id>');
|
|
42
|
+
const r = await api(`/webhooks/${encodeURIComponent(id)}/deliveries`);
|
|
43
|
+
const l = r.deliveries || [];
|
|
44
|
+
return output(l, json, { rows: l.map((x) => ({ event: x.eventType, status: x.status, attempts: x.attempts, code: x.statusCode ?? '—', at: x.createdAt })), columns: ['event', 'status', 'attempts', 'code', 'at'] });
|
|
45
|
+
}
|
|
46
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
47
|
+
const id = a.positionals[0];
|
|
48
|
+
if (!id)
|
|
49
|
+
throw new Error('usage: koigrid webhooks rm <id>');
|
|
50
|
+
await api(`/webhooks/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
51
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`unknown: webhooks ${sub}`);
|
|
54
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid wp — Managed WordPress: cuentas (contenedor OLS, WP ilimitados) + 1-click install + WP-CLI por API.
|
|
4
|
+
// Ver docs/WORDPRESS-HOSTING-PLAN.md.
|
|
5
|
+
export async function wordpress(a) {
|
|
6
|
+
const json = !!a.flags.json;
|
|
7
|
+
const sub = a.sub || 'accounts';
|
|
8
|
+
// ---- cuentas ----
|
|
9
|
+
if (sub === 'accounts' || sub === 'ls') {
|
|
10
|
+
const r = await api('/wordpress/accounts');
|
|
11
|
+
const l = r.accounts || [];
|
|
12
|
+
return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), name: x.name, slug: x.slug, plan: x.planTier, status: x.status })), columns: ['id', 'name', 'slug', 'plan', 'status'] });
|
|
13
|
+
}
|
|
14
|
+
if (sub === 'create') {
|
|
15
|
+
const slug = a.positionals[0];
|
|
16
|
+
if (!slug)
|
|
17
|
+
throw new Error('usage: koigrid wp create <slug> --name "My hosting" [--plan pro] [--php 8.2]');
|
|
18
|
+
const body = { slug, name: String(a.flags.name || slug) };
|
|
19
|
+
if (a.flags.plan)
|
|
20
|
+
body.planTier = String(a.flags.plan);
|
|
21
|
+
if (a.flags.php)
|
|
22
|
+
body.phpVersion = String(a.flags.php);
|
|
23
|
+
const r = await api('/wordpress/accounts', { method: 'POST', body });
|
|
24
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Account "${slug}" created (${r.account?.id})`));
|
|
25
|
+
}
|
|
26
|
+
if (sub === 'account') {
|
|
27
|
+
const id = a.positionals[0];
|
|
28
|
+
if (!id)
|
|
29
|
+
throw new Error('usage: koigrid wp account <accountId>');
|
|
30
|
+
const r = await api(`/wordpress/accounts/${encodeURIComponent(id)}`);
|
|
31
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
32
|
+
}
|
|
33
|
+
if (sub === 'rm') {
|
|
34
|
+
const id = a.positionals[0];
|
|
35
|
+
if (!id)
|
|
36
|
+
throw new Error('usage: koigrid wp rm <accountId>');
|
|
37
|
+
const r = await api(`/wordpress/accounts/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
38
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green('✓ Account deleted'));
|
|
39
|
+
}
|
|
40
|
+
// ---- sites ----
|
|
41
|
+
if (sub === 'sites') {
|
|
42
|
+
const accountId = a.positionals[0];
|
|
43
|
+
if (!accountId)
|
|
44
|
+
throw new Error('usage: koigrid wp sites <accountId>');
|
|
45
|
+
const r = await api(`/wordpress/accounts/${encodeURIComponent(accountId)}/sites`);
|
|
46
|
+
const l = r.sites || [];
|
|
47
|
+
return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), slug: x.slug, domain: x.domainDefault, status: x.status })), columns: ['id', 'slug', 'domain', 'status'] });
|
|
48
|
+
}
|
|
49
|
+
if (sub === 'install') {
|
|
50
|
+
const accountId = a.positionals[0];
|
|
51
|
+
const slug = a.positionals[1];
|
|
52
|
+
if (!accountId || !slug)
|
|
53
|
+
throw new Error('usage: koigrid wp install <accountId> <slug> --title "Blog" --admin-user admin --admin-email you@x.com [--domain blog.com] [--wp-version 6.8.1]');
|
|
54
|
+
const body = { slug, title: String(a.flags.title || slug), adminUser: String(a.flags['admin-user'] || 'admin'), adminEmail: String(a.flags['admin-email'] || '') };
|
|
55
|
+
if (a.flags.domain)
|
|
56
|
+
body.domain = String(a.flags.domain);
|
|
57
|
+
if (a.flags.php)
|
|
58
|
+
body.phpVersion = String(a.flags.php);
|
|
59
|
+
if (a.flags['wp-version'])
|
|
60
|
+
body.wpVersion = String(a.flags['wp-version']);
|
|
61
|
+
const r = await api(`/wordpress/accounts/${encodeURIComponent(accountId)}/sites`, { method: 'POST', body });
|
|
62
|
+
if (json)
|
|
63
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
64
|
+
return console.log(green(`✓ WordPress "${slug}" installing → ${r.site?.domainDefault}\n admin: ${r.site?.adminUser} / ${r.site?.adminPassword} (guárdalo, se muestra una vez)`));
|
|
65
|
+
}
|
|
66
|
+
if (sub === 'site') {
|
|
67
|
+
const id = a.positionals[0];
|
|
68
|
+
if (!id)
|
|
69
|
+
throw new Error('usage: koigrid wp site <siteId>');
|
|
70
|
+
const r = await api(`/wordpress/sites/${encodeURIComponent(id)}`);
|
|
71
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
72
|
+
}
|
|
73
|
+
if (sub === 'uninstall') {
|
|
74
|
+
const id = a.positionals[0];
|
|
75
|
+
if (!id)
|
|
76
|
+
throw new Error('usage: koigrid wp uninstall <siteId>');
|
|
77
|
+
const r = await api(`/wordpress/sites/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
78
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green('✓ Site deleted'));
|
|
79
|
+
}
|
|
80
|
+
// ---- WP-CLI por API (saneado server-side) ----
|
|
81
|
+
if (sub === 'cli') {
|
|
82
|
+
const id = a.positionals[0];
|
|
83
|
+
const command = a.positionals.slice(1).join(' ');
|
|
84
|
+
if (!id || !command)
|
|
85
|
+
throw new Error('usage: koigrid wp cli <siteId> <wp-cli command> (p.ej. wp cli <id> plugin install woocommerce --activate)');
|
|
86
|
+
const r = await api(`/wordpress/sites/${encodeURIComponent(id)}/wp-cli`, { method: 'POST', body: { command } });
|
|
87
|
+
if (json)
|
|
88
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
89
|
+
return console.log(r.stdout || (r.ok ? '✓ ok' : `✗ exit ${r.exitCode}`));
|
|
90
|
+
}
|
|
91
|
+
// ---- dominio propio (probar en el subdominio → apuntar DNS → activar) ----
|
|
92
|
+
if (sub === 'domains') {
|
|
93
|
+
const id = a.positionals[0];
|
|
94
|
+
if (!id)
|
|
95
|
+
throw new Error('usage: koigrid wp domains <siteId>');
|
|
96
|
+
const r = await api(`/wordpress/sites/${encodeURIComponent(id)}/domains`);
|
|
97
|
+
const l = r.domains || [];
|
|
98
|
+
return output(l, json, {
|
|
99
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), domain: x.domain, status: x.status, primary: x.isPrimary ? 'yes' : '', dns: `${x.instruction?.type} ${x.instruction?.name} → ${x.instruction?.value}` })),
|
|
100
|
+
columns: ['id', 'domain', 'status', 'primary', 'dns'],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (sub === 'domain-add') {
|
|
104
|
+
const id = a.positionals[0];
|
|
105
|
+
const domain = a.positionals[1];
|
|
106
|
+
if (!id || !domain)
|
|
107
|
+
throw new Error('usage: koigrid wp domain-add <siteId> <domain>');
|
|
108
|
+
const r = await api(`/wordpress/sites/${encodeURIComponent(id)}/domains`, { method: 'POST', body: { domain } });
|
|
109
|
+
if (json)
|
|
110
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
111
|
+
const i = r.domain?.instruction;
|
|
112
|
+
return console.log(green(`✓ ${domain} conectado. Crea este registro en tu DNS:\n ${i?.type} ${i?.name} → ${i?.value}${i?.note ? `\n ⚠️ ${i.note}` : ''}\n Luego: koigrid wp domain-check ${r.domain?.id}`));
|
|
113
|
+
}
|
|
114
|
+
if (sub === 'domain-check') {
|
|
115
|
+
const id = a.positionals[0];
|
|
116
|
+
if (!id)
|
|
117
|
+
throw new Error('usage: koigrid wp domain-check <domainId>');
|
|
118
|
+
const r = await api(`/wordpress/domains/${encodeURIComponent(id)}`, { method: 'POST' });
|
|
119
|
+
return console.log(json ? JSON.stringify(r, null, 2) : `${r.domain?.domain}: ${r.domain?.status}`);
|
|
120
|
+
}
|
|
121
|
+
if (sub === 'domain-activate') {
|
|
122
|
+
const id = a.positionals[0];
|
|
123
|
+
if (!id)
|
|
124
|
+
throw new Error('usage: koigrid wp domain-activate <domainId> (cambia la URL del WordPress a tu dominio)');
|
|
125
|
+
const r = await api(`/wordpress/domains/${encodeURIComponent(id)}`, { method: 'PATCH', body: { primary: true } });
|
|
126
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${r.domain?.domain} activo: tu WordPress ya vive en tu dominio`));
|
|
127
|
+
}
|
|
128
|
+
if (sub === 'domain-rm') {
|
|
129
|
+
const id = a.positionals[0];
|
|
130
|
+
if (!id)
|
|
131
|
+
throw new Error('usage: koigrid wp domain-rm <domainId>');
|
|
132
|
+
const r = await api(`/wordpress/domains/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
133
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green('✓ Dominio desconectado'));
|
|
134
|
+
}
|
|
135
|
+
// ---- backups ----
|
|
136
|
+
if (sub === 'backups') {
|
|
137
|
+
const id = a.positionals[0];
|
|
138
|
+
if (!id)
|
|
139
|
+
throw new Error('usage: koigrid wp backups <siteId>');
|
|
140
|
+
const r = await api(`/wordpress/sites/${encodeURIComponent(id)}/backups`);
|
|
141
|
+
const l = r.backups || [];
|
|
142
|
+
return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), kind: x.kind, status: x.status, size: x.sizeBytes, at: x.createdAt })), columns: ['id', 'kind', 'status', 'size', 'at'] });
|
|
143
|
+
}
|
|
144
|
+
if (sub === 'backup') {
|
|
145
|
+
const id = a.positionals[0];
|
|
146
|
+
if (!id)
|
|
147
|
+
throw new Error('usage: koigrid wp backup <siteId>');
|
|
148
|
+
const r = await api(`/wordpress/sites/${encodeURIComponent(id)}/backups`, { method: 'POST' });
|
|
149
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Backup ${r.backup?.status} (${r.backup?.id})`));
|
|
150
|
+
}
|
|
151
|
+
throw new Error(`unknown subcommand: ${sub}\n koigrid wp accounts|create|account|rm|sites|install|site|uninstall|cli|backups|backup|` +
|
|
152
|
+
`domains|domain-add|domain-check|domain-activate|domain-rm`);
|
|
153
|
+
}
|