@mytmpvpn/mytmpvpn-cli 4.0.0 → 4.2.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/dist/mytmpvpn.js +71 -39
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +6 -6
- package/src/mytmpvpn.ts +36 -37
- package/tsconfig.json +2 -2
package/dist/mytmpvpn.js
CHANGED
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
#!/usr/bin/env -S NODE_NO_WARNINGS=1 node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
3
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
37
|
// Use NODE_NO_WARNINGS=1 to get rid of the fetch node deprecated API
|
|
5
38
|
// https://github.com/netlify/cli/issues/4608 -- but it hangs the process: https://github.com/nodejs/node/issues/21960
|
|
6
|
-
const fs = require("fs");
|
|
7
|
-
const path = require("path");
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
8
41
|
const commander_1 = require("commander");
|
|
9
|
-
const log = require("loglevel");
|
|
42
|
+
const log = __importStar(require("loglevel"));
|
|
10
43
|
log.setDefaultLevel("info");
|
|
11
|
-
const vpnlib = require("@mytmpvpn/mytmpvpn-common/models/vpn");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
44
|
+
const vpnlib = __importStar(require("@mytmpvpn/mytmpvpn-common/models/vpn"));
|
|
45
|
+
const mytmpvpn_client_1 = require("@mytmpvpn/mytmpvpn-client");
|
|
46
|
+
const appconfig = __importStar(require("@mytmpvpn/mytmpvpn-client/appconfig"));
|
|
47
|
+
const userconfig = __importStar(require("@mytmpvpn/mytmpvpn-client/userconfig"));
|
|
48
|
+
const client = __importStar(require("@mytmpvpn/mytmpvpn-client/client"));
|
|
16
49
|
const program = new commander_1.Command();
|
|
17
50
|
function handleError(error, verbose = false) {
|
|
18
51
|
if (error.response) {
|
|
@@ -43,9 +76,9 @@ program
|
|
|
43
76
|
.description('MyTmpVpn CLI')
|
|
44
77
|
.version('0.0.1')
|
|
45
78
|
.option('--verbose', 'Produce more logs')
|
|
46
|
-
.option('--appConfig <file>', 'Path to the application config file',
|
|
47
|
-
.option('--userConfig <file>', 'Path to the user config file',
|
|
48
|
-
.option('--profile <name>', 'Name of the profile in the user config file to use',
|
|
79
|
+
.option('--appConfig <file>', 'Path to the application config file', appconfig.getDefaultAppConfigFile())
|
|
80
|
+
.option('--userConfig <file>', 'Path to the user config file', userconfig.getDefaultUserConfigFile())
|
|
81
|
+
.option('--profile <name>', 'Name of the profile in the user config file to use', userconfig.getDefaultUserProfile());
|
|
49
82
|
program.on('option:verbose', function () {
|
|
50
83
|
log.setDefaultLevel("trace");
|
|
51
84
|
});
|
|
@@ -53,10 +86,10 @@ program.command('list-peanuts-packs')
|
|
|
53
86
|
.description(`Returns the list of peanuts packs you can purchase. A peanuts pack contains a given number of peanuts.`)
|
|
54
87
|
.action((_, command) => {
|
|
55
88
|
const options = command.optsWithGlobals();
|
|
56
|
-
const appConfig =
|
|
89
|
+
const appConfig = appconfig.loadAppConfig(options.appConfig);
|
|
57
90
|
// We don't need authenticated user to call this API
|
|
58
|
-
const
|
|
59
|
-
|
|
91
|
+
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl);
|
|
92
|
+
clientImpl.listPeanutsPacks()
|
|
60
93
|
.then(((packs) => {
|
|
61
94
|
log.info(JSON.stringify(packs, null, 2));
|
|
62
95
|
}))
|
|
@@ -67,17 +100,17 @@ program.command('get-peanuts-balance')
|
|
|
67
100
|
.action((_, command) => {
|
|
68
101
|
const options = command.optsWithGlobals();
|
|
69
102
|
log.debug(`Get peanuts balance`);
|
|
70
|
-
|
|
103
|
+
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
71
104
|
appConfigFile: options.appConfig,
|
|
72
105
|
userConfigFile: options.userConfig,
|
|
73
106
|
profileName: options.profile
|
|
74
107
|
}).then(client => {
|
|
75
108
|
client.getPeanutsBalance().then(balance => {
|
|
76
109
|
log.info(balance);
|
|
77
|
-
}).catch(err => {
|
|
110
|
+
}).catch((err) => {
|
|
78
111
|
handleError(err);
|
|
79
112
|
});
|
|
80
|
-
}).catch(err => {
|
|
113
|
+
}).catch((err) => {
|
|
81
114
|
handleError(err, options.verbose);
|
|
82
115
|
});
|
|
83
116
|
});
|
|
@@ -85,10 +118,10 @@ program.command('list-regions')
|
|
|
85
118
|
.description('Returns the list of all regions where vpn can be created')
|
|
86
119
|
.action((_, command) => {
|
|
87
120
|
const options = command.optsWithGlobals();
|
|
88
|
-
const appConfig =
|
|
121
|
+
const appConfig = appconfig.loadAppConfig(options.appConfig);
|
|
89
122
|
// We don't need authenticated user to call this API
|
|
90
|
-
const
|
|
91
|
-
|
|
123
|
+
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl);
|
|
124
|
+
clientImpl.listRegions()
|
|
92
125
|
.then(((regions) => {
|
|
93
126
|
log.info(JSON.stringify(regions, null, 2));
|
|
94
127
|
}))
|
|
@@ -98,10 +131,10 @@ program.command('list-regions-detailed')
|
|
|
98
131
|
.description('Returns the detailed list of all regions where vpn can be created')
|
|
99
132
|
.action((_, command) => {
|
|
100
133
|
const options = command.optsWithGlobals();
|
|
101
|
-
const appConfig =
|
|
134
|
+
const appConfig = appconfig.loadAppConfig(options.appConfig);
|
|
102
135
|
// We don't need authenticated user to call this API
|
|
103
|
-
const
|
|
104
|
-
|
|
136
|
+
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl);
|
|
137
|
+
clientImpl.listRegionsDetailed()
|
|
105
138
|
.then(((regions) => {
|
|
106
139
|
log.info(JSON.stringify(regions, null, 2));
|
|
107
140
|
}))
|
|
@@ -121,7 +154,7 @@ program.command('create')
|
|
|
121
154
|
const syncStr = options.sync ? "synchronously" : "asynchronously";
|
|
122
155
|
const deleteAfter = options.deleteAfter ? options.deleteAfter : undefined;
|
|
123
156
|
log.debug(`Creating new ${options.type} vpn into ${region} ${syncStr}`);
|
|
124
|
-
|
|
157
|
+
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
125
158
|
appConfigFile: options.appConfig,
|
|
126
159
|
userConfigFile: options.userConfig,
|
|
127
160
|
profileName: options.profile
|
|
@@ -154,7 +187,7 @@ program.command('delete')
|
|
|
154
187
|
const options = command.optsWithGlobals();
|
|
155
188
|
const syncStr = options.sync ? "synchronously" : "asynchronously";
|
|
156
189
|
log.debug(`Deleting vpn ${vpnId} ${syncStr}`);
|
|
157
|
-
|
|
190
|
+
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
158
191
|
appConfigFile: options.appConfig,
|
|
159
192
|
userConfigFile: options.userConfig,
|
|
160
193
|
profileName: options.profile
|
|
@@ -181,7 +214,7 @@ program.command('get')
|
|
|
181
214
|
.argument('<vpnId>', 'vpnId to get information from')
|
|
182
215
|
.action((vpnId, _, command) => {
|
|
183
216
|
const options = command.optsWithGlobals();
|
|
184
|
-
|
|
217
|
+
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
185
218
|
appConfigFile: options.appConfig,
|
|
186
219
|
userConfigFile: options.userConfig,
|
|
187
220
|
profileName: options.profile
|
|
@@ -197,12 +230,12 @@ program.command('download-config')
|
|
|
197
230
|
.description('Download configuration of the given vpn to the given file')
|
|
198
231
|
.argument('<vpnId>', 'vpnId to get config file from')
|
|
199
232
|
.option('--file <file>', 'file where the config should be downloaded to. Default is <vpnId>.conf')
|
|
200
|
-
.option('--path <path>', 'path where the config file should be written to',
|
|
233
|
+
.option('--path <path>', 'path where the config file should be written to', userconfig.getDefaultUserConfigDir())
|
|
201
234
|
.action((vpnId, _, command) => {
|
|
202
235
|
const options = command.optsWithGlobals();
|
|
203
236
|
const file = options.file ? options.file : `${vpnId}.conf`;
|
|
204
237
|
const fullpath = path.join(options.path, file);
|
|
205
|
-
|
|
238
|
+
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
206
239
|
appConfigFile: options.appConfig,
|
|
207
240
|
userConfigFile: options.userConfig,
|
|
208
241
|
profileName: options.profile
|
|
@@ -231,7 +264,7 @@ program.command('list')
|
|
|
231
264
|
.option('--exclude-state [<state>, ...]', 'Comma separated list of states to exclude from', [vpnlib.VpnState.Deleted])
|
|
232
265
|
.action((_, command) => {
|
|
233
266
|
const options = command.optsWithGlobals();
|
|
234
|
-
|
|
267
|
+
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
235
268
|
appConfigFile: options.appConfig,
|
|
236
269
|
userConfigFile: options.userConfig,
|
|
237
270
|
profileName: options.profile
|
|
@@ -266,7 +299,7 @@ program.command('wait')
|
|
|
266
299
|
return;
|
|
267
300
|
}
|
|
268
301
|
log.debug(`Waiting for ${vpnId} state to be (at least) ${state}`);
|
|
269
|
-
|
|
302
|
+
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
270
303
|
appConfigFile: options.appConfig,
|
|
271
304
|
userConfigFile: options.userConfig,
|
|
272
305
|
profileName: options.profile
|
|
@@ -286,20 +319,20 @@ program.command('register')
|
|
|
286
319
|
.argument('<password>', 'a password')
|
|
287
320
|
.action((username, password, _, command) => {
|
|
288
321
|
const options = command.optsWithGlobals();
|
|
289
|
-
var
|
|
322
|
+
var userConfigData;
|
|
290
323
|
if (fs.existsSync(options.userConfig)) {
|
|
291
|
-
|
|
292
|
-
if (
|
|
324
|
+
userConfigData = userconfig.loadUserConfig(options.userConfig);
|
|
325
|
+
if (userConfigData.profiles[options.profile]) {
|
|
293
326
|
handleError(`Profile ${options.profile} already exists in ${options.userConfig}, specify another profile name using --profile`);
|
|
294
327
|
return;
|
|
295
328
|
}
|
|
296
|
-
|
|
329
|
+
userConfigData.profiles[options.profile] = {
|
|
297
330
|
username: username,
|
|
298
331
|
password: password
|
|
299
332
|
};
|
|
300
333
|
}
|
|
301
334
|
else {
|
|
302
|
-
|
|
335
|
+
userConfigData = {
|
|
303
336
|
version: 1,
|
|
304
337
|
profiles: {
|
|
305
338
|
default: {
|
|
@@ -309,7 +342,7 @@ program.command('register')
|
|
|
309
342
|
}
|
|
310
343
|
};
|
|
311
344
|
}
|
|
312
|
-
|
|
345
|
+
(0, mytmpvpn_client_1.registerUser)(options.appConfig, { username, password })
|
|
313
346
|
.then(user => {
|
|
314
347
|
log.info(`Please confirm your identity with the code sent to ${username}`);
|
|
315
348
|
fs.mkdir(path.dirname(options.userConfig), { recursive: true }, (err, path) => {
|
|
@@ -318,7 +351,7 @@ program.command('register')
|
|
|
318
351
|
return;
|
|
319
352
|
}
|
|
320
353
|
log.debug(`Directory: ${path} created`);
|
|
321
|
-
fs.writeFile(options.userConfig, JSON.stringify(
|
|
354
|
+
fs.writeFile(options.userConfig, JSON.stringify(userConfigData, null, 2), (err) => {
|
|
322
355
|
if (err) {
|
|
323
356
|
handleError(err);
|
|
324
357
|
return;
|
|
@@ -336,8 +369,7 @@ program.command('confirm-registration')
|
|
|
336
369
|
.argument('<code>', 'the code received')
|
|
337
370
|
.action((username, code, _, command) => {
|
|
338
371
|
const options = command.optsWithGlobals();
|
|
339
|
-
|
|
340
|
-
.confirmUser(options.appConfig, username, code)
|
|
372
|
+
(0, mytmpvpn_client_1.confirmUser)(options.appConfig, username, code)
|
|
341
373
|
.then(result => {
|
|
342
374
|
log.debug(result);
|
|
343
375
|
log.info(`User ${username} confirmed!`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/mytmpvpn.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mytmpvpn/mytmpvpn-cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "MyTmpVpn CLI",
|
|
5
5
|
"main": "./dist/mytmpvpn.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "GNU GPL",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@mytmpvpn/mytmpvpn-client": "^
|
|
34
|
-
"@mytmpvpn/mytmpvpn-common": "^
|
|
33
|
+
"@mytmpvpn/mytmpvpn-client": "^6.0.0",
|
|
34
|
+
"@mytmpvpn/mytmpvpn-common": "^8.0.0",
|
|
35
35
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
36
|
-
"commander": "^
|
|
36
|
+
"commander": "^14.0.1",
|
|
37
37
|
"eslint": "^8.57.1",
|
|
38
38
|
"eslint-config-standard-with-typescript": "^39.1.1",
|
|
39
39
|
"eslint-plugin-import": "^2.32.0",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/jest": "^29.5.14",
|
|
46
|
-
"@types/node": "^
|
|
46
|
+
"@types/node": "^24.8.1",
|
|
47
47
|
"jest": "^29.7.0",
|
|
48
48
|
"ts-jest": "^29.4.5",
|
|
49
|
-
"typescript": "^
|
|
49
|
+
"typescript": "^5.9.3"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/mytmpvpn.ts
CHANGED
|
@@ -9,10 +9,10 @@ log.setDefaultLevel("info")
|
|
|
9
9
|
|
|
10
10
|
import * as vpnlib from '@mytmpvpn/mytmpvpn-common/models/vpn'
|
|
11
11
|
import * as peanuts from '@mytmpvpn/mytmpvpn-common/models/peanuts'
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import * as
|
|
15
|
-
import
|
|
12
|
+
import { confirmUser, getLoggedInClientFromFiles, registerUser } from '@mytmpvpn/mytmpvpn-client'
|
|
13
|
+
import * as appconfig from '@mytmpvpn/mytmpvpn-client/appconfig'
|
|
14
|
+
import * as userconfig from '@mytmpvpn/mytmpvpn-client/userconfig'
|
|
15
|
+
import * as client from '@mytmpvpn/mytmpvpn-client/client'
|
|
16
16
|
|
|
17
17
|
const program = new Command()
|
|
18
18
|
|
|
@@ -44,9 +44,9 @@ program
|
|
|
44
44
|
.description('MyTmpVpn CLI')
|
|
45
45
|
.version('0.0.1')
|
|
46
46
|
.option('--verbose', 'Produce more logs')
|
|
47
|
-
.option('--appConfig <file>', 'Path to the application config file', getDefaultAppConfigFile())
|
|
48
|
-
.option('--userConfig <file>', 'Path to the user config file', getDefaultUserConfigFile())
|
|
49
|
-
.option('--profile <name>', 'Name of the profile in the user config file to use', getDefaultUserProfile())
|
|
47
|
+
.option('--appConfig <file>', 'Path to the application config file', appconfig.getDefaultAppConfigFile())
|
|
48
|
+
.option('--userConfig <file>', 'Path to the user config file', userconfig.getDefaultUserConfigFile())
|
|
49
|
+
.option('--profile <name>', 'Name of the profile in the user config file to use', userconfig.getDefaultUserProfile())
|
|
50
50
|
|
|
51
51
|
program.on('option:verbose', function () {
|
|
52
52
|
log.setDefaultLevel("trace")
|
|
@@ -56,10 +56,10 @@ program.command('list-peanuts-packs')
|
|
|
56
56
|
.description(`Returns the list of peanuts packs you can purchase. A peanuts pack contains a given number of peanuts.`)
|
|
57
57
|
.action((_, command) => {
|
|
58
58
|
const options = command.optsWithGlobals()
|
|
59
|
-
const appConfig = loadAppConfig(options.appConfig)
|
|
59
|
+
const appConfig = appconfig.loadAppConfig(options.appConfig)
|
|
60
60
|
// We don't need authenticated user to call this API
|
|
61
|
-
const
|
|
62
|
-
|
|
61
|
+
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl)
|
|
62
|
+
clientImpl.listPeanutsPacks()
|
|
63
63
|
.then(((packs: peanuts.PeanutsPack[]) => {
|
|
64
64
|
log.info(JSON.stringify(packs, null, 2))
|
|
65
65
|
}))
|
|
@@ -71,17 +71,17 @@ program.command('get-peanuts-balance')
|
|
|
71
71
|
.action((_, command) => {
|
|
72
72
|
const options = command.optsWithGlobals()
|
|
73
73
|
log.debug(`Get peanuts balance`)
|
|
74
|
-
|
|
74
|
+
getLoggedInClientFromFiles({
|
|
75
75
|
appConfigFile: options.appConfig,
|
|
76
76
|
userConfigFile: options.userConfig,
|
|
77
77
|
profileName: options.profile
|
|
78
78
|
}).then(client => {
|
|
79
79
|
client.getPeanutsBalance().then(balance => {
|
|
80
80
|
log.info(balance)
|
|
81
|
-
}).catch(err => {
|
|
81
|
+
}).catch((err: any) => {
|
|
82
82
|
handleError(err)
|
|
83
83
|
})
|
|
84
|
-
}).catch(err => {
|
|
84
|
+
}).catch((err: any) => {
|
|
85
85
|
handleError(err, options.verbose)
|
|
86
86
|
})
|
|
87
87
|
})
|
|
@@ -90,28 +90,28 @@ program.command('list-regions')
|
|
|
90
90
|
.description('Returns the list of all regions where vpn can be created')
|
|
91
91
|
.action((_, command) => {
|
|
92
92
|
const options = command.optsWithGlobals()
|
|
93
|
-
const appConfig = loadAppConfig(options.appConfig)
|
|
93
|
+
const appConfig = appconfig.loadAppConfig(options.appConfig)
|
|
94
94
|
// We don't need authenticated user to call this API
|
|
95
|
-
const
|
|
96
|
-
|
|
95
|
+
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl)
|
|
96
|
+
clientImpl.listRegions()
|
|
97
97
|
.then(((regions: any) => {
|
|
98
98
|
log.info(JSON.stringify(regions, null, 2))
|
|
99
99
|
}))
|
|
100
|
-
.catch((err) => handleError(err))
|
|
100
|
+
.catch((err: any) => handleError(err))
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
program.command('list-regions-detailed')
|
|
104
104
|
.description('Returns the detailed list of all regions where vpn can be created')
|
|
105
105
|
.action((_, command) => {
|
|
106
106
|
const options = command.optsWithGlobals()
|
|
107
|
-
const appConfig = loadAppConfig(options.appConfig)
|
|
107
|
+
const appConfig = appconfig.loadAppConfig(options.appConfig)
|
|
108
108
|
// We don't need authenticated user to call this API
|
|
109
|
-
const
|
|
110
|
-
|
|
109
|
+
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl)
|
|
110
|
+
clientImpl.listRegionsDetailed()
|
|
111
111
|
.then(((regions: any) => {
|
|
112
112
|
log.info(JSON.stringify(regions, null, 2))
|
|
113
113
|
}))
|
|
114
|
-
.catch((err) => handleError(err))
|
|
114
|
+
.catch((err: any) => handleError(err))
|
|
115
115
|
})
|
|
116
116
|
|
|
117
117
|
program.command('create')
|
|
@@ -128,7 +128,7 @@ program.command('create')
|
|
|
128
128
|
const syncStr = options.sync ? "synchronously" : "asynchronously"
|
|
129
129
|
const deleteAfter = options.deleteAfter ? options.deleteAfter : undefined
|
|
130
130
|
log.debug(`Creating new ${options.type} vpn into ${region} ${syncStr}`)
|
|
131
|
-
|
|
131
|
+
getLoggedInClientFromFiles({
|
|
132
132
|
appConfigFile: options.appConfig,
|
|
133
133
|
userConfigFile: options.userConfig,
|
|
134
134
|
profileName: options.profile
|
|
@@ -162,7 +162,7 @@ program.command('delete')
|
|
|
162
162
|
const options = command.optsWithGlobals()
|
|
163
163
|
const syncStr = options.sync ? "synchronously" : "asynchronously"
|
|
164
164
|
log.debug(`Deleting vpn ${vpnId} ${syncStr}`)
|
|
165
|
-
|
|
165
|
+
getLoggedInClientFromFiles({
|
|
166
166
|
appConfigFile: options.appConfig,
|
|
167
167
|
userConfigFile: options.userConfig,
|
|
168
168
|
profileName: options.profile
|
|
@@ -190,7 +190,7 @@ program.command('get')
|
|
|
190
190
|
.argument('<vpnId>', 'vpnId to get information from')
|
|
191
191
|
.action((vpnId, _, command) => {
|
|
192
192
|
const options = command.optsWithGlobals()
|
|
193
|
-
|
|
193
|
+
getLoggedInClientFromFiles({
|
|
194
194
|
appConfigFile: options.appConfig,
|
|
195
195
|
userConfigFile: options.userConfig,
|
|
196
196
|
profileName: options.profile
|
|
@@ -207,12 +207,12 @@ program.command('download-config')
|
|
|
207
207
|
.description('Download configuration of the given vpn to the given file')
|
|
208
208
|
.argument('<vpnId>', 'vpnId to get config file from')
|
|
209
209
|
.option('--file <file>', 'file where the config should be downloaded to. Default is <vpnId>.conf')
|
|
210
|
-
.option('--path <path>', 'path where the config file should be written to', getDefaultUserConfigDir())
|
|
210
|
+
.option('--path <path>', 'path where the config file should be written to', userconfig.getDefaultUserConfigDir())
|
|
211
211
|
.action((vpnId, _, command) => {
|
|
212
212
|
const options = command.optsWithGlobals()
|
|
213
213
|
const file = options.file ? options.file : `${vpnId}.conf`
|
|
214
214
|
const fullpath = path.join(options.path, file)
|
|
215
|
-
|
|
215
|
+
getLoggedInClientFromFiles({
|
|
216
216
|
appConfigFile: options.appConfig,
|
|
217
217
|
userConfigFile: options.userConfig,
|
|
218
218
|
profileName: options.profile
|
|
@@ -242,7 +242,7 @@ program.command('list')
|
|
|
242
242
|
.option('--exclude-state [<state>, ...]', 'Comma separated list of states to exclude from', [vpnlib.VpnState.Deleted])
|
|
243
243
|
.action((_, command) => {
|
|
244
244
|
const options = command.optsWithGlobals()
|
|
245
|
-
|
|
245
|
+
getLoggedInClientFromFiles({
|
|
246
246
|
appConfigFile: options.appConfig,
|
|
247
247
|
userConfigFile: options.userConfig,
|
|
248
248
|
profileName: options.profile
|
|
@@ -278,7 +278,7 @@ program.command('wait')
|
|
|
278
278
|
return
|
|
279
279
|
}
|
|
280
280
|
log.debug(`Waiting for ${vpnId} state to be (at least) ${state}`)
|
|
281
|
-
|
|
281
|
+
getLoggedInClientFromFiles({
|
|
282
282
|
appConfigFile: options.appConfig,
|
|
283
283
|
userConfigFile: options.userConfig,
|
|
284
284
|
profileName: options.profile
|
|
@@ -299,19 +299,19 @@ program.command('register')
|
|
|
299
299
|
.argument('<password>', 'a password')
|
|
300
300
|
.action((username, password, _, command) => {
|
|
301
301
|
const options = command.optsWithGlobals()
|
|
302
|
-
var
|
|
302
|
+
var userConfigData: userconfig.UserConfig
|
|
303
303
|
if (fs.existsSync(options.userConfig)) {
|
|
304
|
-
|
|
305
|
-
if (
|
|
304
|
+
userConfigData = userconfig.loadUserConfig(options.userConfig)
|
|
305
|
+
if (userConfigData.profiles[options.profile]) {
|
|
306
306
|
handleError(`Profile ${options.profile} already exists in ${options.userConfig}, specify another profile name using --profile`)
|
|
307
307
|
return
|
|
308
308
|
}
|
|
309
|
-
|
|
309
|
+
userConfigData.profiles[options.profile] = {
|
|
310
310
|
username: username,
|
|
311
311
|
password: password
|
|
312
312
|
}
|
|
313
313
|
} else {
|
|
314
|
-
|
|
314
|
+
userConfigData = {
|
|
315
315
|
version: 1,
|
|
316
316
|
profiles: {
|
|
317
317
|
default: {
|
|
@@ -321,7 +321,7 @@ program.command('register')
|
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
|
-
|
|
324
|
+
registerUser(options.appConfig,
|
|
325
325
|
{ username, password })
|
|
326
326
|
.then(user => {
|
|
327
327
|
log.info(`Please confirm your identity with the code sent to ${username}`)
|
|
@@ -331,7 +331,7 @@ program.command('register')
|
|
|
331
331
|
return
|
|
332
332
|
}
|
|
333
333
|
log.debug(`Directory: ${path} created`)
|
|
334
|
-
fs.writeFile(options.userConfig, JSON.stringify(
|
|
334
|
+
fs.writeFile(options.userConfig, JSON.stringify(userConfigData, null, 2), (err) => {
|
|
335
335
|
if (err) {
|
|
336
336
|
handleError(err)
|
|
337
337
|
return
|
|
@@ -351,8 +351,7 @@ program.command('confirm-registration')
|
|
|
351
351
|
.argument('<code>', 'the code received')
|
|
352
352
|
.action((username, code, _, command) => {
|
|
353
353
|
const options = command.optsWithGlobals()
|
|
354
|
-
|
|
355
|
-
.confirmUser(options.appConfig, username, code)
|
|
354
|
+
confirmUser(options.appConfig, username, code)
|
|
356
355
|
.then(result => {
|
|
357
356
|
log.debug(result)
|
|
358
357
|
log.info(`User ${username} confirmed!`)
|
package/tsconfig.json
CHANGED
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
36
36
|
|
|
37
37
|
/* Modules */
|
|
38
|
-
"module": "
|
|
38
|
+
"module": "Node16", /* Specify what module code is generated. */
|
|
39
39
|
// "rootDir": "./src", /* Specify the root folder within your source files. */
|
|
40
|
-
|
|
40
|
+
"moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
41
41
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
42
42
|
//"typeRoots": ["./node_modules/@types"], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
43
43
|
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|