@spec0/cli 0.4.1 → 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/README.md +3 -2
- package/dist/commands/api/changelog.d.ts.map +1 -1
- package/dist/commands/api/changelog.js +10 -7
- package/dist/commands/api/changelog.js.map +1 -1
- package/dist/commands/api/delete.d.ts +10 -0
- package/dist/commands/api/delete.d.ts.map +1 -0
- package/dist/commands/api/delete.js +72 -0
- package/dist/commands/api/delete.js.map +1 -0
- package/dist/commands/api/index.d.ts.map +1 -1
- package/dist/commands/api/index.js +2 -0
- package/dist/commands/api/index.js.map +1 -1
- package/dist/commands/api/list.d.ts.map +1 -1
- package/dist/commands/api/list.js +10 -7
- package/dist/commands/api/list.js.map +1 -1
- package/dist/commands/api/show.d.ts +5 -2
- package/dist/commands/api/show.d.ts.map +1 -1
- package/dist/commands/api/show.js +80 -18
- package/dist/commands/api/show.js.map +1 -1
- package/dist/commands/auth.d.ts +5 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +49 -31
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/ci/generate.d.ts.map +1 -1
- package/dist/commands/ci/generate.js +10 -7
- package/dist/commands/ci/generate.js.map +1 -1
- package/dist/commands/log.d.ts.map +1 -1
- package/dist/commands/log.js +10 -5
- package/dist/commands/log.js.map +1 -1
- package/dist/commands/mcp.d.ts +7 -1
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +135 -29
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/mock/create.d.ts.map +1 -1
- package/dist/commands/mock/create.js +10 -7
- package/dist/commands/mock/create.js.map +1 -1
- package/dist/commands/mock/delete.d.ts +11 -0
- package/dist/commands/mock/delete.d.ts.map +1 -0
- package/dist/commands/mock/delete.js +65 -0
- package/dist/commands/mock/delete.js.map +1 -0
- package/dist/commands/mock/index.d.ts.map +1 -1
- package/dist/commands/mock/index.js +2 -0
- package/dist/commands/mock/index.js.map +1 -1
- package/dist/commands/mock/list.d.ts.map +1 -1
- package/dist/commands/mock/list.js +10 -7
- package/dist/commands/mock/list.js.map +1 -1
- package/dist/commands/mock/show.d.ts.map +1 -1
- package/dist/commands/mock/show.js +10 -7
- package/dist/commands/mock/show.js.map +1 -1
- package/dist/commands/mock/url.d.ts.map +1 -1
- package/dist/commands/mock/url.js +12 -5
- package/dist/commands/mock/url.js.map +1 -1
- package/dist/commands/publish.js +2 -2
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +12 -5
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +5 -0
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/search.d.ts.map +1 -1
- package/dist/commands/search.js +13 -9
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +10 -5
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync-status.d.ts.map +1 -1
- package/dist/commands/sync-status.js +10 -7
- package/dist/commands/sync-status.js.map +1 -1
- package/dist/commands/team/create.d.ts.map +1 -1
- package/dist/commands/team/create.js +11 -10
- package/dist/commands/team/create.js.map +1 -1
- package/dist/commands/team/delete.d.ts.map +1 -1
- package/dist/commands/team/delete.js +11 -8
- package/dist/commands/team/delete.js.map +1 -1
- package/dist/commands/team/list.d.ts.map +1 -1
- package/dist/commands/team/list.js +11 -9
- package/dist/commands/team/list.js.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/api-client.d.ts +12 -2
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js +65 -14
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/config.d.ts +11 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +14 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/errors.d.ts +46 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +99 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/http-trace.d.ts +37 -0
- package/dist/lib/http-trace.d.ts.map +1 -0
- package/dist/lib/http-trace.js +101 -0
- package/dist/lib/http-trace.js.map +1 -0
- package/dist/lib/output.d.ts +4 -0
- package/dist/lib/output.d.ts.map +1 -1
- package/dist/lib/output.js +8 -0
- package/dist/lib/output.js.map +1 -1
- package/dist/lib/platform-defaults.d.ts +29 -4
- package/dist/lib/platform-defaults.d.ts.map +1 -1
- package/dist/lib/platform-defaults.js +34 -4
- package/dist/lib/platform-defaults.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -108,7 +108,6 @@ Every command supports `--output=text|json|yaml`. Progress / logs go to stderr,
|
|
|
108
108
|
| `spec0 auth login` | Browser-based login; stores API key locally. |
|
|
109
109
|
| `spec0 auth logout` | Clear the locally stored token. |
|
|
110
110
|
| `spec0 auth status` | Print the active org + key metadata. |
|
|
111
|
-
| `spec0 auth switch` | Switch the default org (multi-tenant setups). |
|
|
112
111
|
| `spec0 whoami` | One-line org + user summary. |
|
|
113
112
|
| `spec0 doctor` | Print which source each setting resolved from (env / config / default). |
|
|
114
113
|
|
|
@@ -156,7 +155,8 @@ Every command supports `--output=text|json|yaml`. Progress / logs go to stderr,
|
|
|
156
155
|
| -------------------------- | ------------------------------------------------------------------------ |
|
|
157
156
|
| `spec0 commands` | List every command with its flags, args, and exit codes (JSON-friendly). |
|
|
158
157
|
| `spec0 commands <pattern>` | Filter the manifest by substring. |
|
|
159
|
-
| `spec0 mcp url` | Print the MCP server
|
|
158
|
+
| `spec0 mcp url` | Print the MCP (Streamable HTTP) server config for Cursor / Claude. |
|
|
159
|
+
| `spec0 mcp install` | Install the MCP server into Cursor and/or Claude (`--client`). |
|
|
160
160
|
|
|
161
161
|
### Other
|
|
162
162
|
|
|
@@ -177,6 +177,7 @@ Two paths:
|
|
|
177
177
|
| `SPEC0_ORG_ID` | UUID of the org the CLI acts against. | _required_ |
|
|
178
178
|
| `SPEC0_API_URL` | Platform backend base URL. | `https://api.spec0.io` |
|
|
179
179
|
| `SPEC0_APP_URL` | Platform web app (used for auth callback + dashboard links). | `https://spec0.io` |
|
|
180
|
+
| `SPEC0_MCP_URL` | MCP server endpoint (single Streamable HTTP URL) emitted by `spec0 mcp url` / `mcp install`. | `https://api.spec0.io/mcp` |
|
|
180
181
|
| `SPEC0_MODE` | Set to `agent` to flip every default for machine callers: JSON output, no colour, no spinners, no update banner. See the [agent guide](docs/guides/ai-agents.md). | _unset_ (human mode) |
|
|
181
182
|
|
|
182
183
|
`PLATFORM_*` variants are accepted for backwards compatibility; they'll be removed in the next major. Use `spec0 doctor` to see which source each value is resolving from.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changelog.d.ts","sourceRoot":"","sources":["../../../src/commands/api/changelog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"changelog.d.ts","sourceRoot":"","sources":["../../../src/commands/api/changelog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0BpC,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,QA2EvD"}
|
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import chalk from "chalk";
|
|
12
12
|
import { PublicRegistryService, PublicSpecsService } from "@spec0/sdk-public-platform";
|
|
13
|
-
import { configureSdkAuth
|
|
13
|
+
import { configureSdkAuth } from "../../lib/api-client.js";
|
|
14
14
|
import { requireOrgContext } from "../../lib/auth-context.js";
|
|
15
15
|
import { ExitCode } from "../../lib/exit-codes.js";
|
|
16
|
+
import { failApi } from "../../lib/errors.js";
|
|
17
|
+
import { setHttpTrace } from "../../lib/http-trace.js";
|
|
16
18
|
import { emit, fail, resolveOutputContext, } from "../../lib/output/index.js";
|
|
17
19
|
import { resolveRef, resolveApiId } from "../../lib/ref-resolver.js";
|
|
18
20
|
import { getDefaultOrgId, getOrgConfig } from "../../lib/config.js";
|
|
@@ -24,8 +26,10 @@ export function registerApiChangelogCommand(api) {
|
|
|
24
26
|
.option("--to <tag>", "Later version tag (default: latest published)")
|
|
25
27
|
.option("--org <uuid>", "Org id override")
|
|
26
28
|
.option("--output <format>", "Output format: text, json, markdown, or yaml (default: text)")
|
|
29
|
+
.option("--verbose", "Print HTTP request/response traces to stderr")
|
|
27
30
|
.action(async (ref, opts) => {
|
|
28
31
|
const outCtx = resolveOutputContext(opts);
|
|
32
|
+
setHttpTrace(outCtx.verbose);
|
|
29
33
|
let authCtx;
|
|
30
34
|
try {
|
|
31
35
|
authCtx = requireOrgContext(opts.org);
|
|
@@ -69,17 +73,16 @@ export function registerApiChangelogCommand(api) {
|
|
|
69
73
|
emit(outCtx, payload, renderChangelogText);
|
|
70
74
|
}
|
|
71
75
|
catch (err) {
|
|
72
|
-
if (is401(err)) {
|
|
73
|
-
fail(outCtx, ExitCode.AUTH_MISSING, "Token invalid or expired.", {
|
|
74
|
-
hint: "Run 'spec0 auth login' or refresh SPEC0_TOKEN.",
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
76
|
if (err.message?.includes("No API named")) {
|
|
78
77
|
fail(outCtx, ExitCode.NOT_FOUND, err.message, {
|
|
79
78
|
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
80
79
|
});
|
|
81
80
|
}
|
|
82
|
-
|
|
81
|
+
failApi(outCtx, err, {
|
|
82
|
+
action: "api changelog",
|
|
83
|
+
org: authCtx.orgName ?? authCtx.orgId,
|
|
84
|
+
apiUrl: authCtx.apiUrl,
|
|
85
|
+
});
|
|
83
86
|
}
|
|
84
87
|
});
|
|
85
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changelog.js","sourceRoot":"","sources":["../../../src/commands/api/changelog.ts"],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teTeamApi (`DELETE /api/v1/public/apis/team/{apiId}`).
|
|
5
|
+
* Resolves <ref> (name or UUID) via the shared ref-resolver. Requires `--yes`.
|
|
6
|
+
* Mirrors `spec0 team delete`'s destructive-op contract.
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
export declare function registerApiDeleteCommand(api: Command): void;
|
|
10
|
+
//# sourceMappingURL=delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/commands/api/delete.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBpC,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,QA6DpD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* spec0 api delete <ref> — delete a team-scoped API.
|
|
3
|
+
*
|
|
4
|
+
* Uses PublicApisService.deleteTeamApi (`DELETE /api/v1/public/apis/team/{apiId}`).
|
|
5
|
+
* Resolves <ref> (name or UUID) via the shared ref-resolver. Requires `--yes`.
|
|
6
|
+
* Mirrors `spec0 team delete`'s destructive-op contract.
|
|
7
|
+
*/
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import { PublicApisService } from "@spec0/sdk-public-platform";
|
|
10
|
+
import { configureSdkAuth, errorStatusCode } from "../../lib/api-client.js";
|
|
11
|
+
import { requireOrgContext } from "../../lib/auth-context.js";
|
|
12
|
+
import { ExitCode } from "../../lib/exit-codes.js";
|
|
13
|
+
import { failApi } from "../../lib/errors.js";
|
|
14
|
+
import { setHttpTrace } from "../../lib/http-trace.js";
|
|
15
|
+
import { fail, progress, resolveOutputContext, } from "../../lib/output/index.js";
|
|
16
|
+
import { resolveRef, resolveApiId } from "../../lib/ref-resolver.js";
|
|
17
|
+
export function registerApiDeleteCommand(api) {
|
|
18
|
+
api
|
|
19
|
+
.command("delete <ref>")
|
|
20
|
+
.description("Delete a team-scoped API (name or UUID). Requires --yes.")
|
|
21
|
+
.option("--yes", "Skip the confirmation prompt (required for non-interactive use)")
|
|
22
|
+
.option("--org <uuid>", "Org id override")
|
|
23
|
+
.option("--output <format>", "Output format: text, json, or yaml (default: text)")
|
|
24
|
+
.option("--verbose", "Print HTTP request/response traces to stderr")
|
|
25
|
+
.action(async (ref, opts) => {
|
|
26
|
+
const outCtx = resolveOutputContext(opts);
|
|
27
|
+
setHttpTrace(outCtx.verbose);
|
|
28
|
+
if (!ref.trim()) {
|
|
29
|
+
fail(outCtx, ExitCode.USAGE, "API ref is required.");
|
|
30
|
+
}
|
|
31
|
+
if (!opts.yes) {
|
|
32
|
+
fail(outCtx, ExitCode.USAGE, "Refusing to delete without confirmation. Pass --yes to proceed.", { hint: "spec0 api delete <ref> --yes" });
|
|
33
|
+
}
|
|
34
|
+
let authCtx;
|
|
35
|
+
try {
|
|
36
|
+
authCtx = requireOrgContext(opts.org);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
fail(outCtx, ExitCode.AUTH_MISSING, e.message, {
|
|
40
|
+
hint: "Set SPEC0_TOKEN + SPEC0_ORG_ID, or run 'spec0 auth login'.",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
configureSdkAuth(authCtx);
|
|
44
|
+
let apiId;
|
|
45
|
+
try {
|
|
46
|
+
apiId = await resolveApiId(resolveRef(ref, { defaultOrg: authCtx.orgName }));
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
fail(outCtx, ExitCode.NOT_FOUND, e.message, {
|
|
50
|
+
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await PublicApisService.deleteTeamApi({ apiId });
|
|
55
|
+
progress(outCtx, chalk.green(`✓ Deleted API ${ref} (${apiId})`));
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
const status = errorStatusCode(err);
|
|
59
|
+
if (status === 404) {
|
|
60
|
+
fail(outCtx, ExitCode.NOT_FOUND, `API ${ref} not found.`, {
|
|
61
|
+
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
failApi(outCtx, err, {
|
|
65
|
+
action: "api delete",
|
|
66
|
+
org: authCtx.orgName ?? authCtx.orgId,
|
|
67
|
+
apiUrl: authCtx.apiUrl,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/commands/api/delete.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,oBAAoB,GAErB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,UAAU,wBAAwB,CAAC,GAAY;IACnD,GAAG;SACA,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,OAAO,EAAE,iEAAiE,CAAC;SAClF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC;SACzC,MAAM,CAAC,mBAAmB,EAAE,oD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AC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YACjD,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,iBAAiB,GAAG,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC;QACnE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;YACpC,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;gBACnB,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,aAAa,EAAE;oBACxD,IAAI,EAAE,sDAAsD;iBAC7D,CAAC,CAAC;YACL,CAAC;YACD,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE;gBACnB,MAAM,EAAE,YAAY;gBACpB,GAAG,EAAE,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK;gBACrC,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,QAMnD"}
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
import { registerApiListCommand } from "./list.js";
|
|
5
5
|
import { registerApiShowCommand } from "./show.js";
|
|
6
6
|
import { registerApiChangelogCommand } from "./changelog.js";
|
|
7
|
+
import { registerApiDeleteCommand } from "./delete.js";
|
|
7
8
|
export function registerApiCommands(program) {
|
|
8
9
|
const api = program.command("api").description("Manage APIs in your organisation");
|
|
9
10
|
registerApiListCommand(api);
|
|
10
11
|
registerApiShowCommand(api);
|
|
11
12
|
registerApiChangelogCommand(api);
|
|
13
|
+
registerApiDeleteCommand(api);
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,kCAAkC,CAAC,CAAC;IACnF,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC5B,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC5B,2BAA2B,CAAC,GAAG,CAAC,CAAC;IACjC,wBAAwB,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/api/list.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/api/list.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,QA2ClD"}
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* filter and those columns are dropped accordingly.
|
|
8
8
|
*/
|
|
9
9
|
import { PublicApisService } from "@spec0/sdk-public-platform";
|
|
10
|
-
import { configureSdkAuth
|
|
10
|
+
import { configureSdkAuth } from "../../lib/api-client.js";
|
|
11
11
|
import { requireOrgContext } from "../../lib/auth-context.js";
|
|
12
12
|
import { ExitCode } from "../../lib/exit-codes.js";
|
|
13
|
+
import { failApi } from "../../lib/errors.js";
|
|
14
|
+
import { setHttpTrace } from "../../lib/http-trace.js";
|
|
13
15
|
import { emit, fail, resolveOutputContext } from "../../lib/output/index.js";
|
|
14
16
|
import { renderTable } from "../../lib/output/table.js";
|
|
15
17
|
export function registerApiListCommand(api) {
|
|
@@ -20,8 +22,10 @@ export function registerApiListCommand(api) {
|
|
|
20
22
|
.option("--search <query>", "Filter by name substring (case-insensitive)")
|
|
21
23
|
.option("--org <uuid>", "Org id override")
|
|
22
24
|
.option("--output <format>", "Output format: text, json, or yaml (default: text)")
|
|
25
|
+
.option("--verbose", "Print HTTP request/response traces to stderr")
|
|
23
26
|
.action(async (opts) => {
|
|
24
27
|
const outCtx = resolveOutputContext(opts);
|
|
28
|
+
setHttpTrace(outCtx.verbose);
|
|
25
29
|
let authCtx;
|
|
26
30
|
try {
|
|
27
31
|
authCtx = requireOrgContext(opts.org);
|
|
@@ -38,12 +42,11 @@ export function registerApiListCommand(api) {
|
|
|
38
42
|
emit(outCtx, filtered, renderApiListText);
|
|
39
43
|
}
|
|
40
44
|
catch (err) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
fail(outCtx, ExitCode.GENERIC, `api list failed: ${err.message}`);
|
|
45
|
+
failApi(outCtx, err, {
|
|
46
|
+
action: "api list",
|
|
47
|
+
org: authCtx.orgName ?? authCtx.orgId,
|
|
48
|
+
apiUrl: authCtx.apiUrl,
|
|
49
|
+
});
|
|
47
50
|
}
|
|
48
51
|
});
|
|
49
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/commands/api/list.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/commands/api/list.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,oBAAoB,EAAsB,MAAM,2BAA2B,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,UAAU,sBAAsB,CAAC,GAAY;IACjD,GAAG;SACA,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,kDAAkD,CAAC;SAC/D,MAAM,CAAC,eAAe,EAAE,wCAAwC,CAAC;SACjE,MAAM,CAAC,kBAAkB,EAAE,6CAA6C,CAAC;SACzE,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC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,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACpC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAyB;IAClD,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,OAAO,6CAA6C,CAAC;IACvE,OAAO,WAAW,CAAC,IAA4C,EAAE;QAC/D,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE;QAClC,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE;QACjC,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE;QACnC,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE;KACxC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* spec0 api show <ref> — single-API metadata.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Prefers the rich internal GET /apis/{apiId}/summary (operations, env configs,
|
|
5
|
+
* subscriber count). A team/public principal (e.g. a SAT) isn't entitled to
|
|
6
|
+
* that endpoint (403) and some ids aren't present there (404), so it falls back
|
|
7
|
+
* to the leaner V1 team-API row, which the same principal can read.
|
|
8
|
+
* Resolves <ref> via ref-resolver: accepts <org>/<api>, bare <api>, or a UUID.
|
|
6
9
|
*/
|
|
7
10
|
import { Command } from "commander";
|
|
8
11
|
export declare function registerApiShowCommand(api: Command): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"show.d.ts","sourceRoot":"","sources":["../../../src/commands/api/show.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"show.d.ts","sourceRoot":"","sources":["../../../src/commands/api/show.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8CpC,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,QA2FlD"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* spec0 api show <ref> — single-API metadata.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Prefers the rich internal GET /apis/{apiId}/summary (operations, env configs,
|
|
5
|
+
* subscriber count). A team/public principal (e.g. a SAT) isn't entitled to
|
|
6
|
+
* that endpoint (403) and some ids aren't present there (404), so it falls back
|
|
7
|
+
* to the leaner V1 team-API row, which the same principal can read.
|
|
8
|
+
* Resolves <ref> via ref-resolver: accepts <org>/<api>, bare <api>, or a UUID.
|
|
6
9
|
*/
|
|
7
10
|
import chalk from "chalk";
|
|
8
|
-
import {
|
|
11
|
+
import { PublicApisService } from "@spec0/sdk-public-platform";
|
|
12
|
+
import { configureSdkAuth, createOrgApiClient, is401, errorStatusCode, } from "../../lib/api-client.js";
|
|
9
13
|
import { requireOrgContext } from "../../lib/auth-context.js";
|
|
10
14
|
import { ExitCode } from "../../lib/exit-codes.js";
|
|
11
|
-
import {
|
|
15
|
+
import { failApi } from "../../lib/errors.js";
|
|
16
|
+
import { setHttpTrace } from "../../lib/http-trace.js";
|
|
17
|
+
import { emit, fail, progress, resolveOutputContext, } from "../../lib/output/index.js";
|
|
12
18
|
import { resolveRef, resolveApiId } from "../../lib/ref-resolver.js";
|
|
13
19
|
import { getDefaultOrgId, getOrgConfig } from "../../lib/config.js";
|
|
14
20
|
export function registerApiShowCommand(api) {
|
|
@@ -17,8 +23,10 @@ export function registerApiShowCommand(api) {
|
|
|
17
23
|
.description("Show metadata for a single API (no spec body).")
|
|
18
24
|
.option("--org <uuid>", "Org id override")
|
|
19
25
|
.option("--output <format>", "Output format: text, json, or yaml (default: text)")
|
|
26
|
+
.option("--verbose", "Print HTTP request/response traces to stderr")
|
|
20
27
|
.action(async (ref, opts) => {
|
|
21
28
|
const outCtx = resolveOutputContext(opts);
|
|
29
|
+
setHttpTrace(outCtx.verbose);
|
|
22
30
|
let authCtx;
|
|
23
31
|
try {
|
|
24
32
|
authCtx = requireOrgContext(opts.org);
|
|
@@ -41,19 +49,26 @@ export function registerApiShowCommand(api) {
|
|
|
41
49
|
}
|
|
42
50
|
configureSdkAuth(authCtx);
|
|
43
51
|
const client = createOrgApiClient(authCtx);
|
|
52
|
+
// resolveApiId hits PublicApisService.listTeamApis (V1) for names; UUIDs
|
|
53
|
+
// pass through. A name miss throws "No API named …" → NOT_FOUND.
|
|
54
|
+
let apiId;
|
|
44
55
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!res.api) {
|
|
52
|
-
fail(outCtx, ExitCode.NOT_FOUND, `No API found for ref '${ref}'.`, {
|
|
53
|
-
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
56
|
+
apiId = await resolveApiId(parsed);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (is401(err)) {
|
|
60
|
+
fail(outCtx, ExitCode.AUTH_MISSING, "Token invalid or expired.", {
|
|
61
|
+
hint: "Run 'spec0 auth login' or refresh SPEC0_TOKEN.",
|
|
54
62
|
});
|
|
55
63
|
}
|
|
56
|
-
|
|
64
|
+
fail(outCtx, ExitCode.NOT_FOUND, err.message, {
|
|
65
|
+
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
let summary;
|
|
69
|
+
try {
|
|
70
|
+
const res = (await client.getJson(`/apis/${apiId}/summary`));
|
|
71
|
+
summary = res.api;
|
|
57
72
|
}
|
|
58
73
|
catch (err) {
|
|
59
74
|
if (is401(err)) {
|
|
@@ -61,15 +76,62 @@ export function registerApiShowCommand(api) {
|
|
|
61
76
|
hint: "Run 'spec0 auth login' or refresh SPEC0_TOKEN.",
|
|
62
77
|
});
|
|
63
78
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
// 403 (principal not entitled to the internal summary) or 404 (id not
|
|
80
|
+
// on that surface) → fall back to the leaner V1 team-API row. Other
|
|
81
|
+
// statuses map to the stable exit code (5xx → SERVER_ERROR, …).
|
|
82
|
+
const status = errorStatusCode(err);
|
|
83
|
+
if (status === 403 || status === 404) {
|
|
84
|
+
summary = await leanSummaryFromList(apiId, parsed);
|
|
85
|
+
if (summary) {
|
|
86
|
+
progress(outCtx, chalk.gray("note: limited metadata — operations, environments and subscribers need internal API access."));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
failApi(outCtx, err, {
|
|
91
|
+
action: "api show",
|
|
92
|
+
org: authCtx.orgName ?? authCtx.orgId,
|
|
93
|
+
apiUrl: authCtx.apiUrl,
|
|
67
94
|
});
|
|
68
95
|
}
|
|
69
|
-
fail(outCtx, ExitCode.GENERIC, `api show failed: ${err.message}`);
|
|
70
96
|
}
|
|
97
|
+
if (!summary) {
|
|
98
|
+
fail(outCtx, ExitCode.NOT_FOUND, `No API found for ref '${ref}'.`, {
|
|
99
|
+
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
emit(outCtx, summary, renderApiShowText);
|
|
71
103
|
});
|
|
72
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Build a lean ApiSummary from the V1 team-API list, used when the rich
|
|
107
|
+
* internal summary is unavailable to the caller (e.g. a team SAT → 403).
|
|
108
|
+
* Matches on the resolved id first, then the name for a `<org>/<api>` ref.
|
|
109
|
+
*/
|
|
110
|
+
async function leanSummaryFromList(apiId, ref) {
|
|
111
|
+
let rows;
|
|
112
|
+
try {
|
|
113
|
+
rows = await PublicApisService.listTeamApis();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// The fallback list is itself unavailable (e.g. an org-key principal has no
|
|
117
|
+
// team → 404). Degrade to "not found" rather than crashing.
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const wantedName = ref.kind === "name" ? ref.api.toLowerCase() : undefined;
|
|
121
|
+
const row = rows.find((r) => r.apiId === apiId) ??
|
|
122
|
+
(wantedName ? rows.find((r) => (r.apiName ?? "").toLowerCase() === wantedName) : undefined);
|
|
123
|
+
if (!row)
|
|
124
|
+
return undefined;
|
|
125
|
+
return {
|
|
126
|
+
apiId: row.apiId,
|
|
127
|
+
apiName: row.apiName,
|
|
128
|
+
version: row.version ?? undefined,
|
|
129
|
+
description: row.description ?? undefined,
|
|
130
|
+
teamId: row.teamId ?? undefined,
|
|
131
|
+
teamName: row.teamName ?? undefined,
|
|
132
|
+
updatedAt: row.updatedAt ?? undefined,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
73
135
|
function renderApiShowText(api) {
|
|
74
136
|
const lines = [];
|
|
75
137
|
lines.push(chalk.bold(`${api.apiName ?? "?"} ${chalk.gray(`v${api.version ?? "?"}`)}`));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"show.js","sourceRoot":"","sources":["../../../src/commands/api/show.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"show.js","sourceRoot":"","sources":["../../../src/commands/api/show.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4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4
|
+
* Single-org model: `login` replaces the stored org (see config.replaceSoleOrg),
|
|
5
|
+
* so there is no multi-org `switch`. Point at another backend for testing with
|
|
6
|
+
* the SPEC0_API_URL / SPEC0_APP_URL env vars.
|
|
3
7
|
*/
|
|
4
8
|
import { Command } from "commander";
|
|
5
9
|
export declare function registerAuthCommands(program: Command): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyCpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QAsKpD"}
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* spec0 auth login | logout | status | token
|
|
2
|
+
* spec0 auth login | logout | status | token
|
|
3
|
+
*
|
|
4
|
+
* Single-org model: `login` replaces the stored org (see config.replaceSoleOrg),
|
|
5
|
+
* so there is no multi-org `switch`. Point at another backend for testing with
|
|
6
|
+
* the SPEC0_API_URL / SPEC0_APP_URL env vars.
|
|
3
7
|
*/
|
|
4
8
|
import chalk from "chalk";
|
|
5
9
|
import { createServer } from "http";
|
|
6
10
|
import { randomBytes } from "crypto";
|
|
7
11
|
import open from "open";
|
|
8
|
-
import {
|
|
12
|
+
import { PublicOrgsService } from "@spec0/sdk-public-platform";
|
|
13
|
+
import { getDefaultOrgId, getOrgConfig, replaceSoleOrg, clearConfig } from "../lib/config.js";
|
|
14
|
+
import { resolveOrgContext } from "../lib/auth-context.js";
|
|
15
|
+
import { configureSdkAuth, errorStatusCode, extractErrorMessage } from "../lib/api-client.js";
|
|
9
16
|
import { resolvedPlatformAppUrl, resolvedPlatformApiUrl } from "../lib/platform-defaults.js";
|
|
10
|
-
import { ExitCode, exit } from "../lib/exit-codes.js";
|
|
17
|
+
import { ExitCode, exit, exitCodeForHttpStatus } from "../lib/exit-codes.js";
|
|
11
18
|
function getAppUrl() {
|
|
12
19
|
return resolvedPlatformAppUrl();
|
|
13
20
|
}
|
|
@@ -15,21 +22,22 @@ function getApiUrl() {
|
|
|
15
22
|
return resolvedPlatformApiUrl();
|
|
16
23
|
}
|
|
17
24
|
function printAuthStatus() {
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
// Reflect the context commands will actually use: SPEC0_* env vars override the stored login
|
|
26
|
+
// (resolveOrgContext applies that precedence). Reading only the stored config here misreported
|
|
27
|
+
// the active target whenever the env vars were set.
|
|
28
|
+
const ctx = resolveOrgContext();
|
|
29
|
+
if (!ctx) {
|
|
20
30
|
console.log(chalk.yellow("Not logged in. Run 'spec0 auth login'."));
|
|
21
31
|
console.log(chalk.gray("For CI/CD, set SPEC0_TOKEN and SPEC0_ORG_ID environment variables."));
|
|
22
32
|
return;
|
|
23
33
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
console.log(
|
|
30
|
-
console.log(`
|
|
31
|
-
console.log(` API URL: ${org.apiUrl}`);
|
|
32
|
-
console.log(` Key: ${org.keyName ?? "(unnamed)"}`);
|
|
34
|
+
const fromEnv = Boolean((process.env.SPEC0_TOKEN ?? process.env.PLATFORM_API_TOKEN) &&
|
|
35
|
+
(process.env.SPEC0_ORG_ID ?? process.env.PLATFORM_ORG_ID));
|
|
36
|
+
const stored = getOrgConfig(ctx.orgId);
|
|
37
|
+
console.log(chalk.green("✓ Logged in") + (fromEnv ? chalk.gray(" (via environment)") : ""));
|
|
38
|
+
console.log(` Org: ${ctx.orgName ?? ctx.orgId}`);
|
|
39
|
+
console.log(` API URL: ${ctx.apiUrl}`);
|
|
40
|
+
console.log(` Key: ${fromEnv ? "SPEC0_TOKEN (env)" : (stored?.keyName ?? "(unnamed)")}`);
|
|
33
41
|
}
|
|
34
42
|
export function registerAuthCommands(program) {
|
|
35
43
|
// Top-level whoami shorthand
|
|
@@ -111,15 +119,38 @@ export function registerAuthCommands(program) {
|
|
|
111
119
|
const apiUrlForStore = opts.apiUrl?.trim()
|
|
112
120
|
? opts.apiUrl.trim().replace(/\/$/, "")
|
|
113
121
|
: getApiUrl();
|
|
114
|
-
|
|
122
|
+
// Single-org model: the org you just authenticated becomes the one and
|
|
123
|
+
// only active org. Replacing (not merging) prevents a stale prior login —
|
|
124
|
+
// e.g. an old localhost entry — from remaining the silent default and
|
|
125
|
+
// making every later command fail against a dead host.
|
|
126
|
+
replaceSoleOrg(result.orgId, {
|
|
115
127
|
apiKey: result.token,
|
|
116
128
|
name: result.orgName,
|
|
117
129
|
apiUrl: apiUrlForStore,
|
|
118
130
|
keyName,
|
|
119
131
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
// Verify the stored credentials actually reach the platform before
|
|
133
|
+
// reporting success. The browser redirect only proves the user authorised
|
|
134
|
+
// the CLI; it does not prove the token + API base are usable. One
|
|
135
|
+
// lightweight authenticated call turns a later opaque "api list failed:
|
|
136
|
+
// Not Found" into an explicit, actionable error at login time.
|
|
137
|
+
configureSdkAuth({
|
|
138
|
+
orgId: result.orgId,
|
|
139
|
+
apiKey: result.token,
|
|
140
|
+
apiUrl: apiUrlForStore,
|
|
141
|
+
orgName: result.orgName,
|
|
142
|
+
});
|
|
143
|
+
try {
|
|
144
|
+
await PublicOrgsService.getOrgSummary();
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
const status = errorStatusCode(err);
|
|
148
|
+
const detail = extractErrorMessage(err) ?? err.message;
|
|
149
|
+
console.error(chalk.red(`Logged in, but could not reach the platform at ${apiUrlForStore}` +
|
|
150
|
+
(status ? ` (HTTP ${status})` : "") +
|
|
151
|
+
`: ${detail}`));
|
|
152
|
+
console.error(chalk.gray("Credentials were saved. Retry 'spec0 auth login', or set SPEC0_API_URL to a reachable backend."));
|
|
153
|
+
exit(exitCodeForHttpStatus(status));
|
|
123
154
|
}
|
|
124
155
|
console.log(chalk.green("Logged in successfully."));
|
|
125
156
|
console.log(` Org: ${result.orgName}`);
|
|
@@ -149,18 +180,5 @@ export function registerAuthCommands(program) {
|
|
|
149
180
|
exit(ExitCode.AUTH_MISSING);
|
|
150
181
|
console.log(org.apiKey);
|
|
151
182
|
});
|
|
152
|
-
auth
|
|
153
|
-
.command("switch <org-name>")
|
|
154
|
-
.description("Switch default org")
|
|
155
|
-
.action(async (orgName) => {
|
|
156
|
-
const config = getConfig();
|
|
157
|
-
const entry = Object.entries(config.orgs).find(([, o]) => o.name === orgName);
|
|
158
|
-
if (!entry) {
|
|
159
|
-
console.error(chalk.red(`Org '${orgName}' not found.`));
|
|
160
|
-
exit(ExitCode.NOT_FOUND);
|
|
161
|
-
}
|
|
162
|
-
setDefaultOrg(entry[0]);
|
|
163
|
-
console.log(chalk.green(`Switched to org: ${orgName}`));
|
|
164
|
-
});
|
|
165
183
|
}
|
|
166
184
|
//# sourceMappingURL=auth.js.map
|