@overscore/cli 0.13.11 → 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 +47 -0
- package/package.json +1 -1
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");
|
|
@@ -1177,6 +1180,46 @@ const HUB_HOST = (() => {
|
|
|
1177
1180
|
return "overscore.dev";
|
|
1178
1181
|
}
|
|
1179
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
|
+
}
|
|
1180
1223
|
function slugify(input) {
|
|
1181
1224
|
return input
|
|
1182
1225
|
.toLowerCase()
|
|
@@ -2397,6 +2440,10 @@ async function dev() {
|
|
|
2397
2440
|
console.error("\n Error: VITE_OVERSCORE_PROJECT_SLUG not set in .env.\n");
|
|
2398
2441
|
process.exit(1);
|
|
2399
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();
|
|
2400
2447
|
// Get device token from global config
|
|
2401
2448
|
const configPath = path.join(process.env.HOME || "", ".overscore", "config");
|
|
2402
2449
|
if (!fs.existsSync(configPath)) {
|