@emit-vision/cli 0.2.5 โ†’ 0.2.6

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 (3) hide show
  1. package/README.md +6 -7
  2. package/dist/index.js +113 -34
  3. package/package.json +10 -13
package/README.md CHANGED
@@ -4,7 +4,7 @@ Command-line interface for [Emit Vision](https://emitvision.com) โ€” the self-ho
4
4
 
5
5
  Query telemetry, manage projects and ingest keys, and control feature flags from your terminal, a deploy script, or a coding agent.
6
6
 
7
- ๐Ÿ“– **[Full CLI reference โ†’](https://app.emitvision.com/docs/cli)**
7
+ ๐Ÿ“– **[Full CLI reference โ†’](https://emitvision.com/docs/cli)**
8
8
 
9
9
  ## Installation
10
10
 
@@ -91,12 +91,11 @@ Run `emit-vision --help` for the complete command list, or `emit-vision --versio
91
91
 
92
92
  ## Documentation
93
93
 
94
- - [CLI reference](https://app.emitvision.com/docs/cli) โ€” every command, flag, and example
95
- - [Getting started](https://app.emitvision.com/docs/introduction)
96
- - [Installation & configuration](https://app.emitvision.com/docs/installation)
97
- - [Browser SDK](https://app.emitvision.com/docs/sdk-js) ยท [Node SDK](https://app.emitvision.com/docs/sdk-node)
98
- - [Changelog](https://app.emitvision.com/docs/changelog)
99
- - [Troubleshooting](https://app.emitvision.com/docs/troubleshooting)
94
+ - [CLI reference](https://emitvision.com/docs/cli) โ€” every command, flag, and example
95
+ - [Getting started](https://emitvision.com/docs/introduction)
96
+ - [Installation & configuration](https://emitvision.com/docs/installation)
97
+ - [Browser SDK](https://emitvision.com/docs/sdk-js) ยท [Node SDK](https://emitvision.com/docs/sdk-node)
98
+ - [Troubleshooting](https://emitvision.com/docs/troubleshooting)
100
99
 
101
100
  ## License
102
101
 
package/dist/index.js CHANGED
@@ -42,6 +42,34 @@ var ApiError = class extends Error {
42
42
  }
43
43
  status;
44
44
  };
45
+ var ApiShapeError = class extends Error {
46
+ constructor(path, missing, received) {
47
+ super(
48
+ `Unexpected response shape from ${path}
49
+ missing field(s): ${missing.join(", ")}
50
+ response had: ${received.join(", ") || "(no fields)"}
51
+ This usually means the CLI is out of date with the API. Try \`npm i -g @emit-vision/cli@latest\`, or re-run with --json to see the raw response.`
52
+ );
53
+ this.path = path;
54
+ this.missing = missing;
55
+ this.received = received;
56
+ this.name = "ApiShapeError";
57
+ }
58
+ path;
59
+ missing;
60
+ received;
61
+ };
62
+ function assertShape(data, expect, path) {
63
+ const sample = Array.isArray(data) ? data[0] : data;
64
+ if (sample === void 0 || sample === null || typeof sample !== "object") {
65
+ return;
66
+ }
67
+ const received = Object.keys(sample);
68
+ const missing = expect.filter((field) => !received.includes(field));
69
+ if (missing.length > 0) {
70
+ throw new ApiShapeError(path, missing, received);
71
+ }
72
+ }
45
73
  async function apiFetch(path, options = {}) {
46
74
  const config = loadConfig();
47
75
  const apiUrl = options.apiUrl ?? config.apiUrl ?? DEFAULT_API_URL;
@@ -70,7 +98,10 @@ async function apiFetch(path, options = {}) {
70
98
  } catch {
71
99
  }
72
100
  const suffix = code ? ` (${code})` : "";
73
- throw new ApiError(401, `Not authenticated${suffix}. Run \`emit-vision login\` first.`);
101
+ throw new ApiError(
102
+ 401,
103
+ `Not authenticated${suffix}. Run \`emit-vision login\` first.`
104
+ );
74
105
  }
75
106
  if (!res.ok) {
76
107
  let msg = `HTTP ${res.status}`;
@@ -82,7 +113,11 @@ async function apiFetch(path, options = {}) {
82
113
  throw new ApiError(res.status, msg);
83
114
  }
84
115
  if (res.status === 204) return void 0;
85
- return res.json();
116
+ const data = await res.json();
117
+ if (options.expect) {
118
+ assertShape(data, options.expect, path.split("?")[0] ?? path);
119
+ }
120
+ return data;
86
121
  }
87
122
 
88
123
  // src/commands/login.ts
@@ -316,14 +351,16 @@ async function runProjectEnvCreate(args) {
316
351
  console.log(result.rawIngestKey);
317
352
  }
318
353
  }
354
+ var EMPTY_CELL = "\u2014";
319
355
  function printTable(headers, rows) {
356
+ const cells = rows.map((row) => headers.map((_, i) => row[i] ?? EMPTY_CELL));
320
357
  const widths = headers.map(
321
- (h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length))
358
+ (h, i) => Math.max(h.length, ...cells.map((r) => r[i].length))
322
359
  );
323
- const line = (cells) => cells.map((c, i) => c.padEnd(widths[i])).join(" ");
360
+ const line = (row) => row.map((c, i) => c.padEnd(widths[i])).join(" ");
324
361
  console.log(line(headers));
325
362
  console.log(widths.map((w) => "-".repeat(w)).join(" "));
326
- rows.forEach((r) => console.log(line(r)));
363
+ cells.forEach((r) => console.log(line(r)));
327
364
  }
328
365
 
329
366
  // src/commands/key.ts
@@ -357,7 +394,10 @@ async function runKeyRotate(args) {
357
394
  );
358
395
  process.exit(1);
359
396
  }
360
- const rl = createInterface2({ input: process.stdin, output: process.stdout });
397
+ const rl = createInterface2({
398
+ input: process.stdin,
399
+ output: process.stdout
400
+ });
361
401
  const answer = await new Promise((resolve) => {
362
402
  rl.question(
363
403
  "Rotate the ingest key? This will invalidate the current key. [y/N] ",
@@ -403,11 +443,30 @@ function parseFlags(args) {
403
443
  function buildQs(projectId, flags, extras) {
404
444
  const params = new URLSearchParams({ projectId });
405
445
  const merged = { ...flags, ...extras };
406
- for (const key of ["from", "to", "environment", "release", "limit", "severity"]) {
446
+ for (const key of [
447
+ "from",
448
+ "to",
449
+ "environment",
450
+ "release",
451
+ "limit",
452
+ "severity"
453
+ ]) {
407
454
  if (merged[key]) params.set(key, merged[key]);
408
455
  }
409
456
  return params.toString();
410
457
  }
458
+ var RECENT_FIELDS = ["event_id", "event_name", "timestamp"];
459
+ var GROUPED_FIELDS = [
460
+ "fingerprint",
461
+ "sampleMessage",
462
+ "count",
463
+ "lastSeen"
464
+ ];
465
+ var OVERVIEW_FIELDS = ["totalEvents", "totalErrors"];
466
+ var LOG_FIELDS = ["timestamp", "severity_text", "body"];
467
+ function truncate(value, max) {
468
+ return value.length > max ? `${value.slice(0, max - 3)}...` : value;
469
+ }
411
470
  async function runEventsRecent(args) {
412
471
  const [projectId, ...rest2] = args;
413
472
  if (!projectId) {
@@ -418,7 +477,8 @@ async function runEventsRecent(args) {
418
477
  }
419
478
  const flags = parseFlags(rest2);
420
479
  const events = await apiFetch(
421
- `/v1/events/recent?${buildQs(projectId, flags)}`
480
+ `/v1/events/recent?${buildQs(projectId, flags)}`,
481
+ { expect: RECENT_FIELDS }
422
482
  );
423
483
  if (flags.json) {
424
484
  console.log(JSON.stringify(events, null, 2));
@@ -432,9 +492,9 @@ async function runEventsRecent(args) {
432
492
  ["Timestamp", "Name", "User", "Environment"],
433
493
  events.map((e) => [
434
494
  new Date(e.timestamp).toLocaleString(),
435
- e.name,
436
- e.userId ?? "\u2014",
437
- e.environment ?? "\u2014"
495
+ e.event_name,
496
+ e.user_id || null,
497
+ e.environment || null
438
498
  ])
439
499
  );
440
500
  }
@@ -448,7 +508,8 @@ async function runErrorsRecent(args) {
448
508
  }
449
509
  const flags = parseFlags(rest2);
450
510
  const errors = await apiFetch(
451
- `/v1/errors/recent?${buildQs(projectId, flags)}`
511
+ `/v1/errors/recent?${buildQs(projectId, flags)}`,
512
+ { expect: RECENT_FIELDS }
452
513
  );
453
514
  if (flags.json) {
454
515
  console.log(JSON.stringify(errors, null, 2));
@@ -462,9 +523,9 @@ async function runErrorsRecent(args) {
462
523
  ["Timestamp", "Name", "User", "Environment"],
463
524
  errors.map((e) => [
464
525
  new Date(e.timestamp).toLocaleString(),
465
- e.name,
466
- e.userId ?? "\u2014",
467
- e.environment ?? "\u2014"
526
+ e.event_name,
527
+ e.user_id || null,
528
+ e.environment || null
468
529
  ])
469
530
  );
470
531
  }
@@ -478,7 +539,8 @@ async function runErrorsGrouped(args) {
478
539
  }
479
540
  const flags = parseFlags(rest2);
480
541
  const groups = await apiFetch(
481
- `/v1/errors/grouped?${buildQs(projectId, flags)}`
542
+ `/v1/errors/grouped?${buildQs(projectId, flags)}`,
543
+ { expect: GROUPED_FIELDS }
482
544
  );
483
545
  if (flags.json) {
484
546
  console.log(JSON.stringify(groups, null, 2));
@@ -494,7 +556,7 @@ async function runErrorsGrouped(args) {
494
556
  String(g.count),
495
557
  g.status,
496
558
  new Date(g.lastSeen).toLocaleString(),
497
- g.message.length > 60 ? g.message.slice(0, 57) + "..." : g.message
559
+ truncate(g.sampleMessage, 60)
498
560
  ])
499
561
  );
500
562
  }
@@ -508,7 +570,8 @@ async function runOverview(args) {
508
570
  }
509
571
  const flags = parseFlags(rest2);
510
572
  const data = await apiFetch(
511
- `/v1/overview?${buildQs(projectId, flags)}`
573
+ `/v1/overview?${buildQs(projectId, flags)}`,
574
+ { expect: OVERVIEW_FIELDS }
512
575
  );
513
576
  if (flags.json) {
514
577
  console.log(JSON.stringify(data, null, 2));
@@ -539,6 +602,7 @@ async function runLogs(args) {
539
602
  const { logs } = await apiFetch(
540
603
  `/v1/logs?${buildQs(projectId, flags)}`
541
604
  );
605
+ assertShape(logs, LOG_FIELDS, "/v1/logs");
542
606
  if (flags.json) {
543
607
  console.log(JSON.stringify(logs, null, 2));
544
608
  return;
@@ -551,8 +615,8 @@ async function runLogs(args) {
551
615
  ["Timestamp", "Severity", "Message"],
552
616
  logs.map((l) => [
553
617
  new Date(l.timestamp).toLocaleString(),
554
- l.severity,
555
- l.body.length > 80 ? l.body.slice(0, 77) + "..." : l.body
618
+ l.severity_text,
619
+ truncate(l.body, 80)
556
620
  ])
557
621
  );
558
622
  }
@@ -662,7 +726,10 @@ async function runUsersList(args) {
662
726
  String(u.error_count),
663
727
  u.last_seen ? new Date(u.last_seen).toLocaleDateString() : "\u2014"
664
728
  ]);
665
- printTable(["User ID", "Email", "Name", "Events", "Errors", "Last Seen"], rows);
729
+ printTable(
730
+ ["User ID", "Email", "Name", "Events", "Errors", "Last Seen"],
731
+ rows
732
+ );
666
733
  }
667
734
  async function runAudienceExport(args) {
668
735
  const [projectId, ...rest2] = args;
@@ -749,8 +816,7 @@ async function runAudienceSync(args) {
749
816
  );
750
817
  const preview = contacts.slice(0, 5);
751
818
  console.log(JSON.stringify(preview, null, 2));
752
- if (contacts.length > 5)
753
- console.log(`... and ${contacts.length - 5} more`);
819
+ if (contacts.length > 5) console.log(`... and ${contacts.length - 5} more`);
754
820
  return;
755
821
  }
756
822
  const CHUNK = 5e3;
@@ -792,10 +858,12 @@ function printSnippets(pingUrl, intervalSeconds, filter) {
792
858
  process.exit(1);
793
859
  }
794
860
  const types = filter ? [filter] : SNIPPET_TYPES;
861
+ const releaseUrl = `"${pingUrl}?release=$BUILD_NUMBER"`;
795
862
  const snippets = {
796
863
  curl: [
797
864
  "# cURL",
798
- `curl -fsS -o /dev/null ${pingUrl} \\`,
865
+ "# Optionally report the release/build this ping is running (blank is fine \u2014 omit the query param entirely to skip it)",
866
+ `curl -fsS -o /dev/null ${releaseUrl} \\`,
799
867
  ` -H "Authorization: Bearer $EMIT_VISION_INGEST_KEY"`
800
868
  ].join("\n"),
801
869
  docker: [
@@ -806,6 +874,7 @@ function printSnippets(pingUrl, intervalSeconds, filter) {
806
874
  " restart: unless-stopped",
807
875
  " environment:",
808
876
  " - EMIT_VISION_INGEST_KEY=${EMIT_VISION_INGEST_KEY}",
877
+ " - BUILD_NUMBER=${BUILD_NUMBER}",
809
878
  ` - PULSE_URL=${pingUrl}`,
810
879
  ` - PING_INTERVAL=${intervalSeconds}`,
811
880
  " entrypoint: /bin/sh",
@@ -814,7 +883,7 @@ function printSnippets(pingUrl, intervalSeconds, filter) {
814
883
  " - |",
815
884
  " while true; do",
816
885
  ' wget -q --header="Authorization: Bearer $$EMIT_VISION_INGEST_KEY" \\',
817
- ' -O /dev/null "$$PULSE_URL" || true',
886
+ ' -O /dev/null "$$PULSE_URL?release=$$BUILD_NUMBER" || true',
818
887
  " sleep $$PING_INTERVAL",
819
888
  " done"
820
889
  ].join("\n"),
@@ -826,7 +895,9 @@ function printSnippets(pingUrl, intervalSeconds, filter) {
826
895
  "",
827
896
  "[Service]",
828
897
  "Type=oneshot",
829
- `ExecStart=/usr/bin/curl -fsS -o /dev/null ${pingUrl} -H "Authorization: Bearer %d/ingest-key"`,
898
+ "# BUILD_NUMBER as set by your deploy tooling (systemd expands ${VAR} from Environment=/EnvironmentFile=)",
899
+ "EnvironmentFile=-/etc/emit-vision/release.env",
900
+ `ExecStart=/usr/bin/curl -fsS -o /dev/null ${releaseUrl} -H "Authorization: Bearer %d/ingest-key"`,
830
901
  "",
831
902
  "# /etc/systemd/system/pulse-ping.timer",
832
903
  "[Unit]",
@@ -843,7 +914,8 @@ function printSnippets(pingUrl, intervalSeconds, filter) {
843
914
  const minutes = Math.max(1, Math.floor(intervalSeconds / 60));
844
915
  return [
845
916
  "# crontab entry",
846
- `*/${minutes} * * * * curl -fsS -o /dev/null ${pingUrl} -H "Authorization: Bearer $EMIT_VISION_INGEST_KEY"`
917
+ "# BUILD_NUMBER must be exported by whatever sources this job's environment",
918
+ `*/${minutes} * * * * curl -fsS -o /dev/null ${releaseUrl} -H "Authorization: Bearer $EMIT_VISION_INGEST_KEY"`
847
919
  ].join("\n");
848
920
  })()
849
921
  };
@@ -935,9 +1007,13 @@ async function runPulseList(args) {
935
1007
  c.slug,
936
1008
  c.status,
937
1009
  c.lastPingAt ? new Date(c.lastPingAt).toLocaleString() : "never",
1010
+ c.lastReportedRelease ?? "-",
938
1011
  `${c.expectedIntervalSeconds}s`
939
1012
  ]);
940
- printTable(["Name", "Slug", "Status", "Last Ping", "Interval"], rows);
1013
+ printTable(
1014
+ ["Name", "Slug", "Status", "Last Ping", "Release", "Interval"],
1015
+ rows
1016
+ );
941
1017
  }
942
1018
  var STATUS_COLORS = {
943
1019
  up: "\x1B[32m",
@@ -987,11 +1063,12 @@ async function runPulseStatus(args) {
987
1063
  statusLabel,
988
1064
  lastPing,
989
1065
  nextExpected,
1066
+ c.lastReportedRelease ?? "-",
990
1067
  `${c.expectedIntervalSeconds}s`
991
1068
  ];
992
1069
  });
993
1070
  printTable(
994
- ["Name", "Status", "Last Ping", "Next Expected", "Interval"],
1071
+ ["Name", "Status", "Last Ping", "Next Expected", "Release", "Interval"],
995
1072
  rows
996
1073
  );
997
1074
  }
@@ -1010,9 +1087,7 @@ async function verifyPing(pingUrl) {
1010
1087
  if (res.ok) {
1011
1088
  console.log("\u2713 First ping successful \u2014 check is now UP");
1012
1089
  } else {
1013
- console.error(
1014
- `\u2717 Ping failed: HTTP ${res.status}`
1015
- );
1090
+ console.error(`\u2717 Ping failed: HTTP ${res.status}`);
1016
1091
  }
1017
1092
  } catch (err) {
1018
1093
  console.error(
@@ -1207,7 +1282,10 @@ async function runFlagsArchive(args) {
1207
1282
  );
1208
1283
  process.exit(1);
1209
1284
  }
1210
- const rl = createInterface3({ input: process.stdin, output: process.stdout });
1285
+ const rl = createInterface3({
1286
+ input: process.stdin,
1287
+ output: process.stdout
1288
+ });
1211
1289
  const answer = await new Promise((resolve) => {
1212
1290
  rl.question(
1213
1291
  `Archive flag "${flagKey}"? This cannot be undone. [y/N] `,
@@ -1388,7 +1466,8 @@ async function createBoolean(projectId, key, rest2) {
1388
1466
  variants: booleanVariants()
1389
1467
  };
1390
1468
  if (description !== void 0) body.description = description;
1391
- if (rolloutPercentage !== void 0) body.rolloutPercentage = rolloutPercentage;
1469
+ if (rolloutPercentage !== void 0)
1470
+ body.rolloutPercentage = rolloutPercentage;
1392
1471
  const { flag } = await apiFetch(
1393
1472
  `/v1/flags?projectId=${encodeURIComponent(projectId)}`,
1394
1473
  { method: "POST", body }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emit-vision/cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "CLI for Emit Vision โ€” query telemetry, manage projects and ingest keys, and control feature flags from the terminal.",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -13,14 +13,12 @@
13
13
  "observability",
14
14
  "cli"
15
15
  ],
16
- "homepage": "https://github.com/develemit/emit-vision/tree/main/packages/cli#readme",
16
+ "homepage": "https://emitvision.com/docs/cli",
17
17
  "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/develemit/emit-vision.git",
20
- "directory": "packages/cli"
18
+ "url": "https://emitvision.com/docs/cli"
21
19
  },
22
20
  "bugs": {
23
- "url": "https://github.com/develemit/emit-vision/issues"
21
+ "email": "hello@emit-vision.dev"
24
22
  },
25
23
  "bin": {
26
24
  "emit-vision": "dist/index.js"
@@ -30,16 +28,15 @@
30
28
  "LICENSE",
31
29
  "README.md"
32
30
  ],
33
- "scripts": {
34
- "build": "tsup --config tsup.config.ts",
35
- "typecheck": "tsc -p tsconfig.json --noEmit",
36
- "test": "vitest run",
37
- "prepack": "pnpm run build"
38
- },
39
31
  "publishConfig": {
40
32
  "access": "public"
41
33
  },
42
34
  "devDependencies": {
43
35
  "vitest": "^4.0.15"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup --config tsup.config.ts",
39
+ "typecheck": "tsc -p tsconfig.json --noEmit",
40
+ "test": "vitest run"
44
41
  }
45
- }
42
+ }