@emit-vision/cli 0.2.0 → 0.2.2
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/index.js +143 -43
- package/package.json +2 -2
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
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.
|
|
279
|
+
console.error(
|
|
245
280
|
"\nWarning: Copy this ingest key now \u2014 it will not be shown again."
|
|
246
281
|
);
|
|
247
|
-
console.log(
|
|
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.
|
|
306
|
+
console.error(
|
|
267
307
|
"\nWarning: Copy this ingest key now \u2014 it will not be shown again."
|
|
268
308
|
);
|
|
269
|
-
console.log(
|
|
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
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
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(
|
|
380
|
+
console.log(result.rawIngestKey);
|
|
327
381
|
}
|
|
328
382
|
|
|
329
383
|
// src/commands/query.ts
|
|
@@ -496,9 +550,48 @@ async function runLogs(args) {
|
|
|
496
550
|
);
|
|
497
551
|
}
|
|
498
552
|
|
|
553
|
+
// src/commands/status.ts
|
|
554
|
+
async function runStatus(args = []) {
|
|
555
|
+
const config = loadConfig();
|
|
556
|
+
const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
|
|
557
|
+
const json = args.includes("--json");
|
|
558
|
+
if (!config.pat) {
|
|
559
|
+
if (json) {
|
|
560
|
+
console.log(JSON.stringify({ apiUrl, tokenPrefix: null, valid: false }));
|
|
561
|
+
} else {
|
|
562
|
+
console.log("Not logged in.");
|
|
563
|
+
console.log(` API: ${apiUrl}`);
|
|
564
|
+
console.log("Run `emit-vision login` to authenticate.");
|
|
565
|
+
}
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
let valid = false;
|
|
569
|
+
try {
|
|
570
|
+
await apiFetch("/v1/management/projects");
|
|
571
|
+
valid = true;
|
|
572
|
+
} catch {
|
|
573
|
+
}
|
|
574
|
+
if (json) {
|
|
575
|
+
console.log(
|
|
576
|
+
JSON.stringify({ apiUrl, tokenPrefix: config.pat.slice(0, 12), valid })
|
|
577
|
+
);
|
|
578
|
+
} else {
|
|
579
|
+
console.log(` API: ${apiUrl}`);
|
|
580
|
+
console.log(` Token: ${config.pat.slice(0, 12)}\u2026`);
|
|
581
|
+
console.log(
|
|
582
|
+
valid ? " Auth: valid \u2713" : " Auth: invalid or expired \u2014 run `emit-vision login`"
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
499
587
|
// src/index.ts
|
|
588
|
+
var VERSION = "0.2.2";
|
|
500
589
|
var [cmd, subcmd, ...rest] = process.argv.slice(2);
|
|
501
590
|
async function main() {
|
|
591
|
+
if (cmd === "--version" || cmd === "-v") {
|
|
592
|
+
console.log(VERSION);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
502
595
|
try {
|
|
503
596
|
if (cmd === "login") {
|
|
504
597
|
await runLogin(subcmd ? [subcmd, ...rest] : rest);
|
|
@@ -544,6 +637,8 @@ async function main() {
|
|
|
544
637
|
await runOverview(subcmd ? [subcmd, ...rest] : rest);
|
|
545
638
|
} else if (cmd === "logs") {
|
|
546
639
|
await runLogs(subcmd ? [subcmd, ...rest] : rest);
|
|
640
|
+
} else if (cmd === "status") {
|
|
641
|
+
await runStatus(subcmd ? [subcmd, ...rest] : rest);
|
|
547
642
|
} else {
|
|
548
643
|
printHelp();
|
|
549
644
|
if (cmd !== void 0) process.exit(1);
|
|
@@ -566,16 +661,19 @@ async function main() {
|
|
|
566
661
|
}
|
|
567
662
|
}
|
|
568
663
|
function printHelp() {
|
|
569
|
-
console.log(`emit-vision CLI
|
|
664
|
+
console.log(`emit-vision CLI v${VERSION}
|
|
570
665
|
|
|
571
666
|
Commands:
|
|
572
|
-
login [--api-url <url>]
|
|
667
|
+
login [--token <pat>] [--api-url <url>] Authenticate (non-interactive: --token or EMIT_VISION_PAT env)
|
|
668
|
+
login --browser [--yes] [--api-url <url>] Authenticate via browser OAuth
|
|
573
669
|
logout Clear stored credentials
|
|
670
|
+
status [--json] Show auth status and verify token
|
|
671
|
+
|
|
574
672
|
project list List your projects
|
|
575
|
-
project create <name>
|
|
576
|
-
project env create <projectId> <name> [--type ...]
|
|
673
|
+
project create <name> [--json] Create a new project
|
|
674
|
+
project env create <projectId> <name> [--type ...] [--json] Create a new environment
|
|
577
675
|
key get <projectId> Get ingest key info for a project
|
|
578
|
-
key rotate <projectId>
|
|
676
|
+
key rotate <projectId> [--yes] [--json] Rotate the ingest key (--yes skips confirmation)
|
|
579
677
|
|
|
580
678
|
overview <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--json]
|
|
581
679
|
Project summary (events, errors, top events)
|
|
@@ -587,6 +685,8 @@ Commands:
|
|
|
587
685
|
Grouped/deduplicated errors with counts
|
|
588
686
|
logs <projectId> [--from <iso>] [--to <iso>] [--severity <level>] [--limit <n>] [--json]
|
|
589
687
|
Recent log entries
|
|
688
|
+
|
|
689
|
+
--version, -v Print CLI version
|
|
590
690
|
`);
|
|
591
691
|
}
|
|
592
692
|
main();
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emit-vision/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "CLI for emit-vision project management",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|
|
9
|
-
"emit-vision": "
|
|
9
|
+
"emit-vision": "dist/index.js"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist"
|