@erdoai/cli 0.28.0 → 0.29.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.
Files changed (2) hide show
  1. package/dist/index.js +33 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -209,6 +209,12 @@ var ErdoClient = class {
209
209
  setAutonomyMode(mode) {
210
210
  return this.request("PUT", "/v1/autonomy-mode", { mode });
211
211
  }
212
+ // Run a read-only HogQL query against the org's page-analytics events. Rows are
213
+ // positional per columns; enabled:false means page analytics is off for the org
214
+ // (not zero traffic). A rejected query surfaces PostHog's message as the error.
215
+ queryPageAnalytics(query) {
216
+ return this.request("POST", "/v1/page-analytics/query", { query });
217
+ }
212
218
  listEvalSuites() {
213
219
  return this.request("GET", "/v1/evals/suites");
214
220
  }
@@ -2311,6 +2317,33 @@ datasetsCmd.command("from-integration <app>").description("Create a dataset back
2311
2317
  fail(e);
2312
2318
  }
2313
2319
  });
2320
+ function printAnalyticsTable(columns, rows) {
2321
+ const cell = (v) => v === null || v === void 0 ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
2322
+ const widths = columns.map((c, i) => Math.max(c.length, ...rows.map((r) => cell(r[i]).length), 0));
2323
+ const line = (cells) => cells.map((c, i) => c.padEnd(widths[i])).join(" ").trimEnd();
2324
+ console.log(line(columns));
2325
+ console.log(widths.map((w) => "-".repeat(w)).join(" "));
2326
+ for (const r of rows) console.log(line(columns.map((_, i) => cell(r[i]))));
2327
+ }
2328
+ var analytics = program.command("analytics").description("Query page analytics (how published pages perform with real visitors)");
2329
+ analytics.command("query <hogql>").description("Run a read-only HogQL query against this org's page-analytics events").option("--json", "print the raw JSON result instead of a table").action(async (hogql, opts) => {
2330
+ try {
2331
+ const res = await new ErdoClient().queryPageAnalytics(hogql);
2332
+ if (opts.json) {
2333
+ print(res);
2334
+ return;
2335
+ }
2336
+ if (!res.enabled) {
2337
+ console.log("Page analytics is not enabled for this organization \u2014 turn it on in the Erdo app, then query real traffic here.");
2338
+ return;
2339
+ }
2340
+ printAnalyticsTable(res.columns, res.rows);
2341
+ if (res.truncated) console.log(`
2342
+ (rows truncated at the cap \u2014 aggregate further or add a tighter filter/LIMIT)`);
2343
+ } catch (e) {
2344
+ fail(e);
2345
+ }
2346
+ });
2314
2347
  var OPERATORS = ["equals", "not_equals", "greater_than", "less_than", "contains", "between"];
2315
2348
  function parseCondition(s) {
2316
2349
  const m = s.trim().match(/^(\S+)\s+(\S+)\s+([\s\S]+)$/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {