neonctl 2.19.0 → 2.20.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/package.json +2 -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.
|
|
8
|
+
"version": "2.20.0",
|
|
9
9
|
"description": "CLI tool for NeonDB Cloud management",
|
|
10
10
|
"main": "index.js",
|
|
11
11
|
"author": "NeonDB",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"cli-table": "^0.3.11",
|
|
63
63
|
"crypto-random-string": "^5.0.0",
|
|
64
64
|
"diff": "^5.2.0",
|
|
65
|
-
"neon-init": "^0.
|
|
65
|
+
"neon-init": "^0.11.0",
|
|
66
66
|
"open": "^10.1.0",
|
|
67
67
|
"openid-client": "^6.8.1",
|
|
68
68
|
"prompts": "2.4.2",
|
package/utils/enrichers.js
CHANGED
|
@@ -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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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) {
|