@ora-ai/cli 0.25.0 → 0.26.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 +39 -1
- package/README.md +569 -462
- package/dist/command-tree.d.ts +30 -0
- package/dist/command-tree.d.ts.map +1 -0
- package/dist/command-tree.js +144 -0
- package/dist/command-tree.js.map +1 -0
- package/dist/core/error-envelope.d.ts +13 -4
- package/dist/core/error-envelope.d.ts.map +1 -1
- package/dist/core/error-envelope.js +19 -4
- package/dist/core/error-envelope.js.map +1 -1
- package/dist/core/error-stories.d.ts +36 -0
- package/dist/core/error-stories.d.ts.map +1 -0
- package/dist/core/error-stories.js +155 -0
- package/dist/core/error-stories.js.map +1 -0
- package/dist/core/http.d.ts +14 -3
- package/dist/core/http.d.ts.map +1 -1
- package/dist/core/http.js +24 -6
- package/dist/core/http.js.map +1 -1
- package/dist/core/limit-story.d.ts +2 -0
- package/dist/core/limit-story.d.ts.map +1 -1
- package/dist/core/limit-story.js +9 -4
- package/dist/core/limit-story.js.map +1 -1
- package/dist/core/operation-command.d.ts +10 -0
- package/dist/core/operation-command.d.ts.map +1 -0
- package/dist/core/operation-command.js +15 -0
- package/dist/core/operation-command.js.map +1 -0
- package/dist/core/operation-meta.d.ts +62 -0
- package/dist/core/operation-meta.d.ts.map +1 -0
- package/dist/core/operation-meta.js +15 -0
- package/dist/core/operation-meta.js.map +1 -0
- package/dist/core/output.d.ts +7 -5
- package/dist/core/output.d.ts.map +1 -1
- package/dist/core/output.js +21 -80
- package/dist/core/output.js.map +1 -1
- package/dist/core/problem.d.ts +34 -0
- package/dist/core/problem.d.ts.map +1 -0
- package/dist/core/problem.js +44 -0
- package/dist/core/problem.js.map +1 -0
- package/dist/core/retry-after.d.ts +4 -3
- package/dist/core/retry-after.d.ts.map +1 -1
- package/dist/core/retry-after.js +4 -3
- package/dist/core/retry-after.js.map +1 -1
- package/dist/core/run-operation.d.ts +9 -4
- package/dist/core/run-operation.d.ts.map +1 -1
- package/dist/core/run-operation.js +17 -4
- package/dist/core/run-operation.js.map +1 -1
- package/dist/generated/operations.d.ts +37 -1
- package/dist/generated/operations.d.ts.map +1 -1
- package/dist/generated/operations.js +27540 -191
- package/dist/generated/operations.js.map +1 -1
- package/dist/generated/types.d.ts +1932 -116
- package/dist/generated/types.d.ts.map +1 -1
- package/dist/generated/types.js +1 -1
- package/dist/interactive/derive-prompts.d.ts +13 -5
- package/dist/interactive/derive-prompts.d.ts.map +1 -1
- package/dist/interactive/derive-prompts.js +25 -1
- package/dist/interactive/derive-prompts.js.map +1 -1
- package/dist/interactive/session.d.ts +2 -2
- package/dist/interactive/session.d.ts.map +1 -1
- package/dist/interactive/session.js +31 -2
- package/dist/interactive/session.js.map +1 -1
- package/dist/mcp/defined-tools/defined-call.d.ts +18 -0
- package/dist/mcp/defined-tools/defined-call.d.ts.map +1 -0
- package/dist/mcp/defined-tools/defined-call.js +114 -0
- package/dist/mcp/defined-tools/defined-call.js.map +1 -0
- package/dist/mcp/defined-tools/defined-tool.d.ts +22 -0
- package/dist/mcp/defined-tools/defined-tool.d.ts.map +1 -0
- package/dist/mcp/defined-tools/defined-tool.js +35 -0
- package/dist/mcp/defined-tools/defined-tool.js.map +1 -0
- package/dist/mcp/defined-tools/json-conform.d.ts +28 -0
- package/dist/mcp/defined-tools/json-conform.d.ts.map +1 -0
- package/dist/mcp/defined-tools/json-conform.js +144 -0
- package/dist/mcp/defined-tools/json-conform.js.map +1 -0
- package/dist/mcp/defined-tools/problem-mapping.d.ts +39 -0
- package/dist/mcp/defined-tools/problem-mapping.d.ts.map +1 -0
- package/dist/mcp/defined-tools/problem-mapping.js +179 -0
- package/dist/mcp/defined-tools/problem-mapping.js.map +1 -0
- package/dist/mcp/defined-tools/request-split.d.ts +19 -0
- package/dist/mcp/defined-tools/request-split.d.ts.map +1 -0
- package/dist/mcp/defined-tools/request-split.js +25 -0
- package/dist/mcp/defined-tools/request-split.js.map +1 -0
- package/dist/mcp/defined-tools/tool-problem.d.ts +40 -0
- package/dist/mcp/defined-tools/tool-problem.d.ts.map +1 -0
- package/dist/mcp/defined-tools/tool-problem.js +42 -0
- package/dist/mcp/defined-tools/tool-problem.js.map +1 -0
- package/dist/mcp/defined-tools/tool-results.d.ts +12 -0
- package/dist/mcp/defined-tools/tool-results.d.ts.map +1 -0
- package/dist/mcp/defined-tools/tool-results.js +21 -0
- package/dist/mcp/defined-tools/tool-results.js.map +1 -0
- package/dist/mcp/local-tools/credential-minting.d.ts +24 -0
- package/dist/mcp/local-tools/credential-minting.d.ts.map +1 -0
- package/dist/mcp/local-tools/credential-minting.js +49 -0
- package/dist/mcp/local-tools/credential-minting.js.map +1 -0
- package/dist/mcp/local-tools/env-file.d.ts +30 -0
- package/dist/mcp/local-tools/env-file.d.ts.map +1 -0
- package/dist/mcp/local-tools/env-file.js +71 -0
- package/dist/mcp/local-tools/env-file.js.map +1 -0
- package/dist/mcp/local-tools/local-tools.d.ts +16 -0
- package/dist/mcp/local-tools/local-tools.d.ts.map +1 -0
- package/dist/mcp/local-tools/local-tools.js +16 -0
- package/dist/mcp/local-tools/local-tools.js.map +1 -0
- package/dist/mcp/local-tools/save-transmitter-credential.d.ts +21 -0
- package/dist/mcp/local-tools/save-transmitter-credential.d.ts.map +1 -0
- package/dist/mcp/local-tools/save-transmitter-credential.js +119 -0
- package/dist/mcp/local-tools/save-transmitter-credential.js.map +1 -0
- package/dist/mcp/mcp-call.d.ts +2 -2
- package/dist/mcp/mcp-call.d.ts.map +1 -1
- package/dist/mcp/mcp-call.js +8 -2
- package/dist/mcp/mcp-call.js.map +1 -1
- package/dist/mcp/mcp-command.d.ts +6 -2
- package/dist/mcp/mcp-command.d.ts.map +1 -1
- package/dist/mcp/mcp-command.js +36 -12
- package/dist/mcp/mcp-command.js.map +1 -1
- package/dist/mcp/mcp-install.d.ts +2 -0
- package/dist/mcp/mcp-install.d.ts.map +1 -1
- package/dist/mcp/mcp-install.js +7 -1
- package/dist/mcp/mcp-install.js.map +1 -1
- package/dist/mcp/mcp-protocol.d.ts +2 -0
- package/dist/mcp/mcp-protocol.d.ts.map +1 -1
- package/dist/mcp/mcp-protocol.js.map +1 -1
- package/dist/mcp/mcp-tools.d.ts +28 -25
- package/dist/mcp/mcp-tools.d.ts.map +1 -1
- package/dist/mcp/mcp-tools.js +39 -16
- package/dist/mcp/mcp-tools.js.map +1 -1
- package/dist/mcp/tool-binding.d.ts +35 -0
- package/dist/mcp/tool-binding.d.ts.map +1 -0
- package/dist/mcp/tool-binding.js +7 -0
- package/dist/mcp/tool-binding.js.map +1 -0
- package/dist/mcp/tool-bindings.d.ts +20 -0
- package/dist/mcp/tool-bindings.d.ts.map +1 -0
- package/dist/mcp/tool-bindings.js +31 -0
- package/dist/mcp/tool-bindings.js.map +1 -0
- package/dist/mcp/tool-filter.d.ts +26 -0
- package/dist/mcp/tool-filter.d.ts.map +1 -0
- package/dist/mcp/tool-filter.js +23 -0
- package/dist/mcp/tool-filter.js.map +1 -0
- package/dist/program.d.ts +9 -9
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +12 -83
- package/dist/program.js.map +1 -1
- package/dist/watch.d.ts +3 -3
- package/dist/watch.d.ts.map +1 -1
- package/dist/watch.js +10 -2
- package/dist/watch.js.map +1 -1
- package/package.json +6 -7
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generated command tree: ONE registrar walks the OPERATIONS manifest and builds every command (a data
|
|
3
|
+
* Registry — adding a public operation changes the generated manifest, never this file).
|
|
4
|
+
*
|
|
5
|
+
* Aliases: an operation's other spellings (scripts/lib/command-aliases.mjs) are registered as full command paths of
|
|
6
|
+
* their own. A group that exists ONLY because of an alias (the Study legacy `benchmarkDefinitions`) is hidden from
|
|
7
|
+
* help: the old spelling keeps working, and help shows one name per group.
|
|
8
|
+
*
|
|
9
|
+
* Flags: a query parameter or request header the document requires is a required option, so leaving it out stops
|
|
10
|
+
* the command before any request (exit 2), and commander's error names the flag.
|
|
11
|
+
*
|
|
12
|
+
* Body arguments: the body fields the document says a command-line client takes as plain arguments
|
|
13
|
+
* (`x-ora-cli-arguments` → `cliArguments`) are optional positionals after the path's (`ora audit run example.com`),
|
|
14
|
+
* each also accepted as a hidden `--<name>`. The body is built from them (core/cli-arguments.ts), so a command whose
|
|
15
|
+
* arguments hold every required field needs no --file; a --file's other fields are kept, and an argument wins over
|
|
16
|
+
* the same field in it.
|
|
17
|
+
*/
|
|
18
|
+
import { type Command } from "commander";
|
|
19
|
+
import { type CommandOperation } from "./core/operation-meta.js";
|
|
20
|
+
import type { ResolvedDeps } from "./program.js";
|
|
21
|
+
export declare function describeOperation(meta: Pick<CommandOperation, "summary" | "stability">): string;
|
|
22
|
+
/**
|
|
23
|
+
* What `ora <command> --help` says above its usage: the one-line summary, then the operation's own description from
|
|
24
|
+
* the document (a Front tool's definition carries the same text). The parent's command list shows the summary alone.
|
|
25
|
+
*/
|
|
26
|
+
export declare function explainOperation(meta: Pick<CommandOperation, "summary" | "stability" | "description" | "mcpTool">): string;
|
|
27
|
+
/** Every group path ("study", "study benchmark-definitions") a CANONICAL command path passes through. */
|
|
28
|
+
export declare function canonicalGroups(operations: readonly Pick<CommandOperation, "commandPath">[]): Set<string>;
|
|
29
|
+
export declare function attachOperations(program: Command, operations: readonly CommandOperation[], deps: ResolvedDeps): void;
|
|
30
|
+
//# sourceMappingURL=command-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-tree.d.ts","sourceRoot":"","sources":["../src/command-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAGjD,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAIjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAOjD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,WAAW,CAAC,GAAG,MAAM,CAG/F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,WAAW,GAAG,aAAa,GAAG,SAAS,CAAC,GAAG,MAAM,CAI1H;AAED,yGAAyG;AACzG,wBAAgB,eAAe,CAAC,UAAU,EAAE,SAAS,IAAI,CAAC,gBAAgB,EAAE,aAAa,CAAC,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAMzG;AAgBD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,gBAAgB,EAAE,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAKpH"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generated command tree: ONE registrar walks the OPERATIONS manifest and builds every command (a data
|
|
3
|
+
* Registry — adding a public operation changes the generated manifest, never this file).
|
|
4
|
+
*
|
|
5
|
+
* Aliases: an operation's other spellings (scripts/lib/command-aliases.mjs) are registered as full command paths of
|
|
6
|
+
* their own. A group that exists ONLY because of an alias (the Study legacy `benchmarkDefinitions`) is hidden from
|
|
7
|
+
* help: the old spelling keeps working, and help shows one name per group.
|
|
8
|
+
*
|
|
9
|
+
* Flags: a query parameter or request header the document requires is a required option, so leaving it out stops
|
|
10
|
+
* the command before any request (exit 2), and commander's error names the flag.
|
|
11
|
+
*
|
|
12
|
+
* Body arguments: the body fields the document says a command-line client takes as plain arguments
|
|
13
|
+
* (`x-ora-cli-arguments` → `cliArguments`) are optional positionals after the path's (`ora audit run example.com`),
|
|
14
|
+
* each also accepted as a hidden `--<name>`. The body is built from them (core/cli-arguments.ts), so a command whose
|
|
15
|
+
* arguments hold every required field needs no --file; a --file's other fields are kept, and an argument wins over
|
|
16
|
+
* the same field in it.
|
|
17
|
+
*/
|
|
18
|
+
import { Option } from "commander";
|
|
19
|
+
import { argumentFlag, argumentValues, excessArgumentsMessage } from "./core/cli-arguments.js";
|
|
20
|
+
import { headerParamsOf } from "./core/operation-meta.js";
|
|
21
|
+
import { renderError } from "./core/output.js";
|
|
22
|
+
import { buildHeaders, buildQuery, readBody, runOperation } from "./core/run-operation.js";
|
|
23
|
+
import { COMMAND_GROUPS } from "./generated/operations.js";
|
|
24
|
+
import { resolveOutputMode } from "./render/mode.js";
|
|
25
|
+
import { helpEpilog } from "./watch.js";
|
|
26
|
+
/** How a stability marks a command's one-line description. A stability with no entry adds nothing. */
|
|
27
|
+
const STABILITY_LABELS = { beta: "(beta)" };
|
|
28
|
+
export function describeOperation(meta) {
|
|
29
|
+
const label = meta.stability ? STABILITY_LABELS[meta.stability] : undefined;
|
|
30
|
+
return label ? `${meta.summary} ${label}` : meta.summary;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What `ora <command> --help` says above its usage: the one-line summary, then the operation's own description from
|
|
34
|
+
* the document (a Front tool's definition carries the same text). The parent's command list shows the summary alone.
|
|
35
|
+
*/
|
|
36
|
+
export function explainOperation(meta) {
|
|
37
|
+
const details = meta.description ?? (meta.mcpTool ? meta.mcpTool.description : undefined);
|
|
38
|
+
const summary = describeOperation(meta);
|
|
39
|
+
return details ? `${summary}\n\n${details}` : summary;
|
|
40
|
+
}
|
|
41
|
+
/** Every group path ("study", "study benchmark-definitions") a CANONICAL command path passes through. */
|
|
42
|
+
export function canonicalGroups(operations) {
|
|
43
|
+
const groups = new Set();
|
|
44
|
+
for (const meta of operations) {
|
|
45
|
+
for (let i = 1; i < meta.commandPath.length; i++)
|
|
46
|
+
groups.add(meta.commandPath.slice(0, i).join(" "));
|
|
47
|
+
}
|
|
48
|
+
return groups;
|
|
49
|
+
}
|
|
50
|
+
/** The child group named `seg` under `node`, created (hidden when no canonical path passes through it) if missing. */
|
|
51
|
+
function ensureGroup(node, seg, isRoot, hidden) {
|
|
52
|
+
const existing = node.commands.find((c) => c.name() === seg);
|
|
53
|
+
if (existing)
|
|
54
|
+
return existing;
|
|
55
|
+
const described = isRoot ? COMMAND_GROUPS[seg] : undefined;
|
|
56
|
+
return node.command(seg, hidden ? { hidden: true } : {}).description(described ?? `${seg} commands`);
|
|
57
|
+
}
|
|
58
|
+
/** A required option says so in help, as a required --file does; commander refuses the command without it. */
|
|
59
|
+
function addOption(leaf, spec, description, required) {
|
|
60
|
+
if (required)
|
|
61
|
+
leaf.requiredOption(spec, `${description} (required)`);
|
|
62
|
+
else
|
|
63
|
+
leaf.option(spec, description);
|
|
64
|
+
}
|
|
65
|
+
export function attachOperations(program, operations, deps) {
|
|
66
|
+
const canonical = canonicalGroups(operations);
|
|
67
|
+
for (const meta of operations) {
|
|
68
|
+
for (const path of [meta.commandPath, ...(meta.aliases ?? [])])
|
|
69
|
+
attachOperationAt(program, path, meta, deps, canonical);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function attachOperationAt(program, path, meta, deps, canonical) {
|
|
73
|
+
let node = program;
|
|
74
|
+
path.slice(0, -1).forEach((seg, i) => {
|
|
75
|
+
node = ensureGroup(node, seg, node === program, !canonical.has(path.slice(0, i + 1).join(" ")));
|
|
76
|
+
});
|
|
77
|
+
const leaf = node
|
|
78
|
+
.command(path.at(-1) ?? meta.id)
|
|
79
|
+
.summary(describeOperation(meta))
|
|
80
|
+
.description(explainOperation(meta));
|
|
81
|
+
for (const p of meta.pathParams)
|
|
82
|
+
leaf.argument(`<${p.name}>`, `${p.name} path parameter`);
|
|
83
|
+
for (const name of meta.cliArguments ?? []) {
|
|
84
|
+
leaf.argument(`[${name}]`, meta.bodyFields?.find((f) => f.name === name)?.description ?? `${name} body field`);
|
|
85
|
+
}
|
|
86
|
+
for (const q of meta.queryParams) {
|
|
87
|
+
const spec = q.kind === "boolean" ? `--${q.flag}` : `--${q.flag} <${q.valueName ?? "value"}>`;
|
|
88
|
+
addOption(leaf, spec, q.description ?? `${q.name} query parameter`, q.required);
|
|
89
|
+
}
|
|
90
|
+
for (const h of headerParamsOf(meta)) {
|
|
91
|
+
addOption(leaf, `--${h.flag} <value>`, h.description ?? `the ${h.name} request header`, h.required);
|
|
92
|
+
}
|
|
93
|
+
if (meta.hasBody) {
|
|
94
|
+
// A body its arguments can carry is not required as a file: readBody names what is missing instead.
|
|
95
|
+
const required = meta.bodyRequired && !meta.cliArguments?.length ? " (required)" : "";
|
|
96
|
+
leaf.option("--file <path>", `JSON request body file, or "-" for stdin${required}`);
|
|
97
|
+
}
|
|
98
|
+
leaf.option("--json", "print the raw JSON response");
|
|
99
|
+
leaf.option("--plain", "force plain non-visual output");
|
|
100
|
+
leaf.option("--api-url <url>", "override the API base URL");
|
|
101
|
+
if (meta.watchable) {
|
|
102
|
+
leaf.option("-w, --watch", "after the call, stream the created resource's live events (server-provided streamUrl) until the stream closes");
|
|
103
|
+
}
|
|
104
|
+
for (const name of meta.cliArguments ?? []) {
|
|
105
|
+
const long = `--${argumentFlag(name)}`;
|
|
106
|
+
if (!leaf.options.some((o) => o.long === long))
|
|
107
|
+
leaf.addOption(new Option(`${long} <value>`).hideHelp());
|
|
108
|
+
}
|
|
109
|
+
leaf.addHelpText("after", helpEpilog(meta));
|
|
110
|
+
leaf.action(async (...actionArgs) => {
|
|
111
|
+
const positionals = actionArgs.slice(0, meta.pathParams.length);
|
|
112
|
+
const opts = leaf.opts();
|
|
113
|
+
let body;
|
|
114
|
+
if (meta.hasBody) {
|
|
115
|
+
// The same pure decision runOperation makes, so an unreadable --file under --json is a JSON line too.
|
|
116
|
+
const mode = resolveOutputMode({ json: Boolean(opts.json), plain: Boolean(opts.plain) }, deps.env, deps.stdoutIsTty);
|
|
117
|
+
// An argument past the declared ones is refused, never silently dropped.
|
|
118
|
+
const declared = meta.pathParams.length + (meta.cliArguments?.length ?? 0);
|
|
119
|
+
if (meta.cliArguments?.length && leaf.args.length > declared) {
|
|
120
|
+
deps.errOut(renderError(new Error(excessArgumentsMessage(meta)), { mode }));
|
|
121
|
+
process.exitCode = 2;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const given = argumentValues(meta, actionArgs.slice(meta.pathParams.length), opts);
|
|
125
|
+
const r = readBody(opts.file, meta, deps, mode, given);
|
|
126
|
+
if (r.kind === "error")
|
|
127
|
+
return; // readBody already reported + set exitCode
|
|
128
|
+
body = r.body;
|
|
129
|
+
}
|
|
130
|
+
const headers = buildHeaders(meta, opts);
|
|
131
|
+
const values = {
|
|
132
|
+
positionals,
|
|
133
|
+
query: buildQuery(meta, opts),
|
|
134
|
+
...(Object.keys(headers).length > 0 ? { headers } : {}),
|
|
135
|
+
body,
|
|
136
|
+
json: Boolean(opts.json),
|
|
137
|
+
plain: Boolean(opts.plain),
|
|
138
|
+
watch: Boolean(opts.watch),
|
|
139
|
+
apiUrlFlag: opts.apiUrl,
|
|
140
|
+
};
|
|
141
|
+
await runOperation(meta, values, deps);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=command-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-tree.js","sourceRoot":"","sources":["../src/command-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,EAAgB,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,EAAE,cAAc,EAAyB,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAkB,MAAM,yBAAyB,CAAC;AAC3G,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,sGAAsG;AACtG,MAAM,gBAAgB,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,OAAO;YACT,CAAC;YACD,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;YACnF,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,IAA0B,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC7E,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO;gBAAE,OAAO,CAAC,2CAA2C;YAC3E,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzC,MAAM,MAAM,GAAc;YACxB,WAAW;YACX,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC;YAC7B,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvD,IAAI;YACJ,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YACxB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YAC1B,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YAC1B,UAAU,EAAE,IAAI,CAAC,MAA4B;SAC9C,CAAC;QACF,MAAM,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -2,16 +2,20 @@
|
|
|
2
2
|
* Reads a non-ok response body into the ONE shape ApiError carries: a code, a
|
|
3
3
|
* human message, and every diagnostic the body held.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Four spellings reach this CLI from the public API:
|
|
6
|
+
* - RFC 9457 problem details (the Front API, `application/problem+json`):
|
|
7
|
+
* `{type, title, status, detail?, code, requestId, …}`;
|
|
6
8
|
* - the house shape (`components.schemas.Error`, @ora/auth's guards):
|
|
7
9
|
* `{error: <message>, code: <CODE>, details?}`;
|
|
8
10
|
* - the code-first shape (Autopilot's published error body):
|
|
9
11
|
* `{error: <CODE>, message: <text>, details?}`;
|
|
10
12
|
* - the nested legacy shape (@ora/auth's requireRole and older handlers):
|
|
11
13
|
* `{success: false, error: {code, message, …}}`.
|
|
12
|
-
* Read as the house shape, the
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* Read as the house shape, the others lose their code or their message: a
|
|
15
|
+
* problem's `detail` would be a diagnostic under a bare `HTTP 422`, a
|
|
16
|
+
* code-first body printed `API error 422 (HTTP_ERROR): HARNESS_NOT_DRIVEN`
|
|
17
|
+
* with its message demoted to a detail line, and a nested one printed
|
|
18
|
+
* `[object Object]`.
|
|
15
19
|
*
|
|
16
20
|
* One reader per spelling (Strategy); the first that recognizes a body wins and
|
|
17
21
|
* the house reader takes every other body, exactly as toApiError always did. A
|
|
@@ -28,6 +32,11 @@ export interface ErrorEnvelopeReader {
|
|
|
28
32
|
matches(body: Record<string, unknown>): boolean;
|
|
29
33
|
read(body: Record<string, unknown>): ErrorEnvelope;
|
|
30
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* RFC 9457 `{type, title, status, detail?, code, …}`: `detail` is the message (the title when absent); every other
|
|
37
|
+
* member is a diagnostic. core/problem.ts reads the problem itself; this is its envelope, for ApiError.
|
|
38
|
+
*/
|
|
39
|
+
export declare const problemEnvelope: ErrorEnvelopeReader;
|
|
31
40
|
/** `{error: CODE, message, details?}`; a `code` that merely repeats `error` is the same body. */
|
|
32
41
|
export declare const codeFirstEnvelope: ErrorEnvelopeReader;
|
|
33
42
|
/** `{success: false, error: {code, message, …}}`: the nested object's other fields are its diagnostics. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-envelope.d.ts","sourceRoot":"","sources":["../../src/core/error-envelope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"error-envelope.d.ts","sourceRoot":"","sources":["../../src/core/error-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,qGAAqG;IACrG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;IAChD,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC;CACpD;AAqBD;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,mBAI7B,CAAC;AAEF,iGAAiG;AACjG,eAAO,MAAM,iBAAiB,EAAE,mBAS/B,CAAC;AAEF,2GAA2G;AAC3G,eAAO,MAAM,cAAc,EAAE,mBAO5B,CAAC;AAEF,mGAAmG;AACnG,eAAO,MAAM,aAAa,EAAE,mBAI3B,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,sBAAsB,EAAE,SAAS,mBAAmB,EAKhE,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,OAAO,GAAE,SAAS,mBAAmB,EAA2B,GAC/D,aAAa,CAGf"}
|
|
@@ -2,21 +2,26 @@
|
|
|
2
2
|
* Reads a non-ok response body into the ONE shape ApiError carries: a code, a
|
|
3
3
|
* human message, and every diagnostic the body held.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Four spellings reach this CLI from the public API:
|
|
6
|
+
* - RFC 9457 problem details (the Front API, `application/problem+json`):
|
|
7
|
+
* `{type, title, status, detail?, code, requestId, …}`;
|
|
6
8
|
* - the house shape (`components.schemas.Error`, @ora/auth's guards):
|
|
7
9
|
* `{error: <message>, code: <CODE>, details?}`;
|
|
8
10
|
* - the code-first shape (Autopilot's published error body):
|
|
9
11
|
* `{error: <CODE>, message: <text>, details?}`;
|
|
10
12
|
* - the nested legacy shape (@ora/auth's requireRole and older handlers):
|
|
11
13
|
* `{success: false, error: {code, message, …}}`.
|
|
12
|
-
* Read as the house shape, the
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* Read as the house shape, the others lose their code or their message: a
|
|
15
|
+
* problem's `detail` would be a diagnostic under a bare `HTTP 422`, a
|
|
16
|
+
* code-first body printed `API error 422 (HTTP_ERROR): HARNESS_NOT_DRIVEN`
|
|
17
|
+
* with its message demoted to a detail line, and a nested one printed
|
|
18
|
+
* `[object Object]`.
|
|
15
19
|
*
|
|
16
20
|
* One reader per spelling (Strategy); the first that recognizes a body wins and
|
|
17
21
|
* the house reader takes every other body, exactly as toApiError always did. A
|
|
18
22
|
* new spelling is one more reader, never an edit to toApiError.
|
|
19
23
|
*/
|
|
24
|
+
import { isProblem } from "./problem.js";
|
|
20
25
|
/** A machine-readable code as the code-first shape spells it (`HARNESS_NOT_DRIVEN`), never prose. */
|
|
21
26
|
const CODE_TOKEN = /^[A-Z][A-Z0-9_]*$/;
|
|
22
27
|
function recordOf(value) {
|
|
@@ -32,6 +37,15 @@ function envelope(code, message, details) {
|
|
|
32
37
|
const m = str(message);
|
|
33
38
|
return { ...(c ? { code: c } : {}), ...(m ? { message: m } : {}), details };
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* RFC 9457 `{type, title, status, detail?, code, …}`: `detail` is the message (the title when absent); every other
|
|
42
|
+
* member is a diagnostic. core/problem.ts reads the problem itself; this is its envelope, for ApiError.
|
|
43
|
+
*/
|
|
44
|
+
export const problemEnvelope = {
|
|
45
|
+
name: "problem",
|
|
46
|
+
matches: (body) => isProblem(body),
|
|
47
|
+
read: ({ type: _type, title, status: _status, detail, code, ...extras }) => envelope(code, detail ?? title, extras),
|
|
48
|
+
};
|
|
35
49
|
/** `{error: CODE, message, details?}`; a `code` that merely repeats `error` is the same body. */
|
|
36
50
|
export const codeFirstEnvelope = {
|
|
37
51
|
name: "code-first",
|
|
@@ -58,6 +72,7 @@ export const houseEnvelope = {
|
|
|
58
72
|
};
|
|
59
73
|
/** First match wins; houseEnvelope matches every body, so it stays last. */
|
|
60
74
|
export const ERROR_ENVELOPE_READERS = [
|
|
75
|
+
problemEnvelope,
|
|
61
76
|
codeFirstEnvelope,
|
|
62
77
|
nestedEnvelope,
|
|
63
78
|
houseEnvelope,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-envelope.js","sourceRoot":"","sources":["../../src/core/error-envelope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"error-envelope.js","sourceRoot":"","sources":["../../src/core/error-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAezC,qGAAqG;AACrG,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAEvC,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,GAAG,CAAC,KAAc;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED,SAAS,QAAQ,CAAC,IAAa,EAAE,OAAgB,EAAE,OAAgC;IACjF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Aa,EACb,UAA0C,sBAAsB;IAEhE,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACpC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the CLI tells an API refusal — a Registry of Strategies, first match wins. Each story turns one kind of
|
|
3
|
+
* refusal into guidance a person can act on (the 402 paywall, a missing scope, a dead credential, a rate limit, an
|
|
4
|
+
* RFC 9457 problem), never a bare code. A new story is one more entry, never an edit to renderError (output.ts).
|
|
5
|
+
*
|
|
6
|
+
* A refusal of the credential itself (a 403 missing scope, a 401) is told in the refused credential's own words
|
|
7
|
+
* (credentials/refusal-words.ts), bound by the caller that met it (run-operation.ts callerOf). Without them it is told
|
|
8
|
+
* as the API said it — a problem as a problem, anything else as the generic line — and never worded for one kind of
|
|
9
|
+
* credential: an error met with no credential resolved is no credential's refusal.
|
|
10
|
+
*/
|
|
11
|
+
import type { AuthError } from "./auth.js";
|
|
12
|
+
import type { RefusalWords } from "./credentials/credential.js";
|
|
13
|
+
import type { ApiError } from "./http.js";
|
|
14
|
+
export interface StoryContext {
|
|
15
|
+
/** The operation's declared scope — the fallback when a 403 does not name the missing one. */
|
|
16
|
+
scope?: string | null;
|
|
17
|
+
/** The refused credential's own words; absent when no credential was resolved. */
|
|
18
|
+
words?: RefusalWords;
|
|
19
|
+
/** The command that runs an operation id (`ora front sites get <site>`), so a next step names what to type. */
|
|
20
|
+
commandFor?: (operationId: string) => string | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface ApiErrorStory {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
matches(err: ApiError, ctx: StoryContext): boolean;
|
|
25
|
+
render(err: ApiError, ctx: StoryContext): string;
|
|
26
|
+
}
|
|
27
|
+
/** Order is priority. The specific stories come first; a problem with no specific story still beats the generic. */
|
|
28
|
+
export declare const API_ERROR_STORIES: readonly ApiErrorStory[];
|
|
29
|
+
export declare function tellApiError(err: ApiError, ctx: StoryContext, stories?: readonly ApiErrorStory[]): string;
|
|
30
|
+
/**
|
|
31
|
+
* A credential exchange (or sign-in) that failed. A 5xx is the door's own trouble — the credential is fine and the
|
|
32
|
+
* command can simply be repeated — so it never reads as a dead sign-in. Anything else is the credential's refusal, in
|
|
33
|
+
* its own words when it was resolved.
|
|
34
|
+
*/
|
|
35
|
+
export declare function tellAuthError(err: AuthError, words: RefusalWords | undefined): string;
|
|
36
|
+
//# sourceMappingURL=error-stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-stories.d.ts","sourceRoot":"","sources":["../../src/core/error-stories.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAI1C,MAAM,WAAW,YAAY;IAC3B,8FAA8F;IAC9F,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,kFAAkF;IAClF,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,+GAA+G;IAC/G,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC1D;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC;IACnD,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,CAAC;CAClD;AAuID,oHAAoH;AACpH,eAAO,MAAM,iBAAiB,EAAE,SAAS,aAAa,EAAsE,CAAC;AAE7H,wBAAgB,YAAY,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,GAAE,SAAS,aAAa,EAAsB,GAAG,MAAM,CAE5H;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,CAKrF"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the CLI tells an API refusal — a Registry of Strategies, first match wins. Each story turns one kind of
|
|
3
|
+
* refusal into guidance a person can act on (the 402 paywall, a missing scope, a dead credential, a rate limit, an
|
|
4
|
+
* RFC 9457 problem), never a bare code. A new story is one more entry, never an edit to renderError (output.ts).
|
|
5
|
+
*
|
|
6
|
+
* A refusal of the credential itself (a 403 missing scope, a 401) is told in the refused credential's own words
|
|
7
|
+
* (credentials/refusal-words.ts), bound by the caller that met it (run-operation.ts callerOf). Without them it is told
|
|
8
|
+
* as the API said it — a problem as a problem, anything else as the generic line — and never worded for one kind of
|
|
9
|
+
* credential: an error met with no credential resolved is no credential's refusal.
|
|
10
|
+
*/
|
|
11
|
+
import chalk from "chalk";
|
|
12
|
+
import { limitStory } from "./limit-story.js";
|
|
13
|
+
import { isProblem, problemFacts } from "./problem.js";
|
|
14
|
+
/** A refusal's lines, uncoloured: the first is the headline, the rest say what to do. */
|
|
15
|
+
const headline = (lines) => [chalk.red(lines[0] ?? ""), ...lines.slice(1)].join("\n");
|
|
16
|
+
/**
|
|
17
|
+
* The diagnostics a service attached to its error, rendered as readable
|
|
18
|
+
* lines. `issues` ({path, message}[] — the addon/zod validation shape) gets
|
|
19
|
+
* one line per field; everything else prints as `key: value`. This is what
|
|
20
|
+
* turns a bare `422 addon_validation_failed` into a self-diagnosing message.
|
|
21
|
+
* An issue whose line IS the headline (a one-issue refusal whose message is
|
|
22
|
+
* its issues joined, as Autopilot's are) is not printed a second time.
|
|
23
|
+
*/
|
|
24
|
+
function renderErrorDetails(details, headlineText) {
|
|
25
|
+
if (!details)
|
|
26
|
+
return [];
|
|
27
|
+
const lines = [];
|
|
28
|
+
for (const [key, value] of Object.entries(details)) {
|
|
29
|
+
if (key === "issues" && Array.isArray(value)) {
|
|
30
|
+
for (const issue of value) {
|
|
31
|
+
const line = `${issue.path || "(body)"}: ${issue.message ?? JSON.stringify(issue)}`;
|
|
32
|
+
if (line !== headlineText)
|
|
33
|
+
lines.push(chalk.dim(` - ${line}`));
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
lines.push(chalk.dim(` ${key}: ${typeof value === "string" ? value : JSON.stringify(value)}`));
|
|
38
|
+
}
|
|
39
|
+
return lines;
|
|
40
|
+
}
|
|
41
|
+
/** The refusal as the API said it: its status, code and message, then every diagnostic it attached. */
|
|
42
|
+
function asTheApiSaidIt(err) {
|
|
43
|
+
return [chalk.red(`API error ${err.status} (${err.code}): ${err.message}`), ...renderErrorDetails(err.details, err.message)].join("\n");
|
|
44
|
+
}
|
|
45
|
+
/** A plan limit: what happened (none on the plan, all used, or the count) and where to raise it (limit-story.ts). */
|
|
46
|
+
const paywall = {
|
|
47
|
+
name: "paywall",
|
|
48
|
+
matches: (err) => err.status === 402,
|
|
49
|
+
render: (err) => {
|
|
50
|
+
const story = limitStory(`Limit exceeded: ${err.message}`, err.details);
|
|
51
|
+
return headline([story.headline, ...story.lines]);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
/** The scopes a 403 names (`details.missing`), else the command's own; none when neither says. */
|
|
55
|
+
function missingScopes(err, commandScope) {
|
|
56
|
+
const named = err.details?.missing;
|
|
57
|
+
if (Array.isArray(named) && named.length > 0)
|
|
58
|
+
return named.map(String);
|
|
59
|
+
if (typeof named === "string" && named.length > 0)
|
|
60
|
+
return [named];
|
|
61
|
+
return commandScope ? [commandScope] : [];
|
|
62
|
+
}
|
|
63
|
+
const missingScope = {
|
|
64
|
+
name: "missing-scope",
|
|
65
|
+
matches: (err, ctx) => ctx.words !== undefined && err.status === 403 && err.code === "INSUFFICIENT_SCOPE",
|
|
66
|
+
render: (err, ctx) => (ctx.words ? headline(ctx.words.missingScope(missingScopes(err, ctx.scope))) : asTheApiSaidIt(err)),
|
|
67
|
+
};
|
|
68
|
+
const signedOut = {
|
|
69
|
+
name: "signed-out",
|
|
70
|
+
matches: (err, ctx) => ctx.words !== undefined && err.status === 401,
|
|
71
|
+
render: (err, ctx) => (ctx.words ? headline(ctx.words.signedOut(err.code, err.message)) : asTheApiSaidIt(err)),
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A 429 that is not a problem: a service's envelope, or the ingress's per-IP limit, which answers in plain text with
|
|
75
|
+
* nothing but its status and `Retry-After` (so the message is `HTTP 429`). A problem's 429 is told as the problem it
|
|
76
|
+
* is, with its code and request id.
|
|
77
|
+
*/
|
|
78
|
+
const rateLimited = {
|
|
79
|
+
name: "rate-limited",
|
|
80
|
+
matches: (err) => err.status === 429 && !isProblem(err.body),
|
|
81
|
+
render: (err) => {
|
|
82
|
+
const retryAfter = err.details?.retryAfter;
|
|
83
|
+
if (typeof retryAfter === "string" || typeof retryAfter === "number") {
|
|
84
|
+
return chalk.red(`Rate limited: ${err.message}. Retry after ${retryAfter}s.`);
|
|
85
|
+
}
|
|
86
|
+
return chalk.red(`Rate limited: ${err.message}. Retry in a moment.`);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* What the outcome means for the person deciding whether to run the command again. An outcome with no row adds
|
|
91
|
+
* nothing. A finished answer is replayed to its --idempotency-key, so after `unknown` the same key only repeats it.
|
|
92
|
+
*/
|
|
93
|
+
const OUTCOME_ADVICE = {
|
|
94
|
+
applied: "The change was applied.",
|
|
95
|
+
unknown: "The change may have been applied: check its current state before running the command again. The same " +
|
|
96
|
+
"--idempotency-key replays this answer, so once you know it was not applied, run it again with a new key.",
|
|
97
|
+
};
|
|
98
|
+
/** The one case where the same key is right: the first request with it is still running (IDEMPOTENCY_IN_PROGRESS). */
|
|
99
|
+
const REUSE_KEY_ADVICE = "The first request with this --idempotency-key is still running: retry with the same key to get its answer once it finishes.";
|
|
100
|
+
/** The advice a problem's retry facts call for: reusing the key when the API asks for it, else what its outcome means. */
|
|
101
|
+
function retryAdvice(facts) {
|
|
102
|
+
if (facts.reuseIdempotencyKey)
|
|
103
|
+
return REUSE_KEY_ADVICE;
|
|
104
|
+
return facts.outcome ? OUTCOME_ADVICE[facts.outcome] : undefined;
|
|
105
|
+
}
|
|
106
|
+
function nextStepLine(step, ctx) {
|
|
107
|
+
const does = step.operation ? (ctx.commandFor?.(step.operation) ?? step.operation) : undefined;
|
|
108
|
+
return `Next: ${step.title ?? step.id ?? "a next step"}${does ? chalk.dim(` (${does})`) : ""}`;
|
|
109
|
+
}
|
|
110
|
+
function problemLines(err, facts, ctx) {
|
|
111
|
+
const lines = [chalk.red(`${facts.code ?? err.code}: ${facts.detail ?? facts.title ?? err.message}`)];
|
|
112
|
+
for (const e of facts.errors)
|
|
113
|
+
lines.push(chalk.dim(` - ${e.path || "(body)"}: ${e.message}`));
|
|
114
|
+
for (const step of facts.nextSteps.filter((s) => !s.done))
|
|
115
|
+
lines.push(nextStepLine(step, ctx));
|
|
116
|
+
const advice = retryAdvice(facts);
|
|
117
|
+
if (advice)
|
|
118
|
+
lines.push(advice);
|
|
119
|
+
if (facts.retryable) {
|
|
120
|
+
// The problem's own retryAfter, else the response's Retry-After header (http.ts, in seconds).
|
|
121
|
+
const header = err.details?.retryAfter;
|
|
122
|
+
const retryAfter = facts.retryAfter ?? (typeof header === "number" ? header : undefined);
|
|
123
|
+
lines.push(retryAfter !== undefined ? `You can retry after ${retryAfter}s.` : "You can retry.");
|
|
124
|
+
}
|
|
125
|
+
if (facts.requestId)
|
|
126
|
+
lines.push(chalk.dim(`request ${facts.requestId}`));
|
|
127
|
+
return lines;
|
|
128
|
+
}
|
|
129
|
+
const problem = {
|
|
130
|
+
name: "problem",
|
|
131
|
+
matches: (err) => isProblem(err.body),
|
|
132
|
+
render: (err, ctx) => problemLines(err, problemFacts(err.body), ctx).join("\n"),
|
|
133
|
+
};
|
|
134
|
+
const generic = {
|
|
135
|
+
name: "generic",
|
|
136
|
+
matches: () => true,
|
|
137
|
+
render: (err) => asTheApiSaidIt(err),
|
|
138
|
+
};
|
|
139
|
+
/** Order is priority. The specific stories come first; a problem with no specific story still beats the generic. */
|
|
140
|
+
export const API_ERROR_STORIES = [paywall, missingScope, signedOut, rateLimited, problem, generic];
|
|
141
|
+
export function tellApiError(err, ctx, stories = API_ERROR_STORIES) {
|
|
142
|
+
return (stories.find((s) => s.matches(err, ctx)) ?? generic).render(err, ctx);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* A credential exchange (or sign-in) that failed. A 5xx is the door's own trouble — the credential is fine and the
|
|
146
|
+
* command can simply be repeated — so it never reads as a dead sign-in. Anything else is the credential's refusal, in
|
|
147
|
+
* its own words when it was resolved.
|
|
148
|
+
*/
|
|
149
|
+
export function tellAuthError(err, words) {
|
|
150
|
+
if (err.status >= 500) {
|
|
151
|
+
return [chalk.red(`Signing in is unavailable right now (${err.code}): ${err.message}`), "Try again in a moment."].join("\n");
|
|
152
|
+
}
|
|
153
|
+
return words ? headline(words.signedOut(err.code, err.message)) : chalk.red(`Authentication failed (${err.code}): ${err.message}`);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=error-stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-stories.js","sourceRoot":"","sources":["../../src/core/error-stories.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,YAAY,EAA2C,MAAM,cAAc,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BAA0B,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AACrI,CAAC"}
|
package/dist/core/http.d.ts
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Non-ok responses map to ApiError carrying the platform envelope
|
|
11
11
|
* {error, code, details?} so output.ts can tell the 402/403 stories — read
|
|
12
|
-
* through core/error-envelope.ts, which also accepts
|
|
13
|
-
* nested spellings some services answer with.
|
|
12
|
+
* through core/error-envelope.ts, which also accepts RFC 9457 problems and
|
|
13
|
+
* the code-first and nested spellings some services answer with.
|
|
14
14
|
*/
|
|
15
15
|
export declare class ApiError extends Error {
|
|
16
16
|
readonly status: number;
|
|
@@ -22,12 +22,23 @@ export declare class ApiError extends Error {
|
|
|
22
22
|
/** The response body as the API sent it (parsed JSON, or {} when it was not JSON): what --json prints. */
|
|
23
23
|
body?: unknown | undefined);
|
|
24
24
|
}
|
|
25
|
+
/** One query value; a list repeats the parameter (`?page=/a&page=/b`). */
|
|
26
|
+
export type QueryValue = string | number | boolean;
|
|
27
|
+
/** The final answer's status line, as `CallOptions.onResponse` is told it. */
|
|
28
|
+
export interface ResponseLine {
|
|
29
|
+
readonly status: number;
|
|
30
|
+
readonly headers: Headers;
|
|
31
|
+
}
|
|
25
32
|
export interface CallOptions {
|
|
26
33
|
method: string;
|
|
27
34
|
path: string;
|
|
28
|
-
query?: Record<string,
|
|
35
|
+
query?: Record<string, QueryValue | readonly QueryValue[] | undefined>;
|
|
29
36
|
body?: unknown;
|
|
37
|
+
/** Request headers a command sends (If-Match, Idempotency-Key). Never one the client owns: see CLIENT_HEADERS. */
|
|
38
|
+
headers?: Record<string, string>;
|
|
30
39
|
signal?: AbortSignal;
|
|
40
|
+
/** Told the final answer's status and headers (after any 401 retry), success or not, before it is read. */
|
|
41
|
+
onResponse?: (line: ResponseLine) => void;
|
|
31
42
|
}
|
|
32
43
|
/** The narrow auth port — both members required so a fake-retry can't hide. */
|
|
33
44
|
export interface TokenSource {
|
package/dist/core/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/core/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/core/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,qBAAa,QAAS,SAAQ,KAAK;IAG/B,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC1C,0GAA0G;IAC1G,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO;gBALvB,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;IAC1C,0GAA0G;IACjG,IAAI,CAAC,EAAE,OAAO,YAAA;CAK1B;AAED,0EAA0E;AAC1E,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnD,8EAA8E;AAC9E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,UAAU,EAAE,GAAG,SAAS,CAAC,CAAC;IACvE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,kHAAkH;IAClH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,M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