@mytmpvpn/mytmpvpn-cli 4.1.0 → 5.0.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 +57 -40
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +6 -6
- package/src/mytmpvpn.ts +19 -35
- 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");
|
|
44
|
+
const vpnlib = __importStar(require("@mytmpvpn/mytmpvpn-common/models/vpn"));
|
|
12
45
|
const mytmpvpn_client_1 = require("@mytmpvpn/mytmpvpn-client");
|
|
13
|
-
const appconfig = require("@mytmpvpn/mytmpvpn-client/appconfig");
|
|
14
|
-
const userconfig = require("@mytmpvpn/mytmpvpn-client/userconfig");
|
|
15
|
-
const client = require("@mytmpvpn/mytmpvpn-client/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) {
|
|
@@ -74,59 +107,43 @@ program.command('get-peanuts-balance')
|
|
|
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
|
});
|
|
84
|
-
program.command('list-
|
|
85
|
-
.description('Returns the list of all
|
|
86
|
-
.action((_, command) => {
|
|
87
|
-
const options = command.optsWithGlobals();
|
|
88
|
-
const appConfig = appconfig.loadAppConfig(options.appConfig);
|
|
89
|
-
// We don't need authenticated user to call this API
|
|
90
|
-
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl);
|
|
91
|
-
clientImpl.listRegions()
|
|
92
|
-
.then(((regions) => {
|
|
93
|
-
log.info(JSON.stringify(regions, null, 2));
|
|
94
|
-
}))
|
|
95
|
-
.catch((err) => handleError(err));
|
|
96
|
-
});
|
|
97
|
-
program.command('list-regions-detailed')
|
|
98
|
-
.description('Returns the detailed list of all regions where vpn can be created')
|
|
117
|
+
program.command('list-locations')
|
|
118
|
+
.description('Returns the list of all locations where vpn can be created')
|
|
99
119
|
.action((_, command) => {
|
|
100
120
|
const options = command.optsWithGlobals();
|
|
101
121
|
const appConfig = appconfig.loadAppConfig(options.appConfig);
|
|
102
122
|
// We don't need authenticated user to call this API
|
|
103
123
|
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl);
|
|
104
|
-
clientImpl.
|
|
105
|
-
.then(((
|
|
106
|
-
log.info(JSON.stringify(
|
|
124
|
+
clientImpl.listLocations()
|
|
125
|
+
.then(((locations) => {
|
|
126
|
+
log.info(JSON.stringify(locations, null, 2));
|
|
107
127
|
}))
|
|
108
128
|
.catch((err) => handleError(err));
|
|
109
129
|
});
|
|
110
130
|
program.command('create')
|
|
111
131
|
.description('Create a new vpn')
|
|
112
|
-
.argument('<
|
|
132
|
+
.argument('<geonameId>', 'geonameId where the vpn should be created, as returned by list-locations')
|
|
113
133
|
.option('--sync', 'wait for vpn creation completion')
|
|
114
|
-
.addOption(new commander_1.Option('--type <type>', 'Type of VPN')
|
|
115
|
-
.choices(vpnlib.getVpnConfigTypes())
|
|
116
|
-
.default(vpnlib.VpnType.WireGuard))
|
|
117
134
|
.option('--peanuts <nb>', 'Max number of peanuts to use (specify -1 for maximum)', '-1')
|
|
118
135
|
.option('--deleteAfter seconds', 'Number of seconds after which the vpn will be terminated')
|
|
119
|
-
.action((
|
|
136
|
+
.action((geonameId, _, command) => {
|
|
120
137
|
const options = command.optsWithGlobals();
|
|
121
138
|
const syncStr = options.sync ? "synchronously" : "asynchronously";
|
|
122
139
|
const deleteAfter = options.deleteAfter ? options.deleteAfter : undefined;
|
|
123
|
-
log.debug(`Creating new ${options.type} vpn into ${
|
|
140
|
+
log.debug(`Creating new ${options.type} vpn into ${geonameId} ${syncStr}`);
|
|
124
141
|
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
125
142
|
appConfigFile: options.appConfig,
|
|
126
143
|
userConfigFile: options.userConfig,
|
|
127
144
|
profileName: options.profile
|
|
128
145
|
}).then(client => {
|
|
129
|
-
client.createVpn(
|
|
146
|
+
client.createVpn(Number.parseInt(geonameId), {
|
|
130
147
|
type: options.type,
|
|
131
148
|
maxPeanuts: options.peanuts, deleteAfter
|
|
132
149
|
}).then(vpn => {
|
|
@@ -226,7 +243,7 @@ program.command('download-config')
|
|
|
226
243
|
});
|
|
227
244
|
program.command('list')
|
|
228
245
|
.description('List all vpns')
|
|
229
|
-
.option('--
|
|
246
|
+
.option('--geonameId <geonameId>', 'geonameId to list vpns from')
|
|
230
247
|
.option('--include-state [<state>, ...]', 'Comma separated list of states to include', Object.values(vpnlib.VpnState))
|
|
231
248
|
.option('--exclude-state [<state>, ...]', 'Comma separated list of states to exclude from', [vpnlib.VpnState.Deleted])
|
|
232
249
|
.action((_, command) => {
|
|
@@ -238,8 +255,8 @@ program.command('list')
|
|
|
238
255
|
}).then(client => {
|
|
239
256
|
client.listVpns(options.state)
|
|
240
257
|
.then(vpns => {
|
|
241
|
-
if (options.
|
|
242
|
-
vpns = vpns.filter((vpn) => vpn.
|
|
258
|
+
if (options.location) {
|
|
259
|
+
vpns = vpns.filter((vpn) => vpn.geonamesId === options.geonameId);
|
|
243
260
|
}
|
|
244
261
|
if (options.includeState) {
|
|
245
262
|
vpns = vpns.filter((vpn) => options.includeState.includes(vpn.state));
|
|
@@ -366,11 +383,11 @@ Examples:
|
|
|
366
383
|
|
|
367
384
|
# Then you can use the following command at will:
|
|
368
385
|
|
|
369
|
-
# List available
|
|
370
|
-
$ mytmpvpn list-
|
|
386
|
+
# List available locations:
|
|
387
|
+
$ mytmpvpn list-locations
|
|
371
388
|
|
|
372
389
|
# Create a new vpn in Paris:
|
|
373
|
-
$ mytmpvpn create '
|
|
390
|
+
$ mytmpvpn create '2988507' --sync # This takes several minutes, please be patient or remove --sync
|
|
374
391
|
|
|
375
392
|
# List all my vpns:
|
|
376
393
|
$ mytmpvpn list
|
|
@@ -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": "
|
|
3
|
+
"version": "5.0.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": "^9.0.0",
|
|
34
|
+
"@mytmpvpn/mytmpvpn-common": "^10.0.2",
|
|
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
|
@@ -13,6 +13,7 @@ import { confirmUser, getLoggedInClientFromFiles, registerUser } from '@mytmpvpn
|
|
|
13
13
|
import * as appconfig from '@mytmpvpn/mytmpvpn-client/appconfig'
|
|
14
14
|
import * as userconfig from '@mytmpvpn/mytmpvpn-client/userconfig'
|
|
15
15
|
import * as client from '@mytmpvpn/mytmpvpn-client/client'
|
|
16
|
+
import { ListLocationsResponse } from '@mytmpvpn/mytmpvpn-common/models/location'
|
|
16
17
|
|
|
17
18
|
const program = new Command()
|
|
18
19
|
|
|
@@ -78,62 +79,45 @@ program.command('get-peanuts-balance')
|
|
|
78
79
|
}).then(client => {
|
|
79
80
|
client.getPeanutsBalance().then(balance => {
|
|
80
81
|
log.info(balance)
|
|
81
|
-
}).catch(err => {
|
|
82
|
+
}).catch((err: any) => {
|
|
82
83
|
handleError(err)
|
|
83
84
|
})
|
|
84
|
-
}).catch(err => {
|
|
85
|
+
}).catch((err: any) => {
|
|
85
86
|
handleError(err, options.verbose)
|
|
86
87
|
})
|
|
87
88
|
})
|
|
88
89
|
|
|
89
|
-
program.command('list-
|
|
90
|
-
.description('Returns the list of all
|
|
91
|
-
.action((_, command) => {
|
|
92
|
-
const options = command.optsWithGlobals()
|
|
93
|
-
const appConfig = appconfig.loadAppConfig(options.appConfig)
|
|
94
|
-
// We don't need authenticated user to call this API
|
|
95
|
-
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl)
|
|
96
|
-
clientImpl.listRegions()
|
|
97
|
-
.then(((regions: any) => {
|
|
98
|
-
log.info(JSON.stringify(regions, null, 2))
|
|
99
|
-
}))
|
|
100
|
-
.catch((err) => handleError(err))
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
program.command('list-regions-detailed')
|
|
104
|
-
.description('Returns the detailed list of all regions where vpn can be created')
|
|
90
|
+
program.command('list-locations')
|
|
91
|
+
.description('Returns the list of all locations where vpn can be created')
|
|
105
92
|
.action((_, command) => {
|
|
106
93
|
const options = command.optsWithGlobals()
|
|
107
94
|
const appConfig = appconfig.loadAppConfig(options.appConfig)
|
|
108
95
|
// We don't need authenticated user to call this API
|
|
109
96
|
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl)
|
|
110
|
-
clientImpl.
|
|
111
|
-
.then(((
|
|
112
|
-
log.info(JSON.stringify(
|
|
97
|
+
clientImpl.listLocations()
|
|
98
|
+
.then(((locations: ListLocationsResponse) => {
|
|
99
|
+
log.info(JSON.stringify(locations, null, 2))
|
|
113
100
|
}))
|
|
114
|
-
.catch((err) => handleError(err))
|
|
101
|
+
.catch((err: any) => handleError(err))
|
|
115
102
|
})
|
|
116
103
|
|
|
117
104
|
program.command('create')
|
|
118
105
|
.description('Create a new vpn')
|
|
119
|
-
.argument('<
|
|
106
|
+
.argument('<geonameId>', 'geonameId where the vpn should be created, as returned by list-locations')
|
|
120
107
|
.option('--sync', 'wait for vpn creation completion')
|
|
121
|
-
.addOption(new Option('--type <type>', 'Type of VPN')
|
|
122
|
-
.choices(vpnlib.getVpnConfigTypes())
|
|
123
|
-
.default(vpnlib.VpnType.WireGuard))
|
|
124
108
|
.option('--peanuts <nb>', 'Max number of peanuts to use (specify -1 for maximum)', '-1')
|
|
125
109
|
.option('--deleteAfter seconds', 'Number of seconds after which the vpn will be terminated')
|
|
126
|
-
.action((
|
|
110
|
+
.action((geonameId: string, _, command) => {
|
|
127
111
|
const options = command.optsWithGlobals()
|
|
128
112
|
const syncStr = options.sync ? "synchronously" : "asynchronously"
|
|
129
113
|
const deleteAfter = options.deleteAfter ? options.deleteAfter : undefined
|
|
130
|
-
log.debug(`Creating new ${options.type} vpn into ${
|
|
114
|
+
log.debug(`Creating new ${options.type} vpn into ${geonameId} ${syncStr}`)
|
|
131
115
|
getLoggedInClientFromFiles({
|
|
132
116
|
appConfigFile: options.appConfig,
|
|
133
117
|
userConfigFile: options.userConfig,
|
|
134
118
|
profileName: options.profile
|
|
135
119
|
}).then(client => {
|
|
136
|
-
client.createVpn(
|
|
120
|
+
client.createVpn(Number.parseInt(geonameId), {
|
|
137
121
|
type: options.type,
|
|
138
122
|
maxPeanuts: options.peanuts, deleteAfter
|
|
139
123
|
}).then(vpn => {
|
|
@@ -237,7 +221,7 @@ program.command('download-config')
|
|
|
237
221
|
|
|
238
222
|
program.command('list')
|
|
239
223
|
.description('List all vpns')
|
|
240
|
-
.option('--
|
|
224
|
+
.option('--geonameId <geonameId>', 'geonameId to list vpns from')
|
|
241
225
|
.option('--include-state [<state>, ...]', 'Comma separated list of states to include', Object.values(vpnlib.VpnState))
|
|
242
226
|
.option('--exclude-state [<state>, ...]', 'Comma separated list of states to exclude from', [vpnlib.VpnState.Deleted])
|
|
243
227
|
.action((_, command) => {
|
|
@@ -249,8 +233,8 @@ program.command('list')
|
|
|
249
233
|
}).then(client => {
|
|
250
234
|
client.listVpns(options.state)
|
|
251
235
|
.then(vpns => {
|
|
252
|
-
if (options.
|
|
253
|
-
vpns = vpns.filter((vpn: vpnlib.Vpn) => vpn.
|
|
236
|
+
if (options.location) {
|
|
237
|
+
vpns = vpns.filter((vpn: vpnlib.Vpn) => vpn.geonamesId === options.geonameId)
|
|
254
238
|
}
|
|
255
239
|
if (options.includeState) {
|
|
256
240
|
vpns = vpns.filter((vpn: vpnlib.Vpn) => options.includeState.includes(vpn.state))
|
|
@@ -382,11 +366,11 @@ Examples:
|
|
|
382
366
|
|
|
383
367
|
# Then you can use the following command at will:
|
|
384
368
|
|
|
385
|
-
# List available
|
|
386
|
-
$ mytmpvpn list-
|
|
369
|
+
# List available locations:
|
|
370
|
+
$ mytmpvpn list-locations
|
|
387
371
|
|
|
388
372
|
# Create a new vpn in Paris:
|
|
389
|
-
$ mytmpvpn create '
|
|
373
|
+
$ mytmpvpn create '2988507' --sync # This takes several minutes, please be patient or remove --sync
|
|
390
374
|
|
|
391
375
|
# List all my vpns:
|
|
392
376
|
$ mytmpvpn list
|
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. */
|