@mytmpvpn/mytmpvpn-common 2.1.2 → 2.3.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/vpn.d.ts
CHANGED
package/dist/src/models/vpn.js
CHANGED
|
@@ -35,6 +35,12 @@ function throwIfNotValidVpnId(vpnId) {
|
|
|
35
35
|
throw new Error(`Incorrect vpnId: \'${vpnId}\'`);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
function throwIfNotValidTerminationDate(terminationDate) {
|
|
39
|
+
// Make sure the given date is not in the past
|
|
40
|
+
if (terminationDate.getTime() < new Date().getTime()) {
|
|
41
|
+
throw new Error(`TerminationDate must be in the future: \'${terminationDate}\'`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
38
44
|
function newVpn(region, config, state) {
|
|
39
45
|
// e.g: ap-northeast-3
|
|
40
46
|
if (!/[a-z]{2}-[a-z]+-[1-9]+/.test(region)) {
|
|
@@ -44,6 +50,9 @@ function newVpn(region, config, state) {
|
|
|
44
50
|
const vpnId = `${dateToId(createdAt)}@${region}`;
|
|
45
51
|
// Assert we will be able to deserialize later on...
|
|
46
52
|
throwIfNotValidVpnId(vpnId);
|
|
53
|
+
if (config.terminationDate) {
|
|
54
|
+
throwIfNotValidTerminationDate(config.terminationDate);
|
|
55
|
+
}
|
|
47
56
|
return {
|
|
48
57
|
vpnId,
|
|
49
58
|
createdAt,
|
package/dist/test/models.test.js
CHANGED
|
@@ -20,7 +20,7 @@ describe('Testing Vpn constructors', () => {
|
|
|
20
20
|
expect(() => (0, vpn_1.newVpn)('foo', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }, vpn_1.VpnState.Created))
|
|
21
21
|
.toThrow(new Error("Incorrect region: \'foo\'"));
|
|
22
22
|
});
|
|
23
|
-
it('Should create vpn with all fields set', async () => {
|
|
23
|
+
it('Should create vpn with all mandatory fields set', async () => {
|
|
24
24
|
const vpn = (0, vpn_1.newVpn)('az-test-7', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }, vpn_1.VpnState.Created);
|
|
25
25
|
expect(vpn.createdAt).toBeDefined();
|
|
26
26
|
expect(vpn.region).toEqual('az-test-7');
|
|
@@ -28,12 +28,26 @@ describe('Testing Vpn constructors', () => {
|
|
|
28
28
|
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard });
|
|
29
29
|
expect(vpn.vpnId).toBeDefined();
|
|
30
30
|
});
|
|
31
|
-
it('Should
|
|
32
|
-
const
|
|
31
|
+
it('Should create vpn with optional fields set', async () => {
|
|
32
|
+
const terminationDate = new Date(new Date().getTime() + 3600 * 1000);
|
|
33
|
+
const vpn = (0, vpn_1.newVpn)('az-test-7', {
|
|
34
|
+
maxPeanuts: -1,
|
|
35
|
+
type: vpn_1.VpnType.WireGuard,
|
|
36
|
+
terminationDate
|
|
37
|
+
}, vpn_1.VpnState.Created);
|
|
38
|
+
expect(vpn.createdAt).toBeDefined();
|
|
39
|
+
expect(vpn.region).toEqual('az-test-7');
|
|
40
|
+
expect(vpn.state).toEqual(vpn_1.VpnState.Created);
|
|
41
|
+
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, terminationDate });
|
|
42
|
+
expect(vpn.vpnId).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
it('Should deserialize a vpn with all mandatory fields set', async () => {
|
|
45
|
+
const terminationDate = new Date(new Date().getTime() + 3600 * 1000);
|
|
46
|
+
const vpn = (0, vpn_1.getVpnFrom)('20030902012345678@az-test-7', vpn_1.VpnState.Created, { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, terminationDate });
|
|
33
47
|
expect(vpn.createdAt).toEqual(new Date('2003-09-02T01:23:45.678Z'));
|
|
34
48
|
expect(vpn.region).toEqual('az-test-7');
|
|
35
49
|
expect(vpn.state).toEqual(vpn_1.VpnState.Created);
|
|
36
|
-
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard });
|
|
50
|
+
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, terminationDate });
|
|
37
51
|
expect(vpn.vpnId).toBeDefined();
|
|
38
52
|
});
|
|
39
53
|
it('Should shout when vpnId is empty', async () => {
|
|
@@ -48,6 +62,11 @@ describe('Testing Vpn constructors', () => {
|
|
|
48
62
|
expect(() => (0, vpn_1.getVpnFrom)('20030902012345678@test', vpn_1.VpnState.Created, { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }))
|
|
49
63
|
.toThrow(new Error("Incorrect vpnId: \'20030902012345678@test\'"));
|
|
50
64
|
});
|
|
65
|
+
it('Should shout when termination is in the past', async () => {
|
|
66
|
+
const wrongTerminationDate = new Date(new Date().getTime() - 3600 * 1000);
|
|
67
|
+
expect(() => (0, vpn_1.newVpn)('az-test-7', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, terminationDate: wrongTerminationDate }, vpn_1.VpnState.Created))
|
|
68
|
+
.toThrow(new Error(`TerminationDate must be in the future: \'${wrongTerminationDate}\'`));
|
|
69
|
+
});
|
|
51
70
|
});
|
|
52
71
|
describe('Testing vpnId to Wireguard file name functions ', () => {
|
|
53
72
|
it('Should shout when vpnId is empty', async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mytmpvpn/mytmpvpn-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Common library for all MyTmpVpn related projects",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsc --build",
|
|
21
|
+
"lint": "eslint",
|
|
21
22
|
"watch": "tsc -w",
|
|
22
23
|
"test": "jest",
|
|
23
24
|
"link-deps": "echo \"No dependencies, noop; that's fine\"",
|