neonctl 1.17.3 → 1.18.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/auth.js CHANGED
@@ -40,7 +40,7 @@ export const auth = async ({ oauthHost, clientId }) => {
40
40
  //
41
41
  const server = createServer();
42
42
  server.listen(0, '127.0.0.1', function () {
43
- log.info(`Listening on port ${this.address().port}`);
43
+ log.debug(`Listening on port ${this.address().port}`);
44
44
  });
45
45
  await new Promise((resolve) => server.once('listening', resolve));
46
46
  const listen_port = server.address().port;
package/commands/auth.js CHANGED
@@ -13,13 +13,10 @@ export const builder = (yargs) => yargs;
13
13
  export const handler = async (args) => {
14
14
  await authFlow(args);
15
15
  };
16
- export const authFlow = async ({ configDir, oauthHost, clientId, }) => {
17
- if (isCi()) {
16
+ export const authFlow = async ({ configDir, oauthHost, clientId, forceAuth, }) => {
17
+ if (!forceAuth && isCi()) {
18
18
  throw new Error('Cannot run interactive auth in CI');
19
19
  }
20
- if (!clientId) {
21
- throw new Error('Missing client id');
22
- }
23
20
  const tokenSet = await auth({
24
21
  oauthHost: oauthHost,
25
22
  clientId: clientId,
@@ -0,0 +1,37 @@
1
+ import axios from 'axios';
2
+ import { beforeAll, describe, test, jest, afterAll, expect, } from '@jest/globals';
3
+ import { mkdtempSync, rmSync, readFileSync } from 'node:fs';
4
+ import { startOauthServer } from '../test_utils/oauth_server';
5
+ jest.unstable_mockModule('open', () => ({
6
+ __esModule: true,
7
+ default: jest.fn((url) => {
8
+ axios.get(url);
9
+ }),
10
+ }));
11
+ // "open" module should be imported after mocking
12
+ const authModule = await import('./auth');
13
+ describe('auth', () => {
14
+ let configDir = '';
15
+ let server;
16
+ beforeAll(async () => {
17
+ configDir = mkdtempSync('test-config');
18
+ server = await startOauthServer();
19
+ });
20
+ afterAll(() => {
21
+ rmSync(configDir, { recursive: true });
22
+ server.stop();
23
+ });
24
+ test('should auth', async () => {
25
+ await authModule.authFlow({
26
+ _: ['auth'],
27
+ apiHost: 'http://localhost:1111',
28
+ clientId: 'test-client-id',
29
+ configDir,
30
+ forceAuth: true,
31
+ oauthHost: 'http://localhost:7777',
32
+ });
33
+ const credentials = JSON.parse(readFileSync(`${configDir}/credentials.json`, 'utf-8'));
34
+ expect(credentials.access_token).toEqual(expect.any(String));
35
+ expect(credentials.refresh_token).toEqual(expect.any(String));
36
+ });
37
+ });
@@ -1,5 +1,5 @@
1
1
  import { describe } from '@jest/globals';
2
- import { testCliCommand } from '../test_utils.js';
2
+ import { testCliCommand } from '../test_utils/test_cli_command.js';
3
3
  describe('branches', () => {
4
4
  testCliCommand({
5
5
  name: 'list',
@@ -1,5 +1,5 @@
1
1
  import { describe } from '@jest/globals';
2
- import { testCliCommand } from '../test_utils';
2
+ import { testCliCommand } from '../test_utils/test_cli_command';
3
3
  describe('connection_string', () => {
4
4
  testCliCommand({
5
5
  name: 'connection_string',
@@ -1,5 +1,5 @@
1
1
  import { describe } from '@jest/globals';
2
- import { testCliCommand } from '../test_utils.js';
2
+ import { testCliCommand } from '../test_utils/test_cli_command.js';
3
3
  describe('databases', () => {
4
4
  testCliCommand({
5
5
  name: 'list',
@@ -1,5 +1,5 @@
1
1
  import { describe, expect } from '@jest/globals';
2
- import { testCliCommand } from '../test_utils.js';
2
+ import { testCliCommand } from '../test_utils/test_cli_command.js';
3
3
  describe('help', () => {
4
4
  testCliCommand({
5
5
  name: 'without args',
@@ -1,5 +1,5 @@
1
1
  import { describe } from '@jest/globals';
2
- import { testCliCommand } from '../test_utils.js';
2
+ import { testCliCommand } from '../test_utils/test_cli_command.js';
3
3
  describe('operations', () => {
4
4
  testCliCommand({
5
5
  name: 'list',
@@ -1,5 +1,5 @@
1
1
  import { describe } from '@jest/globals';
2
- import { testCliCommand } from '../test_utils.js';
2
+ import { testCliCommand } from '../test_utils/test_cli_command.js';
3
3
  describe('projects', () => {
4
4
  testCliCommand({
5
5
  name: 'list',
@@ -1,5 +1,5 @@
1
1
  import { describe } from '@jest/globals';
2
- import { testCliCommand } from '../test_utils.js';
2
+ import { testCliCommand } from '../test_utils/test_cli_command.js';
3
3
  describe('roles', () => {
4
4
  testCliCommand({
5
5
  name: 'list',
package/config.js CHANGED
@@ -3,8 +3,8 @@ import { homedir } from 'node:os';
3
3
  import { existsSync, mkdirSync } from 'node:fs';
4
4
  import { isCi } from './env.js';
5
5
  export const defaultDir = join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'neonctl');
6
- export const ensureConfigDir = async ({ 'config-dir': configDir, }) => {
7
- if (!existsSync(configDir) && !isCi()) {
6
+ export const ensureConfigDir = async ({ 'config-dir': configDir, 'force-auth': forceAuth, }) => {
7
+ if (!existsSync(configDir) && (!isCi() || forceAuth)) {
8
8
  mkdirSync(configDir, { recursive: true });
9
9
  }
10
10
  };
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { basename } from 'node:path';
1
2
  import yargs from 'yargs';
2
3
  import { hideBin } from 'yargs/helpers';
3
4
  import axiosDebug from 'axios-debug-log';
@@ -46,6 +47,12 @@ builder = builder
46
47
  group: 'Global options:',
47
48
  type: 'string',
48
49
  default: defaultDir,
50
+ })
51
+ .option('force-auth', {
52
+ describe: 'Force authentication',
53
+ type: 'boolean',
54
+ hidden: true,
55
+ default: false,
49
56
  })
50
57
  .middleware(ensureConfigDir)
51
58
  // Auth flow
@@ -87,6 +94,7 @@ builder = builder
87
94
  .group('help', 'Global options:')
88
95
  .alias('help', 'h')
89
96
  .completion()
97
+ .scriptName(basename(process.argv[1]) === 'neon' ? 'neon' : 'neonctl')
90
98
  .fail(async (msg, err) => {
91
99
  if (isAxiosError(err)) {
92
100
  if (err.code === 'ECONNABORTED') {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git@github.com:neondatabase/neonctl.git"
6
6
  },
7
7
  "type": "module",
8
- "version": "1.17.3",
8
+ "version": "1.18.1",
9
9
  "description": "CLI tool for NeonDB Cloud management",
10
10
  "main": "index.js",
11
11
  "author": "NeonDB",
@@ -15,13 +15,17 @@
15
15
  "node": ">=18"
16
16
  },
17
17
  "bin": {
18
- "neonctl": "cli.js"
18
+ "neonctl": "cli.js",
19
+ "neon": "cli.js"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@apidevtools/swagger-parser": "^10.1.0",
22
23
  "@commitlint/cli": "^17.6.5",
23
24
  "@commitlint/config-conventional": "^17.6.5",
24
25
  "@jest/globals": "^29.5.0",
26
+ "@rollup/plugin-commonjs": "^25.0.2",
27
+ "@rollup/plugin-json": "^6.0.0",
28
+ "@rollup/plugin-node-resolve": "^15.1.0",
25
29
  "@semantic-release/exec": "^6.0.3",
26
30
  "@semantic-release/git": "^10.0.1",
27
31
  "@types/cli-table": "^0.3.0",
@@ -37,7 +41,10 @@
37
41
  "husky": "^8.0.3",
38
42
  "jest": "^29.5.0",
39
43
  "lint-staged": "^13.0.3",
44
+ "oauth2-mock-server": "^6.0.0",
45
+ "pkg": "^5.8.1",
40
46
  "prettier": "^2.7.1",
47
+ "rollup": "^3.26.2",
41
48
  "semantic-release": "^21.0.2",
42
49
  "ts-jest": "^29.1.0",
43
50
  "ts-node": "^10.9.1",
@@ -60,12 +67,25 @@
60
67
  "access": "public",
61
68
  "registry": "https://registry.npmjs.org/"
62
69
  },
70
+ "pkg": {
71
+ "assets": [
72
+ "callback.html"
73
+ ],
74
+ "scripts": [
75
+ "bundle/*.js"
76
+ ],
77
+ "targets": [
78
+ "node18-linux-x64",
79
+ "node18-macos-x64",
80
+ "node18-win-x64"
81
+ ]
82
+ },
63
83
  "scripts": {
64
84
  "watch": "tsc --watch",
65
85
  "lint": "tsc --noEmit && eslint src --ext .ts",
66
86
  "build": "npm run generateParams && npm run clean && tsc && cp src/*.html package*.json README.md ./dist",
67
87
  "clean": "rm -rf dist",
68
- "generateParams": "ts-node --esm generateOptionsFromSpec.ts",
88
+ "generateParams": "node --loader ts-node/esm ./generateOptionsFromSpec.ts",
69
89
  "start": "node src/index.js",
70
90
  "test": "node --experimental-vm-modules node_modules/.bin/jest"
71
91
  },
@@ -0,0 +1,14 @@
1
+ import emocks from 'emocks';
2
+ import express from 'express';
3
+ import { join } from 'node:path';
4
+ import { log } from '../log';
5
+ export const runMockServer = async (mockDir) => new Promise((resolve) => {
6
+ const app = express();
7
+ app.use(express.json());
8
+ app.use('/', emocks(join(process.cwd(), 'mocks', mockDir)));
9
+ const server = app.listen(0);
10
+ server.on('listening', () => {
11
+ log.info('Mock server listening at %d', server.address().port);
12
+ });
13
+ resolve(server);
14
+ });
@@ -0,0 +1,9 @@
1
+ import { log } from '../log';
2
+ import { OAuth2Server } from 'oauth2-mock-server';
3
+ export const startOauthServer = async () => {
4
+ const server = new OAuth2Server();
5
+ await server.issuer.keys.generate('RS256');
6
+ await server.start(7777, 'localhost');
7
+ log.info('Started OAuth server');
8
+ return server;
9
+ };
@@ -1,19 +1,8 @@
1
- /* eslint-disable no-console */
2
1
  import { test, expect, describe, beforeAll, afterAll } from '@jest/globals';
3
- import emocks from 'emocks';
4
- import express from 'express';
5
2
  import { fork } from 'node:child_process';
6
3
  import { join } from 'node:path';
7
- const runMockServer = async (mockDir) => new Promise((resolve) => {
8
- const app = express();
9
- app.use(express.json());
10
- app.use('/', emocks(join(process.cwd(), 'mocks', mockDir)));
11
- const server = app.listen(0);
12
- server.on('listening', () => {
13
- console.log(`Mock server listening at ${server.address().port}`);
14
- });
15
- resolve(server);
16
- });
4
+ import { log } from '../log.js';
5
+ import { runMockServer } from './mock_server.js';
17
6
  export const testCliCommand = ({ args, name, expected, mockDir = 'main', }) => {
18
7
  let server;
19
8
  describe(name, () => {
@@ -33,10 +22,10 @@ export const testCliCommand = ({ args, name, expected, mockDir = 'main', }) => {
33
22
  const cp = fork(join(process.cwd(), './dist/index.js'), [
34
23
  '--api-host',
35
24
  `http://localhost:${server.address().port}`,
36
- '--api-key',
37
- 'test-key',
38
25
  '--output',
39
26
  'yaml',
27
+ '--api-key',
28
+ 'test-key',
40
29
  ...args,
41
30
  ], {
42
31
  stdio: 'pipe',
@@ -47,15 +36,13 @@ export const testCliCommand = ({ args, name, expected, mockDir = 'main', }) => {
47
36
  });
48
37
  cp.stderr?.on('data', (data) => {
49
38
  error += data.toString();
39
+ log.error(data.toString());
50
40
  });
51
41
  cp.on('error', (err) => {
52
42
  throw err;
53
43
  });
54
44
  cp.on('close', (code) => {
55
45
  try {
56
- if (code !== 0 && error) {
57
- console.error(error);
58
- }
59
46
  expect(code).toBe(0);
60
47
  if (code === 0 && expected) {
61
48
  if (expected.snapshot) {