@emit-vision/cli 0.1.0 → 0.2.0
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 +208 -7
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -326,6 +326,176 @@ async function runKeyRotate(args) {
|
|
|
326
326
|
console.log(` ${result.rawIngestKey}`);
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
// src/commands/query.ts
|
|
330
|
+
function parseFlags(args) {
|
|
331
|
+
const flags = {};
|
|
332
|
+
for (let i = 0; i < args.length; i++) {
|
|
333
|
+
const arg = args[i];
|
|
334
|
+
if ((arg === "--from" || arg === "--to" || arg === "--environment" || arg === "--release" || arg === "--limit" || arg === "--severity") && args[i + 1]) {
|
|
335
|
+
flags[arg.slice(2)] = args[++i];
|
|
336
|
+
} else if (arg === "--json") {
|
|
337
|
+
flags.json = "true";
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return flags;
|
|
341
|
+
}
|
|
342
|
+
function buildQs(projectId, flags, extras) {
|
|
343
|
+
const params = new URLSearchParams({ projectId });
|
|
344
|
+
const merged = { ...flags, ...extras };
|
|
345
|
+
for (const key of ["from", "to", "environment", "release", "limit", "severity"]) {
|
|
346
|
+
if (merged[key]) params.set(key, merged[key]);
|
|
347
|
+
}
|
|
348
|
+
return params.toString();
|
|
349
|
+
}
|
|
350
|
+
async function runEventsRecent(args) {
|
|
351
|
+
const [projectId, ...rest2] = args;
|
|
352
|
+
if (!projectId) {
|
|
353
|
+
console.error(
|
|
354
|
+
"Usage: emit-vision events recent <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--limit <n>] [--json]"
|
|
355
|
+
);
|
|
356
|
+
process.exit(1);
|
|
357
|
+
}
|
|
358
|
+
const flags = parseFlags(rest2);
|
|
359
|
+
const events = await apiFetch(
|
|
360
|
+
`/v1/events/recent?${buildQs(projectId, flags)}`
|
|
361
|
+
);
|
|
362
|
+
if (flags.json) {
|
|
363
|
+
console.log(JSON.stringify(events, null, 2));
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (events.length === 0) {
|
|
367
|
+
console.log("No events found.");
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
printTable(
|
|
371
|
+
["Timestamp", "Name", "User", "Environment"],
|
|
372
|
+
events.map((e) => [
|
|
373
|
+
new Date(e.timestamp).toLocaleString(),
|
|
374
|
+
e.name,
|
|
375
|
+
e.userId ?? "\u2014",
|
|
376
|
+
e.environment ?? "\u2014"
|
|
377
|
+
])
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
async function runErrorsRecent(args) {
|
|
381
|
+
const [projectId, ...rest2] = args;
|
|
382
|
+
if (!projectId) {
|
|
383
|
+
console.error(
|
|
384
|
+
"Usage: emit-vision errors recent <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--limit <n>] [--json]"
|
|
385
|
+
);
|
|
386
|
+
process.exit(1);
|
|
387
|
+
}
|
|
388
|
+
const flags = parseFlags(rest2);
|
|
389
|
+
const errors = await apiFetch(
|
|
390
|
+
`/v1/errors/recent?${buildQs(projectId, flags)}`
|
|
391
|
+
);
|
|
392
|
+
if (flags.json) {
|
|
393
|
+
console.log(JSON.stringify(errors, null, 2));
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (errors.length === 0) {
|
|
397
|
+
console.log("No errors found.");
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
printTable(
|
|
401
|
+
["Timestamp", "Name", "User", "Environment"],
|
|
402
|
+
errors.map((e) => [
|
|
403
|
+
new Date(e.timestamp).toLocaleString(),
|
|
404
|
+
e.name,
|
|
405
|
+
e.userId ?? "\u2014",
|
|
406
|
+
e.environment ?? "\u2014"
|
|
407
|
+
])
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
async function runErrorsGrouped(args) {
|
|
411
|
+
const [projectId, ...rest2] = args;
|
|
412
|
+
if (!projectId) {
|
|
413
|
+
console.error(
|
|
414
|
+
"Usage: emit-vision errors grouped <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--limit <n>] [--json]"
|
|
415
|
+
);
|
|
416
|
+
process.exit(1);
|
|
417
|
+
}
|
|
418
|
+
const flags = parseFlags(rest2);
|
|
419
|
+
const groups = await apiFetch(
|
|
420
|
+
`/v1/errors/grouped?${buildQs(projectId, flags)}`
|
|
421
|
+
);
|
|
422
|
+
if (flags.json) {
|
|
423
|
+
console.log(JSON.stringify(groups, null, 2));
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (groups.length === 0) {
|
|
427
|
+
console.log("No error groups found.");
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
printTable(
|
|
431
|
+
["Count", "Status", "Last Seen", "Message"],
|
|
432
|
+
groups.map((g) => [
|
|
433
|
+
String(g.count),
|
|
434
|
+
g.status,
|
|
435
|
+
new Date(g.lastSeen).toLocaleString(),
|
|
436
|
+
g.message.length > 60 ? g.message.slice(0, 57) + "..." : g.message
|
|
437
|
+
])
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
async function runOverview(args) {
|
|
441
|
+
const [projectId, ...rest2] = args;
|
|
442
|
+
if (!projectId) {
|
|
443
|
+
console.error(
|
|
444
|
+
"Usage: emit-vision overview <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--json]"
|
|
445
|
+
);
|
|
446
|
+
process.exit(1);
|
|
447
|
+
}
|
|
448
|
+
const flags = parseFlags(rest2);
|
|
449
|
+
const data = await apiFetch(
|
|
450
|
+
`/v1/overview?${buildQs(projectId, flags)}`
|
|
451
|
+
);
|
|
452
|
+
if (flags.json) {
|
|
453
|
+
console.log(JSON.stringify(data, null, 2));
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
console.log(`Total events: ${data.totalEvents}`);
|
|
457
|
+
console.log(`Total errors: ${data.totalErrors}`);
|
|
458
|
+
if (data.uniqueVisitors !== void 0) {
|
|
459
|
+
console.log(`Unique visitors: ${data.uniqueVisitors}`);
|
|
460
|
+
}
|
|
461
|
+
if (data.topEvents?.length) {
|
|
462
|
+
console.log("\nTop events:");
|
|
463
|
+
printTable(
|
|
464
|
+
["Event", "Count"],
|
|
465
|
+
data.topEvents.map((e) => [e.name, String(e.count)])
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
async function runLogs(args) {
|
|
470
|
+
const [projectId, ...rest2] = args;
|
|
471
|
+
if (!projectId) {
|
|
472
|
+
console.error(
|
|
473
|
+
"Usage: emit-vision logs <projectId> [--from <iso>] [--to <iso>] [--severity <level>] [--limit <n>] [--json]"
|
|
474
|
+
);
|
|
475
|
+
process.exit(1);
|
|
476
|
+
}
|
|
477
|
+
const flags = parseFlags(rest2);
|
|
478
|
+
const { logs } = await apiFetch(
|
|
479
|
+
`/v1/logs?${buildQs(projectId, flags)}`
|
|
480
|
+
);
|
|
481
|
+
if (flags.json) {
|
|
482
|
+
console.log(JSON.stringify(logs, null, 2));
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (logs.length === 0) {
|
|
486
|
+
console.log("No logs found.");
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
printTable(
|
|
490
|
+
["Timestamp", "Severity", "Message"],
|
|
491
|
+
logs.map((l) => [
|
|
492
|
+
new Date(l.timestamp).toLocaleString(),
|
|
493
|
+
l.severity,
|
|
494
|
+
l.body.length > 80 ? l.body.slice(0, 77) + "..." : l.body
|
|
495
|
+
])
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
|
|
329
499
|
// src/index.ts
|
|
330
500
|
var [cmd, subcmd, ...rest] = process.argv.slice(2);
|
|
331
501
|
async function main() {
|
|
@@ -354,6 +524,26 @@ async function main() {
|
|
|
354
524
|
printHelp();
|
|
355
525
|
process.exit(1);
|
|
356
526
|
}
|
|
527
|
+
} else if (cmd === "events") {
|
|
528
|
+
if (subcmd === "recent") {
|
|
529
|
+
await runEventsRecent(rest);
|
|
530
|
+
} else {
|
|
531
|
+
printHelp();
|
|
532
|
+
process.exit(1);
|
|
533
|
+
}
|
|
534
|
+
} else if (cmd === "errors") {
|
|
535
|
+
if (subcmd === "recent") {
|
|
536
|
+
await runErrorsRecent(rest);
|
|
537
|
+
} else if (subcmd === "grouped") {
|
|
538
|
+
await runErrorsGrouped(rest);
|
|
539
|
+
} else {
|
|
540
|
+
printHelp();
|
|
541
|
+
process.exit(1);
|
|
542
|
+
}
|
|
543
|
+
} else if (cmd === "overview") {
|
|
544
|
+
await runOverview(subcmd ? [subcmd, ...rest] : rest);
|
|
545
|
+
} else if (cmd === "logs") {
|
|
546
|
+
await runLogs(subcmd ? [subcmd, ...rest] : rest);
|
|
357
547
|
} else {
|
|
358
548
|
printHelp();
|
|
359
549
|
if (cmd !== void 0) process.exit(1);
|
|
@@ -379,13 +569,24 @@ function printHelp() {
|
|
|
379
569
|
console.log(`emit-vision CLI
|
|
380
570
|
|
|
381
571
|
Commands:
|
|
382
|
-
login [--api-url <url>]
|
|
383
|
-
logout
|
|
384
|
-
project list
|
|
385
|
-
project create <name>
|
|
386
|
-
project env create <projectId> <name> [--type ...]
|
|
387
|
-
key get <projectId>
|
|
388
|
-
key rotate <projectId>
|
|
572
|
+
login [--api-url <url>] Authenticate with a Personal Access Token
|
|
573
|
+
logout Clear stored credentials
|
|
574
|
+
project list List your projects
|
|
575
|
+
project create <name> Create a new project
|
|
576
|
+
project env create <projectId> <name> [--type ...] Create a new environment
|
|
577
|
+
key get <projectId> Get ingest key info for a project
|
|
578
|
+
key rotate <projectId> Rotate the ingest key for a project
|
|
579
|
+
|
|
580
|
+
overview <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--json]
|
|
581
|
+
Project summary (events, errors, top events)
|
|
582
|
+
events recent <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--limit <n>] [--json]
|
|
583
|
+
Recent events
|
|
584
|
+
errors recent <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--limit <n>] [--json]
|
|
585
|
+
Recent error occurrences
|
|
586
|
+
errors grouped <projectId> [--from <iso>] [--to <iso>] [--environment <env>] [--limit <n>] [--json]
|
|
587
|
+
Grouped/deduplicated errors with counts
|
|
588
|
+
logs <projectId> [--from <iso>] [--to <iso>] [--severity <level>] [--limit <n>] [--json]
|
|
589
|
+
Recent log entries
|
|
389
590
|
`);
|
|
390
591
|
}
|
|
391
592
|
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emit-vision/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI for emit-vision project management",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
|
-
"publishConfig": {
|
|
15
|
-
"access": "public"
|
|
16
|
-
},
|
|
17
14
|
"scripts": {
|
|
18
15
|
"build": "tsup --config tsup.config.ts",
|
|
19
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
16
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
17
|
+
"prepack": "pnpm run build"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
20
21
|
}
|
|
21
|
-
}
|
|
22
|
+
}
|