neonctl 1.1.0 → 1.1.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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "git@github.com:neondatabase/neonctl.git"
6
6
  },
7
- "version": "1.1.0",
7
+ "version": "1.1.1",
8
8
  "description": "CLI tool for NeonDB Cloud management",
9
9
  "main": "index.js",
10
10
  "author": "NeonDB",
@@ -46,13 +46,13 @@
46
46
  "registry": "https://registry.npmjs.org/"
47
47
  },
48
48
  "scripts": {
49
- "dev": "node dev.js",
49
+ "watch": "tsc --watch",
50
50
  "lint": "tsc --noEmit && eslint src --ext .ts",
51
- "debug": "node --inspect-brk dev.js",
52
- "build": "npm run clean && tsc && cp src/*.html dist/src/",
51
+ "debug": "node --inspect-brk dist/src",
52
+ "build": "npm run generateParams && npm run clean && tsc && cp src/*.html dist/src/",
53
53
  "clean": "rm -rf dist",
54
- "start": "node index.js",
55
- "postinstall": "ts-node ./generateParams.ts"
54
+ "generateParams": "ts-node generateParams.ts",
55
+ "start": "node src/index.js"
56
56
  },
57
57
  "lint-staged": {
58
58
  "*.ts": [
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.ensureAuth = exports.authFlow = void 0;
35
+ exports.ensureAuth = exports.authFlow = exports.handler = exports.builder = exports.describe = exports.command = void 0;
36
36
  const node_path_1 = require("node:path");
37
37
  const node_fs_1 = require("node:fs");
38
38
  const openid_client_1 = require("openid-client");
@@ -40,6 +40,14 @@ const auth_1 = require("../auth");
40
40
  const log_1 = require("../log");
41
41
  const api_1 = require("../api");
42
42
  const CREDENTIALS_FILE = 'credentials.json';
43
+ exports.command = 'auth';
44
+ exports.describe = 'Authenticate';
45
+ const builder = (yargs) => yargs;
46
+ exports.builder = builder;
47
+ const handler = (args) => __awaiter(void 0, void 0, void 0, function* () {
48
+ yield (0, exports.authFlow)(args);
49
+ });
50
+ exports.handler = handler;
43
51
  const authFlow = ({ configDir, oauthHost, clientId, }) => __awaiter(void 0, void 0, void 0, function* () {
44
52
  if (!clientId) {
45
53
  throw new Error('Missing client id');
@@ -55,19 +63,6 @@ const authFlow = ({ configDir, oauthHost, clientId, }) => __awaiter(void 0, void
55
63
  return tokenSet.access_token || '';
56
64
  });
57
65
  exports.authFlow = authFlow;
58
- const validateToken = (props) => __awaiter(void 0, void 0, void 0, function* () {
59
- try {
60
- const client = (0, api_1.getApiClient)(props);
61
- yield client.getCurrentUserInfo();
62
- }
63
- catch (err) {
64
- if ((0, api_1.isApiError)(err)) {
65
- if (err.response.status === 401) {
66
- throw new Error('Invalid token');
67
- }
68
- }
69
- }
70
- });
71
66
  // updateCredentialsFile correctly sets needed permissions for the credentials file
72
67
  function updateCredentialsFile(path, contents) {
73
68
  (0, node_fs_1.writeFileSync)(path, contents, {
@@ -9,30 +9,58 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.update = exports.deleteProject = exports.create = exports.list = void 0;
12
+ exports.builder = exports.describe = exports.command = void 0;
13
+ const parameters_gen_1 = require("../parameters.gen");
14
+ const utils_1 = require("../utils");
13
15
  const writer_1 = require("../writer");
14
16
  const PROJECT_FIELDS = ['id', 'name', 'region_id', 'created_at'];
17
+ exports.command = 'projects <command>';
18
+ exports.describe = 'Manage projects';
19
+ const builder = (yargs) => yargs
20
+ .usage('usage: $0 projects <cmd> [args]')
21
+ .command('list', 'List projects', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
22
+ yield list(args);
23
+ }))
24
+ .command('create', 'Create a project', (yargs) => yargs.options(parameters_gen_1.projectCreateRequest), (args) => __awaiter(void 0, void 0, void 0, function* () {
25
+ yield create(args);
26
+ }))
27
+ .command('update', 'Update a project', (yargs) => yargs
28
+ .option('project.id', {
29
+ describe: 'Project ID',
30
+ type: 'string',
31
+ demandOption: true,
32
+ })
33
+ .options(parameters_gen_1.projectCreateRequest), (args) => __awaiter(void 0, void 0, void 0, function* () {
34
+ yield update(args);
35
+ }))
36
+ .command('delete', 'Delete a project', (yargs) => yargs.options({
37
+ 'project.id': {
38
+ describe: 'Project ID',
39
+ type: 'string',
40
+ demandOption: true,
41
+ },
42
+ }), (args) => __awaiter(void 0, void 0, void 0, function* () {
43
+ yield deleteProject(args);
44
+ }))
45
+ .middleware(utils_1.showHelpMiddleware);
46
+ exports.builder = builder;
15
47
  const list = (props) => __awaiter(void 0, void 0, void 0, function* () {
16
48
  (0, writer_1.writeOut)(props)((yield props.apiClient.listProjects({})).data.projects, {
17
49
  fields: PROJECT_FIELDS,
18
50
  });
19
51
  });
20
- exports.list = list;
21
52
  const create = (props) => __awaiter(void 0, void 0, void 0, function* () {
22
53
  (0, writer_1.writeOut)(props)((yield props.apiClient.createProject({
23
54
  project: props.project,
24
55
  })).data.project, { fields: PROJECT_FIELDS });
25
56
  });
26
- exports.create = create;
27
57
  const deleteProject = (props) => __awaiter(void 0, void 0, void 0, function* () {
28
58
  (0, writer_1.writeOut)(props)((yield props.apiClient.deleteProject(props.project.id)).data.project, {
29
59
  fields: PROJECT_FIELDS,
30
60
  });
31
61
  });
32
- exports.deleteProject = deleteProject;
33
62
  const update = (props) => __awaiter(void 0, void 0, void 0, function* () {
34
63
  (0, writer_1.writeOut)(props)((yield props.apiClient.updateProject(props.project.id, {
35
64
  project: props.project,
36
65
  })).data.project, { fields: PROJECT_FIELDS });
37
66
  });
38
- exports.update = update;
@@ -9,11 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.me = void 0;
12
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
13
13
  const writer_1 = require("../writer");
14
+ exports.command = 'me';
15
+ exports.describe = 'Show current user';
16
+ const builder = (yargs) => yargs;
17
+ exports.builder = builder;
18
+ const handler = (args) => __awaiter(void 0, void 0, void 0, function* () {
19
+ yield me(args);
20
+ });
21
+ exports.handler = handler;
14
22
  const me = (props) => __awaiter(void 0, void 0, void 0, function* () {
15
23
  (0, writer_1.writeOut)(props)((yield props.apiClient.getCurrentUserInfo()).data, {
16
24
  fields: ['login', 'email', 'name', 'projects_limit'],
17
25
  });
18
26
  });
19
- exports.me = me;
package/src/index.js CHANGED
@@ -36,20 +36,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const yargs = __importStar(require("yargs"));
39
+ const node_path_1 = require("node:path");
39
40
  const package_json_1 = __importDefault(require("../package.json"));
40
41
  const auth_1 = require("./commands/auth");
41
42
  const config_1 = require("./config");
42
43
  const log_1 = require("./log");
43
44
  const auth_2 = require("./auth");
44
45
  const api_1 = require("./api");
45
- const parameters_gen_1 = require("./parameters.gen");
46
46
  const utils_1 = require("./utils");
47
- const showHelpMiddleware = (argv) => {
48
- if (argv._.length === 1) {
49
- yargs.showHelp();
50
- process.exit(0);
51
- }
52
- };
53
47
  const builder = yargs
54
48
  .scriptName(package_json_1.default.name)
55
49
  .usage('usage: $0 <cmd> [args]')
@@ -81,9 +75,6 @@ const builder = yargs
81
75
  type: 'string',
82
76
  default: auth_2.defaultClientID,
83
77
  })
84
- .command('auth', 'Authenticate user', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
85
- (yield Promise.resolve().then(() => __importStar(require('./commands/auth')))).authFlow(args);
86
- }))
87
78
  .option('api-key', {
88
79
  describe: 'API key',
89
80
  type: 'string',
@@ -96,38 +87,7 @@ const builder = yargs
96
87
  })
97
88
  .middleware((args) => (0, utils_1.fillInArgs)(args), true)
98
89
  .middleware(auth_1.ensureAuth)
99
- .command('me', 'Get user info', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
100
- yield (yield Promise.resolve().then(() => __importStar(require('./commands/users')))).me(args);
101
- }))
102
- .command('projects', 'Manage projects', (yargs) => __awaiter(void 0, void 0, void 0, function* () {
103
- yargs
104
- .usage('usage: $0 projects <cmd> [args]')
105
- .command('list', 'List projects', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
106
- yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).list(args);
107
- }))
108
- .command('create', 'Create a project', (yargs) => yargs.options(parameters_gen_1.ProjectCreateRequest), (args) => __awaiter(void 0, void 0, void 0, function* () {
109
- yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).create(args);
110
- }))
111
- .command('update', 'Update a project', (yargs) => yargs
112
- .option('project.id', {
113
- describe: 'Project ID',
114
- type: 'string',
115
- demandOption: true,
116
- })
117
- .options(parameters_gen_1.ProjectCreateRequest), (args) => __awaiter(void 0, void 0, void 0, function* () {
118
- yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).update(args);
119
- }))
120
- .command('delete', 'Delete a project', (yargs) => yargs.options({
121
- 'project.id': {
122
- describe: 'Project ID',
123
- type: 'string',
124
- demandOption: true,
125
- },
126
- }), (args) => __awaiter(void 0, void 0, void 0, function* () {
127
- yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).deleteProject(args);
128
- }))
129
- .middleware(showHelpMiddleware);
130
- }))
90
+ .commandDir((0, node_path_1.join)(__dirname, './commands'))
131
91
  .fail((msg, err) => __awaiter(void 0, void 0, void 0, function* () {
132
92
  var _a;
133
93
  if ((0, api_1.isApiError)(err)) {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  // FILE IS GENERATED, DO NOT EDIT
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ProjectCreateRequest = void 0;
5
- exports.ProjectCreateRequest = {
4
+ exports.projectCreateRequest = void 0;
5
+ exports.projectCreateRequest = {
6
6
  'project.settings.quota.active_time_seconds': {
7
7
  type: 'number',
8
8
  description: "The total amount of wall-clock time allowed to be spent by project's compute endpoints.",
package/src/utils.js CHANGED
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fillInArgs = void 0;
4
- // This middleware is needed to fill in the args for nested objects,
5
- // so that required arguments would work
6
- // otherwise yargs just throws an error
6
+ exports.showHelpMiddleware = exports.fillInArgs = void 0;
7
+ const yargs_1 = __importDefault(require("yargs"));
8
+ /**
9
+ * This middleware is needed to fill in the args for nested objects,
10
+ * so that required arguments would work
11
+ * otherwise yargs just throws an error
12
+ */
7
13
  const fillInArgs = (args, currentArgs = args, acc = []) => {
8
14
  Object.entries(currentArgs).forEach(([k, v]) => {
9
15
  if (k === '_') {
@@ -20,3 +26,10 @@ const fillInArgs = (args, currentArgs = args, acc = []) => {
20
26
  });
21
27
  };
22
28
  exports.fillInArgs = fillInArgs;
29
+ const showHelpMiddleware = (argv) => {
30
+ if (argv._.length === 1) {
31
+ yargs_1.default.showHelp();
32
+ process.exit(0);
33
+ }
34
+ };
35
+ exports.showHelpMiddleware = showHelpMiddleware;