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,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
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid flags — feature flags (activar/desactivar + rollout gradual). Ver docs/FLAGS.md.
|
|
4
|
+
export async function flags(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/flags');
|
|
9
|
+
const l = r.flags || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ key: x.key, enabled: x.enabled ? 'on' : 'off', rollout: `${x.rolloutPercent}%`, description: x.description || '' })),
|
|
12
|
+
columns: ['key', 'enabled', 'rollout', 'description'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'create') {
|
|
16
|
+
const key = a.positionals[0];
|
|
17
|
+
if (!key)
|
|
18
|
+
throw new Error('usage: koigrid flags create <key> [--on] [--rollout N] [--desc "…"]');
|
|
19
|
+
const body = { key, enabled: !!a.flags.on };
|
|
20
|
+
if (a.flags.rollout !== undefined)
|
|
21
|
+
body.rolloutPercent = Number(a.flags.rollout);
|
|
22
|
+
if (a.flags.desc)
|
|
23
|
+
body.description = String(a.flags.desc);
|
|
24
|
+
const r = await api('/flags', { method: 'POST', body });
|
|
25
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Flag "${key}" created`));
|
|
26
|
+
}
|
|
27
|
+
if (sub === 'enable' || sub === 'disable') {
|
|
28
|
+
const key = a.positionals[0];
|
|
29
|
+
if (!key)
|
|
30
|
+
throw new Error(`usage: koigrid flags ${sub} <key>`);
|
|
31
|
+
await api(`/flags/${encodeURIComponent(key)}`, { method: 'PATCH', body: { enabled: sub === 'enable' } });
|
|
32
|
+
return console.log(green(`✓ ${key} ${sub}d`));
|
|
33
|
+
}
|
|
34
|
+
if (sub === 'rollout') {
|
|
35
|
+
const key = a.positionals[0];
|
|
36
|
+
const pct = a.positionals[1];
|
|
37
|
+
if (!key || pct === undefined)
|
|
38
|
+
throw new Error('usage: koigrid flags rollout <key> <percent>');
|
|
39
|
+
await api(`/flags/${encodeURIComponent(key)}`, { method: 'PATCH', body: { rolloutPercent: Number(pct) } });
|
|
40
|
+
return console.log(green(`✓ ${key} → ${pct}% rollout`));
|
|
41
|
+
}
|
|
42
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
43
|
+
const key = a.positionals[0];
|
|
44
|
+
if (!key)
|
|
45
|
+
throw new Error('usage: koigrid flags rm <key>');
|
|
46
|
+
await api(`/flags/${encodeURIComponent(key)}`, { method: 'DELETE' });
|
|
47
|
+
return console.log(green(`✓ Deleted ${key}`));
|
|
48
|
+
}
|
|
49
|
+
if (sub === 'target') {
|
|
50
|
+
const key = a.positionals[0];
|
|
51
|
+
if (!key)
|
|
52
|
+
throw new Error('usage: koigrid flags target <key> <attribute> <in|not_in> <v1,v2> (o --clear)');
|
|
53
|
+
if (a.flags.clear) {
|
|
54
|
+
await api(`/flags/${encodeURIComponent(key)}`, { method: 'PATCH', body: { rules: null } });
|
|
55
|
+
return console.log(green(`✓ ${key}: targeting cleared`));
|
|
56
|
+
}
|
|
57
|
+
const attribute = a.positionals[1];
|
|
58
|
+
const op = a.positionals[2];
|
|
59
|
+
const values = (a.positionals[3] || '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
60
|
+
if (!attribute || (op !== 'in' && op !== 'not_in') || !values.length)
|
|
61
|
+
throw new Error('usage: koigrid flags target <key> <attribute> <in|not_in> <v1,v2>');
|
|
62
|
+
await api(`/flags/${encodeURIComponent(key)}`, { method: 'PATCH', body: { rules: [{ attribute, op, values }] } });
|
|
63
|
+
return console.log(green(`✓ ${key}: ${attribute} ${op} [${values.join(', ')}]`));
|
|
64
|
+
}
|
|
65
|
+
if (sub === 'eval' || sub === 'evaluate') {
|
|
66
|
+
const context = a.flags.context ? String(a.flags.context) : '';
|
|
67
|
+
const attributes = {};
|
|
68
|
+
if (a.flags.attr)
|
|
69
|
+
for (const pair of String(a.flags.attr).split(',')) {
|
|
70
|
+
const [k, v] = pair.split('=');
|
|
71
|
+
if (k && v)
|
|
72
|
+
attributes[k.trim()] = v.trim();
|
|
73
|
+
}
|
|
74
|
+
const body = { context };
|
|
75
|
+
if (Object.keys(attributes).length)
|
|
76
|
+
body.attributes = attributes;
|
|
77
|
+
const r = await api('/flags/evaluate', { method: 'POST', body });
|
|
78
|
+
if (json)
|
|
79
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
80
|
+
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'] });
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`unknown: flags ${sub}`);
|
|
85
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid heartbeats — cron monitoring (dead-man's switch). Ver docs/HEARTBEATS.md.
|
|
4
|
+
export async function heartbeats(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/heartbeats');
|
|
9
|
+
const l = r.heartbeats || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), name: x.name, status: x.status, every: `${x.periodSeconds}s`, ping: x.pingUrl })),
|
|
12
|
+
columns: ['id', 'name', 'status', 'every', 'ping'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'create') {
|
|
16
|
+
const name = a.positionals[0];
|
|
17
|
+
if (!name)
|
|
18
|
+
throw new Error('usage: koigrid heartbeats create "<name>" [--period 3600] [--grace 300] [--webhook URL]');
|
|
19
|
+
const body = { name };
|
|
20
|
+
if (a.flags.period !== undefined)
|
|
21
|
+
body.periodSeconds = Number(a.flags.period);
|
|
22
|
+
if (a.flags.grace !== undefined)
|
|
23
|
+
body.graceSeconds = Number(a.flags.grace);
|
|
24
|
+
if (a.flags.webhook)
|
|
25
|
+
body.webhookUrl = String(a.flags.webhook);
|
|
26
|
+
const r = await api('/heartbeats', { method: 'POST', body });
|
|
27
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Heartbeat created. Ping URL:\n ${r.heartbeat?.pingUrl}`));
|
|
28
|
+
}
|
|
29
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
30
|
+
const id = a.positionals[0];
|
|
31
|
+
if (!id)
|
|
32
|
+
throw new Error('usage: koigrid heartbeats rm <id>');
|
|
33
|
+
await api(`/heartbeats/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
34
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
35
|
+
}
|
|
36
|
+
if (sub === 'update') {
|
|
37
|
+
const id = a.positionals[0];
|
|
38
|
+
if (!id)
|
|
39
|
+
throw new Error("usage: koigrid heartbeats update <id> [--period N] [--grace N] [--webhook URL] [--json '{…}']");
|
|
40
|
+
const body = a.flags.json && a.flags.json !== true ? JSON.parse(String(a.flags.json)) : {};
|
|
41
|
+
if (a.flags.period !== undefined)
|
|
42
|
+
body.periodSeconds = Number(a.flags.period);
|
|
43
|
+
if (a.flags.grace !== undefined)
|
|
44
|
+
body.graceSeconds = Number(a.flags.grace);
|
|
45
|
+
if (a.flags.webhook)
|
|
46
|
+
body.webhookUrl = String(a.flags.webhook);
|
|
47
|
+
const r = await api(`/heartbeats/${encodeURIComponent(id)}`, { method: 'PATCH', body });
|
|
48
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Heartbeat ${id} updated`));
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`unknown: heartbeats ${sub}`);
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { green } from '../output.js';
|
|
3
|
+
// koigrid images — optimización de imágenes (allowlist anti-SSRF + token). Ver docs/IMAGES.md.
|
|
4
|
+
export async function images(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'config';
|
|
7
|
+
if (sub === 'config') {
|
|
8
|
+
const r = await api('/images/config');
|
|
9
|
+
if (json)
|
|
10
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
11
|
+
console.log(`token: ${r.publicToken}`);
|
|
12
|
+
console.log(`allowed hosts: ${(r.allowedHosts || []).join(', ') || '(none — add with: koigrid images allow <host>)'}`);
|
|
13
|
+
console.log(`example: ${r.imgBase}?token=${r.publicToken}&url=https://YOUR_HOST/pic.jpg&w=800&fmt=webp`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (sub === 'allow' || sub === 'hosts') {
|
|
17
|
+
const hosts = a.positionals.filter(Boolean);
|
|
18
|
+
if (!hosts.length)
|
|
19
|
+
throw new Error('usage: koigrid images allow <host> [host2 ...] (e.g. cdn.example.com or *.example.com)');
|
|
20
|
+
const r = await api('/images/config', { method: 'PUT', body: { allowedHosts: hosts } });
|
|
21
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Allowed hosts: ${(r.allowedHosts || []).join(', ')}`));
|
|
22
|
+
}
|
|
23
|
+
// usage
|
|
24
|
+
const days = a.flags.days ? Number(a.flags.days) : 30;
|
|
25
|
+
const r = await api(`/images/usage?days=${days}`);
|
|
26
|
+
if (json)
|
|
27
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
28
|
+
const u = r.usage || {};
|
|
29
|
+
const mb = (n) => (n / 1048576).toFixed(2) + ' MB';
|
|
30
|
+
console.log(`Requests: ${u.requests} In: ${mb(u.sourceBytes || 0)} Out: ${mb(u.outputBytes || 0)} Saved: ${mb(u.savedBytes || 0)} (last ${days}d)`);
|
|
31
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
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.
|
|
4
|
+
export async function logs(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'tail';
|
|
7
|
+
// ── drains ──────────────────────────────────────────────────────────────
|
|
8
|
+
if (sub === 'drains') {
|
|
9
|
+
const r = await api('/log-drains');
|
|
10
|
+
const l = r.drains || [];
|
|
11
|
+
return output(l, json, { rows: l.map((x) => ({ id: String(x.id).slice(0, 8), name: x.name, type: x.type, url: x.url, enabled: x.enabled ? 'on' : 'off' })), columns: ['id', 'name', 'type', 'url', 'enabled'] });
|
|
12
|
+
}
|
|
13
|
+
if (sub === 'drain-add' || sub === 'add') {
|
|
14
|
+
const name = a.positionals[0] || a.flags.name;
|
|
15
|
+
if (!name)
|
|
16
|
+
throw new Error('usage: koigrid logs drain-add <name> [--type http|datadog] [--url https://…] [--header "Authorization: Bearer …"] [--sources app,runtime]');
|
|
17
|
+
const body = { name, type: a.flags.type || 'http' };
|
|
18
|
+
if (a.flags.url)
|
|
19
|
+
body.url = a.flags.url;
|
|
20
|
+
if (a.flags.sources)
|
|
21
|
+
body.sources = String(a.flags.sources).split(',').map((s) => s.trim()).filter(Boolean);
|
|
22
|
+
if (a.flags.header) {
|
|
23
|
+
const h = String(a.flags.header);
|
|
24
|
+
const i = h.indexOf(':');
|
|
25
|
+
if (i > 0)
|
|
26
|
+
body.headers = { [h.slice(0, i).trim()]: h.slice(i + 1).trim() };
|
|
27
|
+
}
|
|
28
|
+
const r = await api('/log-drains', { method: 'POST', body });
|
|
29
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Drain "${name}" created → ${r.drain?.url}`));
|
|
30
|
+
}
|
|
31
|
+
if (sub === 'enable' || sub === 'disable') {
|
|
32
|
+
const id = a.positionals[0];
|
|
33
|
+
if (!id)
|
|
34
|
+
throw new Error(`usage: koigrid logs ${sub} <id>`);
|
|
35
|
+
await api(`/log-drains/${encodeURIComponent(id)}`, { method: 'PATCH', body: { enabled: sub === 'enable' } });
|
|
36
|
+
return console.log(green(`✓ ${sub}d ${id}`));
|
|
37
|
+
}
|
|
38
|
+
if (sub === 'drain-rm' || sub === 'rm') {
|
|
39
|
+
const id = a.positionals[0];
|
|
40
|
+
if (!id)
|
|
41
|
+
throw new Error('usage: koigrid logs drain-rm <id>');
|
|
42
|
+
await api(`/log-drains/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
43
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
44
|
+
}
|
|
45
|
+
// ── buffer ───────────────────────────────────────────────────────────────
|
|
46
|
+
if (sub === 'push') {
|
|
47
|
+
const message = a.positionals[0] || a.flags.message;
|
|
48
|
+
if (!message)
|
|
49
|
+
throw new Error('usage: koigrid logs push "<message>" [--level info|warn|error] [--source app] [--app <appId>]');
|
|
50
|
+
const rec = { message, level: a.flags.level || 'info', source: a.flags.source || 'app' };
|
|
51
|
+
if (a.flags.app)
|
|
52
|
+
rec.appId = String(a.flags.app);
|
|
53
|
+
const r = await api('/logs', { method: 'POST', body: { records: [rec] } });
|
|
54
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Ingested ${r.ingested} record(s)`));
|
|
55
|
+
}
|
|
56
|
+
if (sub === 'tail' || sub === 'ls') {
|
|
57
|
+
const qs = new URLSearchParams();
|
|
58
|
+
if (a.flags.app)
|
|
59
|
+
qs.set('appId', String(a.flags.app));
|
|
60
|
+
if (a.flags.source)
|
|
61
|
+
qs.set('source', String(a.flags.source));
|
|
62
|
+
if (a.flags.limit)
|
|
63
|
+
qs.set('limit', String(a.flags.limit));
|
|
64
|
+
const r = await api(`/logs${qs.toString() ? '?' + qs : ''}`);
|
|
65
|
+
const l = r.logs || [];
|
|
66
|
+
return output(l, json, { rows: l.map((x) => ({ ts: x.ts, level: x.level, source: x.source, message: String(x.message).slice(0, 80) })), columns: ['ts', 'level', 'source', 'message'] });
|
|
67
|
+
}
|
|
68
|
+
throw new Error(`unknown: logs ${sub}`);
|
|
69
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid members — gestión del equipo (miembros + invitaciones). Ver docs/MEMBERS.md.
|
|
4
|
+
export async function members(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/members');
|
|
9
|
+
if (json)
|
|
10
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
11
|
+
const ms = r.members || [];
|
|
12
|
+
output(ms, false, {
|
|
13
|
+
rows: ms.map((x) => ({ userId: String(x.userId).slice(0, 8), email: x.email, name: x.name || '', role: x.role })),
|
|
14
|
+
columns: ['userId', 'email', 'name', 'role'],
|
|
15
|
+
});
|
|
16
|
+
const inv = r.invitations || [];
|
|
17
|
+
if (inv.length) {
|
|
18
|
+
console.log('\nPending invitations:');
|
|
19
|
+
output(inv, false, { rows: inv.map((x) => ({ id: String(x.id).slice(0, 8), email: x.email, role: x.role })), columns: ['id', 'email', 'role'] });
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (sub === 'invite') {
|
|
24
|
+
const email = a.positionals[0];
|
|
25
|
+
if (!email)
|
|
26
|
+
throw new Error('usage: koigrid members invite <email> [--role admin|member]');
|
|
27
|
+
const role = a.flags.role || 'member';
|
|
28
|
+
const r = await api('/members', { method: 'POST', body: { email, role } });
|
|
29
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Invited ${email} (${role})`));
|
|
30
|
+
}
|
|
31
|
+
if (sub === 'role') {
|
|
32
|
+
const userId = a.positionals[0];
|
|
33
|
+
const role = a.positionals[1];
|
|
34
|
+
if (!userId || !role)
|
|
35
|
+
throw new Error('usage: koigrid members role <userId> <admin|member>');
|
|
36
|
+
await api(`/members/${encodeURIComponent(userId)}`, { method: 'PATCH', body: { role } });
|
|
37
|
+
return console.log(green(`✓ ${userId} → ${role}`));
|
|
38
|
+
}
|
|
39
|
+
if (sub === 'rm' || sub === 'remove') {
|
|
40
|
+
const userId = a.positionals[0];
|
|
41
|
+
if (!userId)
|
|
42
|
+
throw new Error('usage: koigrid members rm <userId>');
|
|
43
|
+
await api(`/members/${encodeURIComponent(userId)}`, { method: 'DELETE' });
|
|
44
|
+
return console.log(green(`✓ Removed ${userId}`));
|
|
45
|
+
}
|
|
46
|
+
if (sub === 'revoke') {
|
|
47
|
+
const id = a.positionals[0];
|
|
48
|
+
if (!id)
|
|
49
|
+
throw new Error('usage: koigrid members revoke <invitationId>');
|
|
50
|
+
await api(`/members/invitations/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
51
|
+
return console.log(green(`✓ Revoked invitation ${id}`));
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`unknown: members ${sub}`);
|
|
54
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid notifications — preferencias de aviso por email (por categoría: alarms/anomalies/spend).
|
|
4
|
+
// koigrid notifications ls
|
|
5
|
+
// koigrid notifications set spend off (o on)
|
|
6
|
+
export async function notifications(a) {
|
|
7
|
+
const json = !!a.flags.json, sub = a.sub || 'ls';
|
|
8
|
+
if (sub === 'ls' || sub === 'list') {
|
|
9
|
+
const r = await api('/notifications/preferences');
|
|
10
|
+
const l = r.preferences || [];
|
|
11
|
+
return output(l, json, { rows: l.map((x) => ({ category: x.category, email: x.emailEnabled ? 'on' : 'off' })), columns: ['category', 'email'] });
|
|
12
|
+
}
|
|
13
|
+
if (sub === 'set') {
|
|
14
|
+
const category = a.positionals[0], state = a.positionals[1];
|
|
15
|
+
if (!category || (state !== 'on' && state !== 'off'))
|
|
16
|
+
throw new Error('usage: koigrid notifications set <alarms|anomalies|spend> <on|off>');
|
|
17
|
+
const r = await api('/notifications/preferences', { method: 'PUT', body: { category, emailEnabled: state === 'on' } });
|
|
18
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ ${category} email notifications ${state}`));
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`unknown: notifications ${sub}`);
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { green } from '../output.js';
|
|
3
|
+
// koigrid otel — OpenTelemetry export (endpoint OTLP de métricas). Ver docs/OTEL.md.
|
|
4
|
+
export async function otel(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'show';
|
|
7
|
+
if (sub === 'show' || sub === 'status') {
|
|
8
|
+
const r = await api('/otel');
|
|
9
|
+
if (json)
|
|
10
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
11
|
+
const e = r.exporter;
|
|
12
|
+
if (!e)
|
|
13
|
+
return console.log('no OTLP exporter set');
|
|
14
|
+
return console.log(`${e.endpoint} · enabled=${e.enabled} · lastExport=${e.lastExportAt || 'never'}${e.lastError ? ' · error=' + e.lastError : ''}`);
|
|
15
|
+
}
|
|
16
|
+
if (sub === 'set') {
|
|
17
|
+
const endpoint = a.positionals[0] || String(a.flags.endpoint || '');
|
|
18
|
+
if (!endpoint)
|
|
19
|
+
throw new Error('usage: koigrid otel set <otlp-endpoint> [--header "Authorization: Bearer …"]');
|
|
20
|
+
const body = { endpoint };
|
|
21
|
+
if (a.flags.header) {
|
|
22
|
+
const h = String(a.flags.header);
|
|
23
|
+
const i = h.indexOf(':');
|
|
24
|
+
if (i > 0)
|
|
25
|
+
body.headers = { [h.slice(0, i).trim()]: h.slice(i + 1).trim() };
|
|
26
|
+
}
|
|
27
|
+
const r = await api('/otel', { method: 'PUT', body });
|
|
28
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ OTLP exporter → ${r.exporter?.endpoint}`));
|
|
29
|
+
}
|
|
30
|
+
if (sub === 'rm' || sub === 'remove') {
|
|
31
|
+
await api('/otel', { method: 'DELETE' });
|
|
32
|
+
return console.log(green('✓ OTLP exporter removed'));
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`unknown: otel ${sub}`);
|
|
35
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid projects — agrupación de recursos dentro de la org (ver docs/PROJECTS.md).
|
|
4
|
+
export async function projects(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
if (sub === 'ls' || sub === 'list') {
|
|
8
|
+
const r = await api('/projects');
|
|
9
|
+
const l = r.projects || r || [];
|
|
10
|
+
return output(l, json, {
|
|
11
|
+
rows: l.map((x) => ({ id: String(x.id).slice(0, 8), name: x.name, slug: x.slug, default: x.isDefault ? 'yes' : '' })),
|
|
12
|
+
columns: ['id', 'name', 'slug', 'default'],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (sub === 'create') {
|
|
16
|
+
const name = a.positionals[0];
|
|
17
|
+
if (!name)
|
|
18
|
+
throw new Error('usage: koigrid projects create <name>');
|
|
19
|
+
const r = await api('/projects', { method: 'POST', body: { name } });
|
|
20
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Project "${name}" created`));
|
|
21
|
+
}
|
|
22
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
23
|
+
const id = a.positionals[0];
|
|
24
|
+
if (!id)
|
|
25
|
+
throw new Error('usage: koigrid projects rm <id>');
|
|
26
|
+
await api(`/projects/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
27
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
28
|
+
}
|
|
29
|
+
// Private networking: activar/desactivar <slug>.internal entre recursos del proyecto
|
|
30
|
+
if (sub === 'private-net' || sub === 'private-network') {
|
|
31
|
+
const id = a.positionals[0], act = a.positionals[1];
|
|
32
|
+
if (!id || !['on', 'off'].includes(act))
|
|
33
|
+
throw new Error('usage: koigrid projects private-net <id> on|off');
|
|
34
|
+
const r = await api(`/projects/${encodeURIComponent(id)}`, { method: 'PATCH', body: { privateNetwork: act === 'on' } });
|
|
35
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Private networking ${act} for project ${id}`));
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`unknown: projects ${sub}`);
|
|
38
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
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.
|
|
4
|
+
export async function queues(a) {
|
|
5
|
+
const json = !!a.flags.json;
|
|
6
|
+
const sub = a.sub || 'ls';
|
|
7
|
+
const id = a.positionals[0];
|
|
8
|
+
if (sub === 'ls' || sub === 'list') {
|
|
9
|
+
const r = await api('/queues');
|
|
10
|
+
const l = r.queues || [];
|
|
11
|
+
return output(l, json, { rows: l.map((q) => ({ id: String(q.id).slice(0, 8), name: q.name, vis: `${q.visibilityTimeoutSec}s`, maxRecv: q.maxReceives })), columns: ['id', 'name', 'vis', 'maxRecv'] });
|
|
12
|
+
}
|
|
13
|
+
if (sub === 'create') {
|
|
14
|
+
const name = a.positionals[0];
|
|
15
|
+
if (!name)
|
|
16
|
+
throw new Error('usage: koigrid queues create <name> [--visibility 30] [--max-receives 5]');
|
|
17
|
+
const body = { name };
|
|
18
|
+
if (a.flags.visibility)
|
|
19
|
+
body.visibilityTimeoutSec = Number(a.flags.visibility);
|
|
20
|
+
if (a.flags['max-receives'])
|
|
21
|
+
body.maxReceives = Number(a.flags['max-receives']);
|
|
22
|
+
const r = await api('/queues', { method: 'POST', body });
|
|
23
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Queue "${name}" created (${r.queue?.id})`));
|
|
24
|
+
}
|
|
25
|
+
if (sub === 'show') {
|
|
26
|
+
if (!id)
|
|
27
|
+
throw new Error('usage: koigrid queues show <id>');
|
|
28
|
+
const r = await api(`/queues/${encodeURIComponent(id)}`);
|
|
29
|
+
if (json)
|
|
30
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
31
|
+
const s = r.queue?.stats || {};
|
|
32
|
+
return console.log(`${r.queue?.name}: pending=${s.pending} in-flight=${s.inFlight} dead=${s.dead}`);
|
|
33
|
+
}
|
|
34
|
+
if (sub === 'send') {
|
|
35
|
+
if (!id)
|
|
36
|
+
throw new Error('usage: koigrid queues send <id> <body> [--delay 0] [--dedupe <id>]');
|
|
37
|
+
const bodyText = a.positionals[1];
|
|
38
|
+
if (!bodyText)
|
|
39
|
+
throw new Error('need a message body');
|
|
40
|
+
const body = { body: bodyText };
|
|
41
|
+
if (a.flags.delay)
|
|
42
|
+
body.delaySeconds = Number(a.flags.delay);
|
|
43
|
+
if (a.flags.dedupe)
|
|
44
|
+
body.dedupeId = String(a.flags.dedupe);
|
|
45
|
+
const r = await api(`/queues/${encodeURIComponent(id)}/messages`, { method: 'POST', body });
|
|
46
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Sent (${r.message?.id})${r.message?.deduped ? ' [deduped]' : ''}`));
|
|
47
|
+
}
|
|
48
|
+
if (sub === 'receive') {
|
|
49
|
+
if (!id)
|
|
50
|
+
throw new Error('usage: koigrid queues receive <id> [--max 1]');
|
|
51
|
+
const body = {};
|
|
52
|
+
if (a.flags.max)
|
|
53
|
+
body.max = Number(a.flags.max);
|
|
54
|
+
const r = await api(`/queues/${encodeURIComponent(id)}/receive`, { method: 'POST', body });
|
|
55
|
+
if (json)
|
|
56
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
57
|
+
const msgs = r.messages || [];
|
|
58
|
+
if (!msgs.length)
|
|
59
|
+
return console.log('(no messages)');
|
|
60
|
+
return console.log(msgs.map((m) => `${m.receiptHandle}\t${m.body}`).join('\n'));
|
|
61
|
+
}
|
|
62
|
+
if (sub === 'ack') {
|
|
63
|
+
if (!id)
|
|
64
|
+
throw new Error('usage: koigrid queues ack <id> <receiptHandle>');
|
|
65
|
+
const handle = a.positionals[1];
|
|
66
|
+
if (!handle)
|
|
67
|
+
throw new Error('need <receiptHandle>');
|
|
68
|
+
const r = await api(`/queues/${encodeURIComponent(id)}/ack`, { method: 'POST', body: { receiptHandle: handle } });
|
|
69
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(r.acked ? '✓ Acked' : '✗ Not found (already acked or expired handle)'));
|
|
70
|
+
}
|
|
71
|
+
if (sub === 'rm' || sub === 'delete') {
|
|
72
|
+
if (!id)
|
|
73
|
+
throw new Error('usage: koigrid queues rm <id>');
|
|
74
|
+
await api(`/queues/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
75
|
+
return console.log(green(`✓ Deleted ${id}`));
|
|
76
|
+
}
|
|
77
|
+
if (sub === 'update') {
|
|
78
|
+
const id = a.positionals[0];
|
|
79
|
+
if (!id)
|
|
80
|
+
throw new Error('usage: koigrid queues update <id> [--visibility N] [--max-receives N]');
|
|
81
|
+
const body = {};
|
|
82
|
+
if (a.flags.visibility !== undefined)
|
|
83
|
+
body.visibilityTimeoutSec = Number(a.flags.visibility);
|
|
84
|
+
if (a.flags['max-receives'] !== undefined)
|
|
85
|
+
body.maxReceives = Number(a.flags['max-receives']);
|
|
86
|
+
const r = await api(`/queues/${encodeURIComponent(id)}`, { method: 'PATCH', body });
|
|
87
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Queue ${id} reconfigured`));
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`unknown: queues ${sub}`);
|
|
90
|
+
}
|
package/dist/commands/redis.js
CHANGED
|
@@ -32,6 +32,16 @@ export async function redis(a) {
|
|
|
32
32
|
const r = await api(`/redis/${encodeURIComponent(id)}/connection`);
|
|
33
33
|
return console.log(json ? JSON.stringify(r.connection, null, 2) : r.connection?.uri);
|
|
34
34
|
}
|
|
35
|
+
case 'connect': {
|
|
36
|
+
need();
|
|
37
|
+
const r = await api(`/redis/${encodeURIComponent(id)}/connection`);
|
|
38
|
+
const uri = r.connection?.uri;
|
|
39
|
+
if (!uri)
|
|
40
|
+
throw new Error('no connection string yet (is the cache running?)');
|
|
41
|
+
const { spawnSync } = await import('node:child_process');
|
|
42
|
+
const res = spawnSync('redis-cli', ['-u', uri], { stdio: 'inherit' });
|
|
43
|
+
return process.exit(res.status ?? 0);
|
|
44
|
+
}
|
|
35
45
|
case 'metrics':
|
|
36
46
|
need();
|
|
37
47
|
return console.log(JSON.stringify(await api(`/redis/${encodeURIComponent(id)}/metrics`), null, 2));
|
|
@@ -53,6 +63,14 @@ export async function redis(a) {
|
|
|
53
63
|
const r = await api(`/redis/${encodeURIComponent(id)}/restore`, { method: 'POST', body });
|
|
54
64
|
return console.log(json ? JSON.stringify(r, null, 2) : green('✓ Restoring to a new cache…'));
|
|
55
65
|
}
|
|
66
|
+
case 'rename': {
|
|
67
|
+
need();
|
|
68
|
+
const name = a.positionals[1];
|
|
69
|
+
if (!name)
|
|
70
|
+
throw new Error('usage: koigrid redis rename <id> "<new name>"');
|
|
71
|
+
const r = await api(`/redis/${encodeURIComponent(id)}`, { method: 'PATCH', body: { name } });
|
|
72
|
+
return console.log(json ? JSON.stringify(r, null, 2) : green(`✓ Cache renamed to "${name}"`));
|
|
73
|
+
}
|
|
56
74
|
default: throw new Error(`unknown: redis ${sub}`);
|
|
57
75
|
}
|
|
58
76
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output } from '../output.js';
|
|
3
|
+
const fmtBytes = (n) => n < 1024 ? `${n}B` : n < 1048576 ? `${(n / 1024).toFixed(1)}KB` : n < 1073741824 ? `${(n / 1048576).toFixed(1)}MB` : `${(n / 1073741824).toFixed(2)}GB`;
|
|
4
|
+
// koigrid registry — Container Registry (OCI, vs AWS ECR). El push/pull lo hace docker; aquí se listan repos.
|
|
5
|
+
// Ver docs/REGISTRY.md.
|
|
6
|
+
export async function registry(a) {
|
|
7
|
+
const json = !!a.flags.json;
|
|
8
|
+
const sub = a.sub || 'repos';
|
|
9
|
+
if (sub === 'repos' || sub === 'ls' || sub === 'list') {
|
|
10
|
+
const r = await api('/registry/repositories');
|
|
11
|
+
const l = r.repositories || [];
|
|
12
|
+
if (!json && !l.length)
|
|
13
|
+
return console.log('No images yet. Push one: docker login koigrid.com -u token -p <koi-token-with-registry-scope> && docker push koigrid.com/<name>:<tag>');
|
|
14
|
+
return output(l, json, { rows: l.map((x) => ({ repository: x.name, tags: x.tags })), columns: ['repository', 'tags'] });
|
|
15
|
+
}
|
|
16
|
+
if (sub === 'tags') {
|
|
17
|
+
const repo = a.positionals[0];
|
|
18
|
+
if (!repo)
|
|
19
|
+
throw new Error('usage: koigrid registry tags <name>');
|
|
20
|
+
const r = await api(`/registry/repositories/${Buffer.from(repo).toString('base64url')}/tags`);
|
|
21
|
+
const l = r.tags || [];
|
|
22
|
+
if (!json && !l.length)
|
|
23
|
+
return console.log(`No tags in ${repo}.`);
|
|
24
|
+
return output(l, json, { rows: l.map((x) => ({ tag: x.tag, digest: String(x.digest).slice(0, 19), size: fmtBytes(x.size), pushed: (x.pushedAt || '').slice(0, 16) })), columns: ['tag', 'digest', 'size', 'pushed'] });
|
|
25
|
+
}
|
|
26
|
+
if (sub === 'login') {
|
|
27
|
+
// ayuda: imprime el comando docker login (el push/pull es por docker, no por este CLI)
|
|
28
|
+
return console.log('docker login koigrid.com -u token -p <koi-token-with-registry:read/write>\n# luego: docker tag <img> koigrid.com/<name>:<tag> && docker push koigrid.com/<name>:<tag>');
|
|
29
|
+
}
|
|
30
|
+
throw new Error(`unknown: registry ${sub}`);
|
|
31
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { api } from '../api.js';
|
|
2
|
+
import { output, green } from '../output.js';
|
|
3
|
+
// koigrid rewards — Programa de recompensas (feedback pagado + activación). Ganas saldo por acciones y lo redimes
|
|
4
|
+
// como crédito de infra o gift card. AI-first: un agente que despliega+prueba reclama la recompensa por API.
|
|
5
|
+
// koigrid rewards (mi saldo + mis submissions) (alias: rewards ls)
|
|
6
|
+
// koigrid rewards lines (qué acciones se pagan y cuánto)
|
|
7
|
+
// koigrid rewards submit <reason> [--json '{"...":"..."}'] (reclamar una recompensa)
|
|
8
|
+
// koigrid rewards redeem credit|giftcard [--amount <cents>] (redimir el saldo)
|
|
9
|
+
export async function rewards(a) {
|
|
10
|
+
const json = !!a.flags.json;
|
|
11
|
+
const sub = a.sub || 'ls';
|
|
12
|
+
if (sub === 'ls' || sub === 'list' || sub === 'balance') {
|
|
13
|
+
const r = await api('/rewards');
|
|
14
|
+
if (json)
|
|
15
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
16
|
+
console.log(green(`Saldo: $${((r.balanceCents ?? 0) / 100).toFixed(2)} ${r.currency || 'USD'}`));
|
|
17
|
+
const rows = (r.submissions || []).map((s) => ({ id: String(s.id).slice(0, 8), reason: s.reason, amount: `$${(s.amountCents / 100).toFixed(2)}`, status: s.status }));
|
|
18
|
+
return output(r.submissions || [], false, { rows, columns: ['id', 'reason', 'amount', 'status'] });
|
|
19
|
+
}
|
|
20
|
+
if (sub === 'referral' || sub === 'link') {
|
|
21
|
+
const r = await api('/rewards/referral');
|
|
22
|
+
if (json)
|
|
23
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
24
|
+
console.log(green(`Tu link de referido: ${r.link}`));
|
|
25
|
+
return console.log(` clics: ${r.clicks} · registros: ${r.signups} · ganado: $${((r.earnedCents ?? 0) / 100).toFixed(2)}`);
|
|
26
|
+
}
|
|
27
|
+
if (sub === 'lines') {
|
|
28
|
+
const r = await api('/rewards/lines');
|
|
29
|
+
const l = r.lines || [];
|
|
30
|
+
return output(l, json, { rows: l.map((x) => ({ reason: x.reason, label: x.label, pay: `$${(x.amountCents / 100).toFixed(2)}`, approval: x.manualApproval ? 'manual' : 'auto' })), columns: ['reason', 'label', 'pay', 'approval'] });
|
|
31
|
+
}
|
|
32
|
+
if (sub === 'submit') {
|
|
33
|
+
const reason = a.positionals[0];
|
|
34
|
+
if (!reason)
|
|
35
|
+
throw new Error('usage: koigrid rewards submit <reason> [--json \'{"...":"..."}\'] (reasons: koigrid rewards lines)');
|
|
36
|
+
const body = { reason };
|
|
37
|
+
if (a.flags.json && typeof a.flags.json === 'string')
|
|
38
|
+
body.details = JSON.parse(String(a.flags.json));
|
|
39
|
+
const r = await api('/rewards', { method: 'POST', body });
|
|
40
|
+
if (json)
|
|
41
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
42
|
+
return console.log(green(`✓ Recompensa enviada (${r.submission?.status}) — $${((r.submission?.amountCents ?? 0) / 100).toFixed(2)}`));
|
|
43
|
+
}
|
|
44
|
+
if (sub === 'redeem') {
|
|
45
|
+
const type = a.positionals[0];
|
|
46
|
+
if (type !== 'credit' && type !== 'giftcard')
|
|
47
|
+
throw new Error('usage: koigrid rewards redeem credit|giftcard [--amount <cents>]');
|
|
48
|
+
const body = { type };
|
|
49
|
+
if (a.flags.amount !== undefined)
|
|
50
|
+
body.amountCents = Number(a.flags.amount);
|
|
51
|
+
const r = await api('/rewards/redeem', { method: 'POST', body });
|
|
52
|
+
if (json)
|
|
53
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
54
|
+
return console.log(green(`✓ Redimido $${((r.redeemed ?? 0) / 100).toFixed(2)} como ${r.type} — saldo restante $${((r.newBalance ?? 0) / 100).toFixed(2)}`));
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`unknown: rewards ${sub}`);
|
|
57
|
+
}
|