neonctl 2.19.0 → 2.19.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/enrichers.js +32 -9
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git+ssh://git@github.com/neondatabase/neonctl.git"
6
6
  },
7
7
  "type": "module",
8
- "version": "2.19.0",
8
+ "version": "2.19.1",
9
9
  "description": "CLI tool for NeonDB Cloud management",
10
10
  "main": "index.js",
11
11
  "author": "NeonDB",
@@ -1,4 +1,5 @@
1
1
  import { looksLikeBranchId } from './formats.js';
2
+ import { isAxiosError } from 'axios';
2
3
  export const branchIdResolve = async ({ branch, apiClient, projectId, }) => {
3
4
  branch = branch.toString();
4
5
  if (looksLikeBranchId(branch)) {
@@ -43,17 +44,39 @@ export const fillSingleProject = async (props) => {
43
44
  if (props.projectId) {
44
45
  return props;
45
46
  }
46
- const { data } = await props.apiClient.listProjects({ limit: 2 });
47
- if (data.projects.length === 0) {
48
- throw new Error('No projects found');
47
+ // If no orgId is provided, try to auto-fill it if there's only one org
48
+ let orgId = props.orgId;
49
+ if (!orgId) {
50
+ const { data: orgsData } = await props.apiClient.getCurrentUserOrganizations();
51
+ if (orgsData.organizations.length === 1) {
52
+ orgId = orgsData.organizations[0].id;
53
+ }
49
54
  }
50
- if (data.projects.length > 1) {
51
- throw new Error(`Multiple projects found, please provide one with the --project-id option`);
55
+ try {
56
+ const { data } = await props.apiClient.listProjects({
57
+ limit: 2,
58
+ org_id: orgId,
59
+ });
60
+ if (data.projects.length === 0) {
61
+ throw new Error('No projects found');
62
+ }
63
+ if (data.projects.length > 1) {
64
+ throw new Error(`Multiple projects found, please provide one with the --project-id option`);
65
+ }
66
+ return {
67
+ ...props,
68
+ projectId: data.projects[0].id,
69
+ };
70
+ }
71
+ catch (error) {
72
+ // If the API error is about missing org_id, provide a user-friendly message
73
+ if (isAxiosError(error) &&
74
+ error.response?.status === 400 &&
75
+ error.response?.data?.message?.includes('org_id is required')) {
76
+ throw new Error('Multiple projects found, please provide one with the --project-id option');
77
+ }
78
+ throw error;
52
79
  }
53
- return {
54
- ...props,
55
- projectId: data.projects[0].id,
56
- };
57
80
  };
58
81
  export const fillSingleOrg = async (props) => {
59
82
  if (props.orgId) {