UNPKG

updown.io

Version:
114 lines (113 loc) 4.26 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChecksAPI = void 0; const Endpoints_1 = require("../Endpoints"); class ChecksAPI { constructor(apiClient) { this.apiClient = apiClient; } /** * Add a new check. * @param url The URL you want to monitor. * @param options Further check adding options */ addCheck(url, options) { return __awaiter(this, void 0, void 0, function* () { const endpoint = Endpoints_1.Endpoint.checks(); const params = Object.assign({ url }, options); const { data } = yield this.apiClient.post(endpoint, params); return data; }); } /** * Delete a check. * @param token The check unique token */ deleteCheck(token) { return __awaiter(this, void 0, void 0, function* () { const endpoint = Endpoints_1.Endpoint.checks(token); const { data } = yield this.apiClient.delete(endpoint); return data; }); } /** * Show a single check. * @param token The check unique token * @param metrics Include performance metrics (last hour only) */ getCheck(token, metrics) { return __awaiter(this, void 0, void 0, function* () { const endpoint = Endpoints_1.Endpoint.Checks.check(token); const { data } = yield this.apiClient.get(endpoint, { data: { metrics } }); return data; }); } /** List all your checks. */ getChecks() { return __awaiter(this, void 0, void 0, function* () { const endpoint = Endpoints_1.Endpoint.checks(); const { data } = yield this.apiClient.get(endpoint); return data; }); } /** * Get all the downtimes of a check. * * @param token The check unique token * @param page The page to fetch (100 per page) */ getDowntimes(token, page) { return __awaiter(this, void 0, void 0, function* () { const endpoint = Endpoints_1.Endpoint.Checks.downtimes(token); const { data } = yield this.apiClient.get(endpoint, { params: { page } }); return data; }); } /** * Get detailed metrics about the check. * * Statistic are aggregated per hour which means you can't get more * precise results than this. For example all requests performed * between 5:00 and 5:59 will be reported at 5:00 in this API. * The time range needs to be at least one hour to get data. * * @param token The check unique token * @param page The page to fetch (100 per page) */ getMetrics(token, options) { return __awaiter(this, void 0, void 0, function* () { const endpoint = Endpoints_1.Endpoint.Checks.downtimes(token); const { data } = yield this.apiClient.get(endpoint, { params: options }); return data; }); } /** * Set a new API URL. * @param newURL The new API url */ setApiUrl(newURL) { this.apiClient.setBaseURL(newURL); } /** * Update a check. * @param token The check unique token * @param options Further check updating options */ updateCheck(token, options) { return __awaiter(this, void 0, void 0, function* () { const endpoint = Endpoints_1.Endpoint.checks(token); const { data } = yield this.apiClient.put(endpoint, options); return data; }); } } exports.ChecksAPI = ChecksAPI;