Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@voosh/cli",
"version": "0.1.0",
"version": "0.1.1",
"description": "Node.js CLI for the voosh API.",
"license": "MIT",
"private": false,
Expand Down
5 changes: 4 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function buildProgram(runtime: CliRuntime = {}): Command {
.description("Node.js CLI for the voosh API.")
.option("--json", "Emit stable JSON output.")
.option("--quiet", "Suppress human success output.")
.option("--api-url <url>", "voosh API host URL (defaults to VOOSH_API_URL or http://localhost:8000).")
.option("--api-url <url>", "voosh API host URL (defaults to VOOSH_API_URL or https://voo.sh).")
.option("--profile <name>", "Configuration profile name.", "default")
.option("--timezone <zone>", "Timezone for natural event/slot datetimes: --timezone > VOOSH_TIMEZONE > UTC. Only UTC is currently supported.")
.option("--no-color", "Disable colored output.")
Expand All @@ -176,6 +176,9 @@ export function buildProgram(runtime: CliRuntime = {}): Command {
await clientFactory({ baseUrl: context.config.apiUrl, token }).me.retrieve();
}
updateProfile(context.config.configPath, context.config.profile, (profile) => {
if (context.config.apiUrlSource === "flag") {
profile.apiUrl = context.config.apiUrl;
}
profile.token = token;
});
renderResult(context.io, authStatusData(resolveConfig(getGlobals(this), env), "saved"), {
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export interface VooshClient {
}

export function createVooshClient(options: VooshClientOptions = {}): VooshClient {
const baseUrl = stripTrailingSlash(options.baseUrl ?? "http://localhost:8000");
const baseUrl = stripTrailingSlash(options.baseUrl ?? "https://voo.sh");
const fetchImplementation = options.fetch ?? globalThis.fetch;

if (!fetchImplementation) {
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface StoredConfig {

export type ConfigValueSource = "flag" | "env" | "profile" | "default";

const DEFAULT_API_URL = "http://localhost:8000";
const DEFAULT_API_URL = "https://voo.sh";
const DEFAULT_PROFILE = "default";

export function resolveConfig(options: GlobalOptions, env: CliEnv): CliConfig {
Expand Down
32 changes: 31 additions & 1 deletion tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,23 @@ describe("voosh node CLI", () => {
});
});

it("defaults to production voo.sh host for first-run API commands", async () => {
await withConfigPath(async (configPath) => {
const io = createIo();
const client = createClient();
const createClientMock = vi.fn(() => client);

const exitCode = await run(["me", "show"], {
env: { VOOSH_CONFIG_PATH: configPath, VOOSH_API_TOKEN: "token-123" },
io,
createClient: createClientMock,
});

expect(exitCode).toBe(0);
expect(createClientMock).toHaveBeenCalledWith({ baseUrl: "https://voo.sh", token: "token-123" });
});
});

it("auth login verifies by default before saving", async () => {
await withConfigPath(async (configPath) => {
const io = createIo();
Expand All @@ -1210,7 +1227,20 @@ describe("voosh node CLI", () => {
expect(exitCode).toBe(0);
expect(createClientMock).toHaveBeenCalledWith({ baseUrl: "https://api.example.test", token: "verify-token" });
expect(client.me.retrieve).toHaveBeenCalledOnce();
expect(JSON.parse(output(io.stdout))).toMatchObject({ code: "saved", token_configured: true });
expect(JSON.parse(output(io.stdout))).toMatchObject({
code: "saved",
base_url: "https://api.example.test",
api_url_source: "flag",
token_configured: true,
});
expect(JSON.parse(await readFile(configPath, "utf8"))).toEqual({
profiles: {
default: {
apiUrl: "https://api.example.test",
token: "verify-token",
},
},
});
});
});

Expand Down
Loading