diff --git a/package.json b/package.json index 9ed97cf..1350e9f 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@types/inquirer": "^9.0.7", "@types/node": "^22.13.0", "@types/ws": "^8.5.14", + "eslint": "^9.17.0", "tsup": "^8.0.0", "typescript": "^5.9.3", "vitest": "^4.0.16" diff --git a/src/commands/api/index.ts b/src/commands/api/index.ts index 6278306..a396f01 100644 --- a/src/commands/api/index.ts +++ b/src/commands/api/index.ts @@ -24,9 +24,12 @@ export function registerApiCommands(program: Command): void { } const baseUrl = config.projects[project]?.baseUrl ?? "https://wave.online"; - const url = path.startsWith("http") - ? path - : `${baseUrl}${path.startsWith("/") ? path : `/${path}`}`; + const base = new URL(baseUrl); + const requested = new URL(path, `${base.origin}/`); + if (requested.protocol !== "https:" || requested.origin !== base.origin) { + throw new Error("API requests must use the configured WAVE HTTPS host"); + } + const url = requested.toString(); const headers: Record = { Authorization: `Bearer ${apiKey}`, diff --git a/src/commands/auth/index.ts b/src/commands/auth/index.ts index 9ecfb90..15b7d15 100644 --- a/src/commands/auth/index.ts +++ b/src/commands/auth/index.ts @@ -19,6 +19,18 @@ export function registerAuthCommands(program: Command): void { const config = await loadConfig(); const project = config.currentProject || "default"; await storeApiKey(project, opts.apiKey); + await updateConfig((config) => ({ + ...config, + currentProject: project, + projects: { + ...config.projects, + [project]: config.projects[project] ?? { + organizationId: "", + organizationName: "", + baseUrl: process.env["WAVE_BASE_URL"] ?? "https://wave.online", + }, + }, + })); console.log(chalk.green(`API key stored for project "${project}".`)); return; } @@ -40,6 +52,14 @@ export function registerAuthCommands(program: Command): void { await updateConfig((config) => ({ ...config, currentProject: project, + projects: { + ...config.projects, + [project]: config.projects[project] ?? { + organizationId: "", + organizationName: "", + baseUrl, + }, + }, })); console.log(chalk.green("\nAuthentication complete. You can now use the WAVE CLI.")); diff --git a/src/commands/init/index.ts b/src/commands/init/index.ts index f1f5ff8..8a14d6d 100644 --- a/src/commands/init/index.ts +++ b/src/commands/init/index.ts @@ -2,7 +2,7 @@ import { Command } from "commander"; import chalk from "chalk"; import { writeFile, mkdir, readFile, readdir, copyFile } from "node:fs/promises"; import { existsSync } from "node:fs"; -import { join, dirname, resolve } from "node:path"; +import { join, dirname, resolve, sep } from "node:path"; import { fileURLToPath } from "node:url"; import { spawnSync } from "node:child_process"; import { wrapCommand } from "../../lib/errors.js"; @@ -56,7 +56,8 @@ const TEMPLATES: TemplateDefinition[] = [ function getTemplatesDir(): string { const thisFile = fileURLToPath(import.meta.url); // Walk up from src/commands/init/ or dist/commands/init/ to package root - const packageRoot = resolve(dirname(thisFile), "..", "..", ".."); + const fileDir = dirname(thisFile); + const packageRoot = fileDir.endsWith(`${sep}dist`) ? resolve(fileDir, "..") : resolve(fileDir, "..", "..", ".."); return join(packageRoot, "templates"); } diff --git a/src/lib/sse-client.ts b/src/lib/sse-client.ts index 63f1aec..bc4be74 100644 --- a/src/lib/sse-client.ts +++ b/src/lib/sse-client.ts @@ -93,7 +93,9 @@ export async function connectSSE( while (!controller.signal.aborted) { const { done, value } = await reader.read(); - if (done) break; + if (done) { + throw new Error("SSE connection closed"); + } buffer += decoder.decode(value, { stream: true }); diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 0000000..d714bc7 --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1,30 @@ +export interface DeviceAuthResponse { + device_code: string; + user_code: string; + verification_uri: string; + verification_uri_complete?: string; + expires_in: number; + interval: number; +} + +export interface TokenResponse { + access_token: string; + token_type?: string; + expires_in?: number; + refresh_token?: string; +} + +export interface WaveConfig { + version: string; + currentProject: string; + projects: Record; + defaults: { outputFormat: OutputFormat; protocol?: string; color: "auto" | "on" | "off" }; + telemetry: { enabled: boolean; errorReporting: boolean }; +} + +export type OutputFormat = "table" | "json" | "yaml"; diff --git a/templates/api-integration/package.json b/templates/api-integration/package.json index 4c3e541..f0b058d 100644 --- a/templates/api-integration/package.json +++ b/templates/api-integration/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@wave/sdk": "^2.0.0" + "@wave-av/sdk": "^2.0.0" }, "devDependencies": { "tsx": "^4.0.0", diff --git a/templates/api-integration/src/index.ts b/templates/api-integration/src/index.ts index b54a1bb..3dbd00d 100644 --- a/templates/api-integration/src/index.ts +++ b/templates/api-integration/src/index.ts @@ -1,4 +1,4 @@ -import { Wave } from "@wave/sdk"; +import { Wave } from "@wave-av/sdk"; const wave = new Wave({ apiKey: process.env.WAVE_API_KEY!, diff --git a/templates/blank/package.json b/templates/blank/package.json index 54d5320..1207de4 100644 --- a/templates/blank/package.json +++ b/templates/blank/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@wave/sdk": "^2.0.0" + "@wave-av/sdk": "^2.0.0" }, "devDependencies": { "tsx": "^4.0.0", diff --git a/templates/blank/src/index.ts b/templates/blank/src/index.ts index d117971..ce00421 100644 --- a/templates/blank/src/index.ts +++ b/templates/blank/src/index.ts @@ -1,4 +1,4 @@ -import { Wave } from "@wave/sdk"; +import { Wave } from "@wave-av/sdk"; const wave = new Wave({ apiKey: process.env.WAVE_API_KEY!, diff --git a/templates/multi-camera/package.json b/templates/multi-camera/package.json index 3167bf4..3ce7add 100644 --- a/templates/multi-camera/package.json +++ b/templates/multi-camera/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@wave/sdk": "^2.0.0" + "@wave-av/sdk": "^2.0.0" }, "devDependencies": { "tsx": "^4.0.0", diff --git a/templates/multi-camera/src/index.ts b/templates/multi-camera/src/index.ts index 18cc6ea..2c93734 100644 --- a/templates/multi-camera/src/index.ts +++ b/templates/multi-camera/src/index.ts @@ -1,4 +1,4 @@ -import { Wave } from "@wave/sdk"; +import { Wave } from "@wave-av/sdk"; const wave = new Wave({ apiKey: process.env.WAVE_API_KEY!, diff --git a/templates/podcast/package.json b/templates/podcast/package.json index ec247d1..7cad930 100644 --- a/templates/podcast/package.json +++ b/templates/podcast/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@wave/sdk": "^2.0.0" + "@wave-av/sdk": "^2.0.0" }, "devDependencies": { "tsx": "^4.0.0", diff --git a/templates/podcast/src/index.ts b/templates/podcast/src/index.ts index 5278bf7..640ff2e 100644 --- a/templates/podcast/src/index.ts +++ b/templates/podcast/src/index.ts @@ -1,4 +1,4 @@ -import { Wave } from "@wave/sdk"; +import { Wave } from "@wave-av/sdk"; const wave = new Wave({ apiKey: process.env.WAVE_API_KEY!, diff --git a/templates/srt-contribution/package.json b/templates/srt-contribution/package.json index 59b00fd..0dcfd23 100644 --- a/templates/srt-contribution/package.json +++ b/templates/srt-contribution/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@wave/sdk": "^2.0.0" + "@wave-av/sdk": "^2.0.0" }, "devDependencies": { "tsx": "^4.0.0", diff --git a/templates/srt-contribution/src/index.ts b/templates/srt-contribution/src/index.ts index 62dcef0..f9e3d53 100644 --- a/templates/srt-contribution/src/index.ts +++ b/templates/srt-contribution/src/index.ts @@ -1,4 +1,4 @@ -import { Wave } from "@wave/sdk"; +import { Wave } from "@wave-av/sdk"; const wave = new Wave({ apiKey: process.env.WAVE_API_KEY!, diff --git a/templates/studio-plugin/package.json b/templates/studio-plugin/package.json index 4524c82..00a1ae3 100644 --- a/templates/studio-plugin/package.json +++ b/templates/studio-plugin/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@wave/sdk": "^2.0.0" + "@wave-av/sdk": "^2.0.0" }, "devDependencies": { "tsx": "^4.0.0", diff --git a/templates/studio-plugin/src/index.ts b/templates/studio-plugin/src/index.ts index 3e7448d..9f172f8 100644 --- a/templates/studio-plugin/src/index.ts +++ b/templates/studio-plugin/src/index.ts @@ -1,4 +1,4 @@ -import { Wave } from "@wave/sdk"; +import { Wave } from "@wave-av/sdk"; const wave = new Wave({ apiKey: process.env.WAVE_API_KEY!, diff --git a/templates/webhook-handler/package.json b/templates/webhook-handler/package.json index c2fd75d..8cb4e86 100644 --- a/templates/webhook-handler/package.json +++ b/templates/webhook-handler/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@wave/sdk": "^2.0.0", + "@wave-av/sdk": "^2.0.0", "express": "^4.21.0" }, "devDependencies": { diff --git a/templates/webhook-handler/src/index.ts b/templates/webhook-handler/src/index.ts index c59b68c..8d0ffc4 100644 --- a/templates/webhook-handler/src/index.ts +++ b/templates/webhook-handler/src/index.ts @@ -1,5 +1,5 @@ import express from "express"; -import { Wave } from "@wave/sdk"; +import { Wave } from "@wave-av/sdk"; const wave = new Wave({ apiKey: process.env.WAVE_API_KEY!, diff --git a/templates/webrtc-demo/package.json b/templates/webrtc-demo/package.json index 07192dc..dfdecf7 100644 --- a/templates/webrtc-demo/package.json +++ b/templates/webrtc-demo/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@wave/sdk": "^2.0.0" + "@wave-av/sdk": "^2.0.0" }, "devDependencies": { "tsx": "^4.0.0", diff --git a/templates/webrtc-demo/src/index.ts b/templates/webrtc-demo/src/index.ts index 681fb51..61a4623 100644 --- a/templates/webrtc-demo/src/index.ts +++ b/templates/webrtc-demo/src/index.ts @@ -1,4 +1,4 @@ -import { Wave } from "@wave/sdk"; +import { Wave } from "@wave-av/sdk"; const wave = new Wave({ apiKey: process.env.WAVE_API_KEY!,