openhome-cli 0.1.7 → 0.1.9
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 +67 -41
- package/package.json +1 -1
- package/src/commands/login.ts +26 -34
- package/src/commands/set-jwt.ts +46 -6
package/dist/cli.js
CHANGED
|
@@ -341,16 +341,33 @@ async function loginCommand() {
|
|
|
341
341
|
p.note(
|
|
342
342
|
[
|
|
343
343
|
"To manage your abilities (list, delete, enable/disable) from the CLI,",
|
|
344
|
-
"you need one more thing: a session token.",
|
|
344
|
+
"you need one more thing: a session token. This takes ~30 seconds",
|
|
345
|
+
"and you only do it once.",
|
|
345
346
|
"",
|
|
346
|
-
|
|
347
|
+
`${chalk2.bold("Here's what you'll do:")}`,
|
|
348
|
+
"",
|
|
349
|
+
`${chalk2.bold("1.")} We'll open ${chalk2.bold("app.openhome.com")} \u2014 make sure you're logged in`,
|
|
350
|
+
"",
|
|
351
|
+
`${chalk2.bold("2.")} Open the browser console:`,
|
|
352
|
+
` Mac \u2192 ${chalk2.cyan("Cmd + Option + J")}`,
|
|
353
|
+
` Windows / Linux \u2192 ${chalk2.cyan("F12")} then click ${chalk2.cyan("Console")}`,
|
|
354
|
+
"",
|
|
355
|
+
`${chalk2.bold("3.")} Chrome may show this warning \u2014 it's expected:`,
|
|
356
|
+
` ${chalk2.yellow(`"Don't paste code you don't understand..."`)}`,
|
|
357
|
+
` Type ${chalk2.cyan("allow pasting")} and press Enter to dismiss it.`,
|
|
358
|
+
"",
|
|
359
|
+
`${chalk2.bold("4.")} Paste this command and press Enter:`,
|
|
360
|
+
"",
|
|
361
|
+
` ${chalk2.green("copy(localStorage.getItem('token'))")}`,
|
|
362
|
+
"",
|
|
363
|
+
`${chalk2.bold("5.")} Your token is copied to clipboard \u2014 paste it back here.`
|
|
347
364
|
].join("\n"),
|
|
348
|
-
"
|
|
365
|
+
"Enable management features (one-time setup)"
|
|
349
366
|
);
|
|
350
367
|
const doJwt = await p.confirm({
|
|
351
|
-
message: "
|
|
368
|
+
message: "Ready? Press Enter to open your browser and follow the steps above",
|
|
352
369
|
initialValue: true,
|
|
353
|
-
active: "
|
|
370
|
+
active: "Open browser",
|
|
354
371
|
inactive: "Skip for now"
|
|
355
372
|
});
|
|
356
373
|
handleCancel(doJwt);
|
|
@@ -366,35 +383,11 @@ async function loginCommand() {
|
|
|
366
383
|
}
|
|
367
384
|
async function setupJwt() {
|
|
368
385
|
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`)}
|
|
386
|
+
openBrowser(OPENHOME_APP_URL);
|
|
387
|
+
console.log(
|
|
388
|
+
`
|
|
389
|
+
${chalk2.dim(`Opened ${chalk2.bold("app.openhome.com")} \u2014 follow the steps above`)}
|
|
381
390
|
`
|
|
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.")} Paste this command and press ${chalk2.bold("Enter")}:`,
|
|
391
|
-
"",
|
|
392
|
-
` ${chalk2.green("copy(localStorage.getItem('token'))")}`,
|
|
393
|
-
"",
|
|
394
|
-
`${chalk2.bold("3.")} Your token is now copied to your clipboard.`,
|
|
395
|
-
` Come back here and paste it below.`
|
|
396
|
-
].join("\n"),
|
|
397
|
-
"How to get your session token"
|
|
398
391
|
);
|
|
399
392
|
const token = await p.password({
|
|
400
393
|
message: "Paste your session token here",
|
|
@@ -3144,9 +3137,10 @@ async function logsCommand(opts = {}) {
|
|
|
3144
3137
|
}
|
|
3145
3138
|
|
|
3146
3139
|
// src/commands/set-jwt.ts
|
|
3140
|
+
import chalk13 from "chalk";
|
|
3147
3141
|
async function setJwtCommand(token) {
|
|
3142
|
+
p.intro("\u{1F511} Enable Management Features");
|
|
3148
3143
|
if (token) {
|
|
3149
|
-
p.intro("\u{1F511} Enable Management Features");
|
|
3150
3144
|
try {
|
|
3151
3145
|
saveJwt(token.trim());
|
|
3152
3146
|
success("Session token saved.");
|
|
@@ -3161,14 +3155,46 @@ async function setJwtCommand(token) {
|
|
|
3161
3155
|
}
|
|
3162
3156
|
return;
|
|
3163
3157
|
}
|
|
3164
|
-
p.
|
|
3158
|
+
p.note(
|
|
3159
|
+
[
|
|
3160
|
+
"Here's what you'll do:",
|
|
3161
|
+
"",
|
|
3162
|
+
`${chalk13.bold("1.")} We'll open ${chalk13.bold("app.openhome.com")} \u2014 make sure you're logged in`,
|
|
3163
|
+
"",
|
|
3164
|
+
`${chalk13.bold("2.")} Open the browser console:`,
|
|
3165
|
+
` Mac \u2192 ${chalk13.cyan("Cmd + Option + J")}`,
|
|
3166
|
+
` Windows / Linux \u2192 ${chalk13.cyan("F12")} then click ${chalk13.cyan("Console")}`,
|
|
3167
|
+
"",
|
|
3168
|
+
`${chalk13.bold("3.")} Chrome may show this warning \u2014 it's expected:`,
|
|
3169
|
+
` ${chalk13.yellow(`"Don't paste code you don't understand..."`)}`,
|
|
3170
|
+
` Type ${chalk13.cyan("allow pasting")} and press Enter to dismiss it.`,
|
|
3171
|
+
"",
|
|
3172
|
+
`${chalk13.bold("4.")} Paste this command and press Enter:`,
|
|
3173
|
+
"",
|
|
3174
|
+
` ${chalk13.green("copy(localStorage.getItem('token'))")}`,
|
|
3175
|
+
"",
|
|
3176
|
+
`${chalk13.bold("5.")} Your token is copied to clipboard \u2014 paste it back here.`
|
|
3177
|
+
].join("\n"),
|
|
3178
|
+
"Enable management features (one-time setup)"
|
|
3179
|
+
);
|
|
3180
|
+
const ready = await p.confirm({
|
|
3181
|
+
message: "Ready? Press Enter to open your browser and follow the steps above",
|
|
3182
|
+
initialValue: true,
|
|
3183
|
+
active: "Open browser",
|
|
3184
|
+
inactive: "Cancel"
|
|
3185
|
+
});
|
|
3186
|
+
handleCancel(ready);
|
|
3187
|
+
if (!ready) {
|
|
3188
|
+
p.cancel("Cancelled.");
|
|
3189
|
+
return;
|
|
3190
|
+
}
|
|
3165
3191
|
await setupJwt();
|
|
3166
|
-
p.outro("
|
|
3192
|
+
p.outro("Management features are now unlocked.");
|
|
3167
3193
|
}
|
|
3168
3194
|
|
|
3169
3195
|
// src/commands/validate.ts
|
|
3170
3196
|
import { resolve as resolve5 } from "path";
|
|
3171
|
-
import
|
|
3197
|
+
import chalk14 from "chalk";
|
|
3172
3198
|
async function validateCommand(pathArg = ".") {
|
|
3173
3199
|
const targetDir = resolve5(pathArg);
|
|
3174
3200
|
p.intro(`\u{1F50E} Validate ability`);
|
|
@@ -3184,7 +3210,7 @@ async function validateCommand(pathArg = ".") {
|
|
|
3184
3210
|
if (result.errors.length > 0) {
|
|
3185
3211
|
p.note(
|
|
3186
3212
|
result.errors.map(
|
|
3187
|
-
(issue) => `${
|
|
3213
|
+
(issue) => `${chalk14.red("\u2717")} ${issue.file ? chalk14.bold(`[${issue.file}]`) + " " : ""}${issue.message}`
|
|
3188
3214
|
).join("\n"),
|
|
3189
3215
|
`${result.errors.length} Error(s)`
|
|
3190
3216
|
);
|
|
@@ -3192,7 +3218,7 @@ async function validateCommand(pathArg = ".") {
|
|
|
3192
3218
|
if (result.warnings.length > 0) {
|
|
3193
3219
|
p.note(
|
|
3194
3220
|
result.warnings.map(
|
|
3195
|
-
(w) => `${
|
|
3221
|
+
(w) => `${chalk14.yellow("\u26A0")} ${w.file ? chalk14.bold(`[${w.file}]`) + " " : ""}${w.message}`
|
|
3196
3222
|
).join("\n"),
|
|
3197
3223
|
`${result.warnings.length} Warning(s)`
|
|
3198
3224
|
);
|
|
@@ -3238,9 +3264,9 @@ async function checkForUpdates() {
|
|
|
3238
3264
|
);
|
|
3239
3265
|
process.exit(0);
|
|
3240
3266
|
} else {
|
|
3241
|
-
const { default:
|
|
3267
|
+
const { default: chalk15 } = await import("chalk");
|
|
3242
3268
|
console.log(
|
|
3243
|
-
|
|
3269
|
+
chalk15.yellow(
|
|
3244
3270
|
` Update available: v${version} \u2192 v${latest} Run: npm install -g openhome-cli@latest
|
|
3245
3271
|
`
|
|
3246
3272
|
)
|
package/package.json
CHANGED
package/src/commands/login.ts
CHANGED
|
@@ -88,17 +88,35 @@ export async function loginCommand(): Promise<void> {
|
|
|
88
88
|
p.note(
|
|
89
89
|
[
|
|
90
90
|
"To manage your abilities (list, delete, enable/disable) from the CLI,",
|
|
91
|
-
"you need one more thing: a session token.",
|
|
91
|
+
"you need one more thing: a session token. This takes ~30 seconds",
|
|
92
|
+
"and you only do it once.",
|
|
92
93
|
"",
|
|
93
|
-
|
|
94
|
+
`${chalk.bold("Here's what you'll do:")}`,
|
|
95
|
+
"",
|
|
96
|
+
`${chalk.bold("1.")} We'll open ${chalk.bold("app.openhome.com")} — make sure you're logged in`,
|
|
97
|
+
"",
|
|
98
|
+
`${chalk.bold("2.")} Open the browser console:`,
|
|
99
|
+
` Mac → ${chalk.cyan("Cmd + Option + J")}`,
|
|
100
|
+
` Windows / Linux → ${chalk.cyan("F12")} then click ${chalk.cyan("Console")}`,
|
|
101
|
+
"",
|
|
102
|
+
`${chalk.bold("3.")} Chrome may show this warning — it's expected:`,
|
|
103
|
+
` ${chalk.yellow("\"Don't paste code you don't understand...\"")}`,
|
|
104
|
+
` Type ${chalk.cyan("allow pasting")} and press Enter to dismiss it.`,
|
|
105
|
+
"",
|
|
106
|
+
`${chalk.bold("4.")} Paste this command and press Enter:`,
|
|
107
|
+
"",
|
|
108
|
+
` ${chalk.green("copy(localStorage.getItem('token'))")}`,
|
|
109
|
+
"",
|
|
110
|
+
`${chalk.bold("5.")} Your token is copied to clipboard — paste it back here.`,
|
|
94
111
|
].join("\n"),
|
|
95
|
-
"
|
|
112
|
+
"Enable management features (one-time setup)",
|
|
96
113
|
);
|
|
97
114
|
|
|
98
115
|
const doJwt = await p.confirm({
|
|
99
|
-
message:
|
|
116
|
+
message:
|
|
117
|
+
"Ready? Press Enter to open your browser and follow the steps above",
|
|
100
118
|
initialValue: true,
|
|
101
|
-
active: "
|
|
119
|
+
active: "Open browser",
|
|
102
120
|
inactive: "Skip for now",
|
|
103
121
|
});
|
|
104
122
|
handleCancel(doJwt);
|
|
@@ -118,35 +136,9 @@ export async function loginCommand(): Promise<void> {
|
|
|
118
136
|
export async function setupJwt(): Promise<void> {
|
|
119
137
|
const { saveJwt } = await import("../config/store.js");
|
|
120
138
|
|
|
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.")} Paste this command and press ${chalk.bold("Enter")}:`,
|
|
143
|
-
"",
|
|
144
|
-
` ${chalk.green("copy(localStorage.getItem('token'))")}`,
|
|
145
|
-
"",
|
|
146
|
-
`${chalk.bold("3.")} Your token is now copied to your clipboard.`,
|
|
147
|
-
` Come back here and paste it below.`,
|
|
148
|
-
].join("\n"),
|
|
149
|
-
"How to get your session token",
|
|
139
|
+
openBrowser(OPENHOME_APP_URL);
|
|
140
|
+
console.log(
|
|
141
|
+
`\n ${chalk.dim(`Opened ${chalk.bold("app.openhome.com")} — follow the steps above`)}\n`,
|
|
150
142
|
);
|
|
151
143
|
|
|
152
144
|
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
|
}
|