@insforge/cli 0.1.65 → 0.1.67

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
@@ -1835,6 +1835,15 @@ async function getJwtSecret() {
1835
1835
  return null;
1836
1836
  }
1837
1837
  }
1838
+ async function getDatabaseConnectionString() {
1839
+ try {
1840
+ const res = await ossFetch("/api/metadata/database-connection-string");
1841
+ const data = await res.json();
1842
+ return typeof data.connectionURL === "string" && data.connectionURL.length > 0 ? data.connectionURL : null;
1843
+ } catch {
1844
+ return null;
1845
+ }
1846
+ }
1838
1847
  async function ossFetch(path6, options = {}) {
1839
1848
  const config = requireProjectConfig();
1840
1849
  const headers = {
@@ -2032,8 +2041,11 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
2032
2041
  const envLocalExists = await pathExists(envLocalPath);
2033
2042
  const existingLocal = envLocalExists ? await fs.readFile(envLocalPath, "utf-8") : "";
2034
2043
  const existingLocalKeys = envLocalExists ? extractEnvKeys(existingLocal) : /* @__PURE__ */ new Set();
2035
- const anonKey = await getAnonKey();
2036
- const jwtSecret = await getJwtSecret();
2044
+ const [anonKey, jwtSecret, databaseUrl] = await Promise.all([
2045
+ getAnonKey(),
2046
+ getJwtSecret(),
2047
+ getDatabaseConnectionString()
2048
+ ]);
2037
2049
  const filled = manifest.envExampleAppend.replace(
2038
2050
  /^([A-Z][A-Z0-9_]*=)(.*)$/gm,
2039
2051
  (_, prefix, value) => {
@@ -2043,6 +2055,7 @@ async function applyAuthProvider(provider, cwd, projectConfig, json) {
2043
2055
  if (key === "NEXT_PUBLIC_APP_URL") return `${prefix}https://${projectConfig.appkey}.insforge.site`;
2044
2056
  if (/JWT_SECRET$/.test(key)) return `${prefix}${jwtSecret ?? value}`;
2045
2057
  if (key === "BETTER_AUTH_SECRET") return `${prefix}${randomBytes2(32).toString("hex")}`;
2058
+ if (key === "DATABASE_URL") return `${prefix}${databaseUrl ?? value}`;
2046
2059
  return `${prefix}${value}`;
2047
2060
  }
2048
2061
  );
@@ -4153,6 +4166,27 @@ function registerDbMigrationsCommand(dbCmd2) {
4153
4166
  });
4154
4167
  }
4155
4168
 
4169
+ // src/commands/db/connection-string.ts
4170
+ function registerDbConnectionStringCommand(dbCmd2) {
4171
+ dbCmd2.command("connection-string").description("Print the project Postgres connection URL (cloud projects only)").action(async (_opts, cmd) => {
4172
+ const { json } = getRootOpts(cmd);
4173
+ try {
4174
+ await requireAuth();
4175
+ const res = await ossFetch("/api/metadata/database-connection-string");
4176
+ const body = await res.json();
4177
+ if (json) {
4178
+ outputJson(body);
4179
+ } else {
4180
+ console.log(body.connectionURL);
4181
+ }
4182
+ await reportCliUsage("cli.db.connection-string", true);
4183
+ } catch (err) {
4184
+ await reportCliUsage("cli.db.connection-string", false);
4185
+ handleError(err, json);
4186
+ }
4187
+ });
4188
+ }
4189
+
4156
4190
  // src/commands/records/list.ts
4157
4191
  function registerRecordsCommands(recordsCmd2) {
4158
4192
  recordsCmd2.command("list <table>").description("List records from a table").option("--select <columns>", "Columns to select (comma-separated)").option("--filter <filter>", 'Filter expression (e.g. "name=eq.John")').option("--order <order>", 'Order by (e.g. "created_at.desc")').option("--limit <n>", "Limit number of records", parseInt).option("--offset <n>", "Offset for pagination", parseInt).action(async (table, opts, cmd) => {
@@ -6755,7 +6789,7 @@ function registerDiagnoseCommands(diagnoseCmd2) {
6755
6789
  const s = !json ? clack14.spinner() : null;
6756
6790
  s?.start("Collecting diagnostic data...");
6757
6791
  const data2 = await collectDiagnosticData(projectId, ossMode, apiUrl);
6758
- const cliVersion = "0.1.65";
6792
+ const cliVersion = "0.1.67";
6759
6793
  s?.stop("Data collected");
6760
6794
  if (!json) {
6761
6795
  console.log(`
@@ -8156,6 +8190,7 @@ registerDbRpcCommand(dbCmd);
8156
8190
  registerDbExportCommand(dbCmd);
8157
8191
  registerDbImportCommand(dbCmd);
8158
8192
  registerDbMigrationsCommand(dbCmd);
8193
+ registerDbConnectionStringCommand(dbCmd);
8159
8194
  var recordsCmd = program.command("records", { hidden: true }).description("CRUD operations on table records");
8160
8195
  registerRecordsCommands(recordsCmd);
8161
8196
  registerRecordsCreateCommand(recordsCmd);