UNPKG

@tangany/waas

Version:

node.js SDK for Tangany Wallet as a Service API

168 lines 7.98 kB
"use strict"; 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Monitor = void 0; var t = require("typeforce"); var monitor_iterable_1 = require("./iterables/auto-pagination/monitor-iterable"); var monitor_page_iterable_1 = require("./iterables/pagewise/monitor-page-iterable"); var Monitor = /** @class */ (function () { function Monitor(waas, _monitorId, _wallet) { this.waas = waas; this._monitorId = _monitorId; this._wallet = _wallet; t("?String", _monitorId); t("?String", _wallet); } Object.defineProperty(Monitor.prototype, "monitorId", { /** * Returns the monitor id or throws an error if this optional property is not set. */ get: function () { t("String", this._monitorId); return this._monitorId; }, enumerable: false, configurable: true }); Object.defineProperty(Monitor.prototype, "wallet", { /** * Returns the wallet name or throws an error if this optional property is not set. */ get: function () { t("String", this._wallet); return this._wallet; }, enumerable: false, configurable: true }); Object.defineProperty(Monitor.prototype, "baseUrlSingleResource", { /** * Returns the URL of the endpoint that represents a single monitor resource */ get: function () { return "eth/wallet/".concat(this.wallet, "/monitor/").concat(this.monitorId); }, enumerable: false, configurable: true }); Object.defineProperty(Monitor.prototype, "baseUrlResourceList", { /** * Returns the URL of the endpoint that represents the list of all monitors of the given wallet */ get: function () { return "eth/wallet/".concat(this.wallet, "/monitors"); }, enumerable: false, configurable: true }); Monitor.prototype.list = function (params, options) { var initialRequest = { url: this.baseUrlResourceList, params: params }; if (options === null || options === void 0 ? void 0 : options.autoPagination) { return new monitor_iterable_1.MonitorIterable(this.waas, initialRequest); } else { return new monitor_page_iterable_1.MonitorPageIterable(this.waas, initialRequest, this.wallet); } }; /** * Creates a new monitor based on the passed data. * @param [monitor] - Values to configure the monitor to create * @see [docs]{@link https://docs.tangany.com/#122ab4fc-d567-4fe9-aef0-7b3c332cd595} */ Monitor.prototype.create = function (monitor) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, this.waas.wrap(function () { return _this.waas.instance.post(_this.baseUrlResourceList, monitor); })]; }); }); }; /** * Requests details for the given monitor id. * @see [docs]{@link https://docs.tangany.com/#6eba3872-6c54-4168-adf8-eda38e072e25} */ Monitor.prototype.get = function () { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, this.waas.wrap(function () { return _this.waas.instance.get(_this.baseUrlSingleResource); })]; }); }); }; /** * Updates the given monitor partially. * @param newValues - Subset of properties that are allowed to be updated. Non-primitive properties like arrays or objects replace the previous value and therefore need to contain all desired values. * @see [docs]{@link https://docs.tangany.com/#13aa3fb9-a43d-42eb-83ce-fe7c1e17d021} */ Monitor.prototype.update = function (newValues) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, this.waas.wrap(function () { return _this.waas.instance.patch(_this.baseUrlSingleResource, newValues); })]; }); }); }; /** * Replaces the entire monitor. * @param newMonitorObj - Entire monitor configuration that will replace the previous resource * @see [docs]{@link https://docs.tangany.com/#b31f3bd1-26d2-48ef-b0da-aebcdc39b521} */ Monitor.prototype.replace = function (newMonitorObj) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, this.waas.wrap(function () { return _this.waas.instance.put(_this.baseUrlSingleResource, newMonitorObj); })]; }); }); }; /** * Deletes the current monitor. * @see [docs]{@link https://docs.tangany.com/#c53538bb-e6fd-4948-bcb7-cc917eab7da0} */ Monitor.prototype.delete = function () { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, this.waas.wrap(function () { return _this.waas.instance.delete(_this.baseUrlSingleResource); })]; }); }); }; return Monitor; }()); exports.Monitor = Monitor; //# sourceMappingURL=monitor.js.map