gencow 0.1.9 → 0.1.10
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/bin/gencow.mjs +36 -18
- package/package.json +1 -1
package/bin/gencow.mjs
CHANGED
|
@@ -57,12 +57,33 @@ async function platformFetch(creds, path, opts = {}) {
|
|
|
57
57
|
...opts,
|
|
58
58
|
headers: {
|
|
59
59
|
"Authorization": `Bearer ${creds.apiKey}`,
|
|
60
|
+
"Origin": creds.platformUrl,
|
|
60
61
|
...opts.headers,
|
|
61
62
|
},
|
|
62
63
|
});
|
|
63
64
|
return res;
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
/** RPC query helper */
|
|
68
|
+
async function rpcQuery(creds, queryName, args = {}) {
|
|
69
|
+
const res = await platformFetch(creds, "/api/query", {
|
|
70
|
+
method: "POST",
|
|
71
|
+
headers: { "Content-Type": "application/json" },
|
|
72
|
+
body: JSON.stringify({ name: queryName, args }),
|
|
73
|
+
});
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** RPC mutation helper */
|
|
78
|
+
async function rpcMutation(creds, mutationName, args = {}) {
|
|
79
|
+
const res = await platformFetch(creds, "/api/mutation", {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: { "Content-Type": "application/json" },
|
|
82
|
+
body: JSON.stringify({ name: mutationName, args }),
|
|
83
|
+
});
|
|
84
|
+
return res;
|
|
85
|
+
}
|
|
86
|
+
|
|
66
87
|
|
|
67
88
|
// ─── Helpers ─────────────────────────────────────────────
|
|
68
89
|
|
|
@@ -1766,16 +1787,17 @@ ${BOLD}Examples:${RESET}
|
|
|
1766
1787
|
const creds = requireCreds();
|
|
1767
1788
|
|
|
1768
1789
|
if (!subcmd || subcmd === "list") {
|
|
1769
|
-
// gencow app list
|
|
1790
|
+
// gencow app list — RPC
|
|
1770
1791
|
log(`\n${BOLD}${CYAN}Your Apps${RESET}\n`);
|
|
1771
|
-
const res = await
|
|
1792
|
+
const res = await rpcQuery(creds, "apps.list");
|
|
1793
|
+
if (!res.ok) { error((await res.json().catch(() => ({}))).error || "Failed to list apps"); return; }
|
|
1772
1794
|
const apps = await res.json();
|
|
1773
1795
|
if (!apps.length) { info("No apps yet. Run: gencow app create <name>"); return; }
|
|
1774
|
-
log(` ${'NAME'.padEnd(20)} ${'STATUS'.padEnd(12)}
|
|
1775
|
-
log(` ${'-'.repeat(
|
|
1796
|
+
log(` ${'NAME'.padEnd(20)} ${'STATUS'.padEnd(12)} PORT`);
|
|
1797
|
+
log(` ${'-'.repeat(50)}`);
|
|
1776
1798
|
for (const a of apps) {
|
|
1777
|
-
const status = a.running ? `${GREEN}running${RESET}` : `${DIM}${a.status}${RESET}`;
|
|
1778
|
-
log(` ${a.name.padEnd(20)} ${status.padEnd(12 + GREEN.length + RESET.length)} ${DIM}${a.
|
|
1799
|
+
const status = a.status === 'running' ? `${GREEN}running${RESET}` : `${DIM}${a.status}${RESET}`;
|
|
1800
|
+
log(` ${a.name.padEnd(20)} ${status.padEnd(12 + GREEN.length + RESET.length)} ${DIM}${a.port}${RESET}`);
|
|
1779
1801
|
}
|
|
1780
1802
|
log("");
|
|
1781
1803
|
return;
|
|
@@ -1786,13 +1808,9 @@ ${BOLD}Examples:${RESET}
|
|
|
1786
1808
|
if (!name) { error("Usage: gencow app create <name>"); process.exit(1); }
|
|
1787
1809
|
log(`\n${BOLD}${CYAN}Gencow App Create${RESET}\n`);
|
|
1788
1810
|
info(`Creating app "${name}"...`);
|
|
1789
|
-
const res = await
|
|
1790
|
-
method: "POST",
|
|
1791
|
-
headers: { "Content-Type": "application/json" },
|
|
1792
|
-
body: JSON.stringify({ name }),
|
|
1793
|
-
});
|
|
1811
|
+
const res = await rpcMutation(creds, "apps.create", { name });
|
|
1794
1812
|
const data = await res.json();
|
|
1795
|
-
if (!res.ok) { error(data.error); process.exit(1); }
|
|
1813
|
+
if (!res.ok) { error(data.error || "Failed to create app"); process.exit(1); }
|
|
1796
1814
|
|
|
1797
1815
|
// Save current app to creds
|
|
1798
1816
|
saveCreds({ ...creds, currentApp: name });
|
|
@@ -1868,9 +1886,9 @@ ${BOLD}Examples:${RESET}
|
|
|
1868
1886
|
}
|
|
1869
1887
|
|
|
1870
1888
|
info(`Deleting app "${name}"...`);
|
|
1871
|
-
const delRes = await
|
|
1889
|
+
const delRes = await rpcMutation(creds, "apps.delete", { name });
|
|
1872
1890
|
const delData = await delRes.json();
|
|
1873
|
-
if (!delRes.ok) { error(delData.error); process.exit(1); }
|
|
1891
|
+
if (!delRes.ok) { error(delData.error || "Failed to delete app"); process.exit(1); }
|
|
1874
1892
|
|
|
1875
1893
|
// Clear currentApp if it was the deleted app
|
|
1876
1894
|
const c = loadCreds();
|
|
@@ -1884,12 +1902,12 @@ ${BOLD}Examples:${RESET}
|
|
|
1884
1902
|
if (subcmd === "status") {
|
|
1885
1903
|
const name = rest[0] || loadCreds()?.currentApp;
|
|
1886
1904
|
if (!name) { error("Usage: gencow app status <name>"); process.exit(1); }
|
|
1887
|
-
const res = await
|
|
1905
|
+
const res = await rpcQuery(creds, "apps.get", { name });
|
|
1888
1906
|
const data = await res.json();
|
|
1889
|
-
if (!res.ok) { error(data.error); process.exit(1); }
|
|
1907
|
+
if (!res.ok) { error(data.error || "App not found"); process.exit(1); }
|
|
1890
1908
|
log(`\n ${BOLD}${data.name}${RESET}`);
|
|
1891
|
-
log(` Status: ${data.running ? GREEN + 'running' + RESET : DIM + data.status + RESET}`);
|
|
1892
|
-
log(`
|
|
1909
|
+
log(` Status: ${data.status === 'running' ? GREEN + 'running' + RESET : DIM + data.status + RESET}`);
|
|
1910
|
+
log(` Port: ${data.port}`);
|
|
1893
1911
|
log("");
|
|
1894
1912
|
return;
|
|
1895
1913
|
}
|