koigrid 0.4.0 → 0.5.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 +16 -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/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 +35 -5
- package/dist/registry.js +31 -1
- package/package.json +2 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid checks — uptime & synthetic monitoring (ver docs/CHECKS.md).
|
|
4
|
+
export async function checks(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/checks');
|
|
9
|
+
const l = r.checks || r || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), name: x.name, status: x.status, target: x.target })),
|
|
12
|
+
columns: ['id', 'name', 'status', 'target'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'create') {
|
|
16
|
+
const name = a.positionals[0];
|
|
17
|
+
const target = a.flags.url || a.flags.target || a.positionals[1];
|
|
18
|
+
if (!name || !target)
|
|
19
|
+
throw new Error('usage: koigrid checks create <name> --url <https://…> [--interval 300] [--contains TEXT] [--max-latency 800]');
|
|
20
|
+
const body = { name, target, type: a.flags.type || 'url' };
|
|
21
|
+
if (a.flags.interval)
|
|
22
|
+
body.intervalSeconds = Number(a.flags.interval);
|
|
23
|
+
if (a.flags.method)
|
|
24
|
+
body.method = a.flags.method;
|
|
25
|
+
if (a.flags.webhook)
|
|
26
|
+
body.webhookUrl = a.flags.webhook;
|
|
27
|
+
const assertions = [];
|
|
28
|
+
if (a.flags.status)
|
|
29
|
+
assertions.push({ type: 'status', value: String(a.flags.status) });
|
|
30
|
+
if (a.flags['max-latency'])
|
|
31
|
+
assertions.push({ type: 'latency', value: Number(a.flags['max-latency']) });
|
|
32
|
+
if (a.flags.contains)
|
|
33
|
+
assertions.push({ type: 'body_contains', value: String(a.flags.contains) });
|
|
34
|
+
if (assertions.length)
|
|
35
|
+
body.assertions = assertions;
|
|
36
|
+
const r = await api('/checks', { method: 'POST', body });
|
|
37
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Check "${name}" created → ${target}`));
|
|
38
|
+
}
|
|
39
|
+
if (sub === 'run') {
|
|
40
|
+
const id = a.positionals[0];
|
|
41
|
+
if (!id)
|
|
42
|
+
throw new Error('usage: koigrid checks run <id>');
|
|
43
|
+
const r = await api(`/checks/${encodeURIComponent(id)}/run`, { method: 'POST' });
|
|
44
|
+
return console.log(json ? JSON.stringify(r, null, 2) : `${r.result?.status === 'up' ? green('✓ UP') : '✗ DOWN'} · HTTP ${r.result?.httpStatus ?? '—'} · ${r.result?.latencyMs ?? '—'}ms`);
|
|
45
|
+
}
|
|
46
|
+
if (sub === 'runs') {
|
|
47
|
+
const id = a.positionals[0];
|
|
48
|
+
if (!id)
|
|
49
|
+
throw new Error('usage: koigrid checks runs <id>');
|
|
50
|
+
const r = await api(`/checks/${encodeURIComponent(id)}/runs`);
|
|
51
|
+
if (json)
|
|
52
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
53
|
+
console.log(`uptime ${r.stats?.uptimePct ?? 0}% · p95 ${r.stats?.p95LatencyMs ?? 0}ms · ${r.stats?.total ?? 0} runs`);
|
|
54
|
+
return output(r.runs || [], false, { rows: (r.runs || []).map((x) => ({ status: x.status, http: x.httpStatus ?? '—', ms: x.latencyMs ?? '—', at: x.startedAt })), columns: ['status', 'http', 'ms', 'at'] });
|
|
55
|
+
}
|
|
56
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
57
|
+
const id = a.positionals[0];
|
|
58
|
+
if (!id)
|
|
59
|
+
throw new Error('usage: koigrid checks rm <id>');
|
|
60
|
+
await api(`/checks/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
61
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
62
|
+
}
|
|
63
|
+
if (sub === 'update') {
|
|
64
|
+
const id = a.positionals[0];
|
|
65
|
+
if (!id)
|
|
66
|
+
throw new Error("usage: koigrid checks update <id> [--url <u>] [--interval N] [--contains TEXT] [--max-latency N] [--json '{…}']");
|
|
67
|
+
const body = a.flags.json && a.flags.json !== true ? JSON.parse(String(a.flags.json)) : {};
|
|
68
|
+
if (a.flags.url || a.flags.target)
|
|
69
|
+
body.target = a.flags.url || a.flags.target;
|
|
70
|
+
if (a.flags.interval)
|
|
71
|
+
body.intervalSeconds = Number(a.flags.interval);
|
|
72
|
+
if (a.flags.webhook)
|
|
73
|
+
body.webhookUrl = String(a.flags.webhook);
|
|
74
|
+
const assertions = [];
|
|
75
|
+
if (a.flags.status)
|
|
76
|
+
assertions.push({ type: 'status', value: String(a.flags.status) });
|
|
77
|
+
if (a.flags['max-latency'])
|
|
78
|
+
assertions.push({ type: 'latency', value: Number(a.flags['max-latency']) });
|
|
79
|
+
if (a.flags.contains)
|
|
80
|
+
assertions.push({ type: 'body_contains', value: String(a.flags.contains) });
|
|
81
|
+
if (assertions.length)
|
|
82
|
+
body.assertions = assertions;
|
|
83
|
+
const r = await api(`/checks/${encodeURIComponent(id)}`, { method: 'PATCH', body });
|
|
84
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Check ${id} updated`));
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`unknown: checks ${sub}`);
|
|
87
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid config — config/secrets compartida del proyecto (cifrada). Ver docs/CONFIG.md.
|
|
4
|
+
export async function config(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/config');
|
|
9
|
+
const l = r.config || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ key: x.key, value: x.masked })),
|
|
12
|
+
columns: ['key', 'value'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'set') {
|
|
16
|
+
const key = a.positionals[0];
|
|
17
|
+
const value = a.positionals[1];
|
|
18
|
+
if (!key || value === undefined)
|
|
19
|
+
throw new Error('usage: koigrid config set <KEY> <value>');
|
|
20
|
+
await api('/config', { method: 'PUT', body: { key, value } });
|
|
21
|
+
return console.log(green(`✓ Set ${key}`));
|
|
22
|
+
}
|
|
23
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
24
|
+
const key = a.positionals[0];
|
|
25
|
+
if (!key)
|
|
26
|
+
throw new Error('usage: koigrid config rm <KEY>');
|
|
27
|
+
await api(`/config/${encodeURIComponent(key)}`, { method: 'DELETE' });
|
|
28
|
+
return console.log(green(`✓ Deleted ${key}`));
|
|
29
|
+
}
|
|
30
|
+
if (sub === 'pull') {
|
|
31
|
+
const r = await api('/config/pull');
|
|
32
|
+
const c = r.config || {};
|
|
33
|
+
if (json)
|
|
34
|
+
return console.log(JSON.stringify(c, null, 2));
|
|
35
|
+
// formato .env: KEY=value (para `koigrid config pull > .env`)
|
|
36
|
+
for (const k of Object.keys(c))
|
|
37
|
+
console.log(`${k}=${c[k]}`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (sub === 'run') {
|
|
41
|
+
// Inyecta la config del proyecto (descifrada) como env vars en un proceso LOCAL, sin escribir a disco.
|
|
42
|
+
// Uso: koigrid config run -- <command> [args…] (como `railway run`)
|
|
43
|
+
if (!a.passthrough || a.passthrough.length === 0)
|
|
44
|
+
throw new Error('usage: koigrid config run -- <command> [args…]');
|
|
45
|
+
const r = await api('/config/pull');
|
|
46
|
+
const env = { ...process.env, ...(r.config || {}) };
|
|
47
|
+
const { spawnSync } = await import('node:child_process');
|
|
48
|
+
const res = spawnSync(a.passthrough[0], a.passthrough.slice(1), { stdio: 'inherit', env });
|
|
49
|
+
return process.exit(res.status ?? 0);
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`unknown: config ${sub}`);
|
|
52
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid connect — Connect: broker de credenciales de agente (STS/AssumeRole para agentes).
|
|
4
|
+
// Un GRANT solo puede intercambiarse por tokens EFÍMEROS acotados; en el env va el grant, no un token largo.
|
|
5
|
+
// koigrid connect grants (alias: connect ls)
|
|
6
|
+
// koigrid connect create "ci deploys" --scopes apps:read,apps:deploy --max-ttl 900 [--max-cost 50] [--project <id>]
|
|
7
|
+
// koigrid connect update <id> --disabled (pausa el minteo; --enabled lo reanuda)
|
|
8
|
+
// koigrid connect rm <id> (revoca el grant → corta el minteo)
|
|
9
|
+
// koigrid connect token --grant koicg_xxx --scopes apps:deploy [--ttl 300] [--purpose "deploy #42"]
|
|
10
|
+
export async function connect(a) {
|
|
11
|
+
const json = !!a.flags.json;
|
|
12
|
+
let sub = a.sub || 'ls';
|
|
13
|
+
if (sub === 'grants')
|
|
14
|
+
sub = 'ls';
|
|
15
|
+
if (sub === 'ls' || sub === 'list') {
|
|
16
|
+
const r = await api('/connect/grants');
|
|
17
|
+
const l = r.grants || [];
|
|
18
|
+
return output(l, json, {
|
|
19
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), name: x.name, prefix: x.prefix, scopes: (x.allowedScopes || []).join(',') || '—', maxTtl: x.maxTtlSeconds, enabled: x.enabled ? 'yes' : 'no', mints: x.mintCount })),
|
|
20
|
+
columns: ['id', 'name', 'prefix', 'scopes', 'maxTtl', 'enabled', 'mints'],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (sub === 'create') {
|
|
24
|
+
const name = a.positionals[0];
|
|
25
|
+
const scopes = a.flags.scopes ? String(a.flags.scopes).split(',').map((s) => s.trim()).filter(Boolean) : [];
|
|
26
|
+
if (!name || !scopes.length)
|
|
27
|
+
throw new Error('usage: koigrid connect create <name> --scopes a:b,c:d [--max-ttl <seconds>] [--max-cost <cents>] [--project <id>]');
|
|
28
|
+
const body = { name, allowedScopes: scopes };
|
|
29
|
+
if (a.flags['max-ttl'] !== undefined)
|
|
30
|
+
body.maxTtlSeconds = Number(a.flags['max-ttl']);
|
|
31
|
+
if (a.flags['max-cost'] !== undefined)
|
|
32
|
+
body.maxCostCents = Number(a.flags['max-cost']);
|
|
33
|
+
if (a.flags.project)
|
|
34
|
+
body.projectId = String(a.flags.project);
|
|
35
|
+
const r = await api('/connect/grants', { method: 'POST', body });
|
|
36
|
+
if (json)
|
|
37
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
38
|
+
console.log(green(`✓ Grant "${name}" created — copy the secret now, it won't be shown again:`));
|
|
39
|
+
return console.log(r.grant?.secret || '');
|
|
40
|
+
}
|
|
41
|
+
if (sub === 'update') {
|
|
42
|
+
const id = a.positionals[0];
|
|
43
|
+
if (!id)
|
|
44
|
+
throw new Error('usage: koigrid connect update <id> [--enabled|--disabled] [--name X] [--scopes a:b] [--max-ttl N] [--json <body>]');
|
|
45
|
+
let body = {};
|
|
46
|
+
if (a.flags.json && typeof a.flags.json === 'string')
|
|
47
|
+
body = JSON.parse(String(a.flags.json));
|
|
48
|
+
if (a.flags.enabled)
|
|
49
|
+
body.enabled = true;
|
|
50
|
+
if (a.flags.disabled)
|
|
51
|
+
body.enabled = false;
|
|
52
|
+
if (a.flags.name)
|
|
53
|
+
body.name = String(a.flags.name);
|
|
54
|
+
if (a.flags.scopes)
|
|
55
|
+
body.allowedScopes = String(a.flags.scopes).split(',').map((s) => s.trim()).filter(Boolean);
|
|
56
|
+
if (a.flags['max-ttl'] !== undefined)
|
|
57
|
+
body.maxTtlSeconds = Number(a.flags['max-ttl']);
|
|
58
|
+
const r = await api(`/connect/grants/${encodeURIComponent(id)}`, { method: 'PATCH', body });
|
|
59
|
+
return output(r.grant, json, { rows: [{ id: String(r.grant?.id).slice(0, 8), enabled: r.grant?.enabled ? 'yes' : 'no' }], columns: ['id', 'enabled'] });
|
|
60
|
+
}
|
|
61
|
+
if (sub === 'rm' || sub === 'delete' || sub === 'revoke') {
|
|
62
|
+
const id = a.positionals[0];
|
|
63
|
+
if (!id)
|
|
64
|
+
throw new Error('usage: koigrid connect rm <id>');
|
|
65
|
+
await api(`/connect/grants/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
66
|
+
return console.log(green(`✓ Revoked grant ${id}`));
|
|
67
|
+
}
|
|
68
|
+
if (sub === 'token' || sub === 'exchange') {
|
|
69
|
+
const grant = a.flags.grant ? String(a.flags.grant) : process.env.KOIGRID_GRANT;
|
|
70
|
+
const scopes = a.flags.scopes ? String(a.flags.scopes).split(',').map((s) => s.trim()).filter(Boolean) : [];
|
|
71
|
+
if (!grant || !scopes.length)
|
|
72
|
+
throw new Error('usage: koigrid connect token --grant koicg_… --scopes a:b [--ttl <seconds>] [--purpose "..."]');
|
|
73
|
+
const body = { scopes };
|
|
74
|
+
if (a.flags.ttl !== undefined)
|
|
75
|
+
body.ttlSeconds = Number(a.flags.ttl);
|
|
76
|
+
if (a.flags.purpose)
|
|
77
|
+
body.purpose = String(a.flags.purpose);
|
|
78
|
+
// Auth con el SECRETO DEL GRANT, no con el token global del CLI.
|
|
79
|
+
const r = await api('/connect/token', { method: 'POST', body, token: grant });
|
|
80
|
+
if (json)
|
|
81
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
82
|
+
console.log(green(`✓ Minted ephemeral token (expires ${r.expiresAt}, scopes ${(r.scopes || []).join(',')}):`));
|
|
83
|
+
return console.log(r.token || '');
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`unknown: connect ${sub}`);
|
|
86
|
+
}
|
package/dist/commands/db.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { api } from '../api.js';
|
|
2
2
|
import { output, green } from '../output.js';
|
|
3
|
+
const fmtCell = (v) => (v === null || v === undefined ? '' : typeof v === 'object' ? JSON.stringify(v) : String(v));
|
|
3
4
|
export async function db(a) {
|
|
4
5
|
const json = !!a.flags.json, sub = a.sub || 'ls', id = a.positionals[0];
|
|
5
6
|
const need = () => { if (!id)
|
|
@@ -37,9 +38,22 @@ export async function db(a) {
|
|
|
37
38
|
console.log('# read-only:', r.connection.readUri);
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
41
|
+
case 'connect': {
|
|
42
|
+
need();
|
|
43
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/connection`);
|
|
44
|
+
const uri = r.connection?.uri;
|
|
45
|
+
if (!uri)
|
|
46
|
+
throw new Error('no connection string yet (is the cluster running?)');
|
|
47
|
+
const { spawnSync } = await import('node:child_process');
|
|
48
|
+
const res = spawnSync('psql', [uri], { stdio: 'inherit' });
|
|
49
|
+
return process.exit(res.status ?? 0);
|
|
50
|
+
}
|
|
40
51
|
case 'metrics':
|
|
41
52
|
need();
|
|
42
53
|
return console.log(JSON.stringify(await api(`/databases/${encodeURIComponent(id)}/metrics`), null, 2));
|
|
54
|
+
case 'logs':
|
|
55
|
+
need();
|
|
56
|
+
return console.log((await api(`/databases/${encodeURIComponent(id)}/logs?tail=${a.flags.tail || 200}`)).logs || '');
|
|
43
57
|
case 'backups': {
|
|
44
58
|
need();
|
|
45
59
|
if (a.positionals[1] === 'create') {
|
|
@@ -111,6 +125,232 @@ export async function db(a) {
|
|
|
111
125
|
}
|
|
112
126
|
throw new Error('usage: koigrid db pub <id> ls | add <name> [--all-tables|--tables t1,t2] | rm <name>');
|
|
113
127
|
}
|
|
128
|
+
case 'branch':
|
|
129
|
+
case 'branches': {
|
|
130
|
+
need();
|
|
131
|
+
const act = a.positionals[1];
|
|
132
|
+
const bid = a.positionals[2];
|
|
133
|
+
if (!act || act === 'ls') {
|
|
134
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/branches`);
|
|
135
|
+
const rows = [{ id: String(r.production?.id).slice(0, 8), name: r.production?.branchName || 'production', type: 'production', status: r.production?.status }];
|
|
136
|
+
for (const b of r.branches || [])
|
|
137
|
+
rows.push({ id: String(b.id).slice(0, 8), name: b.branchName, type: b.branchType, status: b.status });
|
|
138
|
+
return output(rows, json, { rows, columns: ['id', 'name', 'type', 'status'] });
|
|
139
|
+
}
|
|
140
|
+
if (act === 'create') {
|
|
141
|
+
const name = bid;
|
|
142
|
+
if (!name)
|
|
143
|
+
throw new Error('usage: koigrid db branch <dbId> create <name> [--from <iso>] [--ttl-hours N] [--protected] [--schema-only]');
|
|
144
|
+
const body = { name };
|
|
145
|
+
if (a.flags.from)
|
|
146
|
+
body.fromTimestamp = String(a.flags.from);
|
|
147
|
+
if (a.flags['ttl-hours'])
|
|
148
|
+
body.ttlHours = Number(a.flags['ttl-hours']);
|
|
149
|
+
if (a.flags.protected)
|
|
150
|
+
body.protected = true;
|
|
151
|
+
if (a.flags['schema-only'])
|
|
152
|
+
body.schemaOnly = true; // clona SOLO la estructura (sin datos), rápido/barato
|
|
153
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/branches`, { method: 'POST', body });
|
|
154
|
+
const how = a.flags['schema-only'] ? 'schema-only, fast' : 'full-copy clone, ~minutes';
|
|
155
|
+
return console.log(json ? JSON.stringify(r.branch || r, null, 2) : green(`✓ Creating branch "${name}"… (${how})`));
|
|
156
|
+
}
|
|
157
|
+
if (act === 'rm' || act === 'delete') {
|
|
158
|
+
if (!bid)
|
|
159
|
+
throw new Error('need <branchId>');
|
|
160
|
+
await api(`/databases/${encodeURIComponent(id)}/branches/${encodeURIComponent(bid)}`, { method: 'DELETE' });
|
|
161
|
+
return console.log(green(`✓ Deleted branch ${bid}`));
|
|
162
|
+
}
|
|
163
|
+
if (act === 'protect') {
|
|
164
|
+
if (!bid)
|
|
165
|
+
throw new Error('need <branchId>');
|
|
166
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/branches/${encodeURIComponent(bid)}`, { method: 'PATCH', body: { protected: !a.flags.off } });
|
|
167
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Protection ${a.flags.off ? 'removed' : 'enabled'} on ${bid}`));
|
|
168
|
+
}
|
|
169
|
+
if (act === 'reset') {
|
|
170
|
+
if (!bid)
|
|
171
|
+
throw new Error('need <branchId>');
|
|
172
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/branches/${encodeURIComponent(bid)}/reset`, { method: 'POST' });
|
|
173
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Resetting branch ${bid} from production… (atomic swap, ~minutes; old branch serves until the clone is ready)`));
|
|
174
|
+
}
|
|
175
|
+
if (act === 'url' || act === 'connection') {
|
|
176
|
+
if (!bid)
|
|
177
|
+
throw new Error('need <branchId>');
|
|
178
|
+
const r = await api(`/databases/${encodeURIComponent(bid)}/connection`);
|
|
179
|
+
if (json)
|
|
180
|
+
return console.log(JSON.stringify(r.connection, null, 2));
|
|
181
|
+
return console.log(r.connection?.uri);
|
|
182
|
+
}
|
|
183
|
+
throw new Error('usage: koigrid db branch <dbId> ls | create <name> [--from <iso>] [--ttl-hours N] [--protected] | rm <branchId> | protect <branchId> [--off] | reset <branchId> | url <branchId>');
|
|
184
|
+
}
|
|
185
|
+
case 'roles': {
|
|
186
|
+
need();
|
|
187
|
+
const act = a.positionals[1];
|
|
188
|
+
const rname = a.positionals[2];
|
|
189
|
+
if (!act || act === 'ls') {
|
|
190
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/roles`);
|
|
191
|
+
const l = r.roles || [];
|
|
192
|
+
return output(l, json, { rows: l.map((x) => ({ name: x.name, login: x.canLogin ? 'yes' : 'no', createdb: x.createdb ? 'yes' : 'no' })), columns: ['name', 'login', 'createdb'] });
|
|
193
|
+
}
|
|
194
|
+
if (act === 'create') {
|
|
195
|
+
if (!rname)
|
|
196
|
+
throw new Error('usage: koigrid db roles <id> create <name> --password <pw> [--no-login] [--createdb]');
|
|
197
|
+
const password = a.flags.password ? String(a.flags.password) : '';
|
|
198
|
+
if (!password)
|
|
199
|
+
throw new Error('--password required');
|
|
200
|
+
const body = { name: rname, password };
|
|
201
|
+
if (a.flags['no-login'])
|
|
202
|
+
body.login = false;
|
|
203
|
+
if (a.flags.createdb)
|
|
204
|
+
body.createdb = true;
|
|
205
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/roles`, { method: 'POST', body });
|
|
206
|
+
return console.log(json ? JSON.stringify(r.role || r, null, 2) : green(`✓ Role ${rname} created`));
|
|
207
|
+
}
|
|
208
|
+
if (act === 'password') {
|
|
209
|
+
if (!rname)
|
|
210
|
+
throw new Error('need <name>');
|
|
211
|
+
const password = a.flags.password ? String(a.flags.password) : '';
|
|
212
|
+
if (!password)
|
|
213
|
+
throw new Error('--password required');
|
|
214
|
+
await api(`/databases/${encodeURIComponent(id)}/roles/${encodeURIComponent(rname)}`, { method: 'PATCH', body: { password } });
|
|
215
|
+
return console.log(green(`✓ Password changed for ${rname}`));
|
|
216
|
+
}
|
|
217
|
+
if (act === 'rm' || act === 'delete') {
|
|
218
|
+
if (!rname)
|
|
219
|
+
throw new Error('need <name>');
|
|
220
|
+
await api(`/databases/${encodeURIComponent(id)}/roles/${encodeURIComponent(rname)}`, { method: 'DELETE' });
|
|
221
|
+
return console.log(green(`✓ Role ${rname} dropped`));
|
|
222
|
+
}
|
|
223
|
+
throw new Error('usage: koigrid db roles <id> ls | create <name> --password <pw> [--no-login] [--createdb] | password <name> --password <pw> | rm <name>');
|
|
224
|
+
}
|
|
225
|
+
case 'rotation': {
|
|
226
|
+
need();
|
|
227
|
+
const act = a.positionals[1];
|
|
228
|
+
if (!act || act === 'show') {
|
|
229
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/rotation`);
|
|
230
|
+
const rot = r.rotation || r;
|
|
231
|
+
if (json)
|
|
232
|
+
return console.log(JSON.stringify(rot, null, 2));
|
|
233
|
+
console.log(`pooler: ${rot.poolerMode}${rot.rotatable ? ' (rotatable)' : ' (migrate to file first)'}`);
|
|
234
|
+
console.log(`interval: ${rot.intervalDays ? rot.intervalDays + ' days' : 'off (manual only)'} grace: ${rot.graceDays} days`);
|
|
235
|
+
console.log(`active: ${rot.activeRole} standby: ${rot.standbyRole ?? '—'} state: ${rot.state}`);
|
|
236
|
+
return console.log(`last rotated: ${String(rot.lastRotatedAt ?? '—')} next due: ${String(rot.nextDueAt ?? '—')}`);
|
|
237
|
+
}
|
|
238
|
+
if (act === 'set') {
|
|
239
|
+
const body = a.flags.json && a.flags.json !== true ? JSON.parse(String(a.flags.json)) : {};
|
|
240
|
+
if (a.flags.interval !== undefined) {
|
|
241
|
+
const iv = String(a.flags.interval);
|
|
242
|
+
body.intervalDays = (iv === 'off' || iv === 'false') ? 0 : Number(iv);
|
|
243
|
+
}
|
|
244
|
+
if (a.flags.grace !== undefined)
|
|
245
|
+
body.graceDays = Number(a.flags.grace);
|
|
246
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/rotation`, { method: 'PUT', body });
|
|
247
|
+
return console.log(json ? JSON.stringify(r.rotation || r, null, 2) : green('✓ Rotation policy updated'));
|
|
248
|
+
}
|
|
249
|
+
if (act === 'rotate') {
|
|
250
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/rotation/rotate`, { method: 'POST' });
|
|
251
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Rotated${r.activeRole ? ` — active role now ${r.activeRole}` : ''}`));
|
|
252
|
+
}
|
|
253
|
+
if (act === 'migrate') {
|
|
254
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/rotation/migrate`, { method: 'POST' });
|
|
255
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green('✓ Pooler migrated to file mode (rotation-ready)'));
|
|
256
|
+
}
|
|
257
|
+
throw new Error('usage: koigrid db rotation <id> show | set --interval <days|off> [--grace <days>] | rotate | migrate');
|
|
258
|
+
}
|
|
259
|
+
case 'data': {
|
|
260
|
+
need();
|
|
261
|
+
const table = a.positionals[1];
|
|
262
|
+
if (!table)
|
|
263
|
+
throw new Error("usage: koigrid db data <id> <table> [--select a,b] [--limit N] [--order col.desc] [--where col=op.val] | --insert '[{…}]' | --update '{col:val}' --where col=op.val | --delete --where col=op.val");
|
|
264
|
+
let path = `/databases/${encodeURIComponent(id)}/data/${encodeURIComponent(table)}`;
|
|
265
|
+
const qs = new URLSearchParams();
|
|
266
|
+
if (a.flags.select)
|
|
267
|
+
qs.set('select', String(a.flags.select));
|
|
268
|
+
if (a.flags.limit)
|
|
269
|
+
qs.set('limit', String(a.flags.limit));
|
|
270
|
+
if (a.flags.order)
|
|
271
|
+
qs.set('order', String(a.flags.order));
|
|
272
|
+
for (const w of [].concat(a.flags.where || [])) {
|
|
273
|
+
const [k, ...rest] = String(w).split('=');
|
|
274
|
+
if (k)
|
|
275
|
+
qs.set(k, rest.join('='));
|
|
276
|
+
}
|
|
277
|
+
if (qs.toString())
|
|
278
|
+
path = `${path}?${qs.toString()}`;
|
|
279
|
+
if (a.flags.insert) {
|
|
280
|
+
const rows = JSON.parse(String(a.flags.insert));
|
|
281
|
+
const r = await api(path, { method: 'POST', body: { rows: Array.isArray(rows) ? rows : [rows] } });
|
|
282
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ inserted ${r.rowCount} row(s)`));
|
|
283
|
+
}
|
|
284
|
+
if (a.flags.update) {
|
|
285
|
+
const set = JSON.parse(String(a.flags.update));
|
|
286
|
+
const r = await api(path, { method: 'PATCH', body: { set } });
|
|
287
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ updated ${r.rowCount} row(s)`));
|
|
288
|
+
} // requiere --where
|
|
289
|
+
if (a.flags.delete) {
|
|
290
|
+
const r = await api(path, { method: 'DELETE' });
|
|
291
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ deleted ${r.rowCount} row(s)`));
|
|
292
|
+
} // requiere --where
|
|
293
|
+
const r = await api(path);
|
|
294
|
+
if (json)
|
|
295
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
296
|
+
const rows = r.rows || [];
|
|
297
|
+
if (rows.length) {
|
|
298
|
+
const cols = Object.keys(rows[0]);
|
|
299
|
+
console.log(cols.join('\t'));
|
|
300
|
+
for (const row of rows)
|
|
301
|
+
console.log(cols.map((c) => fmtCell(row[c])).join('\t'));
|
|
302
|
+
}
|
|
303
|
+
return console.log(`(${r.rowCount} row${r.rowCount === 1 ? '' : 's'}${r.truncated ? ', truncated' : ''})`);
|
|
304
|
+
}
|
|
305
|
+
case 'rpc': {
|
|
306
|
+
need();
|
|
307
|
+
const fn = a.positionals[1];
|
|
308
|
+
if (!fn)
|
|
309
|
+
throw new Error("usage: koigrid db rpc <id> <fn> [--args '{\"a\":1}'] [--write]");
|
|
310
|
+
const args = a.flags.args && a.flags.args !== true ? JSON.parse(String(a.flags.args)) : {};
|
|
311
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/rpc/${encodeURIComponent(fn)}`, { method: 'POST', body: { args, write: !!a.flags.write } });
|
|
312
|
+
if (json)
|
|
313
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
314
|
+
const rows = r.rows || [];
|
|
315
|
+
if (rows.length) {
|
|
316
|
+
const cols = Object.keys(rows[0]);
|
|
317
|
+
console.log(cols.join('\t'));
|
|
318
|
+
for (const row of rows)
|
|
319
|
+
console.log(cols.map((c) => fmtCell(row[c])).join('\t'));
|
|
320
|
+
}
|
|
321
|
+
return console.log(`(${r.rowCount} row${r.rowCount === 1 ? '' : 's'})`);
|
|
322
|
+
}
|
|
323
|
+
case 'tables': {
|
|
324
|
+
need();
|
|
325
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/query`);
|
|
326
|
+
const l = r.tables || [];
|
|
327
|
+
return output(l, json, { rows: l.map((x) => ({ schema: x.schema, table: x.name })), columns: ['schema', 'table'] });
|
|
328
|
+
}
|
|
329
|
+
case 'query':
|
|
330
|
+
case 'sql': {
|
|
331
|
+
need();
|
|
332
|
+
const sql = a.positionals[1];
|
|
333
|
+
if (!sql)
|
|
334
|
+
throw new Error('usage: koigrid db query <id> "SELECT …" [--write]');
|
|
335
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/query`, { method: 'POST', body: { sql, write: !!a.flags.write } });
|
|
336
|
+
if (json)
|
|
337
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
338
|
+
if (r.columns?.length) {
|
|
339
|
+
console.log(r.columns.join('\t'));
|
|
340
|
+
for (const row of r.rows || [])
|
|
341
|
+
console.log(r.columns.map((c) => fmtCell(row[c])).join('\t'));
|
|
342
|
+
}
|
|
343
|
+
console.log(`(${r.rowCount} row${r.rowCount === 1 ? '' : 's'}${r.truncated ? ', truncated' : ''}${r.command ? `, ${r.command}` : ''})`);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
case 'rename': {
|
|
347
|
+
const name = a.positionals[0] === id ? a.positionals[1] : a.positionals[0];
|
|
348
|
+
const nm = a.positionals[1] || name;
|
|
349
|
+
if (!id || !nm)
|
|
350
|
+
throw new Error('usage: koigrid db rename <id> "<new name>"');
|
|
351
|
+
const r = await api(`/databases/${encodeURIComponent(id)}`, { method: 'PATCH', body: { name: nm } });
|
|
352
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Database renamed to "${nm}"`));
|
|
353
|
+
}
|
|
114
354
|
default: throw new Error(`unknown: db ${sub}`);
|
|
115
355
|
}
|
|
116
356
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid dns — DNS Management (BYO: conecta tu zona + CRUD de records). Ver docs/DNS.md.
|
|
4
|
+
export async function dns(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'zones';
|
|
7
|
+
if (sub === 'zones' || sub === 'ls') {
|
|
8
|
+
const r = await api('/dns/zones');
|
|
9
|
+
const l = r.zones || [];
|
|
10
|
+
return output(l, json, { rows: l.map((z) => ({ id: String(z.id).slice(0, 8), domain: z.domain, provider: z.provider })), columns: ['id', 'domain', 'provider'] });
|
|
11
|
+
}
|
|
12
|
+
if (sub === 'connect') {
|
|
13
|
+
const domain = a.positionals[0] || a.flags.domain;
|
|
14
|
+
const zoneId = a.flags.zone || a.flags['zone-id'];
|
|
15
|
+
const apiToken = a.flags['api-token'] || a.flags['provider-token']; // NO --token: es global (override del token de API)
|
|
16
|
+
if (!domain || !zoneId || !apiToken)
|
|
17
|
+
throw new Error('usage: koigrid dns connect <domain> --zone <zoneId> --api-token <providerToken> [--provider cloudflare]');
|
|
18
|
+
const r = await api('/dns/zones', { method: 'POST', body: { provider: a.flags.provider || 'cloudflare', domain, zoneId, apiToken } });
|
|
19
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Zone connected → ${r.zone?.domain} (${r.zone?.id})`));
|
|
20
|
+
}
|
|
21
|
+
if (sub === 'disconnect' || sub === 'rm') {
|
|
22
|
+
const id = a.positionals[0];
|
|
23
|
+
if (!id)
|
|
24
|
+
throw new Error('usage: koigrid dns disconnect <zoneId>');
|
|
25
|
+
await api(`/dns/zones/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
26
|
+
return console.log(green(`✓ Disconnected ${id}`));
|
|
27
|
+
}
|
|
28
|
+
if (sub === 'records') {
|
|
29
|
+
const zid = a.positionals[0];
|
|
30
|
+
if (!zid)
|
|
31
|
+
throw new Error('usage: koigrid dns records <zoneId>');
|
|
32
|
+
const r = await api(`/dns/zones/${encodeURIComponent(zid)}/records`);
|
|
33
|
+
const l = r.records || [];
|
|
34
|
+
return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), type: x.type, name: x.name, content: x.content })), columns: ['id', 'type', 'name', 'content'] });
|
|
35
|
+
}
|
|
36
|
+
if (sub === 'add') {
|
|
37
|
+
const zid = a.positionals[0];
|
|
38
|
+
const type = (a.flags.type || a.positionals[1] || '').toString().toUpperCase();
|
|
39
|
+
const name = a.flags.name || a.positionals[2];
|
|
40
|
+
const content = a.flags.content || a.positionals[3];
|
|
41
|
+
if (!zid || !type || !name || !content)
|
|
42
|
+
throw new Error('usage: koigrid dns add <zoneId> <TYPE> <name> <content> [--priority 10]');
|
|
43
|
+
const body = { type, name, content };
|
|
44
|
+
if (a.flags.priority)
|
|
45
|
+
body.priority = Number(a.flags.priority);
|
|
46
|
+
if (a.flags.ttl)
|
|
47
|
+
body.ttl = Number(a.flags.ttl);
|
|
48
|
+
const r = await api(`/dns/zones/${encodeURIComponent(zid)}/records`, { method: 'POST', body });
|
|
49
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${type} ${name} → ${content}`));
|
|
50
|
+
}
|
|
51
|
+
if (sub === 'del' || sub === 'record-rm') {
|
|
52
|
+
const zid = a.positionals[0];
|
|
53
|
+
const rid = a.positionals[1];
|
|
54
|
+
if (!zid || !rid)
|
|
55
|
+
throw new Error('usage: koigrid dns del <zoneId> <recordId>');
|
|
56
|
+
await api(`/dns/zones/${encodeURIComponent(zid)}/records/${encodeURIComponent(rid)}`, { method: 'DELETE' });
|
|
57
|
+
return console.log(green(`✓ Deleted record ${rid}`));
|
|
58
|
+
}
|
|
59
|
+
if (sub === 'update' || sub === 'record-update') {
|
|
60
|
+
const zid = a.positionals[0];
|
|
61
|
+
const rid = a.positionals[1];
|
|
62
|
+
if (!zid || !rid)
|
|
63
|
+
throw new Error("usage: koigrid dns update <zoneId> <recordId> [--type A|CNAME|TXT|…] [--name host] [--content val] [--ttl N] [--proxied] [--json '{…}']");
|
|
64
|
+
const body = a.flags.json && a.flags.json !== true ? JSON.parse(String(a.flags.json)) : {};
|
|
65
|
+
if (a.flags.type)
|
|
66
|
+
body.type = String(a.flags.type);
|
|
67
|
+
if (a.flags.name)
|
|
68
|
+
body.name = String(a.flags.name);
|
|
69
|
+
if (a.flags.content)
|
|
70
|
+
body.content = String(a.flags.content);
|
|
71
|
+
if (a.flags.ttl)
|
|
72
|
+
body.ttl = Number(a.flags.ttl);
|
|
73
|
+
if (a.flags.proxied !== undefined)
|
|
74
|
+
body.proxied = !!a.flags.proxied;
|
|
75
|
+
const r = await api(`/dns/zones/${encodeURIComponent(zid)}/records/${encodeURIComponent(rid)}`, { method: 'PUT', body });
|
|
76
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Record ${rid} updated`));
|
|
77
|
+
}
|
|
78
|
+
throw new Error(`unknown: dns ${sub}`);
|
|
79
|
+
}
|
package/dist/commands/email.js
CHANGED
|
@@ -24,9 +24,23 @@ export async function email(a) {
|
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
if (sub === 'config') {
|
|
27
|
+
const act = a.positionals[0];
|
|
28
|
+
if (act === 'set') {
|
|
29
|
+
const smtp = a.positionals[1] || a.flags.smtp;
|
|
30
|
+
if (!smtp)
|
|
31
|
+
throw new Error('usage: koigrid email config set "<smtp-connection-string>" [--from default@dom]');
|
|
32
|
+
const body = { smtp };
|
|
33
|
+
if (a.flags.from)
|
|
34
|
+
body.fromDefault = String(a.flags.from);
|
|
35
|
+
const r = await api('/email/config', { method: 'PUT', body });
|
|
36
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green('✓ Email SMTP config saved + verified'));
|
|
37
|
+
}
|
|
38
|
+
if (act === 'rm' || act === 'delete') {
|
|
39
|
+
await api('/email/config', { method: 'DELETE' });
|
|
40
|
+
return console.log(green('✓ Email config removed'));
|
|
41
|
+
}
|
|
27
42
|
const r = await api('/email/config');
|
|
28
|
-
console.log(JSON.stringify(r, null, 2));
|
|
29
|
-
return;
|
|
43
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
30
44
|
}
|
|
31
45
|
throw new Error(`unknown: email ${sub}`);
|
|
32
46
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid errors — error tracking (Sentry-lite). Ver docs/ERRORS.md.
|
|
4
|
+
export async function errors(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/errors');
|
|
9
|
+
const l = r.groups || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), level: x.level, count: x.count, resolved: x.resolved ? 'yes' : '', message: String(x.message).slice(0, 60) })),
|
|
12
|
+
columns: ['id', 'level', 'count', 'resolved', 'message'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'token') {
|
|
16
|
+
const r = await api('/errors');
|
|
17
|
+
return console.log(json ? JSON.stringify({ ingestToken: r.ingestToken }, null, 2) : r.ingestToken);
|
|
18
|
+
}
|
|
19
|
+
if (sub === 'resolve' || sub === 'reopen') {
|
|
20
|
+
const id = a.positionals[0];
|
|
21
|
+
if (!id)
|
|
22
|
+
throw new Error(`usage: koigrid errors ${sub} <id>`);
|
|
23
|
+
await api(`/errors/groups/${encodeURIComponent(id)}`, { method: 'PATCH', body: { resolved: sub === 'resolve' } });
|
|
24
|
+
return console.log(green(`✓ ${id} ${sub}d`));
|
|
25
|
+
}
|
|
26
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
27
|
+
const id = a.positionals[0];
|
|
28
|
+
if (!id)
|
|
29
|
+
throw new Error('usage: koigrid errors rm <id>');
|
|
30
|
+
await api(`/errors/groups/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
31
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`unknown: errors ${sub}`);
|
|
34
|
+
}
|