@emit-vision/cli 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/dist/index.js +129 -43
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -85,13 +85,40 @@ async function runLogin(args) {
85
85
  if (apiUrlIdx !== -1 && args[apiUrlIdx + 1]) {
86
86
  apiUrl = args[apiUrlIdx + 1];
87
87
  }
88
+ const tokenFlagIdx = args.indexOf("--token");
89
+ const token = (tokenFlagIdx !== -1 ? args[tokenFlagIdx + 1] : void 0) ?? process.env.EMIT_VISION_PAT;
90
+ if (token) {
91
+ await runDirectLogin(token, apiUrl);
92
+ return;
93
+ }
94
+ const force = args.includes("--yes") || args.includes("-y");
88
95
  if (args.includes("--browser")) {
89
- await runBrowserLogin(apiUrl);
96
+ await runBrowserLogin(apiUrl, force);
90
97
  return;
91
98
  }
92
99
  await runPasteLogin(apiUrl);
93
100
  }
101
+ async function runDirectLogin(pat, apiUrl) {
102
+ try {
103
+ await apiFetch("/v1/management/projects", { pat, apiUrl });
104
+ const patch = { pat };
105
+ if (apiUrl) patch.apiUrl = apiUrl;
106
+ saveConfig(patch);
107
+ console.log("Logged in successfully.");
108
+ } catch (err) {
109
+ console.error(
110
+ `Login failed: ${err instanceof Error ? err.message : String(err)}`
111
+ );
112
+ process.exit(1);
113
+ }
114
+ }
94
115
  async function runPasteLogin(apiUrl) {
116
+ if (!process.stdin.isTTY) {
117
+ console.error(
118
+ "stdin is not a terminal.\nPass --token <pat> or set EMIT_VISION_PAT=<token> to log in non-interactively."
119
+ );
120
+ process.exit(1);
121
+ }
95
122
  const rl = createInterface({ input: process.stdin, output: process.stdout });
96
123
  const pat = await new Promise((resolve) => {
97
124
  rl.question("Paste your Personal Access Token: ", (answer) => {
@@ -116,22 +143,25 @@ async function runPasteLogin(apiUrl) {
116
143
  process.exit(1);
117
144
  }
118
145
  }
119
- async function runBrowserLogin(apiUrl) {
146
+ async function runBrowserLogin(apiUrl, force = false) {
120
147
  const config = loadConfig();
121
- if (config.pat) {
122
- const rl = createInterface({
123
- input: process.stdin,
124
- output: process.stdout
125
- });
126
- const answer = await new Promise((resolve) => {
127
- rl.question("Already logged in. Overwrite? [y/N] ", (a) => {
128
- rl.close();
129
- resolve(a.trim().toLowerCase());
148
+ if (config.pat && !force) {
149
+ if (!process.stdin.isTTY) {
150
+ } else {
151
+ const rl = createInterface({
152
+ input: process.stdin,
153
+ output: process.stdout
130
154
  });
131
- });
132
- if (answer !== "y" && answer !== "yes") {
133
- console.log("Aborted.");
134
- return;
155
+ const answer = await new Promise((resolve) => {
156
+ rl.question("Already logged in. Overwrite? [y/N] ", (a) => {
157
+ rl.close();
158
+ resolve(a.trim().toLowerCase());
159
+ });
160
+ });
161
+ if (answer !== "y" && answer !== "yes") {
162
+ console.log("Aborted.");
163
+ return;
164
+ }
135
165
  }
136
166
  }
137
167
  let initResult;
@@ -233,27 +263,33 @@ async function runProjectList() {
233
263
  printTable(["Name", "ID", "Environment", "Created"], rows);
234
264
  }
235
265
  async function runProjectCreate(args) {
236
- const name = args[0];
266
+ const name = args.find((a) => !a.startsWith("--"));
267
+ const json = args.includes("--json");
237
268
  if (!name) {
238
- console.error("Usage: emit-vision project create <name>");
269
+ console.error("Usage: emit-vision project create <name> [--json]");
239
270
  process.exit(1);
240
271
  }
241
272
  const result = await apiFetch("/v1/management/projects", { method: "POST", body: { name } });
273
+ if (json) {
274
+ console.log(JSON.stringify(result, null, 2));
275
+ return;
276
+ }
242
277
  console.log(`Project created: ${result.name} (${result.id})`);
243
278
  if (result.rawIngestKey) {
244
- console.log(
279
+ console.error(
245
280
  "\nWarning: Copy this ingest key now \u2014 it will not be shown again."
246
281
  );
247
- console.log(` ${result.rawIngestKey}`);
282
+ console.log(result.rawIngestKey);
248
283
  }
249
284
  }
250
285
  async function runProjectEnvCreate(args) {
251
286
  const [projectId, envName, ...rest2] = args;
252
287
  const typeIdx = rest2.indexOf("--type");
253
288
  const envType = typeIdx !== -1 ? rest2[typeIdx + 1] : void 0;
289
+ const json = rest2.includes("--json");
254
290
  if (!projectId || !envName) {
255
291
  console.error(
256
- "Usage: emit-vision project env create <projectId> <envName> [--type development|staging|custom]"
292
+ "Usage: emit-vision project env create <projectId> <envName> [--type development|staging|custom] [--json]"
257
293
  );
258
294
  process.exit(1);
259
295
  }
@@ -261,12 +297,16 @@ async function runProjectEnvCreate(args) {
261
297
  method: "POST",
262
298
  body: { name: envName, ...envType ? { type: envType } : {} }
263
299
  });
300
+ if (json) {
301
+ console.log(JSON.stringify(result, null, 2));
302
+ return;
303
+ }
264
304
  console.log(`Environment created: ${result.name} (${result.id})`);
265
305
  if (result.rawIngestKey) {
266
- console.log(
306
+ console.error(
267
307
  "\nWarning: Copy this ingest key now \u2014 it will not be shown again."
268
308
  );
269
- console.log(` ${result.rawIngestKey}`);
309
+ console.log(result.rawIngestKey);
270
310
  }
271
311
  }
272
312
  function printTable(headers, rows) {
@@ -299,31 +339,45 @@ async function runKeyGet(args) {
299
339
  async function runKeyRotate(args) {
300
340
  const projectId = args[0];
301
341
  if (!projectId) {
302
- console.error("Usage: emit-vision key rotate <projectId>");
342
+ console.error("Usage: emit-vision key rotate <projectId> [--yes]");
303
343
  process.exit(1);
304
344
  }
305
- const rl = createInterface2({ input: process.stdin, output: process.stdout });
306
- const answer = await new Promise((resolve) => {
307
- rl.question(
308
- "Rotate the ingest key? This will invalidate the current key. [y/N] ",
309
- (a) => {
310
- rl.close();
311
- resolve(a.trim().toLowerCase());
312
- }
313
- );
314
- });
315
- if (answer !== "y" && answer !== "yes") {
316
- console.log("Aborted.");
317
- return;
345
+ const confirmed = args.includes("--yes") || args.includes("-y");
346
+ if (!confirmed) {
347
+ if (!process.stdin.isTTY) {
348
+ console.error(
349
+ "stdin is not a terminal.\nPass --yes to confirm key rotation non-interactively."
350
+ );
351
+ process.exit(1);
352
+ }
353
+ const rl = createInterface2({ input: process.stdin, output: process.stdout });
354
+ const answer = await new Promise((resolve) => {
355
+ rl.question(
356
+ "Rotate the ingest key? This will invalidate the current key. [y/N] ",
357
+ (a) => {
358
+ rl.close();
359
+ resolve(a.trim().toLowerCase());
360
+ }
361
+ );
362
+ });
363
+ if (answer !== "y" && answer !== "yes") {
364
+ console.log("Aborted.");
365
+ return;
366
+ }
318
367
  }
319
368
  const result = await apiFetch(
320
369
  `/v1/management/projects/${encodeURIComponent(projectId)}/keys/rotate`,
321
370
  { method: "POST" }
322
371
  );
323
- console.log(
372
+ const json = args.includes("--json");
373
+ if (json) {
374
+ console.log(JSON.stringify(result, null, 2));
375
+ return;
376
+ }
377
+ console.error(
324
378
  "\nWarning: Copy this new ingest key now \u2014 it will not be shown again."
325
379
  );
326
- console.log(` ${result.rawIngestKey}`);
380
+ console.log(result.rawIngestKey);
327
381
  }
328
382
 
329
383
  // src/commands/query.ts
@@ -496,9 +550,34 @@ async function runLogs(args) {
496
550
  );
497
551
  }
498
552
 
553
+ // src/commands/status.ts
554
+ async function runStatus() {
555
+ const config = loadConfig();
556
+ const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
557
+ if (!config.pat) {
558
+ console.log("Not logged in.");
559
+ console.log(` API: ${apiUrl}`);
560
+ console.log("Run `emit-vision login` to authenticate.");
561
+ return;
562
+ }
563
+ console.log(` API: ${apiUrl}`);
564
+ console.log(` Token: ${config.pat.slice(0, 12)}\u2026`);
565
+ try {
566
+ await apiFetch("/v1/management/projects");
567
+ console.log(" Auth: valid \u2713");
568
+ } catch {
569
+ console.log(" Auth: invalid or expired \u2014 run `emit-vision login`");
570
+ }
571
+ }
572
+
499
573
  // src/index.ts
574
+ var VERSION = "0.2.1";
500
575
  var [cmd, subcmd, ...rest] = process.argv.slice(2);
501
576
  async function main() {
577
+ if (cmd === "--version" || cmd === "-v") {
578
+ console.log(VERSION);
579
+ return;
580
+ }
502
581
  try {
503
582
  if (cmd === "login") {
504
583
  await runLogin(subcmd ? [subcmd, ...rest] : rest);
@@ -544,6 +623,8 @@ async function main() {
544
623
  await runOverview(subcmd ? [subcmd, ...rest] : rest);
545
624
  } else if (cmd === "logs") {
546
625
  await runLogs(subcmd ? [subcmd, ...rest] : rest);
626
+ } else if (cmd === "status") {
627
+ await runStatus();
547
628
  } else {
548
629
  printHelp();
549
630
  if (cmd !== void 0) process.exit(1);
@@ -566,16 +647,19 @@ async function main() {
566
647
  }
567
648
  }
568
649
  function printHelp() {
569
- console.log(`emit-vision CLI
650
+ console.log(`emit-vision CLI v${VERSION}
570
651
 
571
652
  Commands:
572
- login [--api-url <url>] Authenticate with a Personal Access Token
653
+ login [--token <pat>] [--api-url <url>] Authenticate (non-interactive: --token or EMIT_VISION_PAT env)
654
+ login --browser [--yes] [--api-url <url>] Authenticate via browser OAuth
573
655
  logout Clear stored credentials
656
+ status Show auth status and verify token
657
+
574
658
  project list List your projects
575
- project create <name> Create a new project
576
- project env create <projectId> <name> [--type ...] Create a new environment
659
+ project create <name> [--json] Create a new project
660
+ project env create <projectId> <name> [--type ...] [--json] Create a new environment
577
661
  key get <projectId> Get ingest key info for a project
578
- key rotate <projectId> Rotate the ingest key for a project
662
+ key rotate <projectId> [--yes] [--json] Rotate the ingest key (--yes skips confirmation)
579
663
 
580
664
  overview <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--json]
581
665
  Project summary (events, errors, top events)
@@ -587,6 +671,8 @@ Commands:
587
671
  Grouped/deduplicated errors with counts
588
672
  logs <projectId> [--from <iso>] [--to <iso>] [--severity <level>] [--limit <n>] [--json]
589
673
  Recent log entries
674
+
675
+ --version, -v Print CLI version
590
676
  `);
591
677
  }
592
678
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emit-vision/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "CLI for emit-vision project management",
5
5
  "private": false,
6
6
  "license": "MIT",