neonctl 2.16.0 → 2.16.2
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/commands/auth.js +2 -2
- package/commands/auth.test.js +15 -0
- package/commands/init.js +7 -32
- package/commands/init.test.js +17 -7
- package/package.json +2 -2
package/commands/auth.js
CHANGED
|
@@ -95,8 +95,8 @@ const handleExistingToken = async (tokenSet, props, credentialsPath) => {
|
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
97
|
export const ensureAuth = async (props) => {
|
|
98
|
-
// Skip auth for help command or
|
|
99
|
-
if (props._.length === 0 || props.help) {
|
|
98
|
+
// Skip auth for help command, no command, or init command
|
|
99
|
+
if (props._.length === 0 || props.help || props._[0] === 'init') {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
// Use existing API key or handle auth command
|
package/commands/auth.test.js
CHANGED
|
@@ -144,6 +144,21 @@ describe('ensureAuth', () => {
|
|
|
144
144
|
expect(refreshTokenSpy).not.toHaveBeenCalled();
|
|
145
145
|
expect(props.apiKey).toBe('valid-token');
|
|
146
146
|
});
|
|
147
|
+
test('should skip auth for init command', async ({ runMockServer }) => {
|
|
148
|
+
const server = await runMockServer('main');
|
|
149
|
+
const credentialsPath = join(configDir, 'credentials.json');
|
|
150
|
+
if (existsSync(credentialsPath)) {
|
|
151
|
+
rmSync(credentialsPath);
|
|
152
|
+
}
|
|
153
|
+
const props = {
|
|
154
|
+
...setupTestProps(server),
|
|
155
|
+
_: ['init'],
|
|
156
|
+
};
|
|
157
|
+
await ensureAuth(props);
|
|
158
|
+
expect(authSpy).not.toHaveBeenCalled();
|
|
159
|
+
expect(refreshTokenSpy).not.toHaveBeenCalled();
|
|
160
|
+
expect(props.apiKey).toBe('');
|
|
161
|
+
});
|
|
147
162
|
test('should successfully refresh expired token', async ({ runMockServer, }) => {
|
|
148
163
|
refreshTokenSpy.mockImplementationOnce(() => Promise.resolve({
|
|
149
164
|
access_token: 'new-token',
|
package/commands/init.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { log } from '../log.js';
|
|
1
|
+
import { init } from 'neon-init';
|
|
3
2
|
import { sendError } from '../analytics.js';
|
|
4
3
|
export const command = 'init';
|
|
5
4
|
export const describe = 'Initialize a new Neon project using your AI coding assistant';
|
|
@@ -8,37 +7,13 @@ export const builder = (yargs) => yargs
|
|
|
8
7
|
hidden: true,
|
|
9
8
|
})
|
|
10
9
|
.strict(false);
|
|
11
|
-
export const handler = async (
|
|
12
|
-
const passThruArgs = args['--'] || [];
|
|
13
|
-
await runNeonInit(passThruArgs);
|
|
14
|
-
};
|
|
15
|
-
const runNeonInit = async (args) => {
|
|
10
|
+
export const handler = async () => {
|
|
16
11
|
try {
|
|
17
|
-
await
|
|
18
|
-
stdio: 'inherit',
|
|
19
|
-
});
|
|
12
|
+
await init();
|
|
20
13
|
}
|
|
21
|
-
catch
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
sendError(error, 'NPX_NOT_FOUND');
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
// Check if the process was killed by a signal (user cancelled)
|
|
29
|
-
else if (error?.signal) {
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
// Handle all other errors
|
|
33
|
-
else {
|
|
34
|
-
const exitError = new Error(`failed to run neon-init`);
|
|
35
|
-
sendError(exitError, 'NEON_INIT_FAILED');
|
|
36
|
-
if (typeof error?.exitCode === 'number') {
|
|
37
|
-
process.exit(error.exitCode);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
14
|
+
catch {
|
|
15
|
+
const exitError = new Error(`failed to run neon-init`);
|
|
16
|
+
sendError(exitError, 'NEON_INIT_FAILED');
|
|
17
|
+
process.exit(1);
|
|
43
18
|
}
|
|
44
19
|
};
|
package/commands/init.test.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { describe } from 'vitest';
|
|
2
|
-
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
+
// Mock dependencies that require package.json
|
|
3
|
+
vi.mock('../analytics.js', () => ({
|
|
4
|
+
sendError: vi.fn(),
|
|
5
|
+
trackEvent: vi.fn(),
|
|
6
|
+
closeAnalytics: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
// Mock neon-init
|
|
9
|
+
vi.mock('neon-init', () => ({
|
|
10
|
+
init: vi.fn().mockResolvedValue(undefined),
|
|
11
|
+
}));
|
|
3
12
|
describe('init', () => {
|
|
4
|
-
test('
|
|
5
|
-
await
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
test('should call neon-init', async () => {
|
|
14
|
+
const { handler } = await import('./init.js');
|
|
15
|
+
const { init } = await import('neon-init');
|
|
16
|
+
await handler();
|
|
17
|
+
// Verify neon-init was called
|
|
18
|
+
expect(init).toHaveBeenCalledOnce();
|
|
9
19
|
});
|
|
10
20
|
});
|
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.16.
|
|
8
|
+
"version": "2.16.2",
|
|
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
|
-
"
|
|
65
|
+
"neon-init": "^0.8.1",
|
|
66
66
|
"open": "^10.1.0",
|
|
67
67
|
"openid-client": "^6.8.1",
|
|
68
68
|
"prompts": "2.4.2",
|