neon 9.9.6 → 9.9.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.
Files changed (49) hide show
  1. package/dist/_chunks/{api-1MKsfpY3.js → api-Bus6PoKT.js} +23 -11
  2. package/dist/_chunks/{bootstrap-B73qVB39.js → bootstrap-yotTpFtF.js} +2 -1
  3. package/dist/_chunks/{checkout-CczPpuT9.js → checkout-C4kfW64r.js} +3 -3
  4. package/dist/_chunks/{claim-BoN9NPTy.js → claim-u1NrKodG.js} +1 -1
  5. package/dist/_chunks/{config-C8BQIoM2.js → config-DrlP49no.js} +1 -1
  6. package/dist/_chunks/{deploy-BdipMGJE.js → deploy-DnjB7HV_.js} +1 -1
  7. package/dist/_chunks/{dev-DVB7fGiG.js → dev-wpD1Az-t.js} +3 -3
  8. package/dist/_chunks/{functions-PHaU-kRb.js → functions-v9z7zjWD.js} +2 -1
  9. package/dist/_chunks/{git-BZY1WeAw.js → git-DWmx2prl.js} +2 -2
  10. package/dist/_chunks/{link-BVa6Nfji.js → link-D89GPFoO.js} +2 -2
  11. package/dist/_chunks/{neon_auth-mfyjde2x.js → neon_auth-DE6X6FFV.js} +3 -2
  12. package/dist/_chunks/{snapshots-DxNhjcco.js → snapshots-BolN3uBz.js} +2 -1
  13. package/dist/_chunks/{status-BBnw48qR.js → status-DXp_w9U2.js} +1 -1
  14. package/dist/commands/api.js +1 -1
  15. package/dist/commands/bootstrap.js +1 -1
  16. package/dist/commands/checkout.js +1 -1
  17. package/dist/commands/claim.js +1 -1
  18. package/dist/commands/config.js +1 -1
  19. package/dist/commands/deploy.js +1 -1
  20. package/dist/commands/dev.js +1 -1
  21. package/dist/commands/env.js +1 -1
  22. package/dist/commands/functions.js +1 -1
  23. package/dist/commands/functions_new.js +6 -2
  24. package/dist/commands/git.js +1 -1
  25. package/dist/commands/index.js +14 -14
  26. package/dist/commands/link.js +1 -1
  27. package/dist/commands/neon_auth.js +1 -1
  28. package/dist/commands/snapshots.js +1 -1
  29. package/dist/commands/status.js +1 -1
  30. package/dist/commands/subscribe.js +1 -1
  31. package/dist/env_services.js +4 -18
  32. package/dist/errors.js +28 -1
  33. package/dist/functions/registry.js +5 -1
  34. package/dist/help.js +9 -1
  35. package/dist/init/auth.js +1 -1
  36. package/dist/init/deploy.js +1 -1
  37. package/dist/init/link.js +1 -1
  38. package/dist/init/plan.js +2 -1
  39. package/dist/init/run.js +3 -3
  40. package/dist/mcp/agents.js +2 -1
  41. package/dist/mcp/install.js +2 -1
  42. package/dist/mcp/plan.js +2 -1
  43. package/dist/neon_services.js +6 -4
  44. package/dist/plugins/plan.js +2 -1
  45. package/dist/skills/catalog.js +2 -1
  46. package/dist/skills/plan.js +2 -1
  47. package/dist/utils/openapi.js +11 -402
  48. package/package.json +6 -6
  49. package/dist/_chunks/{env-C3HQJO8Z.js → env-BIP63KZa.js} +1 -1
@@ -1,3 +1,4 @@
1
+ import { REDACTED_INVALID_VALUE, didYouMean } from "../errors.js";
1
2
  import { agents, detectGlobalAgents, detectProjectAgents as detectProjectAgents$1, getAgentTypes } from "add-mcp";
2
3
  // src/mcp/agents.ts
3
4
  const UNSUPPORTED_AGENTS = /* @__PURE__ */ new Set(["mastracode"]);
@@ -61,7 +62,7 @@ function tryResolveAddMcpAgentId(rawAgent) {
61
62
  }
62
63
  function resolveAddMcpAgentId(rawAgent) {
63
64
  const resolved = tryResolveAddMcpAgentId(rawAgent);
64
- if (!resolved) throw new Error(`Unknown agent: "${rawAgent}". Supported agents: ${listMcpAgentIds().join(", ")}`);
65
+ if (!resolved) throw new Error(`Unknown agent: ${REDACTED_INVALID_VALUE}.${didYouMean([rawAgent], listMcpAgentIds())} Supported agents: ${listMcpAgentIds().join(", ")}`);
65
66
  return resolved;
66
67
  }
67
68
  async function detectInstalledAgents() {
@@ -1,3 +1,4 @@
1
+ import { REDACTED_INVALID_VALUE, didYouMean } from "../errors.js";
1
2
  import { getCliName } from "../utils/cli_name.js";
2
3
  import { chmodSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
4
  import { basename, dirname, join, relative } from "node:path";
@@ -24,7 +25,7 @@ function isMcpCategory(value) {
24
25
  function parseMcpCategories(raw) {
25
26
  const out = [];
26
27
  for (const value of raw) {
27
- if (!isMcpCategory(value)) throw new Error(`Unknown MCP category: "${value}". Supported categories: ${NEON_MCP_CATEGORIES.join(", ")}`);
28
+ if (!isMcpCategory(value)) throw new Error(`Unknown MCP category: ${REDACTED_INVALID_VALUE}.${didYouMean([value], NEON_MCP_CATEGORIES)} Supported categories: ${NEON_MCP_CATEGORIES.join(", ")}`);
28
29
  out.push(value);
29
30
  }
30
31
  return out;
package/dist/mcp/plan.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { REDACTED_INVALID_VALUE, didYouMean } from "../errors.js";
1
2
  import { tryResolveAddMcpAgentId } from "./agents.js";
2
3
  import { detectMcpAgents, mcpInstallableAgents } from "./targets.js";
3
4
  import { collectYesAgents, noDetectedAgentsMessage } from "../init/plan.js";
@@ -32,7 +33,7 @@ async function resolveMcpPlan(options) {
32
33
  }),
33
34
  resolveSpecified: (raw) => {
34
35
  const id = tryResolveAddMcpAgentId(raw);
35
- if (!id) throw new Error(`Unknown agent: "${raw}". Supported agents: ${available.join(", ")}`);
36
+ if (!id) throw new Error(`Unknown agent: ${REDACTED_INVALID_VALUE}.${didYouMean([raw], available)} Supported agents: ${available.join(", ")}`);
36
37
  return id;
37
38
  },
38
39
  pick: prompt ? options.pickAgents ?? pickAgentsInteractively : void 0,
@@ -1,3 +1,4 @@
1
+ import { REDACTED_INVALID_VALUE, didYouMean } from "./errors.js";
1
2
  // src/neon_services.ts
2
3
  /**
3
4
  * Every Neon service a `--service` flag can name, spelled the way a user types it — one
@@ -76,19 +77,20 @@ const parseServices = (raw, options) => {
76
77
  return canonical;
77
78
  });
78
79
  const unsupported = resolved.filter((name) => !allowed.some((service) => service === name));
79
- if (unsupported.length > 0) throw new Error(`${unsupportedMessage(unsupported, flag)} ${supported}`);
80
+ if (unsupported.length > 0) throw new Error(`${unsupportedMessage(unsupported, allowed, flag)} ${supported}`);
80
81
  for (const [used, canonical] of deprecated) onDeprecated?.(used, canonical);
81
82
  return allowed.filter((service) => resolved.includes(service));
82
83
  };
83
84
  /**
84
85
  * The sentences explaining why a selection was refused. A real Neon service this command
85
86
  * cannot act on is a different mistake from a typo — different cause, different fix — so the
86
- * two are never answered with the same word.
87
+ * two are never answered with the same word. Only a real service is named; anything else is
88
+ * redacted, since it could be a secret pasted into the wrong flag.
87
89
  */
88
- const unsupportedMessage = (unsupported, flag) => {
90
+ const unsupportedMessage = (unsupported, allowed, flag) => {
89
91
  const known = unsupported.filter((name) => NEON_SERVICES.some((service) => service === name));
90
92
  const unknown = unsupported.filter((name) => !known.some((service) => service === name));
91
- return [unknown.length > 0 ? `Unknown service${unknown.length === 1 ? "" : "s"} ${unknown.join(", ")}.` : void 0, ...known.map((service) => `${service} is not something ${flag} can select.`)].filter((part) => part !== void 0).join(" ");
93
+ return [unknown.length > 0 ? `Unknown service${unknown.length === 1 ? "" : "s"} ${unknown.map(() => REDACTED_INVALID_VALUE).join(", ")}.${didYouMean(unknown, allowed)}` : void 0, ...known.map((service) => `${service} is not something ${flag} can select.`)].filter((part) => part !== void 0).join(" ");
92
94
  };
93
95
  /** Every spelling of the services flag, so a habit picked up on one command works on another. */
94
96
  const SERVICE_FLAG_NAMES = [
@@ -1,3 +1,4 @@
1
+ import { REDACTED_INVALID_VALUE, didYouMean } from "../errors.js";
1
2
  import { getAgentDisplayName, tryResolveAddMcpAgentId } from "../mcp/agents.js";
2
3
  import "../init/agents.js";
3
4
  import { detectInstalledPluginsAgents, detectProjectPluginsAgents, getPluginsTargetName, mappedPluginsTargets, missingPluginsCommands, pluginsCommandFix, pluginsCommandProblemText, pluginsInstallableAgents, unusablePluginsCommands } from "./targets.js";
@@ -63,7 +64,7 @@ async function resolvePluginsPlan(options) {
63
64
  resolveSpecified: (raw) => {
64
65
  if (raw === "*") throw new Error("neon plugins does not accept --agent *. Pass --agent <name> for each coding agent, or omit --agent to use detected agents.");
65
66
  const id = tryResolveAddMcpAgentId(raw);
66
- if (!id) throw new Error(`Unknown agent: "${raw}". Supported agents: ${available.join(", ")}`);
67
+ if (!id) throw new Error(`Unknown agent: ${REDACTED_INVALID_VALUE}.${didYouMean([raw], available)} Supported agents: ${available.join(", ")}`);
67
68
  return id;
68
69
  },
69
70
  pick: prompt ? options.pickAgents ?? pickAgentsInteractively : void 0,
@@ -1,3 +1,4 @@
1
+ import { REDACTED_INVALID_VALUE, didYouMean } from "../errors.js";
1
2
  import { helpCsv } from "../utils/help_text.js";
2
3
  // src/skills/catalog.ts
3
4
  const AGENT_SKILLS_SOURCE = "neondatabase/agent-skills";
@@ -58,7 +59,7 @@ const defaultSkillEntries = () => NEON_SKILL_CATALOG.filter((entry) => entry.def
58
59
  function resolveSkillId(raw) {
59
60
  if (raw === "*") throw new Error("neon skills does not accept --skill *. Pass --skill <name> for each skill, or omit --skill to install the default skills with -y.");
60
61
  const entry = CATALOG_BY_SKILL.get(raw);
61
- if (entry === void 0) throw new Error(`Unknown skill: "${raw}". Supported skills: ${listSkillIds().join(", ")}`);
62
+ if (entry === void 0) throw new Error(`Unknown skill: ${REDACTED_INVALID_VALUE}.${didYouMean([raw], listSkillIds())} Supported skills: ${listSkillIds().join(", ")}`);
62
63
  return entry;
63
64
  }
64
65
  function uniqueSkillEntries(entries) {
@@ -1,3 +1,4 @@
1
+ import { REDACTED_INVALID_VALUE, didYouMean } from "../errors.js";
1
2
  import { tryResolveAddMcpAgentId } from "../mcp/agents.js";
2
3
  import "../init/agents.js";
3
4
  import { detectSkillsAgents, skillsInstallableAgents } from "./targets.js";
@@ -51,7 +52,7 @@ async function resolveSkillsPlan(options) {
51
52
  resolveSpecified: (raw) => {
52
53
  if (raw === "*") throw new Error("neon skills does not accept --agent *. Pass --agent <name> for each coding agent, or omit --agent to use detected agents.");
53
54
  const id = tryResolveAddMcpAgentId(raw);
54
- if (!id) throw new Error(`Unknown agent: "${raw}". Supported agents: ${available.join(", ")}`);
55
+ if (!id) throw new Error(`Unknown agent: ${REDACTED_INVALID_VALUE}.${didYouMean([raw], available)} Supported agents: ${available.join(", ")}`);
55
56
  return id;
56
57
  },
57
58
  pick: prompt ? options.pickAgents ?? pickAgentsInteractively : void 0,
@@ -1,44 +1,11 @@
1
1
  import { log } from "../log.js";
2
2
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { dirname, join } from "node:path";
4
+ import { EndpointNotFoundError, NEON_OPENAPI_SPEC_URL, describeEndpoint, fetchOpenApiSpec, listEndpoints } from "@neon/sdk/openapi";
4
5
  // src/utils/openapi.ts
5
- /** Public URL of the released Neon OpenAPI v2 spec. */
6
- const DEFAULT_SPEC_URL = "https://neon.com/api_spec/release/v2.json";
6
+ const DEFAULT_SPEC_URL = NEON_OPENAPI_SPEC_URL;
7
7
  const CACHE_FILE = "openapi-spec.json";
8
8
  const CACHE_TTL_MS = 864e5;
9
- const FETCH_TIMEOUT_MS = 1e4;
10
- const HTTP_METHODS = /* @__PURE__ */ new Set([
11
- "get",
12
- "post",
13
- "put",
14
- "patch",
15
- "delete",
16
- "head",
17
- "options"
18
- ]);
19
- const DESCRIBE_METHODS = [
20
- "GET",
21
- "POST",
22
- "PUT",
23
- "PATCH",
24
- "DELETE"
25
- ];
26
- async function fetchSpec(url) {
27
- const controller = new AbortController();
28
- const timer = setTimeout(() => {
29
- controller.abort();
30
- }, FETCH_TIMEOUT_MS);
31
- try {
32
- const res = await fetch(url, {
33
- signal: controller.signal,
34
- headers: { Accept: "application/json" }
35
- });
36
- if (!res.ok) throw new Error(`Failed to fetch OpenAPI spec (${res.status} ${res.statusText})`);
37
- return await res.json();
38
- } finally {
39
- clearTimeout(timer);
40
- }
41
- }
42
9
  function readCache(cachePath) {
43
10
  try {
44
11
  return JSON.parse(readFileSync(cachePath, "utf8"));
@@ -71,7 +38,7 @@ async function loadSpec(opts) {
71
38
  }
72
39
  try {
73
40
  log.debug("Fetching OpenAPI spec from %s", specUrl);
74
- const spec = await fetchSpec(specUrl);
41
+ const spec = await fetchOpenApiSpec({ url: specUrl });
75
42
  writeCache(cachePath, {
76
43
  fetchedAt: Date.now(),
77
44
  specUrl,
@@ -88,372 +55,14 @@ async function loadSpec(opts) {
88
55
  return null;
89
56
  }
90
57
  }
91
- /** Flatten a spec into a sorted list of routes (by path, then method). */
92
- function getEndpoints(spec) {
93
- const endpoints = [];
94
- for (const [path, item] of Object.entries(spec.paths ?? {})) for (const [method, op] of Object.entries(item)) {
95
- if (!HTTP_METHODS.has(method.toLowerCase())) continue;
96
- const operation = op ?? {};
97
- endpoints.push({
98
- method: method.toUpperCase(),
99
- path,
100
- summary: operation.summary,
101
- operationId: operation.operationId,
102
- tags: operation.tags ?? []
103
- });
104
- }
105
- endpoints.sort((a, b) => a.path === b.path ? a.method.localeCompare(b.method) : a.path.localeCompare(b.path));
106
- return endpoints;
107
- }
108
- function isRecord(value) {
109
- return typeof value === "object" && value !== null && !Array.isArray(value);
110
- }
111
- function asStringArray(value) {
112
- if (!Array.isArray(value)) return [];
113
- return value.filter((item) => typeof item === "string");
114
- }
115
- function stringDesc(value) {
116
- if (!isRecord(value) || typeof value.description !== "string") return "";
117
- return value.description.trim();
118
- }
119
- function specRecord(spec) {
120
- return spec;
121
- }
122
- function resolveRef(spec, ref) {
123
- if (!ref.startsWith("#/")) throw new Error(`Unsupported $ref "${ref}". Only document-local refs are resolved.`);
124
- let node = specRecord(spec);
125
- for (const part of ref.slice(2).split("/")) {
126
- const key = part.replace(/~1/g, "/").replace(/~0/g, "~");
127
- if (!isRecord(node) || !(key in node)) throw new Error(`Unresolved $ref ${ref}.`);
128
- node = node[key];
129
- }
130
- return node;
131
- }
132
- function schemaType(schema) {
133
- const t = schema.type;
134
- if (typeof t === "string") return t;
135
- if (Array.isArray(t)) {
136
- const first = t.find((item) => typeof item === "string");
137
- if (first) return first;
138
- }
139
- if (schema.items !== void 0) return "array";
140
- if (isRecord(schema.properties) || schema.additionalProperties !== void 0) return "object";
141
- if (Array.isArray(schema.enum)) return "string";
142
- return "object";
143
- }
144
- function optionalEnum(schema) {
145
- return Array.isArray(schema.enum) ? { enum: schema.enum } : {};
146
- }
147
- function optionalNullable(schema) {
148
- return schema.nullable === true ? { nullable: true } : {};
149
- }
150
- function mergeSchema(base, overlay) {
151
- const properties = {
152
- ...isRecord(base.properties) ? base.properties : {},
153
- ...isRecord(overlay.properties) ? overlay.properties : {}
154
- };
155
- const required = [.../* @__PURE__ */ new Set([...asStringArray(base.required), ...asStringArray(overlay.required)])];
156
- const description = stringDesc(overlay) || stringDesc(base);
157
- return {
158
- ...base,
159
- ...overlay,
160
- properties,
161
- required,
162
- ...description ? { description } : {}
163
- };
164
- }
165
- function resolveSchema(spec, schema, stack) {
166
- if (!isRecord(schema)) return {};
167
- if (typeof schema.$ref === "string") {
168
- const ref = schema.$ref;
169
- const { $ref: _ref, ...siblings } = schema;
170
- if (stack.includes(ref)) return {
171
- type: "object",
172
- ...siblings
173
- };
174
- return mergeSchema(resolveSchema(spec, resolveRef(spec, ref), [...stack, ref]), siblings);
175
- }
176
- if (Array.isArray(schema.allOf)) {
177
- const { allOf, ...rest } = schema;
178
- let merged = {
179
- type: "object",
180
- properties: {},
181
- required: []
182
- };
183
- for (const part of allOf) merged = mergeSchema(merged, resolveSchema(spec, part, stack));
184
- return mergeSchema(merged, rest);
185
- }
186
- return schema;
187
- }
188
- function fieldFromSchema(location, name, required, schema) {
189
- return {
190
- in: location,
191
- name,
192
- required,
193
- type: schemaType(schema),
194
- description: stringDesc(schema),
195
- ...optionalEnum(schema),
196
- ...optionalNullable(schema)
197
- };
198
- }
199
- function pushedRefs(schema, stack) {
200
- if (!isRecord(schema)) return stack;
201
- let next = stack;
202
- if (typeof schema.$ref === "string" && !next.includes(schema.$ref)) next = [...next, schema.$ref];
203
- if (Array.isArray(schema.allOf)) for (const part of schema.allOf) next = pushedRefs(part, next);
204
- return next;
205
- }
206
- function arrayField(spec, name, required, schema, stack) {
207
- const items = isRecord(schema.items) ? resolveSchema(spec, schema.items, stack) : {};
208
- const itemType = schemaType(items);
209
- const properties = isRecord(items.properties) ? items.properties : void 0;
210
- const requiredItems = new Set(asStringArray(items.required));
211
- return {
212
- in: "body",
213
- name,
214
- required,
215
- type: "array",
216
- description: stringDesc(schema),
217
- items: {
218
- type: itemType,
219
- ...optionalEnum(items),
220
- ...optionalNullable(items),
221
- ...properties ? { properties: Object.entries(properties).map(([propName, propSchema]) => {
222
- const resolved = resolveSchema(spec, propSchema, stack);
223
- return {
224
- name: propName,
225
- type: schemaType(resolved),
226
- required: requiredItems.has(propName),
227
- description: stringDesc(resolved),
228
- ...optionalEnum(resolved),
229
- ...optionalNullable(resolved)
230
- };
231
- }) } : {}
232
- }
233
- };
234
- }
235
- function unionMembers(schema) {
236
- if (Array.isArray(schema.oneOf)) return schema.oneOf;
237
- if (Array.isArray(schema.anyOf)) return schema.anyOf;
238
- return [];
239
- }
240
- function discriminatorField(schema, prefix) {
241
- if (!isRecord(schema.discriminator)) return null;
242
- const propertyName = schema.discriminator.propertyName;
243
- if (typeof propertyName !== "string") return null;
244
- const mapping = schema.discriminator.mapping;
245
- const values = isRecord(mapping) ? Object.keys(mapping) : [];
246
- return {
247
- in: "body",
248
- name: prefix ? `${prefix}.${propertyName}` : propertyName,
249
- required: true,
250
- type: "string",
251
- description: "",
252
- ...values.length > 0 ? { enum: values } : {}
253
- };
254
- }
255
- function flattenUnion(spec, schema, prefix, stack) {
256
- const members = unionMembers(schema);
257
- const byName = /* @__PURE__ */ new Map();
258
- for (const member of members) {
259
- const seen = /* @__PURE__ */ new Set();
260
- for (const field of flattenBody(spec, member, prefix, stack)) {
261
- if (seen.has(field.name)) continue;
262
- seen.add(field.name);
263
- const copies = byName.get(field.name) ?? [];
264
- copies.push(field);
265
- byName.set(field.name, copies);
266
- }
267
- }
268
- const fields = [];
269
- for (const copies of byName.values()) fields.push({
270
- ...copies[0],
271
- required: copies.length === members.length && copies.every((field) => field.required)
272
- });
273
- const discriminator = discriminatorField(schema, prefix);
274
- if (discriminator && !byName.has(discriminator.name)) fields.unshift(discriminator);
275
- else if (discriminator) {
276
- const existing = fields.find((field) => field.name === discriminator.name);
277
- if (existing) {
278
- existing.required = true;
279
- if (!existing.enum && discriminator.enum) existing.enum = discriminator.enum;
280
- }
281
- }
282
- return fields;
283
- }
284
- function flattenBody(spec, schema, prefix, stack = []) {
285
- const nextStack = pushedRefs(schema, stack);
286
- const resolved = resolveSchema(spec, schema, stack);
287
- if (unionMembers(resolved).length > 0) return flattenUnion(spec, resolved, prefix, nextStack);
288
- const properties = isRecord(resolved.properties) ? resolved.properties : void 0;
289
- if (!properties) {
290
- if (prefix === "") return [];
291
- if (schemaType(resolved) === "array") return [arrayField(spec, prefix, false, resolved, nextStack)];
292
- return [fieldFromSchema("body", prefix, false, resolved)];
293
- }
294
- const requiredSet = new Set(asStringArray(resolved.required));
295
- const fields = [];
296
- for (const [key, prop] of Object.entries(properties)) {
297
- const name = prefix ? `${prefix}.${key}` : key;
298
- const required = requiredSet.has(key);
299
- const resolvedProp = resolveSchema(spec, prop, nextStack);
300
- const type = schemaType(resolvedProp);
301
- if (type === "object" && isRecord(resolvedProp.properties)) {
302
- fields.push(...flattenBody(spec, prop, name, nextStack));
303
- continue;
304
- }
305
- if (type === "array") {
306
- fields.push(arrayField(spec, name, required, resolvedProp, nextStack));
307
- continue;
308
- }
309
- fields.push(fieldFromSchema("body", name, required, resolvedProp));
310
- }
311
- return fields;
312
- }
313
- function resolveParameter(spec, parameter) {
314
- if (!isRecord(parameter)) return null;
315
- if (typeof parameter.$ref === "string") {
316
- const resolved = resolveRef(spec, parameter.$ref);
317
- if (!isRecord(resolved)) throw new Error(`Unresolved $ref ${parameter.$ref}.`);
318
- const { $ref: _ref, ...siblings } = parameter;
319
- const description = stringDesc(siblings) || stringDesc(resolved);
320
- return {
321
- ...resolved,
322
- ...siblings,
323
- ...description ? { description } : {}
324
- };
325
- }
326
- return parameter;
327
- }
328
- function paramToField(spec, param) {
329
- const location = param.in;
330
- if (location !== "path" && location !== "query" && location !== "header") return null;
331
- if (typeof param.name !== "string") return null;
332
- const schema = isRecord(param.schema) ? resolveSchema(spec, param.schema, []) : {};
333
- const required = location === "path" ? param.required !== false : param.required === true;
334
- const type = schemaType(schema);
335
- const itemSchema = type === "array" && isRecord(schema.items) ? resolveSchema(spec, schema.items, []) : null;
336
- return {
337
- in: location,
338
- name: param.name,
339
- required,
340
- type,
341
- description: stringDesc(param) || stringDesc(schema),
342
- ...optionalEnum(schema),
343
- ...optionalNullable(schema),
344
- ...itemSchema ? { items: {
345
- type: schemaType(itemSchema),
346
- ...optionalEnum(itemSchema),
347
- ...optionalNullable(itemSchema)
348
- } } : {}
349
- };
350
- }
351
- function pathParamNames(template) {
352
- return [...template.matchAll(/\{([^}]+)\}/g)].map((match) => match[1]);
353
- }
354
- function pathMatchesTemplate(path, template) {
355
- const pathParts = path.split("/");
356
- const templateParts = template.split("/");
357
- if (pathParts.length !== templateParts.length) return false;
358
- return templateParts.every((part, i) => {
359
- if (part.startsWith("{") && part.endsWith("}")) return pathParts[i] !== "";
360
- return part === pathParts[i];
361
- });
362
- }
363
- function matchPath(spec, requestPath) {
364
- const path = requestPath.split("?")[0] ?? requestPath;
365
- const paths = spec.paths ?? {};
366
- const exact = paths[path];
367
- if (isRecord(exact)) return {
368
- template: path,
369
- pathItem: exact
370
- };
371
- const matches = Object.entries(paths).filter(([template, item]) => isRecord(item) && pathMatchesTemplate(path, template));
372
- if (matches.length === 0) throw new Error(`No route matches "${path}". Run \`neon api --list\` to see available routes.`);
373
- matches.sort((a, b) => {
374
- const staticA = a[0].split("/").filter((p) => !p.startsWith("{")).length;
375
- return b[0].split("/").filter((p) => !p.startsWith("{")).length - staticA;
376
- });
377
- const [template, pathItem] = matches[0];
378
- if (!isRecord(pathItem)) throw new Error(`No route matches "${path}". Run \`neon api --list\` to see available routes.`);
379
- return {
380
- template,
381
- pathItem
382
- };
383
- }
384
- function availableMethods(pathItem) {
385
- return DESCRIBE_METHODS.filter((method) => isRecord(pathItem[method.toLowerCase()]));
386
- }
387
- function collectParameters(spec, pathItem, operation, template) {
388
- const raw = [...Array.isArray(pathItem.parameters) ? pathItem.parameters : [], ...Array.isArray(operation.parameters) ? operation.parameters : []];
389
- const byKey = /* @__PURE__ */ new Map();
390
- for (const entry of raw) {
391
- const resolved = resolveParameter(spec, entry);
392
- if (!resolved) continue;
393
- const field = paramToField(spec, resolved);
394
- if (!field) continue;
395
- byKey.set(`${field.in}:${field.name}`, field);
396
- }
397
- const pathFields = pathParamNames(template).map((name) => {
398
- const existing = byKey.get(`path:${name}`);
399
- if (existing) return existing;
400
- return {
401
- in: "path",
402
- name,
403
- required: true,
404
- type: "string",
405
- description: ""
406
- };
407
- });
408
- const query = [...byKey.values()].filter((field) => field.in === "query");
409
- const header = [...byKey.values()].filter((field) => field.in === "header");
410
- return [
411
- ...pathFields,
412
- ...query,
413
- ...header
414
- ];
415
- }
416
- function jsonBodySchema(spec, operation) {
417
- let requestBody = operation.requestBody;
418
- if (isRecord(requestBody) && typeof requestBody.$ref === "string") requestBody = resolveRef(spec, requestBody.$ref);
419
- if (!isRecord(requestBody)) return null;
420
- const content = requestBody.content;
421
- if (!isRecord(content)) return null;
422
- const json = content["application/json"];
423
- let contentType = "application/json";
424
- let selected = json;
425
- if (!isRecord(json)) {
426
- const entry = Object.entries(content).find(([, value]) => isRecord(value));
427
- if (!entry) return null;
428
- contentType = entry[0];
429
- selected = entry[1];
430
- }
431
- if (!isRecord(selected) || selected.schema === void 0) return null;
432
- return {
433
- schema: selected.schema,
434
- required: requestBody.required === true,
435
- contentType
436
- };
437
- }
58
+ /** `describeEndpoint` with the `neon api` flag to pass next in its errors. */
438
59
  function describeOperation(spec, path, method) {
439
- const methodUpper = method.toUpperCase();
440
- const { template, pathItem } = matchPath(spec, path);
441
- const available = availableMethods(pathItem);
442
- const operation = pathItem[methodUpper.toLowerCase()];
443
- if (!isRecord(operation)) {
444
- const hint = available.length > 0 ? ` Available: ${available.join(", ")}. Pass -X ${available[0]}.` : " Run `neon api --list` to see available routes.";
445
- throw new Error(`No ${methodUpper} ${template} in the spec.${hint}`);
60
+ try {
61
+ return describeEndpoint(spec, path, method);
62
+ } catch (err) {
63
+ if (!(err instanceof EndpointNotFoundError)) throw err;
64
+ const hint = err.available.length > 0 ? `Pass -X ${err.available[0]}.` : "Run `neon api --list` to see available routes.";
65
+ throw new Error(`${err.message} ${hint}`);
446
66
  }
447
- const body = jsonBodySchema(spec, operation);
448
- const fields = [...collectParameters(spec, pathItem, operation, template), ...body ? flattenBody(spec, body.schema, "") : []];
449
- return {
450
- method: methodUpper,
451
- path: template,
452
- summary: typeof operation.summary === "string" ? operation.summary : "",
453
- operationId: typeof operation.operationId === "string" ? operation.operationId : "",
454
- bodyRequired: body?.required === true,
455
- contentType: body?.contentType ?? "",
456
- fields
457
- };
458
67
  }
459
- export { DEFAULT_SPEC_URL, describeOperation, getEndpoints, loadSpec };
68
+ export { DEFAULT_SPEC_URL, describeOperation, listEndpoints as getEndpoints, loadSpec };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "9.9.6",
3
+ "version": "9.9.8",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -73,10 +73,10 @@
73
73
  "yaml": "^2.9.0",
74
74
  "yargs": "17.7.2",
75
75
  "yoctocolors": "^2.1.2",
76
- "@neon/config": "1.14.6",
77
- "@neon/config-runtime": "1.12.9",
76
+ "@neon/config": "1.14.7",
77
+ "@neon/config-runtime": "1.12.10",
78
78
  "@neon/realtime": "0.2.1",
79
- "@neon/sdk": "7.15.0"
79
+ "@neon/sdk": "7.16.0"
80
80
  },
81
81
  "optionalDependencies": {
82
82
  "@napi-rs/keyring": "1.3.0",
@@ -112,10 +112,10 @@
112
112
  "tsx": "4.22.3",
113
113
  "typescript": "^5.9.0",
114
114
  "vitest": "^3.0.9",
115
- "@neon-internals/env-core": "0.0.57",
115
+ "@neon-internals/env-core": "0.0.58",
116
116
  "@neon-internals/cli-core": "0.0.0",
117
117
  "@neon/e2e-harness": "0.0.0",
118
- "@neon/env": "2.1.9",
118
+ "@neon/env": "2.1.10",
119
119
  "@neon/functions": "0.11.0"
120
120
  },
121
121
  "publishConfig": {
@@ -7,8 +7,8 @@ import { deprecatedServiceMessage, parseServices, servicesFlagValue, servicesOpt
7
7
  import { mergeEnvFile, readEnvFile, resolveEnvFilePath } from "../env_file.js";
8
8
  import { n as NEON_ENV_VAR_KEYS } from "./env-EJU-0InB.js";
9
9
  import { ENV_PULL_KEY_HELP, ENV_PULL_SERVICES, envKeysForSelection, envPullFlagValue, isLegacyFunctionBaseUrlKey, ownedEnvServiceKeys, parseEnvPullKeys } from "../env_services.js";
10
- import { fillSingleProject, resolveBranchRef } from "../utils/enrichers.js";
11
10
  import { i as dropClaimableUnsupported, o as resolveNeonEnvVars } from "./env-BWvi2_2f.js";
11
+ import { fillSingleProject, resolveBranchRef } from "../utils/enrichers.js";
12
12
  import { warnAiGateway } from "../utils/ai_gateway_notice.js";
13
13
  import { formatPulledEnv, pulledBranch } from "../commands/env_output.js";
14
14
  import { existsSync } from "node:fs";