@mytmpvpn/mytmpvpn-common 1.3.0 → 2.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/.eslintrc.d.ts +24 -0
- package/dist/.eslintrc.js +30 -0
- package/dist/jest.config.d.ts +6 -0
- package/dist/jest.config.js +9 -0
- 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 +1 -2
- package/dist/src/models/vpn.js +14 -13
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +5 -4
- package/dist/test/models.test.js +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1,24 @@
|
|
|
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: {};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
};
|
|
@@ -4,20 +4,20 @@ interface UserVpn {
|
|
|
4
4
|
version: number;
|
|
5
5
|
vpn: vpn.Vpn;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
interface newUserVpnParams {
|
|
8
8
|
userId: string;
|
|
9
9
|
region: string;
|
|
10
10
|
version?: number;
|
|
11
|
-
config
|
|
12
|
-
state
|
|
13
|
-
}
|
|
14
|
-
|
|
11
|
+
config: vpn.VpnConfig;
|
|
12
|
+
state: vpn.VpnState;
|
|
13
|
+
}
|
|
14
|
+
interface getUserVpnFromParams {
|
|
15
15
|
userId: string;
|
|
16
16
|
vpnId: string;
|
|
17
17
|
version?: number;
|
|
18
|
-
config
|
|
19
|
-
state
|
|
20
|
-
}
|
|
18
|
+
config: vpn.VpnConfig;
|
|
19
|
+
state: vpn.VpnState;
|
|
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 { UserVpn, newUserVpn, getUserVpnFrom };
|
|
23
|
+
export { type 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,
|
|
9
|
+
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,
|
|
17
|
+
version,
|
|
18
18
|
vpn: vpn.getVpnFrom(vpnId, rest.state, rest.config)
|
|
19
19
|
};
|
|
20
20
|
}
|
package/dist/src/models/vpn.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ declare enum VpnState {
|
|
|
10
10
|
}
|
|
11
11
|
declare function rank(state: VpnState): number;
|
|
12
12
|
declare enum VpnType {
|
|
13
|
-
OpenVpn = "openvpn",
|
|
14
13
|
WireGuard = "wireguard"
|
|
15
14
|
}
|
|
16
15
|
interface VpnConfig {
|
|
@@ -32,4 +31,4 @@ interface Vpn {
|
|
|
32
31
|
declare function getVpnConfigTypes(): VpnType[];
|
|
33
32
|
declare function newVpn(region: string, config: VpnConfig, state: VpnState): Vpn;
|
|
34
33
|
declare function getVpnFrom(vpnId: string, state: VpnState, config: VpnConfig): Vpn;
|
|
35
|
-
export { VpnState, VpnMetrics, VpnType, VpnConfig, Vpn, rank, newVpn, getVpnFrom, getVpnConfigTypes };
|
|
34
|
+
export { VpnState, type VpnMetrics, VpnType, type VpnConfig, type Vpn, rank, newVpn, getVpnFrom, getVpnConfigTypes };
|
package/dist/src/models/vpn.js
CHANGED
|
@@ -20,7 +20,6 @@ function rank(state) {
|
|
|
20
20
|
exports.rank = rank;
|
|
21
21
|
var VpnType;
|
|
22
22
|
(function (VpnType) {
|
|
23
|
-
VpnType["OpenVpn"] = "openvpn";
|
|
24
23
|
VpnType["WireGuard"] = "wireguard";
|
|
25
24
|
})(VpnType || (VpnType = {}));
|
|
26
25
|
exports.VpnType = VpnType;
|
|
@@ -35,11 +34,11 @@ function newVpn(region, config, state) {
|
|
|
35
34
|
// Replace ':' in the id as it's forbiden in DDB
|
|
36
35
|
const vpnId = `${dateToId(createdAt)}@${region}`;
|
|
37
36
|
return {
|
|
38
|
-
vpnId
|
|
39
|
-
createdAt
|
|
40
|
-
region
|
|
41
|
-
config
|
|
42
|
-
state
|
|
37
|
+
vpnId,
|
|
38
|
+
createdAt,
|
|
39
|
+
region,
|
|
40
|
+
config,
|
|
41
|
+
state
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
44
|
exports.newVpn = newVpn;
|
|
@@ -48,19 +47,21 @@ function getVpnFrom(vpnId, state, config) {
|
|
|
48
47
|
if (tokens.length !== 2) {
|
|
49
48
|
throw new Error(`Bad vpnId format: ${vpnId}`);
|
|
50
49
|
}
|
|
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 */
|
|
53
54
|
return {
|
|
54
|
-
vpnId
|
|
55
|
-
createdAt
|
|
56
|
-
region
|
|
57
|
-
config
|
|
58
|
-
state
|
|
55
|
+
vpnId,
|
|
56
|
+
createdAt,
|
|
57
|
+
region,
|
|
58
|
+
config,
|
|
59
|
+
state
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
exports.getVpnFrom = getVpnFrom;
|
|
62
|
-
// Using a date from an id is convenient for debugging.
|
|
63
|
-
// We can't use Date.toISOString() because some characters are forbidden
|
|
63
|
+
// Using a date from an id is convenient for debugging.
|
|
64
|
+
// We can't use Date.toISOString() because some characters are forbidden
|
|
64
65
|
// E.g: SFn refuse the ':'
|
|
65
66
|
// So we need convertor back and forth
|
|
66
67
|
function dateToId(date) {
|
package/dist/src/utils.d.ts
CHANGED
package/dist/src/utils.js
CHANGED
|
@@ -4,19 +4,20 @@ 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 (
|
|
7
|
+
if (result === null || result === undefined || result.trim() === '') {
|
|
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 */
|
|
14
15
|
function choose(choices) {
|
|
15
|
-
|
|
16
|
+
const index = Math.floor(Math.random() * choices.length);
|
|
16
17
|
return choices[index];
|
|
17
18
|
}
|
|
18
19
|
exports.choose = choose;
|
|
19
|
-
function sleep(millis) {
|
|
20
|
-
|
|
20
|
+
async function sleep(millis) {
|
|
21
|
+
await new Promise(resolve => setTimeout(resolve, millis));
|
|
21
22
|
}
|
|
22
23
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mytmpvpn/mytmpvpn-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Common library for all MyTmpVpn related projects",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -28,9 +28,15 @@
|
|
|
28
28
|
"license": "GNU AGPL",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/jest": "^27.5.2",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
32
|
+
"eslint": "^8.46.0",
|
|
33
|
+
"eslint-config-standard-with-typescript": "^37.0.0",
|
|
34
|
+
"eslint-plugin-import": "^2.28.0",
|
|
35
|
+
"eslint-plugin-n": "^16.0.1",
|
|
36
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
31
37
|
"jest": "^27.5.1",
|
|
32
38
|
"ts-jest": "^27.1.5",
|
|
33
|
-
"typescript": "^4.
|
|
39
|
+
"typescript": "^4.9.5"
|
|
34
40
|
},
|
|
35
41
|
"dependencies": {
|
|
36
42
|
"loglevel": "^1.8.1"
|