neon 8.22.0 → 8.23.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
@@ -1518,6 +1518,28 @@ Id Name Project Created At Last Used At Last
1518
1518
 
1519
1519
  `last_used_at` and `last_used_from_addr` are how you spot a key worth revoking.
1520
1520
 
1521
+ ## Organizations (`orgs`)
1522
+
1523
+ ```bash
1524
+ neon orgs list
1525
+ neon orgs get # the --org-id, linked, or only organization
1526
+ neon orgs members list
1527
+ neon orgs members get <member-id>
1528
+ neon orgs members update <member-id> --role admin
1529
+ neon orgs members remove <member-id>
1530
+ neon orgs invitations list
1531
+ neon orgs invitations create --email dev@example.com --email ops@example.com --role member
1532
+ neon orgs spending-limit get
1533
+ neon orgs spending-limit set 500 # US dollars per month
1534
+ neon orgs spending-limit delete
1535
+ ```
1536
+
1537
+ Every subcommand except `list` takes `--org-id`. Without it, the CLI uses the organization in `.neon`, then the only organization you belong to, and otherwise fails naming `--org-id`. `orgs get` also takes the id as a positional argument.
1538
+
1539
+ `members update` and `invitations create` take `--role`: `admin`, `member`, `editor`, `viewer`, or `collaborator`. The API decides which of them an organization accepts. Every invitee is emailed, and anyone who already has a Neon account joins immediately.
1540
+
1541
+ `spending-limit set` takes dollars with up to two decimals and sends cents. The limit sends emails at 80% and 100% and does not suspend computes. JSON and YAML output keep the API's `spending_limit_cents`, and `members list` keeps the API's `{ member, user }` items. Role changes, member removal, and the spending limit writes need an organization admin.
1542
+
1521
1543
  ## Commands
1522
1544
 
1523
1545
  | Command | Subcommands | Description |
@@ -1527,6 +1549,7 @@ Id Name Project Created At Last Used At Last
1527
1549
  | profile | `list`, `create`, `rotate-key`, `remove` | Manage named sets of credentials |
1528
1550
  | api-keys | `list`, `create`, `revoke` | Manage API keys |
1529
1551
  | api | | Call any Neon API route |
1552
+ | orgs (`org`) | `list`, `get`, `members`, `invitations`, `spending-limit` | Manage organizations |
1530
1553
  | [projects](https://neon.com/docs/reference/cli-projects) | `list`, `create`, `update`, `delete`, `get` | Manage projects |
1531
1554
  | [ip-allow](https://neon.com/docs/reference/cli-ip-allow) | `list`, `add`, `remove`, `reset` | Manage IP Allow |
1532
1555
  | [me](https://neon.com/docs/reference/cli-me) | | Show current user |
@@ -109,7 +109,7 @@ const handler = (args) => args;
109
109
  const list = async (props) => {
110
110
  const out = writer(props);
111
111
  if (props.orgId) {
112
- const { data } = await props.apiClient.listOrgApiKeys(props.orgId);
112
+ const data = await (await orgKeys(props)).list(props.orgId);
113
113
  if (props.output === "table") out.write(data.map((key) => ({
114
114
  ...key,
115
115
  project: key.project_id ?? ALL_PROJECTS
@@ -148,7 +148,7 @@ const create = async (props) => {
148
148
  return;
149
149
  }
150
150
  if (!projectId && orgId) {
151
- const { data } = await props.apiClient.createOrgApiKey(orgId, { key_name: name });
151
+ const data = await (await orgKeys(props)).create(orgId, { keyName: name });
152
152
  await assertUsable(props, data, {
153
153
  orgId,
154
154
  expect: NO_PROJECT
@@ -159,9 +159,9 @@ const create = async (props) => {
159
159
  }
160
160
  const scopeTo = projectId;
161
161
  const resolvedOrgId = await orgIdForProject(props.apiClient, scopeTo);
162
- const { data } = await props.apiClient.createOrgApiKey(resolvedOrgId, {
163
- key_name: name,
164
- project_id: scopeTo
162
+ const data = await (await orgKeys(props)).create(resolvedOrgId, {
163
+ keyName: name,
164
+ projectId: scopeTo
165
165
  });
166
166
  await assertUsable(props, data, {
167
167
  orgId: resolvedOrgId,
@@ -170,6 +170,25 @@ const create = async (props) => {
170
170
  report(props, data, CREATE_FIELDS_SCOPED, CREATE_TABLE_FIELDS_SCOPED);
171
171
  log.info("Limited to %s: it cannot create projects, mint API keys, or read any other project. It can still change and delete everything inside that project.", scopeTo);
172
172
  };
173
+ /** Organization keys through `@neon/sdk`, failing with the CLI's `NeonApiError`. */
174
+ const orgKeys = async (props) => {
175
+ const { fromSdkError, getNeonClient } = await import("../neon_client.js");
176
+ const keys = getNeonClient(props).organizations.apiKeys;
177
+ const fail = (error) => {
178
+ throw fromSdkError(error, props.apiHost);
179
+ };
180
+ return {
181
+ list: (orgId) => keys.list({ orgId }).catch(fail),
182
+ create: (orgId, params) => keys.create({
183
+ orgId,
184
+ ...params
185
+ }).catch(fail),
186
+ revoke: (orgId, keyId) => keys.revoke({
187
+ orgId,
188
+ keyId
189
+ }).catch(fail)
190
+ };
191
+ };
173
192
  /**
174
193
  * The key is shown only once, so human output keeps it on a selectable line.
175
194
  * Structured output keeps it in the object for scripts.
@@ -229,7 +248,7 @@ const assertUsable = async (props, data, scope) => {
229
248
  */
230
249
  const revokeOrExplain = async (props) => {
231
250
  try {
232
- return props.orgId ? await props.apiClient.revokeOrgApiKey(props.orgId, props.id) : await props.apiClient.revokeApiKey(props.id);
251
+ return props.orgId ? await (await orgKeys(props)).revoke(props.orgId, props.id) : (await props.apiClient.revokeApiKey(props.id)).data;
233
252
  } catch (err) {
234
253
  if (isNeonApiError(err) && err.status === 404) throw new Error(props.orgId ? `No API key with id ${props.id} in ${props.orgId}. If it is one of your account's own keys, drop --org-id.` : `No account API key with id ${props.id}. If it belongs to an organization, pass --org-id. Organization keys are not visible to your account.`);
235
254
  throw err;
@@ -239,7 +258,7 @@ const revokeOrExplain = async (props) => {
239
258
  const withdraw = async (props, orgId, keyId) => {
240
259
  if (!Number.isSafeInteger(keyId) || keyId <= 0) return false;
241
260
  try {
242
- const { data } = orgId ? await props.apiClient.revokeOrgApiKey(orgId, keyId) : await props.apiClient.revokeApiKey(keyId);
261
+ const data = orgId ? await (await orgKeys(props)).revoke(orgId, keyId) : (await props.apiClient.revokeApiKey(keyId)).data;
243
262
  return data.revoked === true && data.id === keyId;
244
263
  } catch (err) {
245
264
  log.warning("Failed to revoke API key %d: %s", keyId, err instanceof Error ? err.message : String(err));
@@ -248,7 +267,7 @@ const withdraw = async (props, orgId, keyId) => {
248
267
  };
249
268
  const revoke = async (props) => {
250
269
  const out = writer(props);
251
- const { data } = await revokeOrExplain(props);
270
+ const data = await revokeOrExplain(props);
252
271
  out.write(data, {
253
272
  fields: [
254
273
  "id",
@@ -549,6 +549,12 @@ const handler = (args) => {
549
549
  const resolveBranch = async (props) => {
550
550
  return props.branchId ?? await branchIdFromProps(props);
551
551
  };
552
+ const authSdk = async (props, call) => {
553
+ const { fromSdkError, getNeonClient } = await import("../neon_client.js");
554
+ return call(getNeonClient(props).auth).catch((error) => {
555
+ throw fromSdkError(error, props.apiHost);
556
+ });
557
+ };
552
558
  /** The branch name is only known when it was resolved from a listing, not from an id. */
553
559
  const resolveBranchWithName = async (props) => {
554
560
  if (props.branchId) return { branchId: props.branchId };
@@ -806,7 +812,10 @@ const domainDelete = async (props) => {
806
812
  };
807
813
  const allowLocalhostGet = async (props) => {
808
814
  const branchId = await resolveBranch(props);
809
- const { data } = await props.apiClient.getNeonAuthAllowLocalhost(props.projectId, branchId);
815
+ const data = await authSdk(props, (auth) => auth.allowLocalhost.get({
816
+ projectId: props.projectId,
817
+ branchId
818
+ }));
810
819
  if (props.output === "json" || props.output === "yaml") {
811
820
  writer(props).end(data, { fields: ALLOW_LOCALHOST_FIELDS });
812
821
  return;
@@ -815,12 +824,20 @@ const allowLocalhostGet = async (props) => {
815
824
  };
816
825
  const allowLocalhostEnable = async (props) => {
817
826
  const branchId = await resolveBranch(props);
818
- await props.apiClient.updateNeonAuthAllowLocalhost(props.projectId, branchId, { allow_localhost: true });
827
+ await authSdk(props, (auth) => auth.allowLocalhost.update({
828
+ projectId: props.projectId,
829
+ branchId,
830
+ allow_localhost: true
831
+ }));
819
832
  printMessage("Localhost connections allowed");
820
833
  };
821
834
  const allowLocalhostDisable = async (props) => {
822
835
  const branchId = await resolveBranch(props);
823
- await props.apiClient.updateNeonAuthAllowLocalhost(props.projectId, branchId, { allow_localhost: false });
836
+ await authSdk(props, (auth) => auth.allowLocalhost.update({
837
+ projectId: props.projectId,
838
+ branchId,
839
+ allow_localhost: false
840
+ }));
824
841
  printMessage("Localhost connections restricted");
825
842
  };
826
843
  const printEmailPasswordEntries = (data) => [
@@ -835,7 +852,10 @@ const printEmailPasswordEntries = (data) => [
835
852
  ];
836
853
  const emailPasswordGet = async (props) => {
837
854
  const branchId = await resolveBranch(props);
838
- const { data } = await props.apiClient.getNeonAuthEmailAndPasswordConfig(props.projectId, branchId);
855
+ const data = await authSdk(props, (auth) => auth.emailAndPassword.get({
856
+ projectId: props.projectId,
857
+ branchId
858
+ }));
839
859
  if (props.output === "json" || props.output === "yaml") {
840
860
  writer(props).end(data, { fields: EMAIL_PASSWORD_FIELDS });
841
861
  return;
@@ -844,7 +864,9 @@ const emailPasswordGet = async (props) => {
844
864
  };
845
865
  const emailPasswordUpdate = async (props) => {
846
866
  const branchId = await resolveBranch(props);
847
- const { data } = await props.apiClient.updateNeonAuthEmailAndPasswordConfig(props.projectId, branchId, {
867
+ const data = await authSdk(props, (auth) => auth.emailAndPassword.update({
868
+ projectId: props.projectId,
869
+ branchId,
848
870
  enabled: props.enabled,
849
871
  email_verification_method: props.emailVerificationMethod,
850
872
  require_email_verification: props.requireEmailVerification,
@@ -853,7 +875,7 @@ const emailPasswordUpdate = async (props) => {
853
875
  send_verification_email_on_sign_in: props.sendVerificationEmailOnSignIn,
854
876
  disable_sign_up: props.disableSignUp,
855
877
  revoke_sessions_on_password_reset: props.revokeSessionsOnPasswordReset
856
- });
878
+ }));
857
879
  if (props.output === "json" || props.output === "yaml") {
858
880
  writer(props).end(data, { fields: EMAIL_PASSWORD_FIELDS });
859
881
  return;
@@ -872,7 +894,10 @@ const printEmailProviderEntries = (data) => [
872
894
  ];
873
895
  const emailProviderGet = async (props) => {
874
896
  const branchId = await resolveBranch(props);
875
- const { data } = await props.apiClient.getNeonAuthEmailProvider(props.projectId, branchId);
897
+ const data = await authSdk(props, (auth) => auth.emailProvider.get({
898
+ projectId: props.projectId,
899
+ branchId
900
+ }));
876
901
  if (props.output === "json" || props.output === "yaml") {
877
902
  writer(props).end(data, { fields: EMAIL_PROVIDER_FIELDS });
878
903
  return;
@@ -894,14 +919,22 @@ const emailProviderUpdate = async (props) => {
894
919
  sender_name: props.senderName
895
920
  };
896
921
  else config = { type: "shared" };
897
- const { data } = await props.apiClient.updateNeonAuthEmailProvider(props.projectId, branchId, config);
922
+ const data = await authSdk(props, (auth) => auth.emailProvider.update({
923
+ projectId: props.projectId,
924
+ branchId,
925
+ ...config
926
+ }));
898
927
  if (props.output === "json" || props.output === "yaml") writer(props).end(data, { fields: EMAIL_PROVIDER_FIELDS });
899
928
  else printKvBlock("Email provider configuration updated", printEmailProviderEntries(data));
900
929
  if (warnSharedSender) writeStyled(`${chalk.yellow("Warning:")} --sender-email and --sender-name are ignored for the shared email provider. These values only take effect with --type standard.\n\n`, process.stderr);
901
930
  };
902
931
  const emailProviderTest = async (props) => {
903
932
  const branchId = await resolveBranch(props);
904
- const { data } = await props.apiClient.sendNeonAuthEmailProviderTest(props.projectId, branchId, { recipient_email: props.recipientEmail });
933
+ const data = await authSdk(props, (auth) => auth.emailProvider.sendTest({
934
+ projectId: props.projectId,
935
+ branchId,
936
+ recipient_email: props.recipientEmail
937
+ }));
905
938
  if (props.output === "json" || props.output === "yaml") {
906
939
  writer(props).end(data, { fields: TEST_EMAIL_FIELDS });
907
940
  if (!data.success) throw new Error(emailProviderTestFailureMessage(props.recipientEmail, data.error_message));
@@ -924,8 +957,10 @@ const printOrganizationEntries = (data) => [
924
957
  ];
925
958
  const organizationGet = async (props) => {
926
959
  const branchId = await resolveBranch(props);
927
- const { data } = await props.apiClient.getNeonAuthPluginConfigs(props.projectId, branchId);
928
- const org = data.organization;
960
+ const org = (await authSdk(props, (auth) => auth.plugins.get({
961
+ projectId: props.projectId,
962
+ branchId
963
+ }))).organization;
929
964
  if (!org) {
930
965
  if (props.output === "json" || props.output === "yaml") {
931
966
  writer(props).end({}, { fields: ORGANIZATION_FIELDS });
@@ -942,11 +977,13 @@ const organizationGet = async (props) => {
942
977
  };
943
978
  const organizationUpdate = async (props) => {
944
979
  const branchId = await resolveBranch(props);
945
- const { data } = await props.apiClient.updateNeonAuthOrganizationPlugin(props.projectId, branchId, {
980
+ const data = await authSdk(props, (auth) => auth.plugins.organization.update({
981
+ projectId: props.projectId,
982
+ branchId,
946
983
  enabled: props.enabled,
947
984
  organization_limit: props.limit,
948
985
  creator_role: props.creatorRole
949
- });
986
+ }));
950
987
  if (props.output === "json" || props.output === "yaml") {
951
988
  writer(props).end(data, { fields: ORGANIZATION_FIELDS });
952
989
  return;
@@ -1242,7 +1279,10 @@ const printWebhookEntries = (data) => [
1242
1279
  ];
1243
1280
  const webhookGet = async (props) => {
1244
1281
  const branchId = await resolveBranch(props);
1245
- const { data } = await props.apiClient.getNeonAuthWebhookConfig(props.projectId, branchId);
1282
+ const data = await authSdk(props, (auth) => auth.webhooks.get({
1283
+ projectId: props.projectId,
1284
+ branchId
1285
+ }));
1246
1286
  if (props.output === "json" || props.output === "yaml") {
1247
1287
  writer(props).end(data, { fields: WEBHOOK_FIELDS });
1248
1288
  return;
@@ -1251,12 +1291,14 @@ const webhookGet = async (props) => {
1251
1291
  };
1252
1292
  const webhookUpdate = async (props) => {
1253
1293
  const branchId = await resolveBranch(props);
1254
- const { data } = await props.apiClient.updateNeonAuthWebhookConfig(props.projectId, branchId, {
1294
+ const data = await authSdk(props, (auth) => auth.webhooks.update({
1295
+ projectId: props.projectId,
1296
+ branchId,
1255
1297
  enabled: props.enabled,
1256
1298
  webhook_url: props.url,
1257
1299
  enabled_events: props.enabledEvents,
1258
1300
  timeout_seconds: props.timeout
1259
- });
1301
+ }));
1260
1302
  if (props.output === "json" || props.output === "yaml") {
1261
1303
  writer(props).end(data, { fields: WEBHOOK_FIELDS });
1262
1304
  return;
@@ -1272,7 +1314,10 @@ const formatValue = (v) => {
1272
1314
  };
1273
1315
  const pluginsList = async (props) => {
1274
1316
  const branchId = await resolveBranch(props);
1275
- const { data } = await props.apiClient.getNeonAuthPluginConfigs(props.projectId, branchId);
1317
+ const data = await authSdk(props, (auth) => auth.plugins.get({
1318
+ projectId: props.projectId,
1319
+ branchId
1320
+ }));
1276
1321
  if (props.output === "json" || props.output === "yaml") {
1277
1322
  writer(props).end(data, { fields: Object.keys(data) });
1278
1323
  return;
@@ -1295,7 +1340,10 @@ const pluginsList = async (props) => {
1295
1340
  };
1296
1341
  const pluginsGet = async (props) => {
1297
1342
  const branchId = await resolveBranch(props);
1298
- const { data } = await props.apiClient.getNeonAuthPluginConfigs(props.projectId, branchId);
1343
+ const data = await authSdk(props, (auth) => auth.plugins.get({
1344
+ projectId: props.projectId,
1345
+ branchId
1346
+ }));
1299
1347
  const plugin = data[props.pluginName];
1300
1348
  if (plugin === void 0) {
1301
1349
  const available = Object.keys(data).join(", ");
@@ -0,0 +1,292 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
+ import { log } from "../log.js";
3
+ import { readContextFile } from "../context.js";
4
+ import { writer } from "../writer.js";
5
+ import { noPassthrough, single } from "../utils/flags.js";
6
+ import chalk from "chalk";
7
+ // src/commands/orgs.ts
8
+ var orgs_exports = /* @__PURE__ */ __exportAll({
9
+ aliases: () => aliases,
10
+ builder: () => builder,
11
+ command: () => command,
12
+ describe: () => describe,
13
+ handler: () => handler,
14
+ parseUsdCents: () => parseUsdCents,
15
+ planName: () => planName
16
+ });
17
+ const ORG_FIELDS = [
18
+ "id",
19
+ "name",
20
+ "plan"
21
+ ];
22
+ const ORG_DETAIL_FIELDS = [
23
+ "id",
24
+ "name",
25
+ "handle",
26
+ "plan",
27
+ "created_at"
28
+ ];
29
+ const MEMBER_TABLE_FIELDS = [
30
+ "id",
31
+ "email",
32
+ "role",
33
+ "joined_at"
34
+ ];
35
+ const MEMBER_FIELDS = [
36
+ "id",
37
+ "user_id",
38
+ "role",
39
+ "joined_at"
40
+ ];
41
+ const INVITATION_FIELDS = [
42
+ "id",
43
+ "email",
44
+ "role",
45
+ "invited_at"
46
+ ];
47
+ const SPENDING_LIMIT_TABLE_FIELDS = ["monthly_limit"];
48
+ const MEMBER_ROLES = [
49
+ "admin",
50
+ "member",
51
+ "editor",
52
+ "viewer",
53
+ "collaborator"
54
+ ];
55
+ const orgIdOption = { "org-id": {
56
+ describe: "Organization ID. Defaults to the linked organization, or your only one",
57
+ type: "string",
58
+ coerce: single("org-id")
59
+ } };
60
+ /**
61
+ * An empty, negated, misspelled, or `--`-separated `--org-id` must fail rather than fall
62
+ * back to the linked organization: these commands change members, invitations, and billing.
63
+ */
64
+ const guarded = (yargs) => yargs.strict().check(noPassthrough("orgs"));
65
+ const roleOption = (describe) => ({ role: {
66
+ describe,
67
+ type: "string",
68
+ choices: MEMBER_ROLES,
69
+ demandOption: true
70
+ } });
71
+ const command = "orgs";
72
+ const describe = "Manage organizations";
73
+ const aliases = ["org"];
74
+ const builder = (argv) => {
75
+ return argv.usage("$0 orgs <sub-command> [options]").command("list", "List organizations", (yargs) => yargs, async (args) => {
76
+ await list(args);
77
+ }).command("get [id]", "Show an organization", (yargs) => yargs.positional("id", {
78
+ describe: "Organization ID. Defaults to --org-id, the linked organization, or your only one",
79
+ type: "string"
80
+ }).options(orgIdOption).strict().check(noPassthrough("orgs")), async (args) => await get(args)).command("members", "Manage organization members", (yargs) => yargs.usage("$0 orgs members <sub-command> [options]").options(orgIdOption).command("list", "List members and their organization role", guarded, async (args) => await listMembers(args)).command("get <member-id>", "Show a member", (yargs) => guarded(yargs.positional("member-id", {
81
+ describe: "Member ID, from `orgs members list`",
82
+ type: "string"
83
+ })), async (args) => await getMember(args)).command("update <member-id>", "Change a member's organization role. Admin only", (yargs) => yargs.positional("member-id", {
84
+ describe: "Member ID, from `orgs members list`",
85
+ type: "string"
86
+ }).options(roleOption("The new organization role")).strict().check(noPassthrough("orgs")), async (args) => await updateMember(args)).command("remove <member-id>", "Remove a member from the organization. Admin only", (yargs) => guarded(yargs.positional("member-id", {
87
+ describe: "Member ID, from `orgs members list`",
88
+ type: "string"
89
+ })), async (args) => await removeMember(args))).command("invitations", "Manage organization invitations", (yargs) => yargs.usage("$0 orgs invitations <sub-command> [options]").options(orgIdOption).command("list", "List invitations", guarded, async (args) => await listInvitations(args)).command("create", "Invite people by email. Each one is emailed, and anyone with a Neon account joins immediately", (yargs) => yargs.options({
90
+ email: {
91
+ describe: "Email address to invite. Repeat to invite several",
92
+ type: "string",
93
+ array: true,
94
+ demandOption: true
95
+ },
96
+ ...roleOption("The organization role every invitee gets")
97
+ }).strict().check(noPassthrough("orgs")), async (args) => await createInvitations(args))).command("spending-limit", "Manage the organization's monthly spending limit (Launch and Scale plans)", (yargs) => yargs.usage("$0 orgs spending-limit <sub-command> [options]").options(orgIdOption).command("get", "Show the monthly spending limit", guarded, async (args) => await getSpendingLimit(args)).command("set <usd>", "Set the monthly spending limit. Neon emails at 80% and 100% and keeps computes running. Admin only", (yargs) => guarded(yargs.positional("usd", {
98
+ describe: "Monthly limit in US dollars, e.g. 500 or 250.50",
99
+ type: "string"
100
+ })), async (args) => await setSpendingLimit(args)).command("delete", "Remove the monthly spending limit. Admin only", guarded, async (args) => await deleteSpendingLimit(args)));
101
+ };
102
+ const handler = (args) => {
103
+ return args;
104
+ };
105
+ const list = async (props) => {
106
+ const out = writer(props);
107
+ const { data: { organizations } } = await props.apiClient.getCurrentUserOrganizations();
108
+ const current = readContextFile(props.contextFile).orgId;
109
+ out.write(organizations, {
110
+ fields: ORG_FIELDS,
111
+ title: "Organizations",
112
+ emptyMessage: "You are not a member of any organization.",
113
+ renderColumns: {
114
+ plan: (org) => planName(org.plan),
115
+ name: (org) => org.id === current ? `${chalk.green("[current]")} ${org.name}` : org.name
116
+ }
117
+ });
118
+ out.end();
119
+ };
120
+ /** The SDK client, its error mapper, and the org from the flag, `.neon`, or the only one. */
121
+ const sdk = async (props) => {
122
+ const [{ fromSdkError, getNeonClient }, { fillSingleOrg }] = await Promise.all([import("../neon_client.js"), import("../utils/enrichers.js")]);
123
+ const { orgId } = await fillSingleOrg({
124
+ ...props,
125
+ orgId: props.orgId ?? ""
126
+ });
127
+ return {
128
+ neon: getNeonClient(props),
129
+ orgId,
130
+ fail: (error) => fromSdkError(error, props.apiHost)
131
+ };
132
+ };
133
+ const get = async (props) => {
134
+ const { neon, fail, orgId } = await sdk({
135
+ ...props,
136
+ orgId: props.id ?? props.orgId
137
+ });
138
+ const org = await neon.organizations.get({ orgId }).catch((error) => {
139
+ throw fail(error);
140
+ });
141
+ writer(props).end(org, {
142
+ fields: ORG_DETAIL_FIELDS,
143
+ renderColumns: { plan: (value) => planName(value.plan) }
144
+ });
145
+ };
146
+ const listMembers = async (props) => {
147
+ const { neon, fail, orgId } = await sdk(props);
148
+ const members = await neon.organizations.members.list({ orgId }).all().catch((error) => {
149
+ throw fail(error);
150
+ });
151
+ const config = {
152
+ title: `Members of ${orgId}`,
153
+ emptyMessage: `No members in ${orgId}.`
154
+ };
155
+ if (props.output === "table") {
156
+ writer(props).end(members.map(memberRow), {
157
+ fields: MEMBER_TABLE_FIELDS,
158
+ ...config
159
+ });
160
+ return;
161
+ }
162
+ writer(props).end(members, {
163
+ fields: [],
164
+ ...config
165
+ });
166
+ };
167
+ const memberRow = ({ member, user }) => ({
168
+ id: member.id,
169
+ email: user.email,
170
+ role: member.role,
171
+ joined_at: member.joined_at
172
+ });
173
+ const getMember = async (props) => {
174
+ const { neon, fail, orgId } = await sdk(props);
175
+ const member = await neon.organizations.members.get({
176
+ orgId,
177
+ memberId: props.memberId
178
+ }).catch((error) => {
179
+ throw fail(error);
180
+ });
181
+ writeMember(props, member);
182
+ };
183
+ const updateMember = async (props) => {
184
+ const { neon, fail, orgId } = await sdk(props);
185
+ const member = await neon.organizations.members.update({
186
+ orgId,
187
+ memberId: props.memberId,
188
+ role: props.role
189
+ }).catch((error) => {
190
+ throw fail(error);
191
+ });
192
+ writeMember(props, member);
193
+ };
194
+ const writeMember = (props, member) => {
195
+ writer(props).end(member, { fields: MEMBER_FIELDS });
196
+ };
197
+ const removeMember = async (props) => {
198
+ const { neon, fail, orgId } = await sdk(props);
199
+ await neon.organizations.members.remove({
200
+ orgId,
201
+ memberId: props.memberId
202
+ }).catch((error) => {
203
+ throw fail(error);
204
+ });
205
+ log.info(`Member ${props.memberId} removed from ${orgId}`);
206
+ };
207
+ const listInvitations = async (props) => {
208
+ const { neon, fail, orgId } = await sdk(props);
209
+ const invitations = await neon.organizations.invitations.list({ orgId }).catch((error) => {
210
+ throw fail(error);
211
+ });
212
+ writeInvitations(props, orgId, invitations);
213
+ };
214
+ const createInvitations = async (props) => {
215
+ const { neon, fail, orgId } = await sdk(props);
216
+ const invitations = await neon.organizations.invitations.create({
217
+ orgId,
218
+ invitations: props.email.map((email) => ({
219
+ email,
220
+ role: props.role
221
+ }))
222
+ }).catch((error) => {
223
+ throw fail(error);
224
+ });
225
+ writeInvitations(props, orgId, invitations);
226
+ };
227
+ const writeInvitations = (props, orgId, invitations) => {
228
+ writer(props).end(invitations, {
229
+ fields: INVITATION_FIELDS,
230
+ title: `Invitations to ${orgId}`,
231
+ emptyMessage: `No invitations to ${orgId}.`
232
+ });
233
+ };
234
+ const getSpendingLimit = async (props) => {
235
+ const { neon, fail, orgId } = await sdk(props);
236
+ const limit = await neon.organizations.spendingLimit.get({ orgId }).catch((error) => {
237
+ throw fail(error);
238
+ });
239
+ writeSpendingLimit(props, orgId, limit);
240
+ };
241
+ const setSpendingLimit = async (props) => {
242
+ const spendingLimitCents = parseUsdCents(props.usd);
243
+ const { neon, fail, orgId } = await sdk(props);
244
+ const limit = await neon.organizations.spendingLimit.set({
245
+ orgId,
246
+ spendingLimitCents
247
+ }).catch((error) => {
248
+ throw fail(error);
249
+ });
250
+ writeSpendingLimit(props, orgId, limit);
251
+ };
252
+ const deleteSpendingLimit = async (props) => {
253
+ const { neon, fail, orgId } = await sdk(props);
254
+ await neon.organizations.spendingLimit.delete({ orgId }).catch((error) => {
255
+ throw fail(error);
256
+ });
257
+ log.info(`Spending limit removed from ${orgId}`);
258
+ };
259
+ /** JSON and YAML keep the API's cents; the table shows dollars. */
260
+ const writeSpendingLimit = (props, orgId, limit) => {
261
+ if (props.output !== "table") {
262
+ writer(props).end(limit, { fields: [] });
263
+ return;
264
+ }
265
+ const cents = limit.spending_limit_cents;
266
+ writer(props).end({ monthly_limit: cents === null ? "Not set" : formatUsd(cents) }, {
267
+ fields: SPENDING_LIMIT_TABLE_FIELDS,
268
+ title: `Spending limit for ${orgId}`
269
+ });
270
+ };
271
+ const USD = new Intl.NumberFormat("en-US", {
272
+ style: "currency",
273
+ currency: "USD"
274
+ });
275
+ const formatUsd = (cents) => USD.format(cents / 100);
276
+ /**
277
+ * `500` or `250.50` → cents. Parsed as text, not with `Number()`: `1e3` and `0x10` are
278
+ * numbers too, and a float multiply turns `0.29` into 28.999… cents.
279
+ */
280
+ const parseUsdCents = (value) => {
281
+ const match = typeof value === "string" ? /^(\d+)(?:\.(\d{1,2}))?$/.exec(value.trim()) : null;
282
+ const cents = match ? Number(match[1]) * 100 + Number((match[2] ?? "").padEnd(2, "0")) : NaN;
283
+ if (!Number.isSafeInteger(cents) || cents <= 0) throw new Error(`spending-limit set needs a positive amount in US dollars, such as 500 or 250.50. Got \`${String(value)}\`. To remove the limit, run \`neon orgs spending-limit delete\`.`);
284
+ return cents;
285
+ };
286
+ const ACRONYMS = {
287
+ aws: "AWS",
288
+ pg: "PG"
289
+ };
290
+ /** `free_v3` -> `Free`, `aws_marketplace` -> `AWS Marketplace`; JSON/YAML keep the API id. */
291
+ const planName = (plan) => (plan ?? "").replace(/_v\d+$/, "").split("_").filter(Boolean).map((word) => ACRONYMS[word] ?? word[0].toUpperCase() + word.slice(1)).join(" ");
292
+ export { handler as a, planName as c, describe as i, builder as n, orgs_exports as o, command as r, parseUsdCents as s, aliases as t };
@@ -14,7 +14,7 @@ import { m as usableCredential, n as authFlow } from "./auth-rup6nemJ.js";
14
14
  import { identityFromAuthDetails, isApiKeyMethod, mintedKeyName, notAnApiKeyMessage } from "../profile_keys.js";
15
15
  import { writer } from "../writer.js";
16
16
  import { noPassthrough, single } from "../utils/flags.js";
17
- import { s as orgIdForProject } from "./api_keys-6Xnxl7a8.js";
17
+ import { s as orgIdForProject } from "./api_keys-CTFHd5m_.js";
18
18
  import { existsSync, readFileSync, rmSync } from "node:fs";
19
19
  import { isAbsolute, relative } from "node:path";
20
20
  import prompts from "prompts";
package/dist/api.js CHANGED
@@ -846,74 +846,6 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
846
846
  },
847
847
  body: data
848
848
  })),
849
- getNeonAuthAllowLocalhost: (projectId, branchId) => call(() => raw.getNeonAuthAllowLocalhost({
850
- client,
851
- path: {
852
- project_id: projectId,
853
- branch_id: branchId
854
- }
855
- })),
856
- updateNeonAuthAllowLocalhost: (projectId, branchId, data) => call(() => raw.updateNeonAuthAllowLocalhost({
857
- client,
858
- path: {
859
- project_id: projectId,
860
- branch_id: branchId
861
- },
862
- body: data
863
- })),
864
- getNeonAuthEmailAndPasswordConfig: (projectId, branchId) => call(() => raw.getNeonAuthEmailAndPasswordConfig({
865
- client,
866
- path: {
867
- project_id: projectId,
868
- branch_id: branchId
869
- }
870
- })),
871
- updateNeonAuthEmailAndPasswordConfig: (projectId, branchId, data) => call(() => raw.updateNeonAuthEmailAndPasswordConfig({
872
- client,
873
- path: {
874
- project_id: projectId,
875
- branch_id: branchId
876
- },
877
- body: data
878
- })),
879
- getNeonAuthEmailProvider: (projectId, branchId) => call(() => raw.getNeonAuthEmailProvider({
880
- client,
881
- path: {
882
- project_id: projectId,
883
- branch_id: branchId
884
- }
885
- })),
886
- updateNeonAuthEmailProvider: (projectId, branchId, data) => call(() => raw.updateNeonAuthEmailProvider({
887
- client,
888
- path: {
889
- project_id: projectId,
890
- branch_id: branchId
891
- },
892
- body: data
893
- })),
894
- sendNeonAuthEmailProviderTest: (projectId, branchId, data) => call(() => raw.sendNeonAuthEmailProviderTest({
895
- client,
896
- path: {
897
- project_id: projectId,
898
- branch_id: branchId
899
- },
900
- body: data
901
- })),
902
- getNeonAuthPluginConfigs: (projectId, branchId) => call(() => raw.getNeonAuthPluginConfigs({
903
- client,
904
- path: {
905
- project_id: projectId,
906
- branch_id: branchId
907
- }
908
- })),
909
- updateNeonAuthOrganizationPlugin: (projectId, branchId, data) => call(() => raw.updateNeonAuthOrganizationPlugin({
910
- client,
911
- path: {
912
- project_id: projectId,
913
- branch_id: branchId
914
- },
915
- body: data
916
- })),
917
849
  getNeonAuthOAuthProviderPlugin: (projectId, branchId) => call(() => raw.getNeonAuthOAuthProviderPlugin({
918
850
  client,
919
851
  path: {
@@ -977,21 +909,6 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
977
909
  client_id: clientId
978
910
  }
979
911
  })),
980
- getNeonAuthWebhookConfig: (projectId, branchId) => call(() => raw.getNeonAuthWebhookConfig({
981
- client,
982
- path: {
983
- project_id: projectId,
984
- branch_id: branchId
985
- }
986
- })),
987
- updateNeonAuthWebhookConfig: (projectId, branchId, data) => call(() => raw.updateNeonAuthWebhookConfig({
988
- client,
989
- path: {
990
- project_id: projectId,
991
- branch_id: branchId
992
- },
993
- body: data
994
- })),
995
912
  createBranchNeonAuthNewUser: (projectId, branchId, data) => call(() => raw.createBranchNeonAuthNewUser({
996
913
  client,
997
914
  path: {
@@ -1098,4 +1015,4 @@ const getApiClient = ({ apiKey, apiHost, requestTimeoutMs = REQUEST_TIMEOUT_MS }
1098
1015
  }))
1099
1016
  };
1100
1017
  };
1101
- export { ContentType, DEFAULT_API_HOST, NeonApiError, RETRY_COUNT, UnreadableResponseError, cliFetch, codeFromBody, getApiClient, httpError, isNeonApiError, messageFromBody, pathSegment, retryOnLock, unreadableBodyError };
1018
+ export { ContentType, DEFAULT_API_HOST, NeonApiError, RETRY_COUNT, UnreadableResponseError, cliFetch, codeFromBody, getApiClient, httpError, isAbortError, isNeonApiError, messageFromBody, networkError, pathSegment, retryOnLock, unreadableBodyError };
@@ -1 +1 @@
1
- export { t as aliases, r as builder, i as command, a as describe, o as handler, s as orgIdForProject } from "../_chunks/api_keys-6Xnxl7a8.js";
1
+ export { t as aliases, r as builder, i as command, a as describe, o as handler, s as orgIdForProject } from "../_chunks/api_keys-CTFHd5m_.js";
@@ -1,6 +1,6 @@
1
1
  import { r as auth_exports } from "../_chunks/auth-rup6nemJ.js";
2
2
  import { t as api_exports } from "../_chunks/api-1MKsfpY3.js";
3
- import { n as api_keys_exports } from "../_chunks/api_keys-6Xnxl7a8.js";
3
+ import { n as api_keys_exports } from "../_chunks/api_keys-CTFHd5m_.js";
4
4
  import { n as ask_exports } from "../_chunks/ask-Xlek1Pxh.js";
5
5
  import { o as env_exports } from "../_chunks/env-BtG4vH55.js";
6
6
  import { c as config_exports } from "../_chunks/config-CgtJH8xE.js";
@@ -29,14 +29,14 @@ import { a as init_exports } from "../_chunks/init-D2fClHtC.js";
29
29
  import { o as inspect_exports } from "../_chunks/inspect-yFAb61qo.js";
30
30
  import { a as ip_allow_exports } from "../_chunks/ip_allow-DBdxNEUa.js";
31
31
  import { l as logs_exports } from "../_chunks/logs-BB4uvblR.js";
32
- import { a as neon_auth_exports } from "../_chunks/neon_auth-C1CgNTGP.js";
32
+ import { a as neon_auth_exports } from "../_chunks/neon_auth-C4AXiUR6.js";
33
33
  import { a as open_exports } from "../_chunks/open-T2nI89Oh.js";
34
34
  import { c as operations_exports } from "../_chunks/operations-D7qGkKo3.js";
35
- import { o as orgs_exports } from "../_chunks/orgs-Dpbr-K0A.js";
35
+ import { o as orgs_exports } from "../_chunks/orgs-BrvAWM8Z.js";
36
36
  import { o as psql_exports } from "../_chunks/psql-BcxiPR4W.js";
37
37
  import { f as roles_exports } from "../_chunks/roles-BELJqjTy.js";
38
38
  import { o as postgres_exports } from "../_chunks/postgres-BhR1vUFM.js";
39
- import { o as profile_exports } from "../_chunks/profile-BAlM625e.js";
39
+ import { o as profile_exports } from "../_chunks/profile-CArcjyS4.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";
42
42
  import { s as snapshots_exports } from "../_chunks/snapshots-DxNhjcco.js";
@@ -1 +1 @@
1
- export { t as builder, n as command, r as describe, i as handler } from "../_chunks/neon_auth-C1CgNTGP.js";
1
+ export { t as builder, n as command, r as describe, i as handler } from "../_chunks/neon_auth-C4AXiUR6.js";
@@ -1 +1 @@
1
- export { t as aliases, n as builder, r as command, i as describe, a as handler, s as planName } from "../_chunks/orgs-Dpbr-K0A.js";
1
+ export { t as aliases, n as builder, r as command, i as describe, a as handler, s as parseUsdCents, c as planName } from "../_chunks/orgs-BrvAWM8Z.js";
@@ -1 +1 @@
1
- export { t as aliases, n as builder, r as command, i as describe, a as handler } from "../_chunks/profile-BAlM625e.js";
1
+ export { t as aliases, n as builder, r as command, i as describe, a as handler } from "../_chunks/profile-CArcjyS4.js";
package/dist/mcp/mint.js CHANGED
@@ -2,7 +2,7 @@ import { log } from "../log.js";
2
2
  import { isNeonApiError } from "../api.js";
3
3
  import { getCliName } from "../utils/cli_name.js";
4
4
  import { mintedKeyName } from "../profile_keys.js";
5
- import { s as orgIdForProject } from "../_chunks/api_keys-6Xnxl7a8.js";
5
+ import { s as orgIdForProject } from "../_chunks/api_keys-CTFHd5m_.js";
6
6
  // src/mcp/mint.ts
7
7
  var CannotMintApiKeyError = class extends Error {
8
8
  constructor() {
@@ -1,4 +1,4 @@
1
- import { cliFetch, httpError, unreadableBodyError } from "./api.js";
1
+ import { cliFetch, httpError, isAbortError, networkError, unreadableBodyError } from "./api.js";
2
2
  import { NeonApiError, createNeonClient } from "@neon/sdk";
3
3
  // src/neon_client.ts
4
4
  /**
@@ -15,13 +15,15 @@ const getNeonClient = ({ apiKey, apiHost, requestTimeoutMs }) => createNeonClien
15
15
  });
16
16
  /**
17
17
  * Map an error from {@link getNeonClient} for the top-level handler. A management API
18
- * response becomes the CLI's `NeonApiError`, so 401 and SSO recovery apply. Anything else
18
+ * response becomes the CLI's `NeonApiError`, so 401 and SSO recovery apply, and a request
19
+ * timeout becomes the same `ECONNABORTED` error the raw client throws. Anything else
19
20
  * keeps the SDK's message and drops its `cause`, so a socket code deep in the chain cannot
20
21
  * turn a "role was created, but…" message into the generic connectivity hint.
21
22
  */
22
23
  function fromSdkError(error, apiHost) {
23
24
  const base = apiHost ?? "https://console.neon.tech/api/v2";
24
25
  if (error instanceof NeonApiError && error.response?.url.startsWith(base)) return error.response.ok ? unreadableBodyError(error.response, error.body) : httpError(error.response, error.body);
26
+ if (isAbortError(error)) return networkError(error);
25
27
  return new Error(error instanceof Error ? error.message : String(error));
26
28
  }
27
29
  export { fromSdkError, getNeonClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "8.22.0",
3
+ "version": "8.23.1",
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.11.1",
77
- "@neon/config-runtime": "1.11.5",
76
+ "@neon/config-runtime": "1.11.7",
78
77
  "@neon/realtime": "0.2.0",
79
- "@neon/sdk": "7.8.2"
78
+ "@neon/sdk": "7.10.0",
79
+ "@neon/config": "1.11.3"
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.43",
116
+ "@neon-internals/env-core": "0.0.45",
117
+ "@neon/env": "1.6.15",
117
118
  "@neon/e2e-harness": "0.0.0",
118
- "@neon/env": "1.6.13",
119
119
  "@neon/functions": "0.11.0"
120
120
  },
121
121
  "publishConfig": {
@@ -1,51 +0,0 @@
1
- import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.js";
2
- import { readContextFile } from "../context.js";
3
- import { writer } from "../writer.js";
4
- import chalk from "chalk";
5
- // src/commands/orgs.ts
6
- var orgs_exports = /* @__PURE__ */ __exportAll({
7
- aliases: () => aliases,
8
- builder: () => builder,
9
- command: () => command,
10
- describe: () => describe,
11
- handler: () => handler,
12
- planName: () => planName
13
- });
14
- const ORG_FIELDS = [
15
- "id",
16
- "name",
17
- "plan"
18
- ];
19
- const command = "orgs";
20
- const describe = "Manage organizations";
21
- const aliases = ["org"];
22
- const builder = (argv) => {
23
- return argv.usage("$0 orgs <sub-command> [options]").command("list", "List organizations", (yargs) => yargs, async (args) => {
24
- await list(args);
25
- });
26
- };
27
- const handler = (args) => {
28
- return args;
29
- };
30
- const list = async (props) => {
31
- const out = writer(props);
32
- const { data: { organizations } } = await props.apiClient.getCurrentUserOrganizations();
33
- const current = readContextFile(props.contextFile).orgId;
34
- out.write(organizations, {
35
- fields: ORG_FIELDS,
36
- title: "Organizations",
37
- emptyMessage: "You are not a member of any organization.",
38
- renderColumns: {
39
- plan: (org) => planName(org.plan),
40
- name: (org) => org.id === current ? `${chalk.green("[current]")} ${org.name}` : org.name
41
- }
42
- });
43
- out.end();
44
- };
45
- const ACRONYMS = {
46
- aws: "AWS",
47
- pg: "PG"
48
- };
49
- /** `free_v3` -> `Free`, `aws_marketplace` -> `AWS Marketplace`; JSON/YAML keep the API id. */
50
- const planName = (plan) => (plan ?? "").replace(/_v\d+$/, "").split("_").filter(Boolean).map((word) => ACRONYMS[word] ?? word[0].toUpperCase() + word.slice(1)).join(" ");
51
- export { handler as a, describe as i, builder as n, orgs_exports as o, command as r, planName as s, aliases as t };