@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.
@@ -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
+ };
@@ -0,0 +1,6 @@
1
+ export const testEnvironment: string;
2
+ export const roots: string[];
3
+ export const testMatch: string[];
4
+ export const transform: {
5
+ '^.+\\.tsx?$': string;
6
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ module.exports = {
3
+ testEnvironment: 'node',
4
+ roots: ['<rootDir>/test'],
5
+ testMatch: ['**/*.test.ts'],
6
+ transform: {
7
+ '^.+\\.tsx?$': 'ts-jest'
8
+ }
9
+ };
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PEANUTS_CONFIG = void 0;
4
4
  const PEANUTS_CONFIG = {
5
5
  min: 5,
6
- max: 100,
6
+ max: 100
7
7
  };
8
8
  exports.PEANUTS_CONFIG = PEANUTS_CONFIG;
@@ -4,20 +4,20 @@ interface UserVpn {
4
4
  version: number;
5
5
  vpn: vpn.Vpn;
6
6
  }
7
- type newUserVpnParams = {
7
+ interface newUserVpnParams {
8
8
  userId: string;
9
9
  region: string;
10
10
  version?: number;
11
- config?: any;
12
- state?: any;
13
- };
14
- type getUserVpnFromParams = {
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?: any;
19
- state?: any;
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: userId,
9
- version: 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: userId,
17
- version: version,
16
+ userId,
17
+ version,
18
18
  vpn: vpn.getVpnFrom(vpnId, rest.state, rest.config)
19
19
  };
20
20
  }
@@ -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 };
@@ -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: vpnId,
39
- createdAt: createdAt,
40
- region: region,
41
- config: config,
42
- state: 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: vpnId,
55
- createdAt: createdAt,
56
- region: region,
57
- config: config,
58
- state: 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) {
@@ -1,4 +1,4 @@
1
1
  declare function getFromEnvOrThrow(env: string): string;
2
2
  declare function choose(choices: any[]): any;
3
- declare function sleep(millis: number): Promise<unknown>;
3
+ declare function sleep(millis: number): Promise<void>;
4
4
  export { getFromEnvOrThrow, choose, sleep };
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 (!result) {
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
- var index = Math.floor(Math.random() * choices.length);
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
- return new Promise(resolve => setTimeout(resolve, millis));
20
+ async function sleep(millis) {
21
+ await new Promise(resolve => setTimeout(resolve, millis));
21
22
  }
22
23
  exports.sleep = sleep;
@@ -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("should check that all VpnState are ordered properly", async () => {
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": "1.3.0",
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.8.4"
39
+ "typescript": "^4.9.5"
34
40
  },
35
41
  "dependencies": {
36
42
  "loglevel": "^1.8.1"