@vincentt-xr/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/dist/cli/index.js CHANGED
@@ -12,6 +12,7 @@
12
12
  import os from "node:os";
13
13
  import path from "node:path";
14
14
  import { runLogin } from "../login/login.js";
15
+ import { ensureLoggedIn } from "../login/ensure.js";
15
16
  import { clearMachineToken, clearProjectBinding, loadMachineConfig, } from "../shared/config.js";
16
17
  import { getMe } from "../lib/backend.js";
17
18
  import { diagQuery, diagRead, previewStart, previewStop, previewStopSignal, projectCreate, projectPublish, } from "../lib/lifecycle.js";
@@ -51,6 +52,18 @@ async function login() {
51
52
  console.log(`\n✓ Signed in. Access token saved to ${configPath}`);
52
53
  console.log(` API: ${saved}`);
53
54
  }
55
+ /** The token that would authenticate a machine call, if any (env wins over file). */
56
+ async function currentToken() {
57
+ return process.env.VINCENTT_PAT ?? (await loadMachineConfig()).pat;
58
+ }
59
+ /** Guard an auth-requiring verb: log in inline on first run instead of erroring. */
60
+ async function requireLogin() {
61
+ await ensureLoggedIn({
62
+ currentToken,
63
+ runLogin: login,
64
+ notify: (m) => console.error(m),
65
+ });
66
+ }
54
67
  async function logout() {
55
68
  const { path: p, hadToken } = await clearMachineToken();
56
69
  console.log(hadToken ? `✓ Signed out. Token removed from ${p}` : "Already signed out.");
@@ -79,6 +92,7 @@ async function whoami() {
79
92
  }
80
93
  // ---- dev loop ---------------------------------------------------------------
81
94
  async function create() {
95
+ await requireLogin();
82
96
  const result = await projectCreate(projectDir(), {
83
97
  name: flag("--name"),
84
98
  slug: flag("--slug"),
@@ -102,6 +116,7 @@ async function unbind() {
102
116
  console.log(hadBinding ? `✓ Unbound. Removed ${p}` : "This directory has no project binding.");
103
117
  }
104
118
  async function publish() {
119
+ await requireLogin();
105
120
  const result = await projectPublish(projectDir(), {
106
121
  distDir: flag("--dist"),
107
122
  note: flag("--note"),
@@ -118,6 +133,7 @@ async function preview() {
118
133
  console.log(message);
119
134
  return;
120
135
  }
136
+ await requireLogin();
121
137
  const { preview: p, started } = await previewStart(projectDir(), (m) => console.error(`[preview] ${m}`));
122
138
  if (!started) {
123
139
  console.log(`A preview is already running:\n${p.url}`);
@@ -0,0 +1,10 @@
1
+ export interface EnsureLoginDeps {
2
+ /** Resolve the current token (env override or machine config), or undefined. */
3
+ currentToken: () => Promise<string | undefined>;
4
+ /** Run the interactive login flow (loopback OAuth), persisting a token. */
5
+ runLogin: () => Promise<void>;
6
+ /** Surface a line to the user (stderr, so it never pollutes machine-readable stdout). */
7
+ notify: (message: string) => void;
8
+ }
9
+ /** No-op when a token is already present; otherwise log-and-login before returning. */
10
+ export declare function ensureLoggedIn(deps: EnsureLoginDeps): Promise<void>;
@@ -0,0 +1,13 @@
1
+ // First-run login guard. An auth-requiring verb (create / preview / publish) calls
2
+ // this before doing any work: if there's no token yet, it runs the login flow inline
3
+ // and continues, instead of failing with "not signed in". Login stays a human browser
4
+ // approval — this only removes the separate `vincentt login` step a user had to know
5
+ // to run first. Deps are injected so the branch is unit-testable without a real
6
+ // browser round-trip or a real config file.
7
+ /** No-op when a token is already present; otherwise log-and-login before returning. */
8
+ export async function ensureLoggedIn(deps) {
9
+ if (await deps.currentToken())
10
+ return;
11
+ deps.notify("You're not signed in yet — opening the browser to authorize this device…");
12
+ await deps.runLogin();
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincentt-xr/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Vincentt CLI — the vincentt command-line dev loop (login, create, publish, preview, diagnostics, feedback, relay, mcp)",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",