@mytmpvpn/mytmpvpn-common 3.0.0 → 4.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.
|
@@ -20,4 +20,5 @@ interface getUserVpnFromParams {
|
|
|
20
20
|
}
|
|
21
21
|
declare function newUserVpn({ userId, region, version, ...rest }: newUserVpnParams): UserVpn;
|
|
22
22
|
declare function getUserVpnFrom({ userId, vpnId, version, ...rest }: getUserVpnFromParams): UserVpn;
|
|
23
|
-
|
|
23
|
+
declare function jsonToUserVpn(jsonString: any): UserVpn;
|
|
24
|
+
export { type UserVpn, newUserVpn, getUserVpnFrom, jsonToUserVpn };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUserVpnFrom = exports.newUserVpn = void 0;
|
|
3
|
+
exports.jsonToUserVpn = exports.getUserVpnFrom = exports.newUserVpn = void 0;
|
|
4
4
|
const vpn = require("./vpn");
|
|
5
5
|
const INITIAL_VERSION = 0;
|
|
6
6
|
function newUserVpn({ userId, region, version = INITIAL_VERSION, ...rest }) {
|
|
@@ -19,3 +19,18 @@ function getUserVpnFrom({ userId, vpnId, version = INITIAL_VERSION, ...rest }) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
exports.getUserVpnFrom = getUserVpnFrom;
|
|
22
|
+
function jsonToUserVpn(jsonString) {
|
|
23
|
+
const parsed = JSON.parse(jsonString, (key, value) => {
|
|
24
|
+
if (key === 'createdAt') {
|
|
25
|
+
return new Date(value);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
});
|
|
29
|
+
const result = {
|
|
30
|
+
userId: parsed.userId,
|
|
31
|
+
version: parsed.version,
|
|
32
|
+
vpn: parsed.vpn
|
|
33
|
+
};
|
|
34
|
+
return parsed;
|
|
35
|
+
}
|
|
36
|
+
exports.jsonToUserVpn = jsonToUserVpn;
|
package/dist/test/models.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const uservpn_1 = require("../src/models/uservpn");
|
|
3
4
|
const errors_1 = require("../src/errors");
|
|
4
5
|
const vpn_1 = require("../src/models/vpn");
|
|
5
6
|
describe('Testing VpnState', () => {
|
|
@@ -73,6 +74,22 @@ describe('Testing Vpn constructors', () => {
|
|
|
73
74
|
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: deleteAfter });
|
|
74
75
|
expect(vpn.vpnId).toBeDefined();
|
|
75
76
|
});
|
|
77
|
+
it('Should deserialize a json vpn with all fields set', async () => {
|
|
78
|
+
const originalVpn = (0, uservpn_1.newUserVpn)({
|
|
79
|
+
userId: 'myId',
|
|
80
|
+
region: 'az-test-7',
|
|
81
|
+
version: 1,
|
|
82
|
+
config: {
|
|
83
|
+
maxPeanuts: -1,
|
|
84
|
+
type: vpn_1.VpnType.WireGuard,
|
|
85
|
+
deleteAfter: vpn_1.MIN_DELETE_AFTER
|
|
86
|
+
},
|
|
87
|
+
state: vpn_1.VpnState.Created,
|
|
88
|
+
});
|
|
89
|
+
const jsonString = JSON.stringify(originalVpn);
|
|
90
|
+
const userVpn = (0, uservpn_1.jsonToUserVpn)(jsonString);
|
|
91
|
+
expect(userVpn).toEqual(originalVpn);
|
|
92
|
+
});
|
|
76
93
|
it('Should shout when vpnId is empty', async () => {
|
|
77
94
|
expect(() => (0, vpn_1.getVpnFrom)('', vpn_1.VpnState.Created, { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }))
|
|
78
95
|
.toThrow(new errors_1.MyTmpVpnError("Incorrect vpnId: \'\'"));
|