clawfire 0.4.3 → 0.4.4

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/dev.js CHANGED
@@ -1457,38 +1457,89 @@ async function checkCli(projectDir) {
1457
1457
  return result;
1458
1458
  }
1459
1459
  async function fetchFirebaseSdkConfig(projectDir) {
1460
- const output = await execWithTimeout(
1461
- "firebase",
1462
- ["apps:sdkconfig", "web", "--json"],
1463
- projectDir,
1464
- 15e3
1465
- );
1466
- const data = JSON.parse(output);
1467
- if (data?.result?.sdkConfig) {
1468
- return data.result.sdkConfig;
1469
- }
1470
- if (data?.result?.fileContents) {
1471
- const contents = data.result.fileContents;
1472
- const config = {};
1473
- const extract = (key) => {
1474
- const match = contents.match(new RegExp(`"${key}"\\s*:\\s*"([^"]+)"`));
1475
- return match ? match[1] : void 0;
1476
- };
1477
- config.apiKey = extract("apiKey");
1478
- config.authDomain = extract("authDomain");
1479
- config.projectId = extract("projectId");
1480
- config.storageBucket = extract("storageBucket");
1481
- config.messagingSenderId = extract("messagingSenderId");
1482
- config.appId = extract("appId");
1483
- return config;
1460
+ try {
1461
+ const output = await execWithTimeout(
1462
+ "firebase",
1463
+ ["apps:sdkconfig", "web", "--json"],
1464
+ projectDir,
1465
+ 15e3
1466
+ );
1467
+ const config = parseSdkConfigOutput(output);
1468
+ if (config) return config;
1469
+ } catch {
1470
+ }
1471
+ let webApps = [];
1472
+ try {
1473
+ const appsOutput = await execWithTimeout(
1474
+ "firebase",
1475
+ ["apps:list", "--json"],
1476
+ projectDir,
1477
+ 15e3
1478
+ );
1479
+ const appsData = JSON.parse(appsOutput);
1480
+ const allApps = appsData?.result || [];
1481
+ webApps = allApps.filter((a) => a.platform === "WEB").map((a) => ({
1482
+ appId: String(a.appId || ""),
1483
+ displayName: String(a.displayName || "")
1484
+ })).filter((a) => a.appId);
1485
+ } catch {
1486
+ throw new Error(
1487
+ "Failed to fetch Firebase SDK config. Make sure you are logged in and have an active project selected."
1488
+ );
1489
+ }
1490
+ if (webApps.length === 0) {
1491
+ throw new Error(
1492
+ "No web app registered in this Firebase project. Go to Firebase Console > Project Settings > General > Your apps > Add app (Web) to create one, then click Auto-fill again."
1493
+ );
1494
+ }
1495
+ const appId = webApps[0].appId;
1496
+ try {
1497
+ const output = await execWithTimeout(
1498
+ "firebase",
1499
+ ["apps:sdkconfig", "web", appId, "--json"],
1500
+ projectDir,
1501
+ 15e3
1502
+ );
1503
+ const config = parseSdkConfigOutput(output);
1504
+ if (config) return config;
1505
+ } catch (err) {
1506
+ const msg = err instanceof Error ? err.message : "Unknown error";
1507
+ throw new Error(`Failed to fetch config for web app ${appId}: ${msg}`);
1484
1508
  }
1485
1509
  throw new Error("Could not parse Firebase SDK config from CLI output");
1486
1510
  }
1511
+ function parseSdkConfigOutput(output) {
1512
+ try {
1513
+ const data = JSON.parse(output);
1514
+ if (data?.result?.sdkConfig) {
1515
+ return data.result.sdkConfig;
1516
+ }
1517
+ if (data?.result?.fileContents) {
1518
+ const contents = data.result.fileContents;
1519
+ const config = {};
1520
+ const extract = (key) => {
1521
+ const match = contents.match(new RegExp(`"${key}"\\s*:\\s*"([^"]+)"`));
1522
+ return match ? match[1] : void 0;
1523
+ };
1524
+ config.apiKey = extract("apiKey");
1525
+ config.authDomain = extract("authDomain");
1526
+ config.projectId = extract("projectId");
1527
+ config.storageBucket = extract("storageBucket");
1528
+ config.messagingSenderId = extract("messagingSenderId");
1529
+ config.appId = extract("appId");
1530
+ if (config.apiKey || config.projectId) return config;
1531
+ }
1532
+ } catch {
1533
+ }
1534
+ return null;
1535
+ }
1487
1536
  function execWithTimeout(command, args, cwd, timeoutMs) {
1488
1537
  return new Promise((resolve7, reject) => {
1489
- const proc = execFile(command, args, { cwd, timeout: timeoutMs }, (err, stdout) => {
1538
+ const proc = execFile(command, args, { cwd, timeout: timeoutMs }, (err, stdout, stderr) => {
1490
1539
  if (err) {
1491
- reject(err);
1540
+ const detail = stderr?.trim() || stdout?.trim() || "";
1541
+ const enriched = new Error(`${err.message}${detail ? "\n" + detail : ""}`);
1542
+ reject(enriched);
1492
1543
  } else {
1493
1544
  resolve7(stdout);
1494
1545
  }
@@ -2237,7 +2288,12 @@ function generateDashboardHtml(options) {
2237
2288
  if (wizStatus) wizStatus.style.display = 'none';
2238
2289
 
2239
2290
  fetch(API + '/__dev/firebase-sdk-config')
2240
- .then(function(r) { return r.json(); })
2291
+ .then(function(r) {
2292
+ if (!r.ok) {
2293
+ return r.json().catch(function() { return { error: 'Server error (' + r.status + ')' }; });
2294
+ }
2295
+ return r.json();
2296
+ })
2241
2297
  .then(function(data) {
2242
2298
  if (data.error) {
2243
2299
  showAutoFillResult(false, data.error);