mysterium-vpn-js
Version:
Javascript SDK for Mysterium node
545 lines (544 loc) • 21.6 kB
JavaScript
"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.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TequilapiClient = exports.pathInvoice = exports.pathConfigDefault = exports.pathConfigUser = exports.pathConfig = exports.TEQUILAPI_URL = void 0;
const access_policy_1 = require("./access-policy/access-policy");
const status_1 = require("./connection/status");
const ip_1 = require("./location/ip");
const statistics_1 = require("./connection/statistics");
const location_1 = require("./location/location");
const healthcheck_1 = require("./daemon/healthcheck");
const timeouts_1 = require("./http/timeouts");
const identity_1 = require("./identity/identity");
const registration_1 = require("./identity/registration");
const beneficiary_1 = require("./identity/beneficiary");
const status_2 = require("./nat/status");
const status_3 = require("./node/status");
const proposal_1 = require("./proposal/proposal");
const service_info_1 = require("./provider/service-info");
const session_1 = require("./session/session");
const settlement_1 = require("./transactor/settlement");
const payment_1 = require("./payment");
const payout_1 = require("./identity/payout");
const type_1 = require("./nat/type");
const provider_1 = require("./provider");
exports.TEQUILAPI_URL = 'http://127.0.0.1:4050';
exports.pathConfig = 'config';
exports.pathConfigUser = 'config/user';
exports.pathConfigDefault = 'config/default';
exports.pathInvoice = '/invoice';
class BaseHttpTequilapiClient {
constructor(http) {
this.http = http;
this.payment = new payment_1.PaymentAPI(http);
this.provider = new provider_1.ProviderAPI(http);
}
healthCheck(timeout) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('healthcheck', undefined, timeout);
if (!response) {
throw new Error('Healthcheck response body is missing');
}
return (0, healthcheck_1.parseHealthcheckResponse)(response);
});
}
terms() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('terms');
if (!response) {
throw new Error('Terms response body is missing');
}
return response;
});
}
termsUpdate(request) {
return __awaiter(this, void 0, void 0, function* () {
yield this.http.post('terms', request);
});
}
natStatus() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('nat/status');
return (0, status_2.parseNatStatusResponse)(response);
});
}
nodeMonitoringStatus() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('node/monitoring-status');
return (0, status_3.parseNodeMonitoringStatus)(response);
});
}
natType() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('nat/type');
return (0, type_1.parseNatTypeResponse)(response);
});
}
stop() {
return __awaiter(this, void 0, void 0, function* () {
yield this.http.post('stop');
});
}
location(timeout) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('location', undefined, timeout);
if (!response) {
throw new Error('ServiceLocation response body is missing');
}
return (0, location_1.parseLocation)(response);
});
}
identityList() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('identities');
if (!response) {
throw new Error('Identity list response body is missing');
}
const responseDto = (0, identity_1.parseIdentityList)(response);
return responseDto.identities;
});
}
identity(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get(`identities/${id}`);
if (!response) {
throw new Error('Identity response body is missing');
}
return (0, identity_1.parseIdentity)(response);
});
}
identityCurrent(request) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.put('identities/current', request);
if (!response) {
throw new Error('Identity response body is missing');
}
return (0, identity_1.parseIdentityRef)(response);
});
}
identityCreate(passphrase) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.post('identities', { passphrase });
if (!response) {
throw new Error('Identity creation response body is missing');
}
return (0, identity_1.parseIdentityRef)(response);
});
}
identityUnlock(id, passphrase, timeout) {
return __awaiter(this, void 0, void 0, function* () {
yield this.http.put('identities/' + id + '/unlock', { passphrase }, timeout);
});
}
identityRegister(id, request) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.http.post(`identities/${id}/register`, request !== null && request !== void 0 ? request : {});
});
}
identityRegistration(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get(`identities/${id}/registration`);
if (!response) {
throw new Error('Identity registration response body is missing');
}
return (0, registration_1.parseIdentityRegistrationResponse)(response);
});
}
identityBeneficiary(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get(`identities/${id}/beneficiary`);
if (!response) {
throw new Error('Identity registration response body is missing');
}
return (0, beneficiary_1.parseIdentityBeneficiaryResponse)(response);
});
}
identityBalanceRefresh(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.put(`identities/${id}/balance/refresh`, {});
if (!response) {
throw new Error('Identity balance refresh response body is missing');
}
return response;
});
}
payoutAddressSave(id, address) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.put(`identities/${id}/payout-address`, { address });
if (!response) {
throw new Error('Payout address response body is missing');
}
return (0, payout_1.parsePayoutAddressResponse)(response);
});
}
payoutAddressGet(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get(`identities/${id}/payout-address`);
if (!response) {
throw new Error('Payout address response body is missing');
}
return (0, payout_1.parsePayoutAddressResponse)(response);
});
}
authSetToken(token) {
this.http.setAuthHeader(token);
}
authAuthenticate(request, useToken = true) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.post(`auth/authenticate`, request);
if (useToken) {
this.authSetToken(response.token);
}
return response;
});
}
authLogin(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`auth/login`, request);
});
}
authLogout() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.delete(`auth/logout`);
});
}
authChangePassword(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.put(`auth/password`, request);
});
}
findProposals(query) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('proposals', query);
if (!response) {
throw new Error('Proposals response body is missing');
}
return (0, proposal_1.parseProposalList)(response).proposals || [];
});
}
proposalFilterPresets() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get('proposals/filter-presets');
});
}
pricesCurrent() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get('prices/current');
});
}
pricesCurrentV2() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get('v2/prices/current');
});
}
connectionCreate(request, timeout = timeouts_1.TIMEOUT_DISABLED) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.put('connection', request, timeout);
if (!response) {
throw new Error('Connection creation response body is missing');
}
return (0, status_1.parseConnectionInfo)(response);
});
}
connectionStatus() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('connection');
if (!response) {
throw new Error('Connection status response body is missing');
}
return (0, status_1.parseConnectionInfo)(response);
});
}
connectionCancel(request) {
return __awaiter(this, void 0, void 0, function* () {
yield this.http.delete(`connection${(request === null || request === void 0 ? void 0 : request.proxyPort) !== undefined ? `?id=${request.proxyPort}` : ''}`);
});
}
connectionIp(timeout) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('connection/ip', undefined, timeout);
if (!response) {
throw new Error('Connection IP response body is missing');
}
return (0, ip_1.parseIP)(response);
});
}
connectionLocation() {
return __awaiter(this, void 0, void 0, function* () {
return yield this.http.get('connection/location');
});
}
connectionStatistics() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('connection/statistics');
if (!response) {
throw new Error('Connection statistics response body is missing');
}
return (0, statistics_1.parseConnectionStatistics)(response);
});
}
serviceList(request) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('services', { includeAll: request === null || request === void 0 ? void 0 : request.includeAll });
if (!response) {
throw new Error('Service list response body is missing');
}
return (0, service_info_1.parseServiceListResponse)(response);
});
}
serviceGet(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('services/' + id);
if (!response) {
throw new Error('Service response body is missing');
}
return (0, service_info_1.parseServiceInfo)(response);
});
}
serviceStart(request, timeout = timeouts_1.TIMEOUT_DISABLED) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.post('services', request, timeout);
if (!response) {
throw new Error('Service creation response body is missing');
}
return (0, service_info_1.parseServiceInfo)(response);
});
}
serviceStop(serviceId) {
return __awaiter(this, void 0, void 0, function* () {
yield this.http.delete('services/' + serviceId);
});
}
sessions(query) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('sessions', query);
if (!response) {
throw new Error('Sessions list response body is missing');
}
return (0, session_1.parseSessionListResponse)(response);
});
}
/**
* @deprecated use ProviderAPI
*/
sessionStatsAggregated(query) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('sessions/stats-aggregated', query);
if (!response) {
throw new Error('Session stats aggregated response body is missing');
}
return (0, session_1.parseSessionStatsAggregatedResponse)(response);
});
}
/**
* @deprecated use ProviderAPI
*/
sessionStatsDaily(query) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('sessions/stats-daily', query);
if (!response) {
throw new Error('Session stats daily response body is missing');
}
return (0, session_1.parseSessionStatsDailyResponse)(response);
});
}
accessPolicies() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('access-policies');
if (!response) {
throw new Error('Access policies response body is missing');
}
return (0, access_policy_1.parseAccessPolicyList)(response);
});
}
config() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get(exports.pathConfig);
if (!response) {
throw new Error('Config body is missing');
}
return response;
});
}
defaultConfig() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get(exports.pathConfigDefault);
if (!response) {
throw new Error('Default config body is missing');
}
return response;
});
}
userConfig() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get(exports.pathConfigUser);
if (!response) {
throw new Error('User config body is missing');
}
return response;
});
}
updateUserConfig(config) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(exports.pathConfigUser, config);
});
}
reportIssueGithub(issue, timeout) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`feedback/issue`, issue, timeout);
});
}
/**
* @deprecated use reportIssueSupport
*/
reportIssueIntercom(issue, timeout) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`feedback/issue/intercom`, issue, timeout);
});
}
reportIssueSupport(issue, timeout) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`feedback/bug-report`, issue, timeout);
});
}
transactorFees(chainId) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`transactor/fees`, { chainId });
});
}
transactorFeesV2(chainId) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`v2/transactor/fees`, { chainId });
});
}
settleSync(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`transactor/settle/sync`, request);
});
}
settleAsync(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`transactor/settle/async`, request);
});
}
settleWithBeneficiary(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`identities/${request.providerId}/beneficiary`, request);
});
}
beneficiaryTxStatus(id) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`/identities/${id}/beneficiary-status`);
});
}
chainSummary() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`/transactor/chain-summary`);
});
}
freeRegistrationEligibility(id) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`/identities/${id}/eligibility`);
});
}
freeProviderRegistrationEligibility() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`/identities/provider/eligibility`);
});
}
withdraw(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post('/transactor/settle/withdraw', request);
});
}
settleIntoStakeSync(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`transactor/stake/increase/sync`, request);
});
}
settleIntoStakeAsync(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`transactor/stake/increase/async`, request);
});
}
decreaseStake(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`transactor/stake/decrease`, request);
});
}
settlementHistory(query) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.http.get('transactor/settle/history', query);
if (!response) {
throw new Error('Settlement history response body is missing');
}
return (0, settlement_1.validateSettlementResponse)(response);
});
}
getMMNNodeReport() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`mmn/report`);
});
}
setMMNApiKey(apiKey) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.post(`mmn/api-key`, { apiKey: apiKey });
});
}
getMMNApiKey() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`mmn/api-key`);
});
}
clearMMNApiKey() {
return __awaiter(this, void 0, void 0, function* () {
return this.http.delete(`mmn/api-key`);
});
}
getReferralToken(identity) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`/identities/${identity}/referral`);
});
}
exchangeRate(quoteCurrency = 'usd') {
return __awaiter(this, void 0, void 0, function* () {
const baseCurrency = 'myst';
return this.http.get(`/exchange/${baseCurrency}/${quoteCurrency}`);
});
}
validateEthRPCL2(rpcUrls, timeout = 10000) {
return __awaiter(this, void 0, void 0, function* () {
if (rpcUrls.length == 0) {
return Promise.resolve();
}
return this.http.post('/validation/validate-rpc-chain2-urls', rpcUrls, timeout * rpcUrls.length);
});
}
estimateEntertainment(query) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`/entertainment`, Object.assign({}, query));
});
}
referralTokenRewards(token) {
return __awaiter(this, void 0, void 0, function* () {
return this.http.get(`/transactor/token/${token}/reward`);
});
}
}
class TequilapiClient extends BaseHttpTequilapiClient {
}
exports.TequilapiClient = TequilapiClient;