@overscore/cli 0.13.11 → 0.13.13

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 +59 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -194,6 +194,18 @@ async function apiRequest(method, urlPath, body, command) {
194
194
  console.error(" BigQuery — inspect dataset columns and sample rows with: npm run queries");
195
195
  console.error(" • The project should use BigQuery but no warehouse is connected yet — connect it in the Hub.\n");
196
196
  }
197
+ // Dataset-scoped service account: it can READ a named dataset but can't LIST
198
+ // datasets (project/region INFORMATION_SCHEMA.SCHEMATA needs project-level
199
+ // access). This is where the AI tends to rabbit-hole guessing names — tell it
200
+ // to stop and ASK the user instead.
201
+ if (/INFORMATION_SCHEMA\.SCHEMATA/i.test(errMsg) &&
202
+ /(access denied|datasets\.(get|list)|does not have)/i.test(errMsg)) {
203
+ console.error(" The service account is scoped to specific dataset(s), so it can't LIST datasets.");
204
+ console.error(" • Do NOT guess dataset names. Ask the user: \"Which dataset should I use?\" (and its region, e.g. US).");
205
+ console.error(" • Then explore it directly — this works with a dataset-scoped grant:");
206
+ console.error(" npx @overscore/cli query run \"SELECT table_name FROM \\`<project>\\`.<dataset>.INFORMATION_SCHEMA.TABLES\"");
207
+ console.error(" • For auto-discovery instead, the user can grant BigQuery Data Viewer at the PROJECT level.\n");
208
+ }
197
209
  process.exit(1);
198
210
  }
199
211
  return data;
@@ -431,6 +443,9 @@ function extractZip(zipBuffer, targetDir) {
431
443
  }
432
444
  // ── Commands ────────────────────────────────────────────────────────
433
445
  async function deploy() {
446
+ // Refuse to deploy to the wrong hub (e.g. a staging dashboard to prod because
447
+ // OVERSCORE_HUB_URL wasn't set). Runs before loadEnv so it fails fast.
448
+ assertHubMatchesEnv();
434
449
  const { apiUrl, apiKey, dashboardSlug } = await loadEnv();
435
450
  // Parse --message flag
436
451
  const msgIndex = process.argv.indexOf("--message");
@@ -1177,6 +1192,46 @@ const HUB_HOST = (() => {
1177
1192
  return "overscore.dev";
1178
1193
  }
1179
1194
  })();
1195
+ /**
1196
+ * Fail fast on a hub mismatch. A dashboard's .env names the hub it belongs to
1197
+ * (VITE_OVERSCORE_API_URL), but credentialed CLI ops (key minting, deploy
1198
+ * upload) target HUB_URL — which only repoints at staging when the operator
1199
+ * sets OVERSCORE_HUB_URL. When the .env names a different host than HUB_URL, the
1200
+ * CLI silently falls back to prod (safeApiUrl, audit L6) and mints a key /
1201
+ * deploys to the WRONG hub, surfacing later as a baffling "Invalid API key" in
1202
+ * the browser. We do NOT trust the .env host for anything credentialed — we
1203
+ * just detect the mismatch and tell the user which env var to set. Localhost
1204
+ * dashboards are dev-only and always fine.
1205
+ */
1206
+ function assertHubMatchesEnv() {
1207
+ const envPath = path.resolve(process.cwd(), ".env");
1208
+ if (!fs.existsSync(envPath))
1209
+ return;
1210
+ const envApiUrl = parseEnv(fs.readFileSync(envPath, "utf-8")).VITE_OVERSCORE_API_URL;
1211
+ if (!envApiUrl)
1212
+ return;
1213
+ let envHost;
1214
+ try {
1215
+ envHost = new URL(envApiUrl).hostname;
1216
+ }
1217
+ catch {
1218
+ return;
1219
+ }
1220
+ if (envHost === "localhost" || envHost === "127.0.0.1" || envHost === HUB_HOST)
1221
+ return;
1222
+ const envBase = envApiUrl.replace(/\/api\/?$/, "").replace(/\/+$/, "");
1223
+ console.error(`
1224
+ Error: this dashboard targets ${envHost}, but the CLI is pointed at ${HUB_HOST}.
1225
+
1226
+ Credentialed commands won't authenticate against ${envHost} until you point the
1227
+ CLI there. Set this in your shell first, then re-run:
1228
+
1229
+ export OVERSCORE_HUB_URL=${envBase}
1230
+
1231
+ (Add it to ~/.zshrc to make it stick. A new terminal without it goes back to prod.)
1232
+ `);
1233
+ process.exit(1);
1234
+ }
1180
1235
  function slugify(input) {
1181
1236
  return input
1182
1237
  .toLowerCase()
@@ -2397,6 +2452,10 @@ async function dev() {
2397
2452
  console.error("\n Error: VITE_OVERSCORE_PROJECT_SLUG not set in .env.\n");
2398
2453
  process.exit(1);
2399
2454
  }
2455
+ // Stop now if the dashboard's hub doesn't match where the CLI is pointed —
2456
+ // otherwise we'd mint a key against the wrong hub and the browser would get
2457
+ // "Invalid API key".
2458
+ assertHubMatchesEnv();
2400
2459
  // Get device token from global config
2401
2460
  const configPath = path.join(process.env.HOME || "", ".overscore", "config");
2402
2461
  if (!fs.existsSync(configPath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overscore/cli",
3
- "version": "0.13.11",
3
+ "version": "0.13.13",
4
4
  "description": "CLI for deploying Overscore dashboards and publishing analyses",
5
5
  "bin": {
6
6
  "overscore": "dist/index.js"