@overscore/cli 0.13.10 → 0.13.12

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 CHANGED
@@ -431,6 +431,9 @@ function extractZip(zipBuffer, targetDir) {
431
431
  }
432
432
  // ── Commands ────────────────────────────────────────────────────────
433
433
  async function deploy() {
434
+ // Refuse to deploy to the wrong hub (e.g. a staging dashboard to prod because
435
+ // OVERSCORE_HUB_URL wasn't set). Runs before loadEnv so it fails fast.
436
+ assertHubMatchesEnv();
434
437
  const { apiUrl, apiKey, dashboardSlug } = await loadEnv();
435
438
  // Parse --message flag
436
439
  const msgIndex = process.argv.indexOf("--message");
@@ -572,10 +575,32 @@ async function deploy() {
572
575
  // Pull latest platform rules so the local project stays up to date
573
576
  await syncPlatformRules(process.cwd(), baseUrl, apiKey);
574
577
  }
578
+ /**
579
+ * Print the project's warehouse-connection status. A live connection (e.g.
580
+ * BigQuery) can exist with ZERO registered queries — so this is surfaced
581
+ * independently of the query list. Without it, an empty query list reads as
582
+ * "no warehouse here" even when one is wired and queryable via `query run`.
583
+ */
584
+ function printConnection(connection) {
585
+ if (!connection)
586
+ return;
587
+ if (connection.connected) {
588
+ const label = connection.type === "bigquery" ? "BigQuery" : connection.type ?? "warehouse";
589
+ const where = connection.gcp_project_id ? ` — GCP project: ${connection.gcp_project_id}` : "";
590
+ console.log(` Data connection: ${label} connected${where}`);
591
+ console.log(` A live warehouse is wired up. Explore it with: npx @overscore/cli query run "<sql>"`);
592
+ console.log(` Then register the metrics you want: npx @overscore/cli query add <name> "<sql>"\n`);
593
+ }
594
+ else {
595
+ console.log(` Data connection: none (uploaded datasets only — no warehouse connected)\n`);
596
+ }
597
+ }
575
598
  async function queryList() {
576
599
  const { dashboardSlug } = await loadEnv();
577
600
  const data = (await apiRequest("GET", `/api/dashboards/${dashboardSlug}/queries`, undefined, "query-list"));
578
601
  console.log(`\n Dashboard: ${data.dashboard}\n`);
602
+ // Warehouse connection status (independent of registered queries)
603
+ printConnection(data.connection);
579
604
  // Registered queries
580
605
  if (data.queries.length === 0) {
581
606
  console.log(" No queries registered yet.\n");
@@ -1155,6 +1180,46 @@ const HUB_HOST = (() => {
1155
1180
  return "overscore.dev";
1156
1181
  }
1157
1182
  })();
1183
+ /**
1184
+ * Fail fast on a hub mismatch. A dashboard's .env names the hub it belongs to
1185
+ * (VITE_OVERSCORE_API_URL), but credentialed CLI ops (key minting, deploy
1186
+ * upload) target HUB_URL — which only repoints at staging when the operator
1187
+ * sets OVERSCORE_HUB_URL. When the .env names a different host than HUB_URL, the
1188
+ * CLI silently falls back to prod (safeApiUrl, audit L6) and mints a key /
1189
+ * deploys to the WRONG hub, surfacing later as a baffling "Invalid API key" in
1190
+ * the browser. We do NOT trust the .env host for anything credentialed — we
1191
+ * just detect the mismatch and tell the user which env var to set. Localhost
1192
+ * dashboards are dev-only and always fine.
1193
+ */
1194
+ function assertHubMatchesEnv() {
1195
+ const envPath = path.resolve(process.cwd(), ".env");
1196
+ if (!fs.existsSync(envPath))
1197
+ return;
1198
+ const envApiUrl = parseEnv(fs.readFileSync(envPath, "utf-8")).VITE_OVERSCORE_API_URL;
1199
+ if (!envApiUrl)
1200
+ return;
1201
+ let envHost;
1202
+ try {
1203
+ envHost = new URL(envApiUrl).hostname;
1204
+ }
1205
+ catch {
1206
+ return;
1207
+ }
1208
+ if (envHost === "localhost" || envHost === "127.0.0.1" || envHost === HUB_HOST)
1209
+ return;
1210
+ const envBase = envApiUrl.replace(/\/api\/?$/, "").replace(/\/+$/, "");
1211
+ console.error(`
1212
+ Error: this dashboard targets ${envHost}, but the CLI is pointed at ${HUB_HOST}.
1213
+
1214
+ Credentialed commands won't authenticate against ${envHost} until you point the
1215
+ CLI there. Set this in your shell first, then re-run:
1216
+
1217
+ export OVERSCORE_HUB_URL=${envBase}
1218
+
1219
+ (Add it to ~/.zshrc to make it stick. A new terminal without it goes back to prod.)
1220
+ `);
1221
+ process.exit(1);
1222
+ }
1158
1223
  function slugify(input) {
1159
1224
  return input
1160
1225
  .toLowerCase()
@@ -2375,6 +2440,10 @@ async function dev() {
2375
2440
  console.error("\n Error: VITE_OVERSCORE_PROJECT_SLUG not set in .env.\n");
2376
2441
  process.exit(1);
2377
2442
  }
2443
+ // Stop now if the dashboard's hub doesn't match where the CLI is pointed —
2444
+ // otherwise we'd mint a key against the wrong hub and the browser would get
2445
+ // "Invalid API key".
2446
+ assertHubMatchesEnv();
2378
2447
  // Get device token from global config
2379
2448
  const configPath = path.join(process.env.HOME || "", ".overscore", "config");
2380
2449
  if (!fs.existsSync(configPath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overscore/cli",
3
- "version": "0.13.10",
3
+ "version": "0.13.12",
4
4
  "description": "CLI for deploying Overscore dashboards and publishing analyses",
5
5
  "bin": {
6
6
  "overscore": "dist/index.js"
@@ -24,6 +24,13 @@ Every meaningful exploration step in the log is a new entry: the question being
24
24
 
25
25
  ## How to run BigQuery queries
26
26
 
27
+ This project has a **live BigQuery connection** — the credentials live in the Hub and `query run` executes against your real warehouse. You don't need to "find" or "set up" a connection: if `query run` returns rows, the warehouse is wired and working. If you're unsure what's in it, discover the schema directly rather than assuming there's no data:
28
+
29
+ ```bash
30
+ # list datasets/tables you can reach
31
+ npx @overscore/cli query run "SELECT table_schema, table_name FROM \`<gcp_project>\`.region-us.INFORMATION_SCHEMA.TABLES LIMIT 200"
32
+ ```
33
+
27
34
  Use the Overscore CLI to run SQL against the project's BigQuery connection:
28
35
 
29
36
  ```bash
@@ -33,7 +33,7 @@ Ask these one or two at a time conversationally — don't dump all 7 at once lik
33
33
 
34
34
  ## After the interview
35
35
 
36
- 1. **Read `.claude/knowledge/INDEX.md`** and any relevant knowledge files to understand what previous sessions have already documented about this project's data. Cross-reference what the user said against what's already known.
36
+ 1. **Read `.claude/knowledge/INDEX.md`** and any relevant knowledge files to understand what previous sessions have already documented about this project's data. Cross-reference what the user said against what's already known. An empty knowledge base does NOT mean there's no data — this project has a **live BigQuery connection**. If neither the user nor the knowledge base names the tables, your first approved query can be an `INFORMATION_SCHEMA.TABLES` discovery pass (see CLAUDE.md); never conclude "there's no warehouse/no data" without actually querying it.
37
37
 
38
38
  2. **Write `this-analysis.md` immediately** — before proposing a query plan. Fill in every section:
39
39
  - **Question** — the clarified question, not the original title