@voltade/volty 0.1.14 → 0.1.16
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/dist/volty.js +30 -20
- package/package.json +1 -1
package/dist/volty.js
CHANGED
|
@@ -5,17 +5,6 @@ import { existsSync as existsSync3, mkdirSync as mkdirSync4, readFileSync as rea
|
|
|
5
5
|
import { homedir as homedir3 } from "node:os";
|
|
6
6
|
import { join as join4 } from "node:path";
|
|
7
7
|
|
|
8
|
-
// ../shared/ops/retired-prefix.ts
|
|
9
|
-
function retiredPrefix(retired, argv) {
|
|
10
|
-
for (let n = Math.min(argv.length, 4);n >= 1; n--) {
|
|
11
|
-
const name = argv.slice(0, n).join(" ");
|
|
12
|
-
const replacement = retired[name];
|
|
13
|
-
if (replacement !== undefined)
|
|
14
|
-
return { name, replacement };
|
|
15
|
-
}
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
8
|
// src/api.ts
|
|
20
9
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
21
10
|
import { tmpdir } from "node:os";
|
|
@@ -53,27 +42,31 @@ async function apiFetch(ctx, path, init) {
|
|
|
53
42
|
return { ok: res.ok, status: res.status, body };
|
|
54
43
|
}
|
|
55
44
|
var cachePath = (env) => join(tmpdir(), `volty-catalog-${env}-${targetOrg ?? "default"}.json`);
|
|
45
|
+
function staleKeyHint(env) {
|
|
46
|
+
return `: this key is not valid any more, run \`volty auth login --env ${env}\``;
|
|
47
|
+
}
|
|
56
48
|
async function fetchCatalog(ctx, env, useCache = true) {
|
|
57
49
|
const path = cachePath(env);
|
|
58
50
|
if (useCache && existsSync(path)) {
|
|
59
51
|
try {
|
|
60
52
|
const cached = JSON.parse(readFileSync(path, "utf8"));
|
|
61
|
-
if (Date.now() - cached.at < CATALOG_TTL_MS && cached.renamed)
|
|
53
|
+
if (Date.now() - cached.at < CATALOG_TTL_MS && cached.renamed && cached.inApp)
|
|
62
54
|
return cached;
|
|
63
55
|
} catch {}
|
|
64
56
|
}
|
|
65
57
|
const res = await apiFetch(ctx, "/api/v/_catalog");
|
|
66
58
|
if (!res.ok || !res.body.catalog) {
|
|
67
|
-
throw new Error(`could not fetch the operation catalog (HTTP ${res.status})${res.status === 401 ?
|
|
59
|
+
throw new Error(`could not fetch the operation catalog (HTTP ${res.status})${res.status === 401 ? staleKeyHint(env) : ""}`);
|
|
68
60
|
}
|
|
69
61
|
const ops = res.body.catalog;
|
|
70
62
|
const retired = res.body.retired ?? {};
|
|
71
63
|
const renamed = res.body.renamed ?? {};
|
|
64
|
+
const inApp = res.body.inApp ?? {};
|
|
72
65
|
try {
|
|
73
66
|
mkdirSync(tmpdir(), { recursive: true });
|
|
74
|
-
writeFileSync(path, JSON.stringify({ at: Date.now(), ops, retired, renamed }));
|
|
67
|
+
writeFileSync(path, JSON.stringify({ at: Date.now(), ops, retired, renamed, inApp }));
|
|
75
68
|
} catch {}
|
|
76
|
-
return { ops, retired, renamed };
|
|
69
|
+
return { ops, retired, renamed, inApp };
|
|
77
70
|
}
|
|
78
71
|
async function fetchOrgs(ctx, env, useCache = true) {
|
|
79
72
|
const path = join(tmpdir(), `volty-orgs-${env}.json`);
|
|
@@ -86,7 +79,7 @@ async function fetchOrgs(ctx, env, useCache = true) {
|
|
|
86
79
|
}
|
|
87
80
|
const res = await apiFetch(ctx, "/api/cli/orgs");
|
|
88
81
|
if (!res.ok || !res.body.orgs) {
|
|
89
|
-
throw new Error(`could not fetch your org memberships (HTTP ${res.status})${res.status === 401 ?
|
|
82
|
+
throw new Error(`could not fetch your org memberships (HTTP ${res.status})${res.status === 401 ? staleKeyHint(env) : ""}`);
|
|
90
83
|
}
|
|
91
84
|
const orgs = res.body.orgs;
|
|
92
85
|
try {
|
|
@@ -375,9 +368,29 @@ function parseFlagTokens(props, rest, UsageError) {
|
|
|
375
368
|
return { input, json };
|
|
376
369
|
}
|
|
377
370
|
|
|
371
|
+
// ../shared/ops/retired-prefix.ts
|
|
372
|
+
function retiredPrefix(retired, argv) {
|
|
373
|
+
for (let n = Math.min(argv.length, 4);n >= 1; n--) {
|
|
374
|
+
const name = argv.slice(0, n).join(" ");
|
|
375
|
+
const replacement = retired[name];
|
|
376
|
+
if (replacement !== undefined)
|
|
377
|
+
return { name, replacement };
|
|
378
|
+
}
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
|
|
378
382
|
// src/dispatch.ts
|
|
379
383
|
class CliUsageError extends Error {
|
|
380
384
|
}
|
|
385
|
+
function missMessage(catalog, argv) {
|
|
386
|
+
const inApp = retiredPrefix(catalog.inApp, argv);
|
|
387
|
+
if (inApp)
|
|
388
|
+
return `\`${inApp.name}\` is not run from here. ${inApp.replacement}`;
|
|
389
|
+
const retired = retiredPrefix(catalog.retired, argv);
|
|
390
|
+
if (retired)
|
|
391
|
+
return `\`${retired.name}\` is retired: ${retired.replacement}`;
|
|
392
|
+
return `unknown operation '${argv.join(" ")}' — run \`volty help\``;
|
|
393
|
+
}
|
|
381
394
|
function resolveOp(catalog, argv) {
|
|
382
395
|
const byName = new Map(catalog.ops.map((c) => [c.name, c]));
|
|
383
396
|
for (let n = Math.min(argv.length, 4);n >= 1; n--) {
|
|
@@ -886,10 +899,7 @@ async function main() {
|
|
|
886
899
|
}
|
|
887
900
|
const resolved = resolveOp(catalog, argv);
|
|
888
901
|
if (!resolved) {
|
|
889
|
-
|
|
890
|
-
if (retired)
|
|
891
|
-
fail(`\`${retired.name}\` is retired: ${retired.replacement}`);
|
|
892
|
-
fail(`unknown operation '${argv.join(" ")}' — run \`volty help\``);
|
|
902
|
+
fail(missMessage(catalog, argv));
|
|
893
903
|
}
|
|
894
904
|
if (resolved.renamedFrom)
|
|
895
905
|
process.stderr.write(`${resolved.renamedFrom} is now ${resolved.op.name}
|
package/package.json
CHANGED