UNPKG

@apica-io/url-xi

Version:

URL Check for integrations and API monitoring

82 lines 4.18 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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.ApiController = void 0; const testConfig_1 = require("../../config/testConfig"); const testRunner_1 = require("../../processor/testRunner"); const log4js_1 = require("log4js"); const helpers = __importStar(require("../../lib/helpers")); class ApiController { constructor() { this._testConfig = new testConfig_1.TestConfig(); this._testRunner = new testRunner_1.TestRunner(this._testConfig); this._logger = (0, log4js_1.getLogger)('ApiController'); } parse(request, response) { return __awaiter(this, void 0, void 0, function* () { const ok = yield this._testConfig.create(JSON.stringify(request.body), {}); if (!ok) { const errors = this._testConfig.errors(); response.status(400).send({ error: errors }); return false; } response.status(200).send({ message: 'Parsing ok' }); return true; }); } run(request, response) { var _a, _b, _c, _d, _e; return __awaiter(this, void 0, void 0, function* () { let base_url = ((_b = (_a = request === null || request === void 0 ? void 0 : request.query) === null || _a === void 0 ? void 0 : _a.baseUrl) === null || _b === void 0 ? void 0 : _b.toString()) || ''; if (base_url) { base_url = helpers.unDotify(base_url); } let inputs = ((_d = (_c = request === null || request === void 0 ? void 0 : request.query) === null || _c === void 0 ? void 0 : _c.inputs) === null || _d === void 0 ? void 0 : _d.toString()) || ''; if (inputs && helpers.isDotedString(inputs)) inputs = helpers.unDotify(inputs); const nodata = ((_e = request === null || request === void 0 ? void 0 : request.query) === null || _e === void 0 ? void 0 : _e.nodata) == 'true'; const options = {}; options.noData = nodata; options.baseURL = base_url; options.inputs = inputs.split(','); const ok = yield this._testConfig.create(JSON.stringify(request.body), options); if (!ok) { const errors = this._testConfig.errors(); response.status(400).send({ error: errors }); return false; } const test_results = yield this._testRunner.run(options); response.status(200).send(test_results); return true; }); } } exports.ApiController = ApiController; //# sourceMappingURL=apiController.js.map