@mytmpvpn/mytmpvpn-common 2.0.0 → 2.1.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/src/models/peanuts.js +1 -1
- package/dist/src/models/uservpn.d.ts +9 -9
- package/dist/src/models/uservpn.js +4 -4
- package/dist/src/models/vpn.d.ts +2 -1
- package/dist/src/models/vpn.js +13 -14
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +4 -5
- package/dist/test/models.test.js +1 -1
- package/package.json +1 -1
- package/dist/.eslintrc.d.ts +0 -24
- package/dist/.eslintrc.js +0 -30
- package/dist/jest.config.d.ts +0 -6
- package/dist/jest.config.js +0 -9
|
@@ -4,20 +4,20 @@ interface UserVpn {
|
|
|
4
4
|
version: number;
|
|
5
5
|
vpn: vpn.Vpn;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
type newUserVpnParams = {
|
|
8
8
|
userId: string;
|
|
9
9
|
region: string;
|
|
10
10
|
version?: number;
|
|
11
|
-
config
|
|
12
|
-
state
|
|
13
|
-
}
|
|
14
|
-
|
|
11
|
+
config?: any;
|
|
12
|
+
state?: any;
|
|
13
|
+
};
|
|
14
|
+
type getUserVpnFromParams = {
|
|
15
15
|
userId: string;
|
|
16
16
|
vpnId: string;
|
|
17
17
|
version?: number;
|
|
18
|
-
config
|
|
19
|
-
state
|
|
20
|
-
}
|
|
18
|
+
config?: any;
|
|
19
|
+
state?: any;
|
|
20
|
+
};
|
|
21
21
|
declare function newUserVpn({ userId, region, version, ...rest }: newUserVpnParams): UserVpn;
|
|
22
22
|
declare function getUserVpnFrom({ userId, vpnId, version, ...rest }: getUserVpnFromParams): UserVpn;
|
|
23
|
-
export {
|
|
23
|
+
export { UserVpn, newUserVpn, getUserVpnFrom };
|
|
@@ -5,16 +5,16 @@ const vpn = require("./vpn");
|
|
|
5
5
|
const INITIAL_VERSION = 0;
|
|
6
6
|
function newUserVpn({ userId, region, version = INITIAL_VERSION, ...rest }) {
|
|
7
7
|
return {
|
|
8
|
-
userId,
|
|
9
|
-
version,
|
|
8
|
+
userId: userId,
|
|
9
|
+
version: version,
|
|
10
10
|
vpn: vpn.newVpn(region, rest.config, rest.state)
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
exports.newUserVpn = newUserVpn;
|
|
14
14
|
function getUserVpnFrom({ userId, vpnId, version = INITIAL_VERSION, ...rest }) {
|
|
15
15
|
return {
|
|
16
|
-
userId,
|
|
17
|
-
version,
|
|
16
|
+
userId: userId,
|
|
17
|
+
version: version,
|
|
18
18
|
vpn: vpn.getVpnFrom(vpnId, rest.state, rest.config)
|
|
19
19
|
};
|
|
20
20
|
}
|
package/dist/src/models/vpn.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare enum VpnState {
|
|
|
10
10
|
}
|
|
11
11
|
declare function rank(state: VpnState): number;
|
|
12
12
|
declare enum VpnType {
|
|
13
|
+
OpenVpn = "openvpn",
|
|
13
14
|
WireGuard = "wireguard"
|
|
14
15
|
}
|
|
15
16
|
interface VpnConfig {
|
|
@@ -31,4 +32,4 @@ interface Vpn {
|
|
|
31
32
|
declare function getVpnConfigTypes(): VpnType[];
|
|
32
33
|
declare function newVpn(region: string, config: VpnConfig, state: VpnState): Vpn;
|
|
33
34
|
declare function getVpnFrom(vpnId: string, state: VpnState, config: VpnConfig): Vpn;
|
|
34
|
-
export { VpnState,
|
|
35
|
+
export { VpnState, VpnMetrics, VpnType, VpnConfig, Vpn, rank, newVpn, getVpnFrom, getVpnConfigTypes };
|
package/dist/src/models/vpn.js
CHANGED
|
@@ -20,6 +20,7 @@ function rank(state) {
|
|
|
20
20
|
exports.rank = rank;
|
|
21
21
|
var VpnType;
|
|
22
22
|
(function (VpnType) {
|
|
23
|
+
VpnType["OpenVpn"] = "openvpn";
|
|
23
24
|
VpnType["WireGuard"] = "wireguard";
|
|
24
25
|
})(VpnType || (VpnType = {}));
|
|
25
26
|
exports.VpnType = VpnType;
|
|
@@ -34,11 +35,11 @@ function newVpn(region, config, state) {
|
|
|
34
35
|
// Replace ':' in the id as it's forbiden in DDB
|
|
35
36
|
const vpnId = `${dateToId(createdAt)}@${region}`;
|
|
36
37
|
return {
|
|
37
|
-
vpnId,
|
|
38
|
-
createdAt,
|
|
39
|
-
region,
|
|
40
|
-
config,
|
|
41
|
-
state
|
|
38
|
+
vpnId: vpnId,
|
|
39
|
+
createdAt: createdAt,
|
|
40
|
+
region: region,
|
|
41
|
+
config: config,
|
|
42
|
+
state: state,
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
exports.newVpn = newVpn;
|
|
@@ -47,21 +48,19 @@ function getVpnFrom(vpnId, state, config) {
|
|
|
47
48
|
if (tokens.length !== 2) {
|
|
48
49
|
throw new Error(`Bad vpnId format: ${vpnId}`);
|
|
49
50
|
}
|
|
50
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
51
51
|
const createdAt = idToDate(tokens[0]);
|
|
52
52
|
const region = tokens[1];
|
|
53
|
-
/* eslint-enable @typescript-eslint/no-non-null-assertion */
|
|
54
53
|
return {
|
|
55
|
-
vpnId,
|
|
56
|
-
createdAt,
|
|
57
|
-
region,
|
|
58
|
-
config,
|
|
59
|
-
state
|
|
54
|
+
vpnId: vpnId,
|
|
55
|
+
createdAt: createdAt,
|
|
56
|
+
region: region,
|
|
57
|
+
config: config,
|
|
58
|
+
state: state,
|
|
60
59
|
};
|
|
61
60
|
}
|
|
62
61
|
exports.getVpnFrom = getVpnFrom;
|
|
63
|
-
// Using a date from an id is convenient for debugging.
|
|
64
|
-
// We can't use Date.toISOString() because some characters are forbidden
|
|
62
|
+
// Using a date from an id is convenient for debugging.
|
|
63
|
+
// We can't use Date.toISOString() because some characters are forbidden
|
|
65
64
|
// E.g: SFn refuse the ':'
|
|
66
65
|
// So we need convertor back and forth
|
|
67
66
|
function dateToId(date) {
|
package/dist/src/utils.d.ts
CHANGED
package/dist/src/utils.js
CHANGED
|
@@ -4,20 +4,19 @@ exports.sleep = exports.choose = exports.getFromEnvOrThrow = void 0;
|
|
|
4
4
|
const log = require("loglevel");
|
|
5
5
|
function getFromEnvOrThrow(env) {
|
|
6
6
|
const result = process.env[env];
|
|
7
|
-
if (result
|
|
7
|
+
if (!result) {
|
|
8
8
|
throw new Error(`${env} unset in environment!`);
|
|
9
9
|
}
|
|
10
10
|
log.debug(`Using ${env} = ${result}`);
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
13
13
|
exports.getFromEnvOrThrow = getFromEnvOrThrow;
|
|
14
|
-
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
15
14
|
function choose(choices) {
|
|
16
|
-
|
|
15
|
+
var index = Math.floor(Math.random() * choices.length);
|
|
17
16
|
return choices[index];
|
|
18
17
|
}
|
|
19
18
|
exports.choose = choose;
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
function sleep(millis) {
|
|
20
|
+
return new Promise(resolve => setTimeout(resolve, millis));
|
|
22
21
|
}
|
|
23
22
|
exports.sleep = sleep;
|
package/dist/test/models.test.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vpn_1 = require("../src/models/vpn");
|
|
4
4
|
describe('Testing VpnState', () => {
|
|
5
|
-
it(
|
|
5
|
+
it("should check that all VpnState are ordered properly", async () => {
|
|
6
6
|
expect((0, vpn_1.rank)(vpn_1.VpnState.Creating) <= (0, vpn_1.rank)(vpn_1.VpnState.Created)).toBe(true);
|
|
7
7
|
expect((0, vpn_1.rank)(vpn_1.VpnState.Created) <= (0, vpn_1.rank)(vpn_1.VpnState.Provisioning)).toBe(true);
|
|
8
8
|
expect((0, vpn_1.rank)(vpn_1.VpnState.Provisioning) <= (0, vpn_1.rank)(vpn_1.VpnState.Running)).toBe(true);
|
package/package.json
CHANGED
package/dist/.eslintrc.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare namespace env {
|
|
2
|
-
const browser: boolean;
|
|
3
|
-
const es2021: boolean;
|
|
4
|
-
}
|
|
5
|
-
declare const _extends: string[];
|
|
6
|
-
export { _extends as extends };
|
|
7
|
-
export declare const parser: string;
|
|
8
|
-
export declare const plugins: string[];
|
|
9
|
-
export declare const root: boolean;
|
|
10
|
-
export declare const overrides: {
|
|
11
|
-
env: {
|
|
12
|
-
node: boolean;
|
|
13
|
-
};
|
|
14
|
-
files: string[];
|
|
15
|
-
parserOptions: {
|
|
16
|
-
sourceType: string;
|
|
17
|
-
};
|
|
18
|
-
}[];
|
|
19
|
-
export declare namespace parserOptions {
|
|
20
|
-
const ecmaVersion: string;
|
|
21
|
-
const project: string;
|
|
22
|
-
const sourceType: string;
|
|
23
|
-
}
|
|
24
|
-
export declare const rules: {};
|
package/dist/.eslintrc.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = {
|
|
3
|
-
env: {
|
|
4
|
-
browser: true,
|
|
5
|
-
es2021: true
|
|
6
|
-
},
|
|
7
|
-
extends: ['standard-with-typescript', 'eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
|
8
|
-
parser: '@typescript-eslint/parser',
|
|
9
|
-
plugins: ['@typescript-eslint'],
|
|
10
|
-
root: true,
|
|
11
|
-
overrides: [
|
|
12
|
-
{
|
|
13
|
-
env: {
|
|
14
|
-
node: true
|
|
15
|
-
},
|
|
16
|
-
files: [
|
|
17
|
-
'.eslintrc.{js,cjs}'
|
|
18
|
-
],
|
|
19
|
-
parserOptions: {
|
|
20
|
-
sourceType: 'script'
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
],
|
|
24
|
-
parserOptions: {
|
|
25
|
-
ecmaVersion: 'latest',
|
|
26
|
-
project: './tsconfig.json',
|
|
27
|
-
sourceType: 'module'
|
|
28
|
-
},
|
|
29
|
-
rules: {}
|
|
30
|
-
};
|
package/dist/jest.config.d.ts
DELETED