UNPKG

mysterium-vpn-js

Version:
85 lines (84 loc) 3.4 kB
"use strict"; /** * 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.parseSessionStatsDailyResponse = exports.parseSessionStatsAggregatedResponse = exports.parseSessionListResponse = exports.parseSessionStats = exports.parseSession = exports.SessionDirection = exports.SessionStatus = void 0; const validation_1 = require("../fmt/validation"); const pageable_1 = require("../common/pageable"); /** * @deprecated use ProviderAPI */ var SessionStatus; (function (SessionStatus) { SessionStatus["NEW"] = "New"; SessionStatus["COMPLETED"] = "Completed"; })(SessionStatus = exports.SessionStatus || (exports.SessionStatus = {})); /** * @deprecated use ProviderAPI */ var SessionDirection; (function (SessionDirection) { SessionDirection["CONSUMED"] = "Consumed"; SessionDirection["PROVIDED"] = "Provided"; })(SessionDirection = exports.SessionDirection || (exports.SessionDirection = {})); function parseSession(data) { (0, validation_1.validateMultiple)('Session', data, [ { name: 'id', type: 'string' }, { name: 'direction', type: 'string' }, { name: 'consumerId', type: 'string' }, { name: 'hermesId', type: 'string' }, { name: 'providerId', type: 'string' }, { name: 'serviceType', type: 'string' }, { name: 'providerCountry', type: 'string' }, { name: 'createdAt', type: 'string' }, { name: 'duration', type: 'number' }, { name: 'bytesReceived', type: 'number' }, { name: 'bytesSent', type: 'number' }, { name: 'tokens', type: 'number' }, { name: 'status', type: 'string' }, ]); return data; } exports.parseSession = parseSession; function parseSessionStats(data) { (0, validation_1.validateMultiple)('SessionStats', data, [ { name: 'count', type: 'number' }, { name: 'countConsumers', type: 'number' }, { name: 'sumBytesReceived', type: 'number' }, { name: 'sumBytesSent', type: 'number' }, { name: 'sumDuration', type: 'number' }, { name: 'sumTokens', type: 'number' }, ]); return data; } exports.parseSessionStats = parseSessionStats; function parseSessionListResponse(responseData) { const response = (0, pageable_1.parsePageable)(responseData); response.items = responseData.items.map(parseSession); return response; } exports.parseSessionListResponse = parseSessionListResponse; function parseSessionStatsAggregatedResponse(data) { (0, validation_1.validate)('SessionStatsAggregatedResponse', data, { name: 'stats', type: 'object' }); return { stats: parseSessionStats(data.stats), }; } exports.parseSessionStatsAggregatedResponse = parseSessionStatsAggregatedResponse; function parseSessionStatsDailyResponse(data) { (0, validation_1.validateMultiple)('SessionStatsDailyResponse', data, [ { name: 'items', type: 'object' }, { name: 'stats', type: 'object' }, ]); const response = data; response.stats = parseSessionStats(data.stats); Object.keys(data.items).forEach((key) => { response.items[key] = parseSessionStats(data.items[key]); }); return response; } exports.parseSessionStatsDailyResponse = parseSessionStatsDailyResponse;