@insforge/cli 0.1.71 → 0.1.72

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
@@ -1865,11 +1865,22 @@ async function getJwtSecret() {
1865
1865
  return null;
1866
1866
  }
1867
1867
  }
1868
+ function spliceDatabasePassword(maskedUrl, password3) {
1869
+ return maskedUrl.replace(/^(postgresql:\/\/[^:]+:)[^@]+(@)/, `$1${password3}$2`);
1870
+ }
1868
1871
  async function getDatabaseConnectionString() {
1869
1872
  try {
1870
- const res = await ossFetch("/api/metadata/database-connection-string");
1871
- const data = await res.json();
1872
- return typeof data.connectionURL === "string" && data.connectionURL.length > 0 ? data.connectionURL : null;
1873
+ const [urlRes, pwRes] = await Promise.all([
1874
+ ossFetch("/api/metadata/database-connection-string"),
1875
+ ossFetch("/api/metadata/database-password")
1876
+ ]);
1877
+ const urlBody = await urlRes.json();
1878
+ const pwBody = await pwRes.json();
1879
+ const masked = urlBody.connectionURL;
1880
+ const password3 = pwBody.databasePassword;
1881
+ if (typeof masked !== "string" || !masked) return null;
1882
+ if (typeof password3 !== "string" || !password3) return null;
1883
+ return spliceDatabasePassword(masked, password3);
1873
1884
  } catch {
1874
1885
  return null;
1875
1886
  }
@@ -3111,6 +3122,26 @@ async function runNpmInstall(startMessage = "Installing dependencies...") {
3111
3122
  clack13.log.info("Run `npm install` manually to install dependencies.");
3112
3123
  }
3113
3124
  }
3125
+ async function runNpmSetupIfPresent() {
3126
+ const pkgPath = path5.join(process.cwd(), "package.json");
3127
+ let hasSetup = false;
3128
+ try {
3129
+ const pkg2 = JSON.parse(await fs5.readFile(pkgPath, "utf-8"));
3130
+ hasSetup = typeof pkg2.scripts?.setup === "string";
3131
+ } catch {
3132
+ }
3133
+ if (!hasSetup) return;
3134
+ const spinner10 = clack13.spinner();
3135
+ spinner10.start("Running setup (schema + migrations)...");
3136
+ try {
3137
+ await execAsync3("npm run setup", { cwd: process.cwd(), maxBuffer: 20 * 1024 * 1024 });
3138
+ spinner10.stop("Setup complete");
3139
+ } catch (err) {
3140
+ spinner10.stop("Setup failed");
3141
+ clack13.log.warn(`npm run setup failed: ${err.message.split("\n")[0]}`);
3142
+ clack13.log.info("Inspect the error, fix DATABASE_URL or network access, then run `npm run setup` manually.");
3143
+ }
3144
+ }
3114
3145
  function registerProjectLinkCommand(program2) {
3115
3146
  program2.command("link").description("Link current directory to an InsForge project").option("--project-id <id>", "Project ID to link").option("--org-id <id>", "Organization ID").option("--template <template>", "Download a template after linking: react, nextjs, chatbot, crm, e-commerce, todo").option("--auth <provider>", "Wire a third-party auth provider into the chosen template (currently: better-auth)").option("--api-base-url <url>", "API Base URL for direct linking (OSS/Self-hosted)").option("--api-key <key>", "API Key for direct linking (OSS/Self-hosted)").action(async (opts, cmd) => {
3116
3147
  const { json, apiUrl } = getRootOpts(cmd);
@@ -3196,6 +3227,9 @@ function registerProjectLinkCommand(program2) {
3196
3227
  }
3197
3228
  if (templateDownloaded && !json) {
3198
3229
  await runNpmInstall();
3230
+ if (opts.auth) {
3231
+ await runNpmSetupIfPresent();
3232
+ }
3199
3233
  }
3200
3234
  await installSkills(json);
3201
3235
  trackCommand("link", "oss-org", { direct: true, template: template2 });
@@ -3235,8 +3269,8 @@ function registerProjectLinkCommand(program2) {
3235
3269
  }
3236
3270
  if (result.packageJsonPatched && !json) {
3237
3271
  await runNpmInstall("Installing new dependencies...");
3272
+ await runNpmSetupIfPresent();
3238
3273
  }
3239
- if (!json) clack13.note(result.nextSteps, "What's next");
3240
3274
  } catch (err) {
3241
3275
  const msg = `Failed to apply --auth ${opts.auth}: ${err.message}`;
3242
3276
  if (json) console.error(JSON.stringify({ warning: msg }));
@@ -3390,6 +3424,9 @@ function registerProjectLinkCommand(program2) {
3390
3424
  }
3391
3425
  if (templateDownloaded && !json) {
3392
3426
  await runNpmInstall();
3427
+ if (opts.auth) {
3428
+ await runNpmSetupIfPresent();
3429
+ }
3393
3430
  }
3394
3431
  await installSkills(json);
3395
3432
  await reportCliUsage("cli.link", true, 6, projectConfig);
@@ -3416,8 +3453,8 @@ function registerProjectLinkCommand(program2) {
3416
3453
  }
3417
3454
  if (result.packageJsonPatched && !json) {
3418
3455
  await runNpmInstall("Installing new dependencies...");
3456
+ await runNpmSetupIfPresent();
3419
3457
  }
3420
- if (!json) clack13.note(result.nextSteps, "What's next");
3421
3458
  } catch (err) {
3422
3459
  const msg = `Failed to apply --auth ${opts.auth}: ${err.message}`;
3423
3460
  if (json) console.error(JSON.stringify({ warning: msg }));
@@ -4236,12 +4273,14 @@ function registerDbConnectionStringCommand(dbCmd2) {
4236
4273
  const { json } = getRootOpts(cmd);
4237
4274
  try {
4238
4275
  await requireAuth();
4239
- const res = await ossFetch("/api/metadata/database-connection-string");
4240
- const body = await res.json();
4276
+ const url = await getDatabaseConnectionString();
4277
+ if (!url) {
4278
+ throw new CLIError("Could not fetch the database connection string. This command requires a cloud project (self-hosted instances expose Postgres directly via your docker-compose).");
4279
+ }
4241
4280
  if (json) {
4242
- outputJson(body);
4281
+ outputJson({ connectionURL: url });
4243
4282
  } else {
4244
- console.log(body.connectionURL);
4283
+ console.log(url);
4245
4284
  }
4246
4285
  await reportCliUsage("cli.db.connection-string", true);
4247
4286
  } catch (err) {
@@ -6853,7 +6892,7 @@ function registerDiagnoseCommands(diagnoseCmd2) {
6853
6892
  const s = !json ? clack15.spinner() : null;
6854
6893
  s?.start("Collecting diagnostic data...");
6855
6894
  const data2 = await collectDiagnosticData(projectId, ossMode, apiUrl);
6856
- const cliVersion = "0.1.71";
6895
+ const cliVersion = "0.1.72";
6857
6896
  s?.stop("Data collected");
6858
6897
  if (!json) {
6859
6898
  console.log(`