neon 6.4.0 → 7.0.1

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/README.md CHANGED
@@ -966,15 +966,12 @@ The plugins CLI installs every plugin it finds in the Neon plugin package. Today
966
966
 
967
967
  `neon snapshots` (alias `neon snapshot`) manages **snapshots** — point-in-time backups of a branch that you can list, rename, expire, restore into a branch, or schedule automatically. Snapshots are a Beta Neon feature and were previously only available in the Console and REST API; this command group brings them to the CLI.
968
968
 
969
- Every sub-command resolves the project through the standard chain (`--project-id`, then the `.neon` context file, then a single-project auto-detect). Branch-scoped sub-commands (`create`, `schedule`) default to the branch pinned in `.neon`, falling back to the project's default branch, and accept `--branch <id|name>`. The `get`, `update`, `delete`, and `restore` sub-commands take a snapshot **id, unique name, or slug** as their positional argument. An id wins. A unique name still wins over another snapshot's matching slug, so a name you already use keeps targeting that snapshot. Slug is used when no name matches. An ambiguous name errors and asks you to use the id.
969
+ Every sub-command resolves the project through the standard chain (`--project-id`, then the `.neon` context file, then a single-project auto-detect). Branch-scoped sub-commands (`create`, `schedule`) default to the branch pinned in `.neon`, falling back to the project's default branch, and accept `--branch <id|name>`. The `get`, `update`, `delete`, and `restore` sub-commands take a snapshot **id or name** as their positional argument (an id wins; an ambiguous name errors and asks you to use the id).
970
970
 
971
971
  ```bash
972
972
  # Snapshot the head of the current/default branch
973
973
  neon snapshots create --name pre-migration
974
974
 
975
- # Give the snapshot a slug (unique in the project; omit to let the API generate one)
976
- neon snapshots create --branch main --name "Before migration" --slug before-migration
977
-
978
975
  # Snapshot a specific branch at a point in time (RFC 3339 timestamp OR LSN — mutually exclusive)
979
976
  neon snapshots create --branch main --timestamp 2025-01-01T00:00:00Z
980
977
  neon snapshots create --branch main --lsn 0/1F3C8A0 --expires-at 2025-12-31T23:59:59Z
@@ -982,7 +979,6 @@ neon snapshots create --branch main --lsn 0/1F3C8A0 --expires-at 2025-12-31T23:5
982
979
  # List / inspect
983
980
  neon snapshots list
984
981
  neon snapshots get pre-migration
985
- neon snapshots get before-migration
986
982
 
987
983
  # Rename or change expiration (omit both to error; --expires-at and --clear-expiration conflict)
988
984
  neon snapshots update snap-1234 --name nightly
@@ -82,7 +82,7 @@ const builder = (argv) => argv.usage("$0 bucket <sub-command> [options]").option
82
82
  demandOption: true
83
83
  }).options(scopeOptions),
84
84
  handler: (args) => deleteBucket(args)
85
- }).command("object <sub-command>", "List, download, upload or delete objects in a bucket", (yargs) => yargs.usage("$0 bucket object <sub-command> [options]").command({
85
+ }).command("object", "List, download, upload or delete objects in a bucket", (yargs) => yargs.usage("$0 bucket object <sub-command> [options]").command({
86
86
  command: "list <target>",
87
87
  aliases: ["ls"],
88
88
  describe: "List objects in a bucket. By default folders are collapsed (like \"aws s3 ls\"); pass --recursive for a flat listing of every key",
@@ -153,7 +153,7 @@ const builder = (argv) => argv.usage("$0 bucket <sub-command> [options]").option
153
153
  }
154
154
  }),
155
155
  handler: (args) => deleteObject(args)
156
- }).demandCommand(1, "").strictCommands());
156
+ }).strictCommands());
157
157
  const handler = (args) => {
158
158
  return args;
159
159
  };
@@ -476,7 +476,7 @@ const builder = (argv) => argv.usage("$0 config <sub-command> [options]").option
476
476
  kind: "bucket",
477
477
  name: args.name,
478
478
  access: args.access
479
- }))).demandCommand(1, "Specify what to add: auth, data-api, ai-gateway, function, or bucket.")).command("init", "Scaffold a neon.ts policy and install the Neon config packages", (yargs) => yargs.options({
479
+ })))).command("init", "Scaffold a neon.ts policy and install the Neon config packages", (yargs) => yargs.options({
480
480
  install: {
481
481
  describe: "Install @neon/config and @neon/env if they're missing. On by default; use --no-install to just print the command.",
482
482
  type: "boolean",
@@ -129,7 +129,7 @@ const builder = (argv) => argv.usage("$0 function <sub-command> [options]").opti
129
129
  describe: "Function slug",
130
130
  type: "string",
131
131
  demandOption: true
132
- }), (args) => deleteFn(args)).command(["domains", "domain"], "Manage custom domains on the branch (beta)", (yargs) => yargs.demandCommand(1).command("list", "List custom domains on the branch", (yargs) => yargs, (args) => listDomains(args)).command("register <domain>", "Point a domain you already own at a function on the branch", (yargs) => yargs.positional("domain", {
132
+ }), (args) => deleteFn(args)).command(["domains", "domain"], "Manage custom domains on the branch (beta)", (yargs) => yargs.command("list", "List custom domains on the branch", (yargs) => yargs, (args) => listDomains(args)).command("register <domain>", "Point a domain you already own at a function on the branch", (yargs) => yargs.positional("domain", {
133
133
  describe: "Domain you already own (for example docs.example.com)",
134
134
  type: "string",
135
135
  demandOption: true
@@ -17,7 +17,6 @@ var snapshots_exports = /* @__PURE__ */ __exportAll({
17
17
  const SNAPSHOT_FIELDS = [
18
18
  "id",
19
19
  "name",
20
- "slug",
21
20
  "source_branch_id",
22
21
  "expires_at",
23
22
  "created_at"
@@ -39,10 +38,8 @@ const SNAPSHOT_FREQUENCIES = [
39
38
  "weekly",
40
39
  "monthly"
41
40
  ];
42
- /** Matches createSnapshot.query.slug in the Management API spec. */
43
- const SNAPSHOT_SLUG = /^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$/;
44
41
  const SNAPSHOT_REF = {
45
- describe: "Snapshot id, unique name, or slug. Lookup order: id, unique name, slug.",
42
+ describe: "Snapshot id or name. An id match wins over a name.",
46
43
  type: "string"
47
44
  };
48
45
  /** Narrow an arbitrary string to a supported {@link SnapshotFrequency}. */
@@ -53,7 +50,7 @@ const aliases = ["snapshot"];
53
50
  const builder = (argv) => argv.usage("$0 snapshots <sub-command> [options]").options({ "project-id": {
54
51
  describe: "Project ID",
55
52
  type: "string"
56
- } }).middleware(fillSingleProject).command("list", "List snapshots in the project", (yargs) => yargs, (args) => list(args)).command("get <id>", "Get a snapshot by id, unique name, or slug", (yargs) => yargs.positional("id", SNAPSHOT_REF), (args) => get(args)).command("create", "Create a snapshot from a branch", (yargs) => yargs.options({
53
+ } }).middleware(fillSingleProject).command("list", "List snapshots in the project", (yargs) => yargs, (args) => list(args)).command("get <id>", "Get a snapshot by id or name", (yargs) => yargs.positional("id", SNAPSHOT_REF), (args) => get(args)).command("create", "Create a snapshot from a branch", (yargs) => yargs.strict().options({
57
54
  branch: {
58
55
  alias: "b",
59
56
  describe: "Branch id or name to snapshot. Defaults to the branch in your context, or the project's default branch.",
@@ -63,10 +60,6 @@ const builder = (argv) => argv.usage("$0 snapshots <sub-command> [options]").opt
63
60
  describe: "A name for the snapshot",
64
61
  type: "string"
65
62
  },
66
- slug: {
67
- describe: "User-defined resource ID, unique in the project (1-63 characters: start with a lowercase letter, then lowercase letters, digits, or hyphens, ending with a letter or digit). Omit to let the API generate one. It cannot be changed later.",
68
- type: "string"
69
- },
70
63
  timestamp: {
71
64
  describe: "Take the snapshot at this point in time (RFC 3339, e.g. 2025-01-01T00:00:00Z). Must fall within the branch's restore window. Mutually exclusive with --lsn.",
72
65
  type: "string"
@@ -82,10 +75,9 @@ const builder = (argv) => argv.usage("$0 snapshots <sub-command> [options]").opt
82
75
  }).conflicts("timestamp", "lsn").example([
83
76
  ["$0 snapshots create", "Snapshot the head of the context/default branch"],
84
77
  ["$0 snapshots create --branch main --name pre-migration", "Snapshot the head of main with a name"],
85
- ["$0 snapshots create --branch main --name \"Before migration\" --slug before-migration", "Snapshot main with a display name and a slug"],
86
78
  ["$0 snapshots create --branch main --timestamp 2025-01-01T00:00:00Z", "Snapshot main at a point in time"],
87
79
  ["$0 snapshots create --branch main --lsn 0/1F3C8A0 --expires-at 2025-12-31T23:59:59Z", "Snapshot main at an LSN, auto-deleting at the given time"]
88
- ]), (args) => create(args)).command("update <id>", "Update a snapshot's name or expiration by id, unique name, or slug", (yargs) => yargs.positional("id", SNAPSHOT_REF).options({
80
+ ]), (args) => create(args)).command("update <id>", "Update a snapshot's name or expiration", (yargs) => yargs.positional("id", SNAPSHOT_REF).options({
89
81
  name: {
90
82
  describe: "Rename the snapshot",
91
83
  type: "string"
@@ -98,7 +90,7 @@ const builder = (argv) => argv.usage("$0 snapshots <sub-command> [options]").opt
98
90
  describe: "Clear the expiration so the snapshot is kept indefinitely.",
99
91
  type: "boolean"
100
92
  }
101
- }).conflicts("expires-at", "clear-expiration"), (args) => update(args)).command("delete <id>", "Delete a snapshot by id, unique name, or slug", (yargs) => yargs.positional("id", SNAPSHOT_REF), (args) => deleteSnapshot(args)).command("restore <id>", "Restore a snapshot (id, unique name, or slug) into a branch", (yargs) => yargs.positional("id", SNAPSHOT_REF).options({
93
+ }).conflicts("expires-at", "clear-expiration"), (args) => update(args)).command("delete <id>", "Delete a snapshot by id or name", (yargs) => yargs.positional("id", SNAPSHOT_REF), (args) => deleteSnapshot(args)).command("restore <id>", "Restore a snapshot into a branch", (yargs) => yargs.positional("id", SNAPSHOT_REF).options({
102
94
  name: {
103
95
  describe: "Name for the newly restored branch. Auto-generated when omitted.",
104
96
  type: "string"
@@ -154,7 +146,7 @@ const builder = (argv) => argv.usage("$0 snapshots <sub-command> [options]").opt
154
146
  describe: "Full schedule as JSON, for multi-entry schedules, e.g. '[{\"frequency\":\"daily\",\"hour\":3,\"retention_seconds\":604800}]'. Overrides the single-entry flags.",
155
147
  type: "string"
156
148
  }
157
- }).example([["$0 snapshots schedule set --branch main --frequency daily --hour 3 --retention 604800", "A daily 03:00 snapshot kept for 7 days"], ["$0 snapshots schedule set --branch main --schedule '[{\"frequency\":\"weekly\",\"day\":1,\"hour\":2},{\"frequency\":\"daily\",\"hour\":3}]'", "A multi-entry schedule via JSON"]]), (args) => scheduleSet(args)).demandCommand(1, "Specify `get` or `set`."), () => {});
149
+ }).example([["$0 snapshots schedule set --branch main --frequency daily --hour 3 --retention 604800", "A daily 03:00 snapshot kept for 7 days"], ["$0 snapshots schedule set --branch main --schedule '[{\"frequency\":\"weekly\",\"day\":1,\"hour\":2},{\"frequency\":\"daily\",\"hour\":3}]'", "A multi-entry schedule via JSON"]]), (args) => scheduleSet(args)), () => {});
158
150
  const handler = (args) => {
159
151
  return args;
160
152
  };
@@ -167,8 +159,9 @@ const toIso = (value, flag) => {
167
159
  return new Date(ms).toISOString();
168
160
  };
169
161
  /**
170
- * Unique names precede slugs so existing name-based commands keep targeting
171
- * the named snapshot when another snapshot's slug matches that name.
162
+ * Resolve a snapshot from an id **or** a name. Snapshot names are not guaranteed
163
+ * unique, so an id match wins; a name that resolves to more than one snapshot is a
164
+ * hard error asking the user to disambiguate by id.
172
165
  */
173
166
  const resolveSnapshot = async (props) => {
174
167
  const { data: { snapshots } } = await props.apiClient.listSnapshots(props.projectId);
@@ -177,11 +170,8 @@ const resolveSnapshot = async (props) => {
177
170
  const byName = snapshots.filter((s) => s.name === props.id);
178
171
  if (byName.length === 1) return byName[0];
179
172
  if (byName.length > 1) throw new Error(`Multiple snapshots are named "${props.id}". Re-run with the snapshot id:\n${byName.map((s) => ` ${s.id}`).join("\n")}`);
180
- const bySlug = snapshots.find((s) => s.slug === props.id);
181
- if (bySlug) return bySlug;
182
- throw new Error(`Snapshot "${props.id}" not found.\nAvailable snapshots: ${snapshots.map((s) => formatSnapshotRef(s)).join(", ") || "none"}`);
173
+ throw new Error(`Snapshot "${props.id}" not found.\nAvailable snapshots: ${snapshots.map((s) => `${s.name} (${s.id})`).join(", ") || "none"}`);
183
174
  };
184
- const formatSnapshotRef = (snapshot) => snapshot.slug ? `${snapshot.name} (${snapshot.id}, slug: ${snapshot.slug})` : `${snapshot.name} (${snapshot.id})`;
185
175
  const list = async (props) => {
186
176
  const { data: { snapshots } } = await props.apiClient.listSnapshots(props.projectId);
187
177
  writer(props).end(snapshots, {
@@ -201,14 +191,12 @@ const get = async (props) => {
201
191
  const create = async (props) => {
202
192
  if (props.lsn !== void 0 && !looksLikeLSN(props.lsn)) throw new Error(`Invalid --lsn value: "${props.lsn}". Expected an LSN like 0/1F3C8A0.`);
203
193
  if (props.timestamp !== void 0 && !looksLikeTimestamp(props.timestamp)) throw new Error(`Invalid --timestamp value: "${props.timestamp}". Use an RFC 3339 timestamp, e.g. 2025-01-01T00:00:00Z.`);
204
- if (props.slug !== void 0 && !SNAPSHOT_SLUG.test(props.slug)) throw new Error(`Invalid --slug value: "${props.slug}". Use 1-63 characters: start with a lowercase letter, then lowercase letters, digits, or hyphens, and end with a letter or digit.`);
205
194
  const { branchId } = await resolveBranchRef({
206
195
  ...props,
207
196
  branch: props.branch
208
197
  });
209
198
  const { data } = await retryOnLock(() => props.apiClient.createSnapshot(props.projectId, branchId, {
210
199
  name: props.name,
211
- slug: props.slug,
212
200
  timestamp: props.timestamp,
213
201
  lsn: props.lsn,
214
202
  expires_at: props.expiresAt ? toIso(props.expiresAt, "--expires-at") : void 0
@@ -28,10 +28,9 @@ const builder = (argv) => {
28
28
  },
29
29
  "region-id": {
30
30
  describe: `The region ID. Possible values: ${REGIONS.join(", ")}`,
31
- type: "string",
32
- demandOption: true
31
+ type: "string"
33
32
  }
34
- }).middleware(fillSingleOrg).command("list", "List configured VPC endpoints for this organization.", (yargs) => yargs, async (args) => {
33
+ }).middleware(fillSingleOrg).command("list", "List configured VPC endpoints for this organization.", (yargs) => yargs.demandOption("region-id"), async (args) => {
35
34
  await listOrg(args);
36
35
  }).command({
37
36
  command: "assign <id>",
@@ -40,13 +39,13 @@ const builder = (argv) => {
40
39
  builder: (yargs) => yargs.options({ label: {
41
40
  describe: "An optional descriptive label for the VPC endpoint",
42
41
  type: "string"
43
- } }),
42
+ } }).demandOption("region-id"),
44
43
  handler: async (args) => {
45
44
  await assignOrg(args);
46
45
  }
47
- }).command("remove <id>", "Remove a VPC endpoint from this organization.", (yargs) => yargs, async (args) => {
46
+ }).command("remove <id>", "Remove a VPC endpoint from this organization.", (yargs) => yargs.demandOption("region-id"), async (args) => {
48
47
  await removeOrg(args);
49
- }).command("status <id>", "Get the status of a VPC endpoint for this organization.", (yargs) => yargs, async (args) => {
48
+ }).command("status <id>", "Get the status of a VPC endpoint for this organization.", (yargs) => yargs.demandOption("region-id"), async (args) => {
50
49
  await statusOrg(args);
51
50
  });
52
51
  }).command("project", "Manage project-level VPC endpoint restrictions.\nBy default, connections are accepted from any VPC configured at the organization level.\nA project-level VPC endpoint restriction can be used to restrict connections to a specific VPC.", (yargs) => {
package/dist/help.js CHANGED
@@ -232,19 +232,58 @@ const formatHelp = (help) => {
232
232
  }
233
233
  return [...result, ...lines];
234
234
  };
235
- const showHelp = async (argv) => {
236
- const help = await argv.getHelp();
237
- const text = `${formatHelp(help).join("\n")}\n`;
238
- await new Promise((resolve, reject) => {
239
- process.stdout.write(text, (err) => {
240
- if (err) {
241
- reject(err);
242
- return;
243
- }
244
- resolve();
245
- });
235
+ const writeHelp = (help, stream) => new Promise((resolve, reject) => {
236
+ stream.write(`${formatHelp(help).join("\n")}\n`, (err) => {
237
+ if (err) {
238
+ reject(err);
239
+ return;
240
+ }
241
+ resolve();
246
242
  });
243
+ });
244
+ const showHelp = async (argv) => {
245
+ await writeHelp(await argv.getHelp(), process.stdout);
247
246
  process.exit(0);
248
247
  };
248
+ /**
249
+ * A yargs validation failure: a missing required option or positional, an unknown
250
+ * subcommand, a value outside `choices`. Carries the failing command's help, captured
251
+ * in `.fail` because yargs has restored the parent's context by the time the error
252
+ * reaches the caller.
253
+ */
254
+ var UsageError = class extends Error {
255
+ constructor(message, help) {
256
+ super(message);
257
+ this.help = help;
258
+ }
259
+ };
260
+ /** On stderr, so `-o json` stdout stays empty. */
261
+ const showUsageErrorHelp = (err) => writeHelp(err.help, process.stderr);
262
+ /**
263
+ * The yargs `.fail` handler. yargs passes its usage instance as the third argument
264
+ * (`@types/yargs` declares it as `Argv`). Errors thrown by a handler, a `coerce`, or the
265
+ * parser arrive with their own `err` and are rethrown unchanged.
266
+ */
267
+ const failOnUsageError = (msg, err, usage) => {
268
+ if (err) throw err;
269
+ if (typeof usage !== "object" || usage === null || !("help" in usage) || typeof usage.help !== "function") throw new Error("yargs no longer passes its usage instance to .fail(); update failOnUsageError for the installed yargs");
270
+ const help = usage.help();
271
+ if (typeof help !== "string") throw new Error("yargs usage.help() did not return a string");
272
+ throw new UsageError(msg ?? "Invalid usage", help);
273
+ };
274
+ function assertYargsInternals(argv) {
275
+ if (!("getInternalMethods" in argv) || typeof argv.getInternalMethods !== "function") throw new Error("yargs no longer exposes getInternalMethods(); update isBareParentCommand for the installed yargs");
276
+ }
277
+ /**
278
+ * True when the command yargs is running groups subcommands and none was given, at any
279
+ * depth: `neon config add`, `neon snapshots schedule`. `@types/yargs` doesn't declare the
280
+ * running command's context, so this reads yargs 17's internals.
281
+ */
282
+ const isBareParentCommand = (argv, positionals) => {
283
+ assertYargsInternals(argv);
284
+ const internals = argv.getInternalMethods();
285
+ const path = internals.getContext().commands;
286
+ return path.length > 0 && positionals.length === path.length && internals.getCommandInstance().getCommands().length > 0;
287
+ };
249
288
  //#endregion
250
- export { showHelp };
289
+ export { UsageError, failOnUsageError, isBareParentCommand, showHelp, showUsageErrorHelp };
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { AuthRefreshError, defaultClientID } from "./auth.js";
11
11
  import { getCliName } from "./utils/cli_name.js";
12
12
  import { ensureAuth } from "./commands/auth.js";
13
13
  import { recoverFrom401 } from "./auth_recovery.js";
14
- import { showHelp } from "./help.js";
14
+ import { UsageError, failOnUsageError, isBareParentCommand, showHelp, showUsageErrorHelp } from "./help.js";
15
15
  import { rewriteUnknownAgentArg } from "./init/plan.js";
16
16
  import commands_default from "./commands/index.js";
17
17
  import { recoverFromSSO } from "./sso_recovery.js";
@@ -125,13 +125,16 @@ builder = builder.scriptName(pkg_default.name).locale("en").usage("$0 <command>
125
125
  type: "boolean",
126
126
  default: false
127
127
  }).alias("help", "h").middleware(async (args) => {
128
- if (args.help || args._.length === 1 && !NO_SUBCOMMANDS_VERBS.includes(args._[0])) await showHelp(builder);
129
- }).middleware(ensureAuth).middleware(enrichFromContext).middleware(analyticsMiddleware).command(commands_default).strictCommands().version(pkg_default.version).group("version", "Global options:").alias("version", "v").completion().scriptName(getCliName()).epilog("For more information, visit https://neon.com/docs/reference/neon-cli").wrap(null).fail(false);
128
+ if (args.help) await showHelp(builder);
129
+ }, true).middleware(async (args) => {
130
+ if (args._.length === 1 && !NO_SUBCOMMANDS_VERBS.includes(args._[0]) || args._.length > 1 && isBareParentCommand(builder, args._)) await showHelp(builder);
131
+ }).middleware(ensureAuth).middleware(enrichFromContext).middleware(analyticsMiddleware).command(commands_default).strictCommands().version(pkg_default.version).group("version", "Global options:").alias("version", "v").completion().scriptName(getCliName()).epilog("For more information, visit https://neon.com/docs/reference/neon-cli").wrap(null).fail(failOnUsageError);
130
132
  async function handleError(msg, err, canRetry) {
131
133
  if (process.argv.some((arg) => arg === "--help" || arg === "-h")) {
132
134
  await showHelp(builder);
133
135
  process.exit(0);
134
136
  }
137
+ if (err instanceof UsageError) await showUsageErrorHelp(err);
135
138
  if (err instanceof Error && err.stack) log.debug("Stack: %s", err.stack);
136
139
  if (err instanceof Error) {
137
140
  const rewritten = rewriteUnknownAgentArg({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "6.4.0",
3
+ "version": "7.0.1",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -64,9 +64,9 @@
64
64
  "yaml": "^2.9.0",
65
65
  "yargs": "17.7.2",
66
66
  "yoctocolors": "^2.1.2",
67
- "@neon/config-runtime": "1.7.2",
68
- "@neon/sdk": "6.1.2",
69
- "@neon/config": "1.8.2"
67
+ "@neon/config": "1.8.3",
68
+ "@neon/config-runtime": "1.7.3",
69
+ "@neon/sdk": "7.0.0"
70
70
  },
71
71
  "optionalDependencies": {
72
72
  "@napi-rs/keyring": "1.3.0",
@@ -99,9 +99,9 @@
99
99
  "tsx": "4.22.3",
100
100
  "typescript": "^5.9.0",
101
101
  "vitest": "^3.0.9",
102
- "@neon-internals/cli-core": "0.0.0",
103
- "@neon-internals/env-core": "0.0.25",
102
+ "@neon-internals/env-core": "0.0.26",
104
103
  "@neon/e2e-harness": "0.0.0",
104
+ "@neon-internals/cli-core": "0.0.0",
105
105
  "@neon/functions": "0.11.0"
106
106
  },
107
107
  "publishConfig": {