postgresai 0.17.0-dev.6 → 0.17.0-dev.8

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.
@@ -13533,7 +13533,7 @@ var {
13533
13533
  // package.json
13534
13534
  var package_default = {
13535
13535
  name: "postgresai",
13536
- version: "0.17.0-dev.6",
13536
+ version: "0.17.0-dev.8",
13537
13537
  description: "postgres_ai CLI",
13538
13538
  license: "Apache-2.0",
13539
13539
  private: false,
@@ -16893,7 +16893,7 @@ var Result = import_lib.default.Result;
16893
16893
  var TypeOverrides = import_lib.default.TypeOverrides;
16894
16894
  var defaults = import_lib.default.defaults;
16895
16895
  // package.json
16896
- var version = "0.17.0-dev.6";
16896
+ var version = "0.17.0-dev.8";
16897
16897
  var package_default2 = {
16898
16898
  name: "postgresai",
16899
16899
  version,
@@ -28142,18 +28142,19 @@ async function billingFor(q, name, opts, deps, show) {
28142
28142
  if (opts.coupon) {
28143
28143
  billing.coupon = q.promo?.valid ? { code: q.promo.code, valid: true, description: q.promo.discount_description } : { code: opts.coupon, valid: false, error: q.promo?.error ?? "not valid" };
28144
28144
  }
28145
- const billingPage = { ...billing, requires_payment_method: true, next: `Add a payment method at ${q.billing_url ?? deps.billingUrl(q.org_alias)}, then re-run` };
28146
- const stop = (next) => ({ billing, billingPage, accepted: false, stop: { ...billing, next } });
28145
+ const billingUrl = q.billing_url ?? deps.billingUrl(q.org_alias);
28146
+ const billingPage = { ...billing, requires_payment_method: true, next: `Add a payment method at ${billingUrl}, then re-run` };
28147
+ const stop = (next) => ({ billing, billingPage, billingUrl, accepted: false, stop: { ...billing, next } });
28147
28148
  if (billing.coupon && !billing.coupon.valid) {
28148
28149
  return stop(`Promo code ${opts.coupon}: ${billing.coupon.error}. Nothing was changed: re-run with a valid code, or without ${opts.agent ? "coupon" : "--coupon"}`);
28149
28150
  }
28150
28151
  if (q.requires_payment_method)
28151
- return { billing, billingPage, accepted: false, stop: billingPage };
28152
+ return { billing, billingPage, billingUrl, accepted: false, stop: billingPage };
28152
28153
  show(billing.price);
28153
28154
  if (q.billed && !opts.yes && !await deps.confirm(`Provision ${name}? (y/N): `)) {
28154
28155
  return stop(opts.agent ? `Call connect_database again with yes: true to accept ${billing.price}` : `Re-run with --yes to accept ${billing.price}`);
28155
28156
  }
28156
- return { billing, billingPage, accepted: q.billed };
28157
+ return { billing, billingPage, billingUrl, accepted: q.billed };
28157
28158
  }
28158
28159
  async function connect(url, opts, deps) {
28159
28160
  const started = deps.now();
@@ -28183,6 +28184,8 @@ async function connect(url, opts, deps) {
28183
28184
  let billing = {};
28184
28185
  let billingPage;
28185
28186
  let accepted = false;
28187
+ let billingUrl;
28188
+ let undoRole;
28186
28189
  const findOrg = async () => {
28187
28190
  try {
28188
28191
  return await deps.clickhouseOrg(new URL(url).hostname, key.keyId, key.keySecret);
@@ -28244,7 +28247,7 @@ async function connect(url, opts, deps) {
28244
28247
  const b = await billingFor(await deps.quote(opts.coupon, clusterOf(url)), name, opts, deps, (price) => progress("billing", `Billing: ${price}`));
28245
28248
  if (b.stop)
28246
28249
  return { status: "action_required", provider, name, ...b.stop };
28247
- ({ billing, billingPage, accepted } = b);
28250
+ ({ billing, billingPage, billingUrl, accepted } = b);
28248
28251
  }
28249
28252
  if (opts.resetPassword) {
28250
28253
  let lock;
@@ -28328,6 +28331,8 @@ async function connect(url, opts, deps) {
28328
28331
  await deps.resetUnlock(lockId).catch(() => {});
28329
28332
  }
28330
28333
  row = { id: created.id, name: created.name, provider, status: created.status, dashboard_url: null, host_metrics: !!ch };
28334
+ const made = prepared;
28335
+ undoRole = () => undo(made);
28331
28336
  if (prepared.storedPassword) {
28332
28337
  progress("checkup", `Express checkup skipped: it runs only as ${DEFAULT_MONITORING_USER}, whose password PostgresAI keeps for this server. The full checkup follows on the box.`);
28333
28338
  } else {
@@ -28338,6 +28343,18 @@ async function connect(url, opts, deps) {
28338
28343
  }
28339
28344
  let shown;
28340
28345
  for (const deadline = deps.now() + opts.waitMs;; ) {
28346
+ if (undoRole && row.billing_error && disconnecting(row.status)) {
28347
+ await undoRole();
28348
+ return {
28349
+ status: "action_required",
28350
+ provider,
28351
+ name,
28352
+ id: row.id,
28353
+ ...billing,
28354
+ ...checkup ? { checkup } : {},
28355
+ next: `The first charge failed (${row.billing_error}): the box was removed and nothing is billed. Update the payment method at ${billingUrl}, then re-run`
28356
+ };
28357
+ }
28341
28358
  const result = connectStatus(row, provider, fresh);
28342
28359
  const state = boxState(row);
28343
28360
  if (state !== shown && (shown !== undefined || result.status === "provisioning"))
@@ -28351,7 +28368,15 @@ async function connect(url, opts, deps) {
28351
28368
  return { ...rest, ...billing, ...checkup ? { checkup } : {}, next: next + note };
28352
28369
  }
28353
28370
  await deps.sleep(POLL_MS);
28354
- row = (await deps.list().catch(() => [])).find((d) => d.id === row.id) ?? row;
28371
+ const listed = await deps.list().catch(() => {
28372
+ return;
28373
+ });
28374
+ const now = listed?.find((d) => d.id === row.id);
28375
+ if (listed && !now && undoRole) {
28376
+ await undoRole();
28377
+ return { status: "failed", provider, name, id: row.id, ...billing, next: "The monitoring box was removed before it became active: see pgai databases, then re-run pgai connect" };
28378
+ }
28379
+ row = now ?? row;
28355
28380
  }
28356
28381
  }
28357
28382
  async function openConnection(url, opts) {
@@ -36948,18 +36973,19 @@ async function billingFor2(q, name, opts, deps, show) {
36948
36973
  if (opts.coupon) {
36949
36974
  billing.coupon = q.promo?.valid ? { code: q.promo.code, valid: true, description: q.promo.discount_description } : { code: opts.coupon, valid: false, error: q.promo?.error ?? "not valid" };
36950
36975
  }
36951
- const billingPage = { ...billing, requires_payment_method: true, next: `Add a payment method at ${q.billing_url ?? deps.billingUrl(q.org_alias)}, then re-run` };
36952
- const stop = (next) => ({ billing, billingPage, accepted: false, stop: { ...billing, next } });
36976
+ const billingUrl = q.billing_url ?? deps.billingUrl(q.org_alias);
36977
+ const billingPage = { ...billing, requires_payment_method: true, next: `Add a payment method at ${billingUrl}, then re-run` };
36978
+ const stop = (next) => ({ billing, billingPage, billingUrl, accepted: false, stop: { ...billing, next } });
36953
36979
  if (billing.coupon && !billing.coupon.valid) {
36954
36980
  return stop(`Promo code ${opts.coupon}: ${billing.coupon.error}. Nothing was changed: re-run with a valid code, or without ${opts.agent ? "coupon" : "--coupon"}`);
36955
36981
  }
36956
36982
  if (q.requires_payment_method)
36957
- return { billing, billingPage, accepted: false, stop: billingPage };
36983
+ return { billing, billingPage, billingUrl, accepted: false, stop: billingPage };
36958
36984
  show(billing.price);
36959
36985
  if (q.billed && !opts.yes && !await deps.confirm(`Provision ${name}? (y/N): `)) {
36960
36986
  return stop(opts.agent ? `Call connect_database again with yes: true to accept ${billing.price}` : `Re-run with --yes to accept ${billing.price}`);
36961
36987
  }
36962
- return { billing, billingPage, accepted: q.billed };
36988
+ return { billing, billingPage, billingUrl, accepted: q.billed };
36963
36989
  }
36964
36990
  async function connect2(url, opts, deps) {
36965
36991
  const started = deps.now();
@@ -36989,6 +37015,8 @@ async function connect2(url, opts, deps) {
36989
37015
  let billing = {};
36990
37016
  let billingPage;
36991
37017
  let accepted = false;
37018
+ let billingUrl;
37019
+ let undoRole;
36992
37020
  const findOrg = async () => {
36993
37021
  try {
36994
37022
  return await deps.clickhouseOrg(new URL(url).hostname, key.keyId, key.keySecret);
@@ -37050,7 +37078,7 @@ async function connect2(url, opts, deps) {
37050
37078
  const b = await billingFor2(await deps.quote(opts.coupon, clusterOf2(url)), name, opts, deps, (price) => progress("billing", `Billing: ${price}`));
37051
37079
  if (b.stop)
37052
37080
  return { status: "action_required", provider, name, ...b.stop };
37053
- ({ billing, billingPage, accepted } = b);
37081
+ ({ billing, billingPage, billingUrl, accepted } = b);
37054
37082
  }
37055
37083
  if (opts.resetPassword) {
37056
37084
  let lock;
@@ -37134,6 +37162,8 @@ async function connect2(url, opts, deps) {
37134
37162
  await deps.resetUnlock(lockId).catch(() => {});
37135
37163
  }
37136
37164
  row = { id: created.id, name: created.name, provider, status: created.status, dashboard_url: null, host_metrics: !!ch };
37165
+ const made = prepared;
37166
+ undoRole = () => undo(made);
37137
37167
  if (prepared.storedPassword) {
37138
37168
  progress("checkup", `Express checkup skipped: it runs only as ${DEFAULT_MONITORING_USER}, whose password PostgresAI keeps for this server. The full checkup follows on the box.`);
37139
37169
  } else {
@@ -37144,6 +37174,18 @@ async function connect2(url, opts, deps) {
37144
37174
  }
37145
37175
  let shown;
37146
37176
  for (const deadline = deps.now() + opts.waitMs;; ) {
37177
+ if (undoRole && row.billing_error && disconnecting2(row.status)) {
37178
+ await undoRole();
37179
+ return {
37180
+ status: "action_required",
37181
+ provider,
37182
+ name,
37183
+ id: row.id,
37184
+ ...billing,
37185
+ ...checkup ? { checkup } : {},
37186
+ next: `The first charge failed (${row.billing_error}): the box was removed and nothing is billed. Update the payment method at ${billingUrl}, then re-run`
37187
+ };
37188
+ }
37147
37189
  const result = connectStatus2(row, provider, fresh);
37148
37190
  const state = boxState2(row);
37149
37191
  if (state !== shown && (shown !== undefined || result.status === "provisioning"))
@@ -37157,7 +37199,15 @@ async function connect2(url, opts, deps) {
37157
37199
  return { ...rest, ...billing, ...checkup ? { checkup } : {}, next: next + note };
37158
37200
  }
37159
37201
  await deps.sleep(POLL_MS2);
37160
- row = (await deps.list().catch(() => [])).find((d) => d.id === row.id) ?? row;
37202
+ const listed = await deps.list().catch(() => {
37203
+ return;
37204
+ });
37205
+ const now = listed?.find((d) => d.id === row.id);
37206
+ if (listed && !now && undoRole) {
37207
+ await undoRole();
37208
+ return { status: "failed", provider, name, id: row.id, ...billing, next: "The monitoring box was removed before it became active: see pgai databases, then re-run pgai connect" };
37209
+ }
37210
+ row = now ?? row;
37161
37211
  }
37162
37212
  }
37163
37213
  async function openConnection2(url, opts) {
@@ -37376,8 +37426,13 @@ async function clickhouseOrgFor2(host, keyId, keySecret) {
37376
37426
  }
37377
37427
  function disconnectBilling(reply) {
37378
37428
  const r = reply ?? {};
37429
+ if (r.billing?.subscription === "canceled" && r.billing.credited && r.billing_warning)
37430
+ return `subscription canceled: no further charges; the refund failed (${r.billing_warning})`;
37379
37431
  if (r.billing_warning)
37380
37432
  return `not released (${r.billing_warning}): contact support`;
37433
+ if (r.billing?.subscription === "canceled" && typeof r.billing.refunded === "number" && r.billing.refunded > 0) {
37434
+ return `subscription canceled: no further charges; refunded ${money2(r.billing.refunded, r.billing.currency ?? "usd")} to your card`;
37435
+ }
37381
37436
  if (r.billing?.subscription === "canceled")
37382
37437
  return "subscription canceled: no further charges; the unused part of this period is credited (prorated)";
37383
37438
  if (r.billing?.subscription === "active" && typeof r.billing.quantity === "number") {
@@ -46139,10 +46194,10 @@ function updatePgwatchConfig(configPath, updates) {
46139
46194
  console.error(`Warning: could not restrict permissions on ${configPath}: ${message}`);
46140
46195
  }
46141
46196
  }
46142
- function applyApiKey(projectDir, apiKey) {
46197
+ function applyApiKey(projectDir, apiKey, opts) {
46143
46198
  const configPath = path9.resolve(projectDir, ".pgwatch-config");
46144
46199
  try {
46145
- updatePgwatchConfig(configPath, { api_key: apiKey });
46200
+ updatePgwatchConfig(configPath, { api_key: apiKey, api_url: resolveBaseUrls2(opts).apiBaseUrl });
46146
46201
  } catch (err) {
46147
46202
  console.error(`\u2717 ${err instanceof Error ? err.message : String(err)}`);
46148
46203
  return false;
@@ -46760,7 +46815,7 @@ Use demo mode without API key: postgres-ai mon local-install --demo`);
46760
46815
  if (apiKey) {
46761
46816
  console.log("Using API key provided via --api-key parameter");
46762
46817
  writeConfig({ apiKey });
46763
- if (!applyApiKey(projectDir, apiKey)) {
46818
+ if (!applyApiKey(projectDir, apiKey, globalOpts)) {
46764
46819
  process.exitCode = 1;
46765
46820
  return;
46766
46821
  }
@@ -46778,7 +46833,7 @@ Use demo mode without API key: postgres-ai mon local-install --demo`);
46778
46833
  const trimmedKey = inputApiKey.trim();
46779
46834
  if (trimmedKey) {
46780
46835
  writeConfig({ apiKey: trimmedKey });
46781
- if (!applyApiKey(projectDir, trimmedKey)) {
46836
+ if (!applyApiKey(projectDir, trimmedKey, globalOpts)) {
46782
46837
  process.exitCode = 1;
46783
46838
  return;
46784
46839
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresai",
3
- "version": "0.17.0-dev.6",
3
+ "version": "0.17.0-dev.8",
4
4
  "description": "postgres_ai CLI",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,