@nasebanal/cli 0.12.0 → 0.14.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/README.md +283 -79
- package/dist/apis.js +2 -1
- package/dist/auth.js +75 -2
- package/dist/config.js +30 -0
- package/dist/index.js +12 -3
- package/dist/reports/monitors.js +57 -0
- package/dist/reports/upload.js +119 -252
- package/dist/spec/build.js +65 -12
- package/dist/specs/apiVersion.js +38 -0
- package/dist/specs/command.js +212 -13
- package/dist/specs/docs.js +73 -0
- package/dist/specs/pull.js +18 -13
- package/dist/specs/push.js +227 -16
- package/dist/specs/resolve.js +182 -0
- package/dist/specs/servers.js +88 -0
- package/dist/specs/settings.js +48 -0
- package/package.json +1 -1
- package/specs/account.yaml +90 -1
- package/specs/assurance.yaml +229 -1215
- package/specs/recorder.yaml +253 -1
- package/specs/specs.yaml +1587 -0
- package/specs/target.yaml +187 -1
package/dist/index.js
CHANGED
|
@@ -14,7 +14,8 @@ import { buildAuthCommand } from "./auth.js";
|
|
|
14
14
|
import { specExists } from "./spec/loader.js";
|
|
15
15
|
import { printError } from "./output.js";
|
|
16
16
|
import { buildReportUploadCommand } from "./reports/upload.js";
|
|
17
|
-
import {
|
|
17
|
+
import { attachMonitorSpecOptions } from "./reports/monitors.js";
|
|
18
|
+
import { attachSpecsCommands, buildSpecsCommand } from "./specs/command.js";
|
|
18
19
|
import { buildUpgradeCommand, startUpdateNotifier } from "./update.js";
|
|
19
20
|
// Single source of truth for the version: package.json (dist/ and src/ both sit
|
|
20
21
|
// next to it). A hard-coded string here drifts from the release tag.
|
|
@@ -29,9 +30,13 @@ program
|
|
|
29
30
|
.showHelpAfterError();
|
|
30
31
|
program.addCommand(buildAuthCommand());
|
|
31
32
|
program.addCommand(buildUpgradeCommand(version));
|
|
32
|
-
program.addCommand(buildSpecsCommand());
|
|
33
33
|
for (const api of API_CATALOG) {
|
|
34
34
|
if (!specExists(api.spec)) {
|
|
35
|
+
// `nb specs push` / `pull` need no contract to run: without one the old standalone group still works.
|
|
36
|
+
if (api.name === "specs") {
|
|
37
|
+
program.addCommand(buildSpecsCommand());
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
35
40
|
// Spec not synced yet — register a stub that explains how to fix it rather
|
|
36
41
|
// than crashing the whole CLI.
|
|
37
42
|
program
|
|
@@ -46,11 +51,15 @@ for (const api of API_CATALOG) {
|
|
|
46
51
|
}
|
|
47
52
|
const group = buildApiCommand(api);
|
|
48
53
|
// `assurance report` already holds the generated availability report; the
|
|
49
|
-
// hand-written `upload` (test-result files -> a
|
|
54
|
+
// hand-written `upload` (test-result files -> a spec) joins it.
|
|
50
55
|
if (api.name === "assurance") {
|
|
51
56
|
const report = group.commands.find((c) => c.name() === "report") ?? group.command("report").description("Reports");
|
|
52
57
|
report.addCommand(buildReportUploadCommand());
|
|
58
|
+
attachMonitorSpecOptions(group);
|
|
53
59
|
}
|
|
60
|
+
// `nb specs`: the generated tree plus the pipeline verbs (`specs push`, `repositories upsert`) and the old direct form.
|
|
61
|
+
if (api.name === "specs")
|
|
62
|
+
attachSpecsCommands(group);
|
|
54
63
|
program.addCommand(group);
|
|
55
64
|
}
|
|
56
65
|
async function main() {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolveAccessToken, resolveEnv } from "../config.js";
|
|
3
|
+
import { checkOrg, specsBaseUrl } from "../specs/push.js";
|
|
4
|
+
import { resolveSpec } from "../specs/resolve.js";
|
|
5
|
+
import { specRefOf } from "./upload.js";
|
|
6
|
+
function readBody(data) {
|
|
7
|
+
if (data === undefined)
|
|
8
|
+
return {};
|
|
9
|
+
const raw = data.startsWith("@") ? readFileSync(data.slice(1), "utf8") : data;
|
|
10
|
+
let parsed;
|
|
11
|
+
try {
|
|
12
|
+
parsed = JSON.parse(raw);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
throw new Error(`--data must be valid JSON (or @file containing JSON); got: ${data}`);
|
|
16
|
+
}
|
|
17
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
18
|
+
throw new Error("--data must be a JSON object");
|
|
19
|
+
return parsed;
|
|
20
|
+
}
|
|
21
|
+
const NAMES = ["specId", "repository", "component", "group", "apiVersion", "spec", "repositoryProvider"];
|
|
22
|
+
/** Add the spec options to one generated leaf (`create` or `update`) and resolve them just before it runs. */
|
|
23
|
+
function attach(leaf, required) {
|
|
24
|
+
leaf
|
|
25
|
+
.option("--spec-id <id>", `the spec this monitor is about, by its id in the catalog${required ? " (default: $NB_SPEC_ID)" : ""}: sets spec_id and repository_id. Exclusive with --repository / --component / --spec`)
|
|
26
|
+
.option("--repository <owner/name>", "by names: the repository the spec is tied to; needs --spec (--component optional: none = the repository as a whole)")
|
|
27
|
+
.option("--component <name>", "by names: the component part of the repository's key; optional")
|
|
28
|
+
.option("--group <name>", "by names: the group the spec is filed in (an environment, say); optional, none = the specs in no group (not any group)")
|
|
29
|
+
.option("--api-version <v>", "by names: the API version (v1, v2) of the spec, part of its key; left out = the API version of the one spec the rest of the key matches (several: the error lists them)")
|
|
30
|
+
.option("--spec <name>", "by names: the spec's name in the catalog; needs --repository")
|
|
31
|
+
.option("--repository-provider <provider>", "with --repository: github | gitlab | bitbucket | other (default: github)");
|
|
32
|
+
leaf.hook("preAction", async (thisCommand) => {
|
|
33
|
+
const opts = thisCommand.optsWithGlobals();
|
|
34
|
+
const asked = NAMES.some((n) => opts[n] !== undefined);
|
|
35
|
+
const body = readBody(opts.data);
|
|
36
|
+
// `create` must say which spec; `update` only when it moves the monitor (or the body already carries both ids).
|
|
37
|
+
if (!asked && !required)
|
|
38
|
+
return;
|
|
39
|
+
if (!asked && body.spec_id !== undefined && body.repository_id !== undefined)
|
|
40
|
+
return;
|
|
41
|
+
const ref = specRefOf(opts);
|
|
42
|
+
const env = opts.env || resolveEnv();
|
|
43
|
+
const hit = await resolveSpec({ baseUrl: specsBaseUrl(env), token: opts.token || (await resolveAccessToken()), org: checkOrg(opts.org ?? process.env.NB_ASSURANCE_ORG ?? process.env.NB_SPECS_ORG) }, ref);
|
|
44
|
+
thisCommand.setOptionValue("data", JSON.stringify({ ...body, spec_id: hit.spec_id, repository_id: hit.repository_id }));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Called once on the generated `assurance` group. */
|
|
48
|
+
export function attachMonitorSpecOptions(assurance) {
|
|
49
|
+
const monitors = assurance.commands.find((c) => c.name() === "monitors");
|
|
50
|
+
if (!monitors)
|
|
51
|
+
return;
|
|
52
|
+
for (const [verb, required] of [["create", true], ["update", false]]) {
|
|
53
|
+
const leaf = monitors.commands.find((c) => c.name() === verb);
|
|
54
|
+
if (leaf)
|
|
55
|
+
attach(leaf, required);
|
|
56
|
+
}
|
|
57
|
+
}
|