openhome-cli 0.1.8 → 0.1.10
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 +77 -46
- package/package.json +1 -1
- package/src/commands/login.ts +37 -39
- package/src/commands/set-jwt.ts +46 -6
package/dist/cli.js
CHANGED
|
@@ -291,8 +291,17 @@ function openBrowser(url) {
|
|
|
291
291
|
}
|
|
292
292
|
async function loginCommand() {
|
|
293
293
|
p.intro("\u{1F511} OpenHome Login");
|
|
294
|
+
p.note(
|
|
295
|
+
[
|
|
296
|
+
"Your API key is a private password that lets this CLI talk to your",
|
|
297
|
+
"OpenHome account. You can find it on your settings page.",
|
|
298
|
+
"",
|
|
299
|
+
`Press Enter and we'll open it for you \u2014 click the ${chalk2.bold("API Keys")} tab.`
|
|
300
|
+
].join("\n"),
|
|
301
|
+
"Step 1 of 2 \u2014 Connect your account"
|
|
302
|
+
);
|
|
294
303
|
const openSettings = await p.confirm({
|
|
295
|
-
message:
|
|
304
|
+
message: "Ready? Press Enter to open your browser",
|
|
296
305
|
initialValue: true,
|
|
297
306
|
active: "Open browser",
|
|
298
307
|
inactive: "Skip"
|
|
@@ -341,16 +350,33 @@ async function loginCommand() {
|
|
|
341
350
|
p.note(
|
|
342
351
|
[
|
|
343
352
|
"To manage your abilities (list, delete, enable/disable) from the CLI,",
|
|
344
|
-
"you need one more thing: a session token.",
|
|
353
|
+
"you need one more thing: a session token. This takes ~30 seconds",
|
|
354
|
+
"and you only do it once.",
|
|
355
|
+
"",
|
|
356
|
+
`${chalk2.bold("Here's what you'll do:")}`,
|
|
357
|
+
"",
|
|
358
|
+
`${chalk2.bold("1.")} We'll open ${chalk2.bold("app.openhome.com")} \u2014 make sure you're logged in`,
|
|
359
|
+
"",
|
|
360
|
+
`${chalk2.bold("2.")} Open the browser console:`,
|
|
361
|
+
` Mac \u2192 ${chalk2.cyan("Cmd + Option + J")}`,
|
|
362
|
+
` Windows / Linux \u2192 ${chalk2.cyan("F12")} then click ${chalk2.cyan("Console")}`,
|
|
363
|
+
"",
|
|
364
|
+
`${chalk2.bold("3.")} Chrome may show this warning \u2014 it's expected:`,
|
|
365
|
+
` ${chalk2.yellow(`"Don't paste code you don't understand..."`)}`,
|
|
366
|
+
` Type ${chalk2.cyan("allow pasting")} and press Enter to dismiss it.`,
|
|
367
|
+
"",
|
|
368
|
+
`${chalk2.bold("4.")} Paste this command and press Enter:`,
|
|
369
|
+
"",
|
|
370
|
+
` ${chalk2.green("copy(localStorage.getItem('token'))")}`,
|
|
345
371
|
"",
|
|
346
|
-
|
|
372
|
+
`${chalk2.bold("5.")} Your token is copied to clipboard \u2014 paste it back here.`
|
|
347
373
|
].join("\n"),
|
|
348
|
-
"
|
|
374
|
+
"Enable management features (one-time setup)"
|
|
349
375
|
);
|
|
350
376
|
const doJwt = await p.confirm({
|
|
351
|
-
message: "
|
|
377
|
+
message: "Ready? Press Enter to open your browser and follow the steps above",
|
|
352
378
|
initialValue: true,
|
|
353
|
-
active: "
|
|
379
|
+
active: "Open browser",
|
|
354
380
|
inactive: "Skip for now"
|
|
355
381
|
});
|
|
356
382
|
handleCancel(doJwt);
|
|
@@ -366,39 +392,11 @@ async function loginCommand() {
|
|
|
366
392
|
}
|
|
367
393
|
async function setupJwt() {
|
|
368
394
|
const { saveJwt: saveJwt2 } = await import("./store-USDMWKXY.js");
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
inactive: "Skip"
|
|
374
|
-
});
|
|
375
|
-
handleCancel(openApp);
|
|
376
|
-
if (openApp) {
|
|
377
|
-
openBrowser(OPENHOME_APP_URL);
|
|
378
|
-
console.log(
|
|
379
|
-
`
|
|
380
|
-
${chalk2.dim(`Opened ${chalk2.bold("app.openhome.com")} \u2014 make sure you're logged in`)}
|
|
395
|
+
openBrowser(OPENHOME_APP_URL);
|
|
396
|
+
console.log(
|
|
397
|
+
`
|
|
398
|
+
${chalk2.dim(`Opened ${chalk2.bold("app.openhome.com")} \u2014 follow the steps above`)}
|
|
381
399
|
`
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
p.note(
|
|
385
|
-
[
|
|
386
|
-
`${chalk2.bold("1.")} Open the browser console:`,
|
|
387
|
-
` Mac \u2192 press ${chalk2.cyan("Cmd + Option + J")}`,
|
|
388
|
-
` Windows / Linux \u2192 press ${chalk2.cyan("F12")}, then click ${chalk2.cyan("Console")}`,
|
|
389
|
-
"",
|
|
390
|
-
`${chalk2.bold("2.")} Chrome may show a warning:`,
|
|
391
|
-
` ${chalk2.yellow(`"Don't paste code you don't understand..."`)}`,
|
|
392
|
-
` If so, type ${chalk2.cyan("allow pasting")} and press ${chalk2.bold("Enter")} first.`,
|
|
393
|
-
"",
|
|
394
|
-
`${chalk2.bold("3.")} Paste this command and press ${chalk2.bold("Enter")}:`,
|
|
395
|
-
"",
|
|
396
|
-
` ${chalk2.green("copy(localStorage.getItem('token'))")}`,
|
|
397
|
-
"",
|
|
398
|
-
`${chalk2.bold("4.")} Your token is now copied to your clipboard.`,
|
|
399
|
-
` Come back here and paste it below.`
|
|
400
|
-
].join("\n"),
|
|
401
|
-
"How to get your session token"
|
|
402
400
|
);
|
|
403
401
|
const token = await p.password({
|
|
404
402
|
message: "Paste your session token here",
|
|
@@ -3148,9 +3146,10 @@ async function logsCommand(opts = {}) {
|
|
|
3148
3146
|
}
|
|
3149
3147
|
|
|
3150
3148
|
// src/commands/set-jwt.ts
|
|
3149
|
+
import chalk13 from "chalk";
|
|
3151
3150
|
async function setJwtCommand(token) {
|
|
3151
|
+
p.intro("\u{1F511} Enable Management Features");
|
|
3152
3152
|
if (token) {
|
|
3153
|
-
p.intro("\u{1F511} Enable Management Features");
|
|
3154
3153
|
try {
|
|
3155
3154
|
saveJwt(token.trim());
|
|
3156
3155
|
success("Session token saved.");
|
|
@@ -3165,14 +3164,46 @@ async function setJwtCommand(token) {
|
|
|
3165
3164
|
}
|
|
3166
3165
|
return;
|
|
3167
3166
|
}
|
|
3168
|
-
p.
|
|
3167
|
+
p.note(
|
|
3168
|
+
[
|
|
3169
|
+
"Here's what you'll do:",
|
|
3170
|
+
"",
|
|
3171
|
+
`${chalk13.bold("1.")} We'll open ${chalk13.bold("app.openhome.com")} \u2014 make sure you're logged in`,
|
|
3172
|
+
"",
|
|
3173
|
+
`${chalk13.bold("2.")} Open the browser console:`,
|
|
3174
|
+
` Mac \u2192 ${chalk13.cyan("Cmd + Option + J")}`,
|
|
3175
|
+
` Windows / Linux \u2192 ${chalk13.cyan("F12")} then click ${chalk13.cyan("Console")}`,
|
|
3176
|
+
"",
|
|
3177
|
+
`${chalk13.bold("3.")} Chrome may show this warning \u2014 it's expected:`,
|
|
3178
|
+
` ${chalk13.yellow(`"Don't paste code you don't understand..."`)}`,
|
|
3179
|
+
` Type ${chalk13.cyan("allow pasting")} and press Enter to dismiss it.`,
|
|
3180
|
+
"",
|
|
3181
|
+
`${chalk13.bold("4.")} Paste this command and press Enter:`,
|
|
3182
|
+
"",
|
|
3183
|
+
` ${chalk13.green("copy(localStorage.getItem('token'))")}`,
|
|
3184
|
+
"",
|
|
3185
|
+
`${chalk13.bold("5.")} Your token is copied to clipboard \u2014 paste it back here.`
|
|
3186
|
+
].join("\n"),
|
|
3187
|
+
"Enable management features (one-time setup)"
|
|
3188
|
+
);
|
|
3189
|
+
const ready = await p.confirm({
|
|
3190
|
+
message: "Ready? Press Enter to open your browser and follow the steps above",
|
|
3191
|
+
initialValue: true,
|
|
3192
|
+
active: "Open browser",
|
|
3193
|
+
inactive: "Cancel"
|
|
3194
|
+
});
|
|
3195
|
+
handleCancel(ready);
|
|
3196
|
+
if (!ready) {
|
|
3197
|
+
p.cancel("Cancelled.");
|
|
3198
|
+
return;
|
|
3199
|
+
}
|
|
3169
3200
|
await setupJwt();
|
|
3170
|
-
p.outro("
|
|
3201
|
+
p.outro("Management features are now unlocked.");
|
|
3171
3202
|
}
|
|
3172
3203
|
|
|
3173
3204
|
// src/commands/validate.ts
|
|
3174
3205
|
import { resolve as resolve5 } from "path";
|
|
3175
|
-
import
|
|
3206
|
+
import chalk14 from "chalk";
|
|
3176
3207
|
async function validateCommand(pathArg = ".") {
|
|
3177
3208
|
const targetDir = resolve5(pathArg);
|
|
3178
3209
|
p.intro(`\u{1F50E} Validate ability`);
|
|
@@ -3188,7 +3219,7 @@ async function validateCommand(pathArg = ".") {
|
|
|
3188
3219
|
if (result.errors.length > 0) {
|
|
3189
3220
|
p.note(
|
|
3190
3221
|
result.errors.map(
|
|
3191
|
-
(issue) => `${
|
|
3222
|
+
(issue) => `${chalk14.red("\u2717")} ${issue.file ? chalk14.bold(`[${issue.file}]`) + " " : ""}${issue.message}`
|
|
3192
3223
|
).join("\n"),
|
|
3193
3224
|
`${result.errors.length} Error(s)`
|
|
3194
3225
|
);
|
|
@@ -3196,7 +3227,7 @@ async function validateCommand(pathArg = ".") {
|
|
|
3196
3227
|
if (result.warnings.length > 0) {
|
|
3197
3228
|
p.note(
|
|
3198
3229
|
result.warnings.map(
|
|
3199
|
-
(w) => `${
|
|
3230
|
+
(w) => `${chalk14.yellow("\u26A0")} ${w.file ? chalk14.bold(`[${w.file}]`) + " " : ""}${w.message}`
|
|
3200
3231
|
).join("\n"),
|
|
3201
3232
|
`${result.warnings.length} Warning(s)`
|
|
3202
3233
|
);
|
|
@@ -3242,9 +3273,9 @@ async function checkForUpdates() {
|
|
|
3242
3273
|
);
|
|
3243
3274
|
process.exit(0);
|
|
3244
3275
|
} else {
|
|
3245
|
-
const { default:
|
|
3276
|
+
const { default: chalk15 } = await import("chalk");
|
|
3246
3277
|
console.log(
|
|
3247
|
-
|
|
3278
|
+
chalk15.yellow(
|
|
3248
3279
|
` Update available: v${version} \u2192 v${latest} Run: npm install -g openhome-cli@latest
|
|
3249
3280
|
`
|
|
3250
3281
|
)
|
package/package.json
CHANGED
package/src/commands/login.ts
CHANGED
|
@@ -26,8 +26,18 @@ export async function loginCommand(): Promise<void> {
|
|
|
26
26
|
p.intro("🔑 OpenHome Login");
|
|
27
27
|
|
|
28
28
|
// Step 1: API key
|
|
29
|
+
p.note(
|
|
30
|
+
[
|
|
31
|
+
"Your API key is a private password that lets this CLI talk to your",
|
|
32
|
+
"OpenHome account. You can find it on your settings page.",
|
|
33
|
+
"",
|
|
34
|
+
`Press Enter and we'll open it for you — click the ${chalk.bold("API Keys")} tab.`,
|
|
35
|
+
].join("\n"),
|
|
36
|
+
"Step 1 of 2 — Connect your account",
|
|
37
|
+
);
|
|
38
|
+
|
|
29
39
|
const openSettings = await p.confirm({
|
|
30
|
-
message:
|
|
40
|
+
message: "Ready? Press Enter to open your browser",
|
|
31
41
|
initialValue: true,
|
|
32
42
|
active: "Open browser",
|
|
33
43
|
inactive: "Skip",
|
|
@@ -88,17 +98,35 @@ export async function loginCommand(): Promise<void> {
|
|
|
88
98
|
p.note(
|
|
89
99
|
[
|
|
90
100
|
"To manage your abilities (list, delete, enable/disable) from the CLI,",
|
|
91
|
-
"you need one more thing: a session token.",
|
|
101
|
+
"you need one more thing: a session token. This takes ~30 seconds",
|
|
102
|
+
"and you only do it once.",
|
|
103
|
+
"",
|
|
104
|
+
`${chalk.bold("Here's what you'll do:")}`,
|
|
105
|
+
"",
|
|
106
|
+
`${chalk.bold("1.")} We'll open ${chalk.bold("app.openhome.com")} — make sure you're logged in`,
|
|
107
|
+
"",
|
|
108
|
+
`${chalk.bold("2.")} Open the browser console:`,
|
|
109
|
+
` Mac → ${chalk.cyan("Cmd + Option + J")}`,
|
|
110
|
+
` Windows / Linux → ${chalk.cyan("F12")} then click ${chalk.cyan("Console")}`,
|
|
92
111
|
"",
|
|
93
|
-
|
|
112
|
+
`${chalk.bold("3.")} Chrome may show this warning — it's expected:`,
|
|
113
|
+
` ${chalk.yellow("\"Don't paste code you don't understand...\"")}`,
|
|
114
|
+
` Type ${chalk.cyan("allow pasting")} and press Enter to dismiss it.`,
|
|
115
|
+
"",
|
|
116
|
+
`${chalk.bold("4.")} Paste this command and press Enter:`,
|
|
117
|
+
"",
|
|
118
|
+
` ${chalk.green("copy(localStorage.getItem('token'))")}`,
|
|
119
|
+
"",
|
|
120
|
+
`${chalk.bold("5.")} Your token is copied to clipboard — paste it back here.`,
|
|
94
121
|
].join("\n"),
|
|
95
|
-
"
|
|
122
|
+
"Enable management features (one-time setup)",
|
|
96
123
|
);
|
|
97
124
|
|
|
98
125
|
const doJwt = await p.confirm({
|
|
99
|
-
message:
|
|
126
|
+
message:
|
|
127
|
+
"Ready? Press Enter to open your browser and follow the steps above",
|
|
100
128
|
initialValue: true,
|
|
101
|
-
active: "
|
|
129
|
+
active: "Open browser",
|
|
102
130
|
inactive: "Skip for now",
|
|
103
131
|
});
|
|
104
132
|
handleCancel(doJwt);
|
|
@@ -118,39 +146,9 @@ export async function loginCommand(): Promise<void> {
|
|
|
118
146
|
export async function setupJwt(): Promise<void> {
|
|
119
147
|
const { saveJwt } = await import("../config/store.js");
|
|
120
148
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
active: "Open browser",
|
|
125
|
-
inactive: "Skip",
|
|
126
|
-
});
|
|
127
|
-
handleCancel(openApp);
|
|
128
|
-
|
|
129
|
-
if (openApp) {
|
|
130
|
-
openBrowser(OPENHOME_APP_URL);
|
|
131
|
-
console.log(
|
|
132
|
-
`\n ${chalk.dim(`Opened ${chalk.bold("app.openhome.com")} — make sure you're logged in`)}\n`,
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
p.note(
|
|
137
|
-
[
|
|
138
|
-
`${chalk.bold("1.")} Open the browser console:`,
|
|
139
|
-
` Mac → press ${chalk.cyan("Cmd + Option + J")}`,
|
|
140
|
-
` Windows / Linux → press ${chalk.cyan("F12")}, then click ${chalk.cyan("Console")}`,
|
|
141
|
-
"",
|
|
142
|
-
`${chalk.bold("2.")} Chrome may show a warning:`,
|
|
143
|
-
` ${chalk.yellow("\"Don't paste code you don't understand...\"")}`,
|
|
144
|
-
` If so, type ${chalk.cyan("allow pasting")} and press ${chalk.bold("Enter")} first.`,
|
|
145
|
-
"",
|
|
146
|
-
`${chalk.bold("3.")} Paste this command and press ${chalk.bold("Enter")}:`,
|
|
147
|
-
"",
|
|
148
|
-
` ${chalk.green("copy(localStorage.getItem('token'))")}`,
|
|
149
|
-
"",
|
|
150
|
-
`${chalk.bold("4.")} Your token is now copied to your clipboard.`,
|
|
151
|
-
` Come back here and paste it below.`,
|
|
152
|
-
].join("\n"),
|
|
153
|
-
"How to get your session token",
|
|
149
|
+
openBrowser(OPENHOME_APP_URL);
|
|
150
|
+
console.log(
|
|
151
|
+
`\n ${chalk.dim(`Opened ${chalk.bold("app.openhome.com")} — follow the steps above`)}\n`,
|
|
154
152
|
);
|
|
155
153
|
|
|
156
154
|
const token = await p.password({
|
package/src/commands/set-jwt.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { setupJwt } from "./login.js";
|
|
1
|
+
import { setupJwt, openBrowser } from "./login.js";
|
|
2
2
|
import { saveJwt } from "../config/store.js";
|
|
3
|
-
import { success, error, p } from "../ui/format.js";
|
|
3
|
+
import { success, error, p, handleCancel } from "../ui/format.js";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
|
|
6
|
+
const OPENHOME_APP_URL = "https://app.openhome.com";
|
|
4
7
|
|
|
5
8
|
export async function setJwtCommand(token?: string): Promise<void> {
|
|
9
|
+
p.intro("🔑 Enable Management Features");
|
|
10
|
+
|
|
6
11
|
// Direct usage: openhome set-jwt eyJ...
|
|
7
12
|
if (token) {
|
|
8
|
-
p.intro("🔑 Enable Management Features");
|
|
9
13
|
try {
|
|
10
14
|
saveJwt(token.trim());
|
|
11
15
|
success("Session token saved.");
|
|
@@ -21,8 +25,44 @@ export async function setJwtCommand(token?: string): Promise<void> {
|
|
|
21
25
|
return;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
// Guided flow —
|
|
25
|
-
p.
|
|
28
|
+
// Guided flow — show instructions first, then open browser
|
|
29
|
+
p.note(
|
|
30
|
+
[
|
|
31
|
+
"Here's what you'll do:",
|
|
32
|
+
"",
|
|
33
|
+
`${chalk.bold("1.")} We'll open ${chalk.bold("app.openhome.com")} — make sure you're logged in`,
|
|
34
|
+
"",
|
|
35
|
+
`${chalk.bold("2.")} Open the browser console:`,
|
|
36
|
+
` Mac → ${chalk.cyan("Cmd + Option + J")}`,
|
|
37
|
+
` Windows / Linux → ${chalk.cyan("F12")} then click ${chalk.cyan("Console")}`,
|
|
38
|
+
"",
|
|
39
|
+
`${chalk.bold("3.")} Chrome may show this warning — it's expected:`,
|
|
40
|
+
` ${chalk.yellow("\"Don't paste code you don't understand...\"")}`,
|
|
41
|
+
` Type ${chalk.cyan("allow pasting")} and press Enter to dismiss it.`,
|
|
42
|
+
"",
|
|
43
|
+
`${chalk.bold("4.")} Paste this command and press Enter:`,
|
|
44
|
+
"",
|
|
45
|
+
` ${chalk.green("copy(localStorage.getItem('token'))")}`,
|
|
46
|
+
"",
|
|
47
|
+
`${chalk.bold("5.")} Your token is copied to clipboard — paste it back here.`,
|
|
48
|
+
].join("\n"),
|
|
49
|
+
"Enable management features (one-time setup)",
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const ready = await p.confirm({
|
|
53
|
+
message:
|
|
54
|
+
"Ready? Press Enter to open your browser and follow the steps above",
|
|
55
|
+
initialValue: true,
|
|
56
|
+
active: "Open browser",
|
|
57
|
+
inactive: "Cancel",
|
|
58
|
+
});
|
|
59
|
+
handleCancel(ready);
|
|
60
|
+
|
|
61
|
+
if (!ready) {
|
|
62
|
+
p.cancel("Cancelled.");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
26
66
|
await setupJwt();
|
|
27
|
-
p.outro("
|
|
67
|
+
p.outro("Management features are now unlocked.");
|
|
28
68
|
}
|