openhome-cli 0.1.1 → 0.1.2
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/dist/cli.js +65 -18
- package/package.json +1 -1
- package/src/cli.ts +10 -0
- package/src/commands/assign.ts +6 -0
- package/src/commands/delete.ts +6 -0
- package/src/commands/list.ts +6 -0
- package/src/commands/login.ts +0 -22
- package/src/commands/set-jwt.ts +40 -0
- package/src/commands/toggle.ts +6 -0
package/dist/cli.js
CHANGED
|
@@ -301,24 +301,6 @@ async function loginCommand() {
|
|
|
301
301
|
}
|
|
302
302
|
saveApiKey(apiKey);
|
|
303
303
|
success("API key saved.");
|
|
304
|
-
p.note(
|
|
305
|
-
[
|
|
306
|
-
"Some features (list, toggle, delete, assign) require a session token.",
|
|
307
|
-
"To get it: go to app.openhome.com \u2192 open DevTools Console \u2192 run:",
|
|
308
|
-
" localStorage.getItem('access_token')"
|
|
309
|
-
].join("\n"),
|
|
310
|
-
"Optional: Session Token"
|
|
311
|
-
);
|
|
312
|
-
const jwtInput = await p.text({
|
|
313
|
-
message: "Paste your session token (or press Enter to skip)",
|
|
314
|
-
placeholder: "eyJhbGci..."
|
|
315
|
-
});
|
|
316
|
-
handleCancel(jwtInput);
|
|
317
|
-
const jwt = jwtInput?.trim();
|
|
318
|
-
if (jwt) {
|
|
319
|
-
saveJwt(jwt);
|
|
320
|
-
success("Session token saved.");
|
|
321
|
-
}
|
|
322
304
|
if (agents.length > 0) {
|
|
323
305
|
p.note(
|
|
324
306
|
agents.map((a) => `${chalk2.bold(a.name)} ${chalk2.gray(a.id)}`).join("\n"),
|
|
@@ -1848,6 +1830,12 @@ async function deleteCommand(abilityArg, opts = {}) {
|
|
|
1848
1830
|
error("Not authenticated. Run: openhome login");
|
|
1849
1831
|
process.exit(1);
|
|
1850
1832
|
}
|
|
1833
|
+
if (!jwt) {
|
|
1834
|
+
error(
|
|
1835
|
+
"This command requires a session token.\nGet it from app.openhome.com \u2192 DevTools \u2192 Application \u2192 Local Storage \u2192 token\nThen run: openhome set-jwt <token>"
|
|
1836
|
+
);
|
|
1837
|
+
process.exit(1);
|
|
1838
|
+
}
|
|
1851
1839
|
client = new ApiClient(apiKey, getConfig().api_base_url, jwt);
|
|
1852
1840
|
}
|
|
1853
1841
|
const s = p.spinner();
|
|
@@ -1931,6 +1919,12 @@ async function toggleCommand(abilityArg, opts = {}) {
|
|
|
1931
1919
|
error("Not authenticated. Run: openhome login");
|
|
1932
1920
|
process.exit(1);
|
|
1933
1921
|
}
|
|
1922
|
+
if (!jwt) {
|
|
1923
|
+
error(
|
|
1924
|
+
"This command requires a session token.\nGet it from app.openhome.com \u2192 DevTools \u2192 Application \u2192 Local Storage \u2192 token\nThen run: openhome set-jwt <token>"
|
|
1925
|
+
);
|
|
1926
|
+
process.exit(1);
|
|
1927
|
+
}
|
|
1934
1928
|
client = new ApiClient(apiKey, getConfig().api_base_url, jwt);
|
|
1935
1929
|
}
|
|
1936
1930
|
const s = p.spinner();
|
|
@@ -2024,6 +2018,12 @@ async function assignCommand(opts = {}) {
|
|
|
2024
2018
|
error("Not authenticated. Run: openhome login");
|
|
2025
2019
|
process.exit(1);
|
|
2026
2020
|
}
|
|
2021
|
+
if (!jwt) {
|
|
2022
|
+
error(
|
|
2023
|
+
"This command requires a session token.\nGet it from app.openhome.com \u2192 DevTools \u2192 Application \u2192 Local Storage \u2192 token\nThen run: openhome set-jwt <token>"
|
|
2024
|
+
);
|
|
2025
|
+
process.exit(1);
|
|
2026
|
+
}
|
|
2027
2027
|
client = new ApiClient(apiKey, getConfig().api_base_url, jwt);
|
|
2028
2028
|
}
|
|
2029
2029
|
const s = p.spinner();
|
|
@@ -2127,6 +2127,12 @@ async function listCommand(opts = {}) {
|
|
|
2127
2127
|
error("Not authenticated. Run: openhome login");
|
|
2128
2128
|
process.exit(1);
|
|
2129
2129
|
}
|
|
2130
|
+
if (!jwt) {
|
|
2131
|
+
error(
|
|
2132
|
+
"This command requires a session token.\nGet it from app.openhome.com \u2192 DevTools \u2192 Application \u2192 Local Storage \u2192 token\nThen run: openhome set-jwt <token>"
|
|
2133
|
+
);
|
|
2134
|
+
process.exit(1);
|
|
2135
|
+
}
|
|
2130
2136
|
client = new ApiClient(apiKey, getConfig().api_base_url, jwt);
|
|
2131
2137
|
}
|
|
2132
2138
|
const s = p.spinner();
|
|
@@ -3037,6 +3043,42 @@ async function logsCommand(opts = {}) {
|
|
|
3037
3043
|
});
|
|
3038
3044
|
}
|
|
3039
3045
|
|
|
3046
|
+
// src/commands/set-jwt.ts
|
|
3047
|
+
async function setJwtCommand(token) {
|
|
3048
|
+
p.intro("\u{1F511} Set Session Token");
|
|
3049
|
+
let jwt = token;
|
|
3050
|
+
if (!jwt) {
|
|
3051
|
+
const input = await p.text({
|
|
3052
|
+
message: "Paste your OpenHome session token",
|
|
3053
|
+
placeholder: "eyJ...",
|
|
3054
|
+
validate: (val) => {
|
|
3055
|
+
if (!val || !val.trim()) return "Token is required";
|
|
3056
|
+
if (!val.trim().startsWith("eyJ"))
|
|
3057
|
+
return "Doesn't look like a JWT \u2014 should start with eyJ";
|
|
3058
|
+
}
|
|
3059
|
+
});
|
|
3060
|
+
if (typeof input === "symbol") {
|
|
3061
|
+
p.cancel("Cancelled.");
|
|
3062
|
+
return;
|
|
3063
|
+
}
|
|
3064
|
+
jwt = input;
|
|
3065
|
+
}
|
|
3066
|
+
try {
|
|
3067
|
+
saveJwt(jwt.trim());
|
|
3068
|
+
success("Session token saved.");
|
|
3069
|
+
p.note(
|
|
3070
|
+
"Management commands (list, delete, toggle, assign) are now unlocked.",
|
|
3071
|
+
"Token saved"
|
|
3072
|
+
);
|
|
3073
|
+
p.outro("Done.");
|
|
3074
|
+
} catch (err) {
|
|
3075
|
+
error(
|
|
3076
|
+
`Failed to save token: ${err instanceof Error ? err.message : String(err)}`
|
|
3077
|
+
);
|
|
3078
|
+
process.exit(1);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3040
3082
|
// src/cli.ts
|
|
3041
3083
|
var __filename = fileURLToPath(import.meta.url);
|
|
3042
3084
|
var __dirname = dirname(__filename);
|
|
@@ -3235,6 +3277,11 @@ program.command("logs").description("Stream live agent messages and logs").optio
|
|
|
3235
3277
|
program.command("whoami").description("Show auth status, default agent, and tracked abilities").action(async () => {
|
|
3236
3278
|
await whoamiCommand();
|
|
3237
3279
|
});
|
|
3280
|
+
program.command("set-jwt [token]").description(
|
|
3281
|
+
"Save a session token to enable management commands (list, delete, toggle, assign)"
|
|
3282
|
+
).action(async (token) => {
|
|
3283
|
+
await setJwtCommand(token);
|
|
3284
|
+
});
|
|
3238
3285
|
if (process.argv.length <= 2) {
|
|
3239
3286
|
interactiveMenu().catch((err) => {
|
|
3240
3287
|
console.error(err instanceof Error ? err.message : String(err));
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { triggerCommand } from "./commands/trigger.js";
|
|
|
18
18
|
import { whoamiCommand } from "./commands/whoami.js";
|
|
19
19
|
import { configEditCommand } from "./commands/config-edit.js";
|
|
20
20
|
import { logsCommand } from "./commands/logs.js";
|
|
21
|
+
import { setJwtCommand } from "./commands/set-jwt.js";
|
|
21
22
|
import { p, handleCancel } from "./ui/format.js";
|
|
22
23
|
|
|
23
24
|
// Read version from package.json
|
|
@@ -316,6 +317,15 @@ program
|
|
|
316
317
|
await whoamiCommand();
|
|
317
318
|
});
|
|
318
319
|
|
|
320
|
+
program
|
|
321
|
+
.command("set-jwt [token]")
|
|
322
|
+
.description(
|
|
323
|
+
"Save a session token to enable management commands (list, delete, toggle, assign)",
|
|
324
|
+
)
|
|
325
|
+
.action(async (token?: string) => {
|
|
326
|
+
await setJwtCommand(token);
|
|
327
|
+
});
|
|
328
|
+
|
|
319
329
|
// ── Entry point: menu if no args, subcommand otherwise ───────────
|
|
320
330
|
|
|
321
331
|
if (process.argv.length <= 2) {
|
package/src/commands/assign.ts
CHANGED
|
@@ -20,6 +20,12 @@ export async function assignCommand(
|
|
|
20
20
|
error("Not authenticated. Run: openhome login");
|
|
21
21
|
process.exit(1);
|
|
22
22
|
}
|
|
23
|
+
if (!jwt) {
|
|
24
|
+
error(
|
|
25
|
+
"This command requires a session token.\nGet it from app.openhome.com → DevTools → Application → Local Storage → token\nThen run: openhome set-jwt <token>",
|
|
26
|
+
);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
23
29
|
client = new ApiClient(apiKey, getConfig().api_base_url, jwt);
|
|
24
30
|
}
|
|
25
31
|
|
package/src/commands/delete.ts
CHANGED
|
@@ -21,6 +21,12 @@ export async function deleteCommand(
|
|
|
21
21
|
error("Not authenticated. Run: openhome login");
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
|
+
if (!jwt) {
|
|
25
|
+
error(
|
|
26
|
+
"This command requires a session token.\nGet it from app.openhome.com → DevTools → Application → Local Storage → token\nThen run: openhome set-jwt <token>",
|
|
27
|
+
);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
24
30
|
client = new ApiClient(apiKey, getConfig().api_base_url, jwt);
|
|
25
31
|
}
|
|
26
32
|
|
package/src/commands/list.ts
CHANGED
|
@@ -36,6 +36,12 @@ export async function listCommand(
|
|
|
36
36
|
error("Not authenticated. Run: openhome login");
|
|
37
37
|
process.exit(1);
|
|
38
38
|
}
|
|
39
|
+
if (!jwt) {
|
|
40
|
+
error(
|
|
41
|
+
"This command requires a session token.\nGet it from app.openhome.com → DevTools → Application → Local Storage → token\nThen run: openhome set-jwt <token>",
|
|
42
|
+
);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
39
45
|
client = new ApiClient(apiKey, getConfig().api_base_url, jwt);
|
|
40
46
|
}
|
|
41
47
|
|
package/src/commands/login.ts
CHANGED
|
@@ -38,28 +38,6 @@ export async function loginCommand(): Promise<void> {
|
|
|
38
38
|
saveApiKey(apiKey as string);
|
|
39
39
|
success("API key saved.");
|
|
40
40
|
|
|
41
|
-
// Ask for JWT for full management access
|
|
42
|
-
p.note(
|
|
43
|
-
[
|
|
44
|
-
"Some features (list, toggle, delete, assign) require a session token.",
|
|
45
|
-
"To get it: go to app.openhome.com → open DevTools Console → run:",
|
|
46
|
-
" localStorage.getItem('access_token')",
|
|
47
|
-
].join("\n"),
|
|
48
|
-
"Optional: Session Token",
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const jwtInput = await p.text({
|
|
52
|
-
message: "Paste your session token (or press Enter to skip)",
|
|
53
|
-
placeholder: "eyJhbGci...",
|
|
54
|
-
});
|
|
55
|
-
handleCancel(jwtInput);
|
|
56
|
-
|
|
57
|
-
const jwt = (jwtInput as string | undefined)?.trim();
|
|
58
|
-
if (jwt) {
|
|
59
|
-
saveJwt(jwt);
|
|
60
|
-
success("Session token saved.");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
41
|
// Show agents on this account
|
|
64
42
|
if (agents.length > 0) {
|
|
65
43
|
p.note(
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { saveJwt } from "../config/store.js";
|
|
2
|
+
import { success, error, p } from "../ui/format.js";
|
|
3
|
+
|
|
4
|
+
export async function setJwtCommand(token?: string): Promise<void> {
|
|
5
|
+
p.intro("🔑 Set Session Token");
|
|
6
|
+
|
|
7
|
+
let jwt = token;
|
|
8
|
+
|
|
9
|
+
if (!jwt) {
|
|
10
|
+
const input = await p.text({
|
|
11
|
+
message: "Paste your OpenHome session token",
|
|
12
|
+
placeholder: "eyJ...",
|
|
13
|
+
validate: (val) => {
|
|
14
|
+
if (!val || !val.trim()) return "Token is required";
|
|
15
|
+
if (!val.trim().startsWith("eyJ"))
|
|
16
|
+
return "Doesn't look like a JWT — should start with eyJ";
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
if (typeof input === "symbol") {
|
|
20
|
+
p.cancel("Cancelled.");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
jwt = input;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
saveJwt(jwt.trim());
|
|
28
|
+
success("Session token saved.");
|
|
29
|
+
p.note(
|
|
30
|
+
"Management commands (list, delete, toggle, assign) are now unlocked.",
|
|
31
|
+
"Token saved",
|
|
32
|
+
);
|
|
33
|
+
p.outro("Done.");
|
|
34
|
+
} catch (err) {
|
|
35
|
+
error(
|
|
36
|
+
`Failed to save token: ${err instanceof Error ? err.message : String(err)}`,
|
|
37
|
+
);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/commands/toggle.ts
CHANGED
|
@@ -21,6 +21,12 @@ export async function toggleCommand(
|
|
|
21
21
|
error("Not authenticated. Run: openhome login");
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
|
+
if (!jwt) {
|
|
25
|
+
error(
|
|
26
|
+
"This command requires a session token.\nGet it from app.openhome.com → DevTools → Application → Local Storage → token\nThen run: openhome set-jwt <token>",
|
|
27
|
+
);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
24
30
|
client = new ApiClient(apiKey, getConfig().api_base_url, jwt);
|
|
25
31
|
}
|
|
26
32
|
|