@batadata/cli 0.1.15 → 0.1.16

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.
@@ -1,10 +1,12 @@
1
1
  /**
2
- * bata claim <token> — redeem a claimable database into your team.
2
+ * bata claim <token> — redeem a legacy claim token into your team.
3
3
  *
4
- * Authed. Resolves the team (like `bata create`), calls
5
- * POST /v1/claim/redeem { claim_token, team_id }, and on success the project
6
- * becomes a permanent member of your team (its TTL is cleared). Typed,
7
- * agent-friendly errors for unknown / expired / already-claimed tokens.
4
+ * LEGACY: the anonymous, no-signup flow that issued claim tokens is gone —
5
+ * `bata new` now creates a database directly in your team. This command remains
6
+ * only to redeem a token from that retired flow. Authed. Resolves the team
7
+ * (like `bata create`), calls POST /v1/claim/redeem { claim_token, team_id },
8
+ * and on success the project becomes a permanent member of your team (its TTL
9
+ * is cleared). Typed errors for unknown / expired / already-claimed tokens.
8
10
  */
9
11
  export interface ClaimArgs {
10
12
  token?: string;
@@ -1,10 +1,12 @@
1
1
  /**
2
- * bata claim <token> — redeem a claimable database into your team.
2
+ * bata claim <token> — redeem a legacy claim token into your team.
3
3
  *
4
- * Authed. Resolves the team (like `bata create`), calls
5
- * POST /v1/claim/redeem { claim_token, team_id }, and on success the project
6
- * becomes a permanent member of your team (its TTL is cleared). Typed,
7
- * agent-friendly errors for unknown / expired / already-claimed tokens.
4
+ * LEGACY: the anonymous, no-signup flow that issued claim tokens is gone —
5
+ * `bata new` now creates a database directly in your team. This command remains
6
+ * only to redeem a token from that retired flow. Authed. Resolves the team
7
+ * (like `bata create`), calls POST /v1/claim/redeem { claim_token, team_id },
8
+ * and on success the project becomes a permanent member of your team (its TTL
9
+ * is cleared). Typed errors for unknown / expired / already-claimed tokens.
8
10
  */
9
11
  import { api, apiError, resolveTeamId } from "../api.js";
10
12
  import { requireToken, saveConfig, isJsonMode } from "../config.js";
@@ -25,7 +27,8 @@ function printHelp() {
25
27
  log();
26
28
  log(` ${colors.bold("bata claim")} ${colors.dim("<token>")}`);
27
29
  log();
28
- log(` Claim an instant database (from ${colors.cyan("bata new")}) into your team.`);
30
+ log(` ${colors.yellow("Legacy:")} redeem a claim token from the retired anonymous flow.`);
31
+ log(` ${colors.cyan("bata new")} now creates a database directly in your team — no token to claim.`);
29
32
  log(` Requires login — pass ${colors.cyan("--api-key")}, set ${colors.cyan("BATA_API_KEY")}, or run ${colors.cyan("bata login")}.`);
30
33
  log();
31
34
  log(` ${colors.bold("Examples")}`);
@@ -1,17 +1,21 @@
1
1
  /**
2
- * bata new — instant, no-signup Postgres (bata.new / claimable databases).
2
+ * bata new — instant Postgres in your team (one call, zero config).
3
3
  *
4
- * Calls the PUBLIC POST /v1/claim/new (no credentials needed), prints the
5
- * connection string, the expiry, and how to claim the database into a real
6
- * team later. `--json` emits the full payload (including the one-time claim
7
- * token) for agents.
4
+ * Authed (like every other command): requires a credential. Calls
5
+ * POST /v1/claim/new, which creates a REAL project directly in your team
6
+ * owned, billed, and quota'd like any other and prints the connection string.
7
+ * No name or region to pick; the compute is the smallest box and scales to zero.
8
8
  *
9
- * Honest wording: an UNCLAIMED database is permanently DELETED at its expiry.
9
+ * `--team <id>` targets a specific team (else your resolved/default team).
10
+ * `--json` emits the full payload for agents.
11
+ *
12
+ * (The old anonymous, no-signup flow with claim tokens is gone.)
10
13
  */
11
14
  export interface NewArgs {
15
+ team?: string;
12
16
  help: boolean;
13
17
  }
14
- /** Parse `bata new` args. No positional/flags today beyond --help (global
15
- * flags like --json are stripped upstream in index.ts). Exported for tests. */
18
+ /** Parse `bata new` args: optional `--team <id>` and `--help` (global flags
19
+ * like --json are stripped upstream in index.ts). Exported for tests. */
16
20
  export declare function parseNewArgs(args: string[]): NewArgs;
17
21
  export declare function newDb(args: string[]): Promise<void>;
@@ -1,41 +1,45 @@
1
1
  /**
2
- * bata new — instant, no-signup Postgres (bata.new / claimable databases).
2
+ * bata new — instant Postgres in your team (one call, zero config).
3
3
  *
4
- * Calls the PUBLIC POST /v1/claim/new (no credentials needed), prints the
5
- * connection string, the expiry, and how to claim the database into a real
6
- * team later. `--json` emits the full payload (including the one-time claim
7
- * token) for agents.
4
+ * Authed (like every other command): requires a credential. Calls
5
+ * POST /v1/claim/new, which creates a REAL project directly in your team
6
+ * owned, billed, and quota'd like any other and prints the connection string.
7
+ * No name or region to pick; the compute is the smallest box and scales to zero.
8
8
  *
9
- * Honest wording: an UNCLAIMED database is permanently DELETED at its expiry.
9
+ * `--team <id>` targets a specific team (else your resolved/default team).
10
+ * `--json` emits the full payload for agents.
11
+ *
12
+ * (The old anonymous, no-signup flow with claim tokens is gone.)
10
13
  */
11
- import { api, apiError } from "../api.js";
12
- import { isJsonMode } from "../config.js";
14
+ import { api, apiError, resolveTeamId } from "../api.js";
15
+ import { requireToken, isJsonMode, saveConfig } from "../config.js";
13
16
  import { colors, log, json, success, kvList } from "../utils/logger.js";
14
17
  import { emitError } from "../utils/errors.js";
15
- /** Parse `bata new` args. No positional/flags today beyond --help (global
16
- * flags like --json are stripped upstream in index.ts). Exported for tests. */
18
+ /** Parse `bata new` args: optional `--team <id>` and `--help` (global flags
19
+ * like --json are stripped upstream in index.ts). Exported for tests. */
17
20
  export function parseNewArgs(args) {
18
- for (const arg of args) {
21
+ let team;
22
+ for (let i = 0; i < args.length; i++) {
23
+ const arg = args[i];
19
24
  if (arg === "--help" || arg === "-h")
20
- return { help: true };
25
+ return { team, help: true };
26
+ if (arg === "--team" && args[i + 1])
27
+ team = args[++i];
21
28
  }
22
- return { help: false };
29
+ return { team, help: false };
23
30
  }
24
31
  function printHelp() {
25
32
  log();
26
33
  log(` ${colors.bold("bata new")}`);
27
34
  log();
28
- log(` Create an instant, no-signup Postgres database and print how to connect.`);
29
- log(` You get a connection string immediately plus a one-time claim token.`);
30
- log();
31
- log(` ${colors.bold("Claim it later")}`);
32
- log(` ${colors.cyan("bata claim <token>")} Move the database into your team (clears the expiry)`);
33
- log();
34
- log(` ${colors.yellow("Unclaimed databases are permanently DELETED at their expiry.")}`);
35
+ log(` Create an instant Postgres database in your team and print how to connect.`);
36
+ log(` One call, zero config you get a connection string immediately.`);
37
+ log(` Requires login — pass ${colors.cyan("--api-key")}, set ${colors.cyan("BATA_API_KEY")}, or run ${colors.cyan("bata login")}.`);
35
38
  log();
36
39
  log(` ${colors.bold("Options")}`);
37
- log(` ${colors.dim("--json")} Machine-readable output (includes the claim token)`);
38
- log(` ${colors.dim("--help, -h")} Show this help`);
40
+ log(` ${colors.dim("--team <id>")} Team to create the database in (default: your team)`);
41
+ log(` ${colors.dim("--json")} Machine-readable output`);
42
+ log(` ${colors.dim("--help, -h")} Show this help`);
39
43
  log();
40
44
  }
41
45
  export async function newDb(args) {
@@ -44,33 +48,38 @@ export async function newDb(args) {
44
48
  printHelp();
45
49
  return;
46
50
  }
47
- // No credentials: this hits the PUBLIC endpoint.
48
- const res = await api.post("/v1/claim/new", {});
51
+ // Authed like every other command. Exits 4 NO_CREDENTIALS when absent.
52
+ const token = requireToken();
53
+ // Resolve the team unless one was passed explicitly. The server verifies
54
+ // membership either way.
55
+ const teamId = parsed.team ?? (await resolveTeamId(token));
56
+ const body = {};
57
+ if (teamId)
58
+ body.team_id = teamId;
59
+ const res = await api.post("/v1/claim/new", body, token);
49
60
  if (!res.ok) {
50
61
  const data = res.data;
51
62
  const code = data?.code;
52
63
  if (res.status === 404 && code === "CLAIMABLE_DISABLED") {
53
- emitError("NOT_FOUND", "Instant databases (bata.new) are not enabled on this server.", "Contact the operator, or create a project with `bata create` after `bata login`.");
54
- }
55
- if (res.status === 503 || code === "CLAIM_POOL_EXHAUSTED") {
56
- emitError("API_UNAVAILABLE", "The free database pool is full right now. Try again shortly.", "This is transient — retry in a minute.");
64
+ emitError("NOT_FOUND", "Instant databases (bata new) are not enabled on this server.", "Create a project with `bata create <name>` instead.");
57
65
  }
58
66
  if (res.status === 429) {
59
- emitError("API_UNAVAILABLE", "Rate limit reached for instant databases from this network.", "Wait a bit before creating another, or claim one you already made.");
67
+ emitError("API_UNAVAILABLE", "Rate limit reached for instant databases from this network.", "Wait a bit before creating another.");
60
68
  }
61
69
  emitError("CLI_ERROR", apiError(res, "Failed to create instant database"));
62
70
  }
63
71
  const db = res.data;
72
+ saveConfig({ defaultProject: db.project_id });
64
73
  if (isJsonMode()) {
65
74
  json(db);
66
75
  return;
67
76
  }
68
77
  log();
69
- success("Your instant database is ready to claim!");
78
+ success("Your instant database is ready!");
70
79
  log();
71
80
  kvList([
72
81
  ["Project ID", colors.dim(db.project_id)],
73
- ["Expires", db.expires_at],
82
+ ["Team", colors.dim(db.team_id)],
74
83
  ]);
75
84
  log();
76
85
  log(` ${colors.bold("Connection")}`);
@@ -80,11 +89,7 @@ export async function newDb(args) {
80
89
  ["Pooled", colors.dim(db.connection.pooled)],
81
90
  ]);
82
91
  log();
83
- log(` ${colors.bold("Claim token")} ${colors.dim("(shown once)")}`);
84
- log(` ${colors.cyan(db.claim_token)}`);
85
- log();
86
- log(` ${colors.dim("Claim it into your team:")} ${colors.cyan(`bata claim ${db.claim_token}`)}`);
87
- log(` ${colors.yellow("Unclaimed databases are permanently DELETED at expiry.")}`);
92
+ log(` ${colors.dim("Connect:")} ${colors.cyan("bata db url")}`);
88
93
  log(` ${colors.dim("First connection may take a few seconds while the compute wakes.")}`);
89
94
  log();
90
95
  }
package/dist/index.js CHANGED
@@ -27,8 +27,8 @@ function help() {
27
27
  log(` ${colors.cyan("bata")} ${colors.dim("<command>")} ${colors.dim("[options]")}`);
28
28
  log();
29
29
  log(` ${colors.bold("Quick Start")}`);
30
- log(` ${colors.cyan("new")} Instant no-signup database ${colors.dim("(no login) claim it later")}`);
31
- log(` ${colors.cyan("claim <token>")} Claim a ` + "`bata new`" + ` database into your team`);
30
+ log(` ${colors.cyan("new")} Instant database in your team ${colors.dim("(one call, zero config)")}`);
31
+ log(` ${colors.cyan("claim <token>")} ${colors.dim("Legacy: redeem a claim token from the retired anonymous flow")}`);
32
32
  log(` ${colors.cyan("create <name>")} Create a project and wait for it to be ready`);
33
33
  log(` ${colors.cyan("connect <name>")} Open psql to a project (auto-wakes if suspended)`);
34
34
  log(` ${colors.cyan("status")} Show all projects and their status`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batadata/cli",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "CLI for BataDB — serverless Postgres platform",
5
5
  "bin": {
6
6
  "bata": "./dist/index.js"