neon 8.21.0 → 8.22.0

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
@@ -1534,7 +1534,7 @@ Id Name Project Created At Last Used At Last
1534
1534
  | postgres (`pg`, `lakebase`) | `computes`, `databases`, `roles`, `connection-string`, `psql` | Manage Postgres and connect to it |
1535
1535
  | [databases](https://neon.com/docs/reference/cli-databases) | `list`, `create`, `delete` | Manage databases |
1536
1536
  | function | `deploy`, `list`, `get`, `delete`, `domains list`, `domains register`, `domains delete` | Manage Neon Functions |
1537
- | [roles](https://neon.com/docs/reference/cli-roles) | `list`, `create`, `delete` | Manage roles |
1537
+ | [roles](https://neon.com/docs/reference/cli-roles) | `list`, `get`, `create`, `reset-password`, `delete` | Manage roles |
1538
1538
  | [operations](https://neon.com/docs/reference/cli-operations) | `list`, `get` | Manage operations |
1539
1539
  | logs | `query`, `fields`, `field-values` | Query branch logs (Beta) |
1540
1540
  | inspect | `db stalled-queries` | Inspect Postgres diagnostics |
@@ -3,7 +3,7 @@ import { a as computes_exports } from "./computes-OKFUNFee.js";
3
3
  import { o as connection_string_exports } from "./connection_string-6WhV4WFx.js";
4
4
  import { s as databases_exports } from "./databases-B-qY303S.js";
5
5
  import { o as psql_exports } from "./psql-BcxiPR4W.js";
6
- import { u as roles_exports } from "./roles-BXGtPGjv.js";
6
+ import { f as roles_exports } from "./roles-BELJqjTy.js";
7
7
  // src/commands/postgres.ts
8
8
  var postgres_exports = /* @__PURE__ */ __exportAll({
9
9
  aliases: () => aliases,
@@ -12,8 +12,10 @@ var roles_exports = /* @__PURE__ */ __exportAll({
12
12
  create: () => create,
13
13
  deleteRole: () => deleteRole,
14
14
  describe: () => describe,
15
+ get: () => get,
15
16
  handler: () => handler,
16
- list: () => list
17
+ list: () => list,
18
+ resetPassword: () => resetPassword
17
19
  });
18
20
  const ROLES_FIELDS = ["name", "created_at"];
19
21
  const CREATED_ROLE_FIELDS = [
@@ -21,6 +23,14 @@ const CREATED_ROLE_FIELDS = [
21
23
  "password",
22
24
  "created_at"
23
25
  ];
26
+ const ROLE_DETAIL_FIELDS = [
27
+ "name",
28
+ "branch_id",
29
+ "protected",
30
+ "authentication_method",
31
+ "created_at",
32
+ "updated_at"
33
+ ];
24
34
  const ROLE_ACCESS = [
25
35
  "admin",
26
36
  "read_only",
@@ -66,7 +76,11 @@ const builderFor = (usage) => (argv) => argv.usage(`$0 ${usage} <sub-command> [o
66
76
  }).check((args) => {
67
77
  if (args.access === "admin" && (args.database !== void 0 || args.schema !== void 0)) throw new Error("--database and --schema need --access read_only or --access read_write");
68
78
  return true;
69
- }), (args) => create(args)).command("delete <role>", "Delete a role", (yargs) => yargs, (args) => deleteRole(args));
79
+ }), (args) => create(args)).command("get <role>", "Get a role", (yargs) => yargs, (args) => get(args)).command("reset-password <role>", "Reset a role's password and print the new one", (yargs) => yargs.options({ wait: {
80
+ describe: "Wait until the compute applies the new password. Use --no-wait to return as soon as the API accepts the reset",
81
+ type: "boolean",
82
+ default: true
83
+ } }), (args) => resetPassword(args)).command("delete <role>", "Delete a role", (yargs) => yargs, (args) => deleteRole(args));
70
84
  const builder = builderFor("roles");
71
85
  const handler = (args) => {
72
86
  return args;
@@ -127,4 +141,32 @@ const deleteRole = async (props) => {
127
141
  }
128
142
  log.info(`Role "${props.role}" not found on branch ${branch?.name ?? branchId}; nothing to delete.`);
129
143
  };
130
- export { create as a, handler as c, command as i, list as l, builder as n, deleteRole as o, builderFor as r, describe as s, aliases as t, roles_exports as u };
144
+ const get = async (props) => {
145
+ const { branchId } = await resolveBranchFromProps(props);
146
+ const { fromSdkError, getNeonClient } = await import("../neon_client.js");
147
+ const role = await getNeonClient(props).postgres.roles.get({
148
+ projectId: props.projectId,
149
+ branchId,
150
+ roleName: props.role
151
+ }).catch((error) => {
152
+ throw fromSdkError(error, props.apiHost);
153
+ });
154
+ writer(props).end(role, { fields: ROLE_DETAIL_FIELDS });
155
+ };
156
+ const resetPassword = async (props) => {
157
+ const { branchId, branch } = await resolveBranchFromProps(props);
158
+ const { fromSdkError, getNeonClient } = await import("../neon_client.js");
159
+ const role = await getNeonClient(props).postgres.roles.resetPassword({
160
+ projectId: props.projectId,
161
+ branchId,
162
+ roleName: props.role
163
+ }, { waitForReadiness: props.wait }).catch((error) => {
164
+ throw fromSdkError(error, props.apiHost);
165
+ });
166
+ const branchLabel = branch?.name ?? branchId;
167
+ writer(props).end(role, {
168
+ fields: CREATED_ROLE_FIELDS,
169
+ humanTitle: props.wait ? `Password reset for ${props.role} on ${branchLabel}` : `Password reset for ${props.role} on ${branchLabel} accepted, not yet applied`
170
+ });
171
+ };
172
+ export { create as a, get as c, resetPassword as d, roles_exports as f, command as i, handler as l, builder as n, deleteRole as o, builderFor as r, describe as s, aliases as t, list as u };
package/dist/api.js CHANGED
@@ -194,6 +194,15 @@ function unreadableBodyError(response, cause) {
194
194
  });
195
195
  }
196
196
  /**
197
+ * Encode one segment of a path built outside the SDK. `encodeURIComponent` leaves `.` and
198
+ * `..` intact, and URL parsing then resolves them as dot segments, so the request would go to
199
+ * a different route.
200
+ */
201
+ function pathSegment(name, value) {
202
+ if (value === "." || value === "..") throw new Error(`Path parameter ${name} cannot be "${value}".`);
203
+ return encodeURIComponent(value);
204
+ }
205
+ /**
197
206
  * Translate a thrown `fetch` failure into a {@link NeonApiError}. A request
198
207
  * timeout uses `ECONNABORTED` (matching the old axios behaviour, and excluded
199
208
  * from `isNetworkError`'s connectivity codes so it's still reported as a
@@ -313,6 +322,7 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
313
322
  } catch (err) {
314
323
  throw networkError(err);
315
324
  }
325
+ if (result.error instanceof Error && "kind" in result.error && result.error.kind === "client") throw result.error;
316
326
  const response = result.response;
317
327
  if (!response) throw networkError(result.error ?? /* @__PURE__ */ new Error("No response from Neon API"));
318
328
  if (!response.ok) throw httpError(response, rawErrorBody(result.error) ?? result.data);
@@ -1088,4 +1098,4 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
1088
1098
  }))
1089
1099
  };
1090
1100
  };
1091
- export { ContentType, DEFAULT_API_HOST, NeonApiError, RETRY_COUNT, UnreadableResponseError, cliFetch, codeFromBody, getApiClient, httpError, isNeonApiError, messageFromBody, retryOnLock };
1101
+ export { ContentType, DEFAULT_API_HOST, NeonApiError, RETRY_COUNT, UnreadableResponseError, cliFetch, codeFromBody, getApiClient, httpError, isNeonApiError, messageFromBody, pathSegment, retryOnLock, unreadableBodyError };
@@ -1,3 +1,4 @@
1
+ import { pathSegment } from "../api.js";
1
2
  // src/claimable/api.ts
2
3
  const REQUEST_TIMEOUT_MS = 6e4;
3
4
  const JWT_BEARER_GRANT = "urn:ietf:params:oauth:grant-type:jwt-bearer";
@@ -198,19 +199,19 @@ var ClaimableClient = class {
198
199
  }));
199
200
  }
200
201
  async credentials(projectId, accessToken) {
201
- return parseCredentialsResponse(await this.request(`/v1/projects/${encodeURIComponent(projectId)}/credentials`, { accessToken }));
202
+ return parseCredentialsResponse(await this.request(`/v1/projects/${pathSegment("project_id", projectId)}/credentials`, { accessToken }));
202
203
  }
203
204
  async createClaim(projectId, accessToken) {
204
- return parseClaimCodeResponse(await this.request(`/v1/projects/${encodeURIComponent(projectId)}/claim`, {
205
+ return parseClaimCodeResponse(await this.request(`/v1/projects/${pathSegment("project_id", projectId)}/claim`, {
205
206
  method: "POST",
206
207
  accessToken
207
208
  }));
208
209
  }
209
210
  async claimStatus(projectId, accessToken) {
210
- return parseClaimStatusResponse(await this.request(`/v1/projects/${encodeURIComponent(projectId)}/claim`, { accessToken }));
211
+ return parseClaimStatusResponse(await this.request(`/v1/projects/${pathSegment("project_id", projectId)}/claim`, { accessToken }));
211
212
  }
212
213
  async deleteProject(projectId, accessToken) {
213
- await this.request(`/v1/projects/${encodeURIComponent(projectId)}`, {
214
+ await this.request(`/v1/projects/${pathSegment("project_id", projectId)}`, {
214
215
  method: "DELETE",
215
216
  accessToken
216
217
  });
@@ -34,8 +34,8 @@ import { a as open_exports } from "../_chunks/open-T2nI89Oh.js";
34
34
  import { c as operations_exports } from "../_chunks/operations-D7qGkKo3.js";
35
35
  import { o as orgs_exports } from "../_chunks/orgs-Dpbr-K0A.js";
36
36
  import { o as psql_exports } from "../_chunks/psql-BcxiPR4W.js";
37
- import { u as roles_exports } from "../_chunks/roles-BXGtPGjv.js";
38
- import { o as postgres_exports } from "../_chunks/postgres-BkJPZRov.js";
37
+ import { f as roles_exports } from "../_chunks/roles-BELJqjTy.js";
38
+ import { o as postgres_exports } from "../_chunks/postgres-BhR1vUFM.js";
39
39
  import { o as profile_exports } from "../_chunks/profile-BAlM625e.js";
40
40
  import { s as realtime_exports } from "../_chunks/realtime-BwtzYf5a.js";
41
41
  import { a as set_context_exports } from "../_chunks/set_context-ompB6d2D.js";
@@ -1 +1 @@
1
- export { t as aliases, n as builder, r as command, i as describe, a as handler } from "../_chunks/postgres-BkJPZRov.js";
1
+ export { t as aliases, n as builder, r as command, i as describe, a as handler } from "../_chunks/postgres-BhR1vUFM.js";
@@ -1 +1 @@
1
- export { t as aliases, n as builder, r as builderFor, i as command, a as create, o as deleteRole, s as describe, c as handler, l as list } from "../_chunks/roles-BXGtPGjv.js";
1
+ export { t as aliases, n as builder, r as builderFor, i as command, a as create, o as deleteRole, s as describe, c as get, l as handler, u as list, d as resetPassword } from "../_chunks/roles-BELJqjTy.js";
@@ -1,5 +1,6 @@
1
+ import { pathSegment } from "./api.js";
1
2
  // src/custom_domains_api.ts
2
- const customDomainsPath = (projectId, branchId) => `/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(branchId)}/custom-domains`;
3
+ const customDomainsPath = (projectId, branchId) => `/projects/${pathSegment("project_id", projectId)}/branches/${pathSegment("branch_id", branchId)}/custom-domains`;
3
4
  const listCustomDomains = async (apiClient, projectId, branchId, { cursor, limit } = {}) => {
4
5
  const { data } = await apiClient.request({
5
6
  path: customDomainsPath(projectId, branchId),
@@ -28,7 +29,7 @@ const registerCustomDomain = async (apiClient, projectId, branchId, input) => {
28
29
  };
29
30
  const deleteCustomDomain = async (apiClient, projectId, branchId, domain) => {
30
31
  await apiClient.request({
31
- path: `${customDomainsPath(projectId, branchId)}/${encodeURIComponent(domain)}`,
32
+ path: `${customDomainsPath(projectId, branchId)}/${pathSegment("domain", domain)}`,
32
33
  method: "DELETE",
33
34
  secure: true
34
35
  });
@@ -1,6 +1,6 @@
1
- import "./api.js";
1
+ import { pathSegment } from "./api.js";
2
2
  // src/functions_api.ts
3
- const functionsPath = (projectId, branchId) => `/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(branchId)}/functions`;
3
+ const functionsPath = (projectId, branchId) => `/projects/${pathSegment("project_id", projectId)}/branches/${pathSegment("branch_id", branchId)}/functions`;
4
4
  const listFunctions = async (apiClient, projectId, branchId, { cursor, limit } = {}) => {
5
5
  const { data } = await apiClient.request({
6
6
  path: functionsPath(projectId, branchId),
@@ -19,7 +19,7 @@ const listFunctions = async (apiClient, projectId, branchId, { cursor, limit } =
19
19
  };
20
20
  const getFunction = async (apiClient, projectId, branchId, slug) => {
21
21
  const { data } = await apiClient.request({
22
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}`,
22
+ path: `${functionsPath(projectId, branchId)}/${pathSegment("slug", slug)}`,
23
23
  method: "GET",
24
24
  secure: true,
25
25
  format: "json"
@@ -28,7 +28,7 @@ const getFunction = async (apiClient, projectId, branchId, slug) => {
28
28
  };
29
29
  const deleteFunction = async (apiClient, projectId, branchId, slug) => {
30
30
  await apiClient.request({
31
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}`,
31
+ path: `${functionsPath(projectId, branchId)}/${pathSegment("slug", slug)}`,
32
32
  method: "DELETE",
33
33
  secure: true
34
34
  });
@@ -39,7 +39,7 @@ const createDeployment = async (apiClient, projectId, branchId, slug, params) =>
39
39
  form.append("runtime", params.runtime);
40
40
  if (params.environment) form.append("environment", params.environment);
41
41
  await apiClient.request({
42
- path: `${functionsPath(projectId, branchId)}/${encodeURIComponent(slug)}/deployments`,
42
+ path: `${functionsPath(projectId, branchId)}/${pathSegment("slug", slug)}/deployments`,
43
43
  method: "POST",
44
44
  type: "multipart/form-data",
45
45
  body: form,
@@ -1,4 +1,4 @@
1
- import { cliFetch, httpError } from "./api.js";
1
+ import { cliFetch, httpError, unreadableBodyError } from "./api.js";
2
2
  import { NeonApiError, createNeonClient } from "@neon/sdk";
3
3
  // src/neon_client.ts
4
4
  /**
@@ -21,7 +21,7 @@ const getNeonClient = ({ apiKey, apiHost, requestTimeoutMs }) => createNeonClien
21
21
  */
22
22
  function fromSdkError(error, apiHost) {
23
23
  const base = apiHost ?? "https://console.neon.tech/api/v2";
24
- if (error instanceof NeonApiError && error.response?.url.startsWith(base)) return httpError(error.response, error.body);
24
+ if (error instanceof NeonApiError && error.response?.url.startsWith(base)) return error.response.ok ? unreadableBodyError(error.response, error.body) : httpError(error.response, error.body);
25
25
  return new Error(error instanceof Error ? error.message : String(error));
26
26
  }
27
27
  export { fromSdkError, getNeonClient };
@@ -1,6 +1,7 @@
1
+ import { pathSegment } from "./api.js";
1
2
  // src/storage_api.ts
2
- const bucketsPath = (projectId, branchId) => `/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(branchId)}/buckets`;
3
- const bucketPath = (projectId, branchId, bucketName) => `${bucketsPath(projectId, branchId)}/${encodeURIComponent(bucketName)}`;
3
+ const bucketsPath = (projectId, branchId) => `/projects/${pathSegment("project_id", projectId)}/branches/${pathSegment("branch_id", branchId)}/buckets`;
4
+ const bucketPath = (projectId, branchId, bucketName) => `${bucketsPath(projectId, branchId)}/${pathSegment("bucket_name", bucketName)}`;
4
5
  /**
5
6
  * Create a bucket on a branch.
6
7
  *
@@ -66,7 +67,7 @@ const listProjectBranchBucketObjects = (apiClient, { projectId, branchId, bucket
66
67
  * @request GET /projects/{project_id}/branches/{branch_id}/buckets/{bucket_name}/objects/{object_key}/download
67
68
  */
68
69
  const getProjectBranchBucketObject = (apiClient, { projectId, branchId, bucketName, objectKey }) => apiClient.request({
69
- path: `${bucketPath(projectId, branchId, bucketName)}/objects/${encodeURIComponent(objectKey)}/download`,
70
+ path: `${bucketPath(projectId, branchId, bucketName)}/objects/${pathSegment("object_key", objectKey)}/download`,
70
71
  method: "GET",
71
72
  format: "stream",
72
73
  secure: true
@@ -80,7 +81,7 @@ const getProjectBranchBucketObject = (apiClient, { projectId, branchId, bucketNa
80
81
  * @request DELETE /projects/{project_id}/branches/{branch_id}/buckets/{bucket_name}/objects/{object_key}
81
82
  */
82
83
  const deleteProjectBranchBucketObject = (apiClient, { projectId, branchId, bucketName, objectKey }) => apiClient.request({
83
- path: `${bucketPath(projectId, branchId, bucketName)}/objects/${encodeURIComponent(objectKey)}`,
84
+ path: `${bucketPath(projectId, branchId, bucketName)}/objects/${pathSegment("object_key", objectKey)}`,
84
85
  method: "DELETE",
85
86
  secure: true
86
87
  });
@@ -122,7 +123,7 @@ const presignUpload = (apiClient, { projectId, branchId, bucketName, objectKey,
122
123
  if (contentType !== void 0) body.content_type = contentType;
123
124
  if (expiresInSeconds !== void 0) body.expires_in_seconds = expiresInSeconds;
124
125
  return apiClient.request({
125
- path: `${bucketPath(projectId, branchId, bucketName)}/objects/${encodeURIComponent(objectKey)}/presign`,
126
+ path: `${bucketPath(projectId, branchId, bucketName)}/objects/${pathSegment("object_key", objectKey)}/presign`,
126
127
  method: "POST",
127
128
  body,
128
129
  format: "json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "8.21.0",
3
+ "version": "8.22.0",
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-runtime": "1.11.4",
76
+ "@neon/config": "1.11.1",
77
+ "@neon/config-runtime": "1.11.5",
77
78
  "@neon/realtime": "0.2.0",
78
- "@neon/sdk": "7.8.1",
79
- "@neon/config": "1.11.0"
79
+ "@neon/sdk": "7.8.2"
80
80
  },
81
81
  "optionalDependencies": {
82
82
  "@napi-rs/keyring": "1.3.0",
@@ -113,9 +113,9 @@
113
113
  "typescript": "^5.9.0",
114
114
  "vitest": "^3.0.9",
115
115
  "@neon-internals/cli-core": "0.0.0",
116
- "@neon-internals/env-core": "0.0.42",
116
+ "@neon-internals/env-core": "0.0.43",
117
117
  "@neon/e2e-harness": "0.0.0",
118
- "@neon/env": "1.6.12",
118
+ "@neon/env": "1.6.13",
119
119
  "@neon/functions": "0.11.0"
120
120
  },
121
121
  "publishConfig": {