mysterium-vpn-js
Version:
Javascript SDK for Mysterium node
43 lines (42 loc) • 1.61 kB
JavaScript
;
/**
* Copyright (c) 2020 BlockDev AG
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseHealthcheckResponse = exports.parseNodeBuildInfo = void 0;
const validation_1 = require("../fmt/validation");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function parseNodeBuildInfo(data) {
(0, validation_1.validateMultiple)('NodeBuildInfo', data, [
{ name: 'commit', type: 'string' },
{ name: 'branch', type: 'string' },
{ name: 'buildNumber', type: 'string' },
]);
return data;
}
exports.parseNodeBuildInfo = parseNodeBuildInfo;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function parseHealthcheckResponse(data) {
const errorMessage = `Unable to parse healthcheck response: ${JSON.stringify(data)}`;
if (data == null || typeof data !== 'object') {
throw new Error(errorMessage);
}
if (typeof data.uptime !== 'string') {
throw new Error(errorMessage);
}
if (typeof data.process !== 'number') {
throw new Error(errorMessage);
}
if (typeof data.version !== 'string') {
throw new Error(errorMessage);
}
if (data.buildInfo === null || typeof data.buildInfo !== 'object') {
throw new Error(errorMessage);
}
const buildInfo = parseNodeBuildInfo(data.buildInfo);
return Object.assign(Object.assign({}, data), { buildInfo });
}
exports.parseHealthcheckResponse = parseHealthcheckResponse;