@mybase-dev/cli 1.0.3 → 1.0.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.
Files changed (2) hide show
  1. package/dist/mybase.js +53 -5
  2. package/package.json +1 -1
package/dist/mybase.js CHANGED
@@ -139,7 +139,7 @@ function parseDotenv(text) {
139
139
  // package.json
140
140
  var package_default = {
141
141
  name: "@mybase-dev/cli",
142
- version: "1.0.3",
142
+ version: "1.0.4",
143
143
  description: "The mybase CLI: projects, keys, cron, queues, cache, rate limits, analytics, docs, and agent setup for a self-hosted mybase.",
144
144
  type: "module",
145
145
  repository: {
@@ -5146,24 +5146,72 @@ async function databasePublic(args) {
5146
5146
  if (!off && values.POSTGRES_BIND === "127.0.0.1")
5147
5147
  ui.info("Postgres now listens on your network again (POSTGRES_BIND), so the router can reach it.");
5148
5148
  await saveEnv(dir, mergeEnv(text, updates));
5149
- const version = await startStack(dir, values, false);
5149
+ if (await writeCompose(dir, interactive, true))
5150
+ ui.success(`compose.yml updated to this CLI's (${CLI_VERSION})`);
5151
+ const version = await startStack(dir, values);
5152
+ const status = off ? null : await waitForDbPublic(localUrl(values));
5150
5153
  const port = values.POSTGRES_PORT || "5432";
5151
5154
  const lan = addresses().find((a) => a.label.startsWith("LAN IP"))?.value ?? "<this machine's LAN IP>";
5152
5155
  const host = off ? null : updates.MYBASE_DB_PUBLIC_HOST;
5153
5156
  if (jsonMode)
5154
- return print({ dir, version, host, port: Number(port), forward: host ? `${lan}:${port}` : null }, () => {});
5157
+ return print({ dir, version, host, port: Number(port), forward: host ? `${lan}:${port}` : null, status }, () => {});
5155
5158
  if (!host)
5156
5159
  return outro("Public Postgres off. Connection strings point at your network address again. Remove the port forward on your router.");
5157
5160
  ui.note([
5158
5161
  `On your router (usually "Port forwarding" or "Virtual server"):`,
5159
5162
  ` TCP ${port} (external) \u2192 ${lan}:${port}`,
5160
5163
  ``,
5161
- dim2("mybase now points the DNS record at your public IP and requests the certificate (about a minute)."),
5162
- dim2("Check progress in the dashboard (Database \u2192 Settings) or with `mybase doctor`.")
5164
+ dim2(status?.tls.active ? "DNS and the certificate are ready." : "Check progress in the dashboard (Database \u2192 Settings) or with `mybase doctor`.")
5163
5165
  ].join(`
5164
5166
  `), "Last step");
5165
5167
  outro(`New connection strings: postgres://<project>:<password>@${host}:${port}/<project>?sslmode=require`);
5166
5168
  }
5169
+ async function waitForDbPublic(url) {
5170
+ const s = ui.spinner();
5171
+ s.start("Pointing DNS at your public IP and getting a certificate (about a minute)");
5172
+ const deadline = Date.now() + 150000;
5173
+ let last = null;
5174
+ for (;; ) {
5175
+ try {
5176
+ last = await api("/database/public", { url });
5177
+ } catch (err) {
5178
+ const status = err.status;
5179
+ if (status === 401 || status === 403) {
5180
+ s.stop("Can't check progress: this CLI isn't signed in to the server as admin");
5181
+ return null;
5182
+ }
5183
+ if (status !== 404)
5184
+ throw err;
5185
+ last = null;
5186
+ }
5187
+ if (typeof last?.enabled !== "boolean") {
5188
+ s.error("The server doesn't support public Postgres");
5189
+ throw new CliError("the running mybase image is older than this CLI. Run `mybase server update` (or set MYBASE_IMAGE to a newer build), then this command again.");
5190
+ }
5191
+ if (!last.enabled) {
5192
+ s.error("The server didn't get the settings");
5193
+ throw new CliError("MYBASE_DB_PUBLIC isn't reaching the API. Check that compose.yml passes it (`mybase server update` refreshes compose.yml).");
5194
+ }
5195
+ if (last.problem) {
5196
+ s.error(last.problem);
5197
+ throw new CliError(last.problem);
5198
+ }
5199
+ if (last.dns.error || last.tls.error) {
5200
+ s.error([last.dns.error && `DNS: ${last.dns.error}`, last.tls.error && `Certificate: ${last.tls.error}`].filter(Boolean).join("; "));
5201
+ ui.info("mybase keeps retrying (certificate: in 1 h, 6 h, then daily). Fix the cause, then run `mybase server update` to retry now.");
5202
+ return last;
5203
+ }
5204
+ if (last.tls.active) {
5205
+ s.stop(`${last.host} \u2192 ${last.dns.ip}, certificate valid until ${last.tls.notAfter?.slice(0, 10)}`);
5206
+ return last;
5207
+ }
5208
+ if (Date.now() > deadline) {
5209
+ s.stop(`Still working (${last.dns.ip ? `DNS \u2192 ${last.dns.ip}` : "DNS pending"}, certificate pending)`);
5210
+ return last;
5211
+ }
5212
+ await Bun.sleep(3000);
5213
+ }
5214
+ }
5167
5215
  async function autostart(args) {
5168
5216
  const mode = args[0];
5169
5217
  if (mode !== "on" && mode !== "off")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mybase-dev/cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "The mybase CLI: projects, keys, cron, queues, cache, rate limits, analytics, docs, and agent setup for a self-hosted mybase.",
5
5
  "type": "module",
6
6
  "repository": {