@blankdotpage/cli 0.1.3 → 0.1.4
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/README.md +1 -0
- package/dist/index.js +35 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -486,6 +486,37 @@ async function commandWhoAmI(ctx) {
|
|
|
486
486
|
`${whoami.email}${whoami.handle ? ` (@${whoami.handle})` : ""}`
|
|
487
487
|
);
|
|
488
488
|
}
|
|
489
|
+
async function commandLogout(ctx) {
|
|
490
|
+
if (ctx.positionals.length > 0) {
|
|
491
|
+
throw new Error("Usage: blankpage logout");
|
|
492
|
+
}
|
|
493
|
+
const config = await loadConfig();
|
|
494
|
+
const token = config.token;
|
|
495
|
+
let revokedRemote = false;
|
|
496
|
+
if (token) {
|
|
497
|
+
const client = new ApiClient({ appUrl: ctx.appUrl, token });
|
|
498
|
+
try {
|
|
499
|
+
await client.post("/api/cli/logout", {});
|
|
500
|
+
revokedRemote = true;
|
|
501
|
+
} catch (error) {
|
|
502
|
+
if (!(error instanceof ApiError) || error.status >= 500) {
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
await saveConfig({
|
|
508
|
+
appUrl: config.appUrl ?? ctx.appUrl
|
|
509
|
+
});
|
|
510
|
+
output(
|
|
511
|
+
ctx.json,
|
|
512
|
+
{
|
|
513
|
+
event: "logout_success",
|
|
514
|
+
revokedRemote,
|
|
515
|
+
hadToken: Boolean(token)
|
|
516
|
+
},
|
|
517
|
+
token ? "Logged out. CLI token removed." : "Already logged out. No CLI token found."
|
|
518
|
+
);
|
|
519
|
+
}
|
|
489
520
|
async function commandList(ctx) {
|
|
490
521
|
if (ctx.positionals.length > 0) {
|
|
491
522
|
throw new Error("Usage: blankpage list");
|
|
@@ -699,6 +730,7 @@ function printHelp() {
|
|
|
699
730
|
|
|
700
731
|
Commands:
|
|
701
732
|
blankpage login [--app-url <url>] [--no-browser] [--json]
|
|
733
|
+
blankpage logout [--app-url <url>] [--json]
|
|
702
734
|
blankpage whoami [--app-url <url>] [--json]
|
|
703
735
|
blankpage list [--app-url <url>] [--json]
|
|
704
736
|
blankpage create <markdown-file> [--app-url <url>] [--json]
|
|
@@ -728,6 +760,9 @@ async function main() {
|
|
|
728
760
|
case "login":
|
|
729
761
|
await commandLogin(ctx);
|
|
730
762
|
return;
|
|
763
|
+
case "logout":
|
|
764
|
+
await commandLogout(ctx);
|
|
765
|
+
return;
|
|
731
766
|
case "whoami":
|
|
732
767
|
await commandWhoAmI(ctx);
|
|
733
768
|
return;
|