UNPKG

opennms

Version:

Client API for the OpenNMS network monitoring platform

1 lines 34.6 kB
{"remainingRequest":"/data/node_modules/babel-loader/lib/index.js!/data/node_modules/ts-loader/index.js!/data/src/rest/AxiosHTTP.ts","dependencies":[{"path":"/data/src/rest/AxiosHTTP.ts","mtime":1553611371628},{"path":"/data/node_modules/typescript-logging/dist/commonjs/typescript-logging.d.ts","mtime":1553611387808},{"path":"/data/node_modules/typescript-logging/dist/commonjs/control/LogGroupControl.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/control/CategoryServiceControl.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/MessagesToExtensionJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/MessagesFromExtensionJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/ExtensionMessageJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/ExtensionHelper.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/AbstractCategoryLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/LoggerOptions.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryService.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryConsoleLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryDelegateLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryMessageBufferImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/Logger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactory.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactoryService.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactoryRuntimeSettings.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/AbstractLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/ConsoleLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/MessageBufferLoggerImpl.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/DataStructures.d.ts","mtime":1553611387936},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/JSONHelper.d.ts","mtime":1553611387936},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/MessageUtils.d.ts","mtime":1553611387936},{"path":"/data/node_modules/moment/moment.d.ts","mtime":1553611386704},{"path":"/data/node_modules/axios/index.d.ts","mtime":1553611386356},{"path":"/data/typings/index.d.ts","mtime":1553611371628},{"path":"/data/node_modules/@types/fs-extra/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/node/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/node/inspector.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/glob/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/minimatch/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/glob/node_modules/@types/minimatch/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/handlebars/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/highlight.js/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/jest/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/jquery/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/lodash/index.d.ts","mtime":1553611386320},{"path":"/data/node_modules/@types/lodash/common/common.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/array.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/collection.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/date.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/function.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/lang.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/math.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/number.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/object.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/seq.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/string.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/util.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/marked/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/shelljs/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/urijs/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/typescript/lib/lib.es2015.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.core.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.collection.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.generator.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.promise.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.iterable.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.symbol.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.proxy.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.reflect.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es5.d.ts","mtime":1553611387388},{"path":"/data/node_modules/typescript/lib/lib.dom.d.ts","mtime":1553611387384},{"path":"/data/node_modules/axios/index.d.ts","mtime":1553611386356},{"path":"/data/node_modules/axios/index.d.ts","mtime":1553611386356},{"path":"/data/node_modules/qs/lib/index.js","mtime":1553611387280},{"path":"/data/node_modules/lodash.clonedeep/index.js","mtime":1553611386624},{"path":"/data/src/rest/AbstractHTTP.ts","mtime":1553611371628},{"path":"/data/src/api/OnmsError.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsHTTPOptions.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsResult.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsServer.ts","mtime":1553611371624},{"path":"/data/src/api/Log.ts","mtime":1553611371624},{"path":"/data/node_modules/typescript-logging/dist/commonjs/typescript-logging.d.ts","mtime":1553611387808},{"path":"/data/src/internal/Util.ts","mtime":1553611371628},{"path":"/data/.babelrc","mtime":1553611371556},{"path":"/data/node_modules/cache-loader/dist/cjs.js","mtime":1553611387012},{"path":"/data/node_modules/babel-loader/lib/index.js","mtime":1553611386992},{"path":"/data/node_modules/ts-loader/index.js","mtime":1553611386824}],"contextDependencies":[],"result":["\"use strict\";\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if (\"value\" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar axios_1 = require(\"axios\");\nvar clonedeep = require(\"lodash.clonedeep\");\n/** @hidden */\n// tslint:disable-next-line\nvar URI = require('urijs');\nvar AbstractHTTP_1 = require(\"./AbstractHTTP\");\nvar OnmsError_1 = require(\"../api/OnmsError\");\nvar OnmsResult_1 = require(\"../api/OnmsResult\");\nvar Log_1 = require(\"../api/Log\");\nvar typescript_logging_1 = require(\"typescript-logging\");\n/** @hidden */\nvar catAxios = new typescript_logging_1.Category('axios', Log_1.catRest);\n/**\n * Implementation of the [[IOnmsHTTP]] interface using Axios: https://github.com/mzabriskie/axios\n * @module AxiosHTTP\n * @implements IOnmsHTTP\n */\n\nvar AxiosHTTP = function (_AbstractHTTP_1$Abstr) {\n _inherits(AxiosHTTP, _AbstractHTTP_1$Abstr);\n\n /**\n * Construct an AxiosHTTP instance.\n * @param server - The server to connect to.\n * @param axiosImpl - The Axios implementation class to use.\n * @param timeout - The default timeout for ReST connections.\n */\n function AxiosHTTP(server, axiosImpl) {\n var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10000;\n\n _classCallCheck(this, AxiosHTTP);\n\n var _this = _possibleConstructorReturn(this, (AxiosHTTP.__proto__ || Object.getPrototypeOf(AxiosHTTP)).call(this, server, timeout));\n\n _this.axiosImpl = axiosImpl || axios_1.default;\n return _this;\n }\n /**\n * Make an HTTP GET call using `axios.request({method:'get'})`.\n */\n\n\n _createClass(AxiosHTTP, [{\n key: \"get\",\n value: function get(url, options) {\n var _this2 = this;\n\n var realUrl = this.getServer(options).resolveURL(url);\n var opts = this.getConfig(options);\n var urlObj = new URI(realUrl);\n urlObj.search(opts.params);\n Log_1.log.debug('GET ' + urlObj.toString(), catAxios);\n opts.method = 'get';\n opts.url = realUrl;\n return this.getImpl(options).request(opts).then(function (response) {\n var type = void 0;\n if (response.headers && response.headers['content-type']) {\n type = response.headers['content-type'];\n }\n return OnmsResult_1.OnmsResult.ok(_this2.getData(response), undefined, response.status, type);\n }).catch(function (err) {\n throw _this2.handleError(err, opts);\n });\n }\n /**\n * Make an HTTP PUT call using `axios.request({method:'put'})`.\n */\n\n }, {\n key: \"put\",\n value: function put(url, options) {\n var _this3 = this;\n\n var realUrl = this.getServer(options).resolveURL(url);\n var opts = this.getConfig(options);\n var urlObj = new URI(realUrl);\n urlObj.search(opts.params);\n Log_1.log.debug('PUT ' + urlObj.toString(), catAxios);\n opts.data = Object.apply({}, opts.params);\n opts.method = 'put';\n opts.url = realUrl;\n return this.getImpl(options).request(opts).then(function (response) {\n var type = void 0;\n if (response.headers && response.headers['content-type']) {\n type = response.headers['content-type'];\n }\n return OnmsResult_1.OnmsResult.ok(_this3.getData(response), undefined, response.status, type);\n }).catch(function (err) {\n throw _this3.handleError(err, opts);\n });\n }\n /**\n * Make an HTTP POST call using `axios.request({method:'post'})`.\n */\n\n }, {\n key: \"post\",\n value: function post(url, options) {\n var _this4 = this;\n\n var realUrl = this.getServer(options).resolveURL(url);\n var opts = this.getConfig(options);\n var urlObj = new URI(realUrl);\n urlObj.search(opts.params);\n Log_1.log.debug('POST ' + urlObj.toString(), catAxios);\n opts.method = 'post';\n opts.url = realUrl;\n return this.getImpl(options).request(opts).then(function (response) {\n var type = void 0;\n if (response.headers && response.headers['content-type']) {\n type = response.headers['content-type'];\n }\n return OnmsResult_1.OnmsResult.ok(_this4.getData(response), undefined, response.status, type);\n }).catch(function (err) {\n throw _this4.handleError(err, opts);\n });\n }\n /**\n * Make an HTTP DELETE call using `axios.request({method:'delete'})`.\n */\n\n }, {\n key: \"httpDelete\",\n value: function httpDelete(url, options) {\n var _this5 = this;\n\n var realUrl = this.getServer(options).resolveURL(url);\n var opts = this.getConfig(options);\n var urlObj = new URI(realUrl);\n urlObj.search(opts.params);\n Log_1.log.debug('DELETE ' + urlObj.toString(), catAxios);\n opts.method = 'delete';\n opts.url = realUrl;\n return this.getImpl(options).request(opts).then(function (response) {\n var type = void 0;\n if (response.headers && response.headers['content-type']) {\n type = response.headers['content-type'];\n }\n return OnmsResult_1.OnmsResult.ok(_this5.getData(response), undefined, response.status, type);\n }).catch(function (err) {\n throw _this5.handleError(err, opts);\n });\n }\n /**\n * Clear the current [[AxiosInstance]] so it is recreated on next request with the\n * new server configuration.\n */\n\n }, {\n key: \"onSetServer\",\n value: function onSetServer() {\n _get(AxiosHTTP.prototype.__proto__ || Object.getPrototypeOf(AxiosHTTP.prototype), \"onSetServer\", this).call(this);\n this.axiosObj = undefined;\n }\n /**\n * Internal method to turn [[OnmsHTTPOptions]] into an [[AxiosRequestConfig]] object.\n * @hidden\n */\n\n }, {\n key: \"getConfig\",\n value: function getConfig(options) {\n var allOptions = this.getOptions(options);\n var ret = {\n transformResponse: []\n };\n if (allOptions.auth && allOptions.auth.username && allOptions.auth.password) {\n ret.auth = {\n password: allOptions.auth.password,\n username: allOptions.auth.username\n };\n }\n if (allOptions.timeout) {\n ret.timeout = allOptions.timeout;\n }\n if (allOptions.headers) {\n ret.headers = clonedeep(allOptions.headers);\n } else {\n ret.headers = {};\n }\n if (!ret.headers.accept) {\n ret.headers.accept = 'application/json';\n }\n if (!ret.headers['content-type']) {\n ret.headers['content-type'] = 'application/json;charset=utf-8';\n }\n var type = ret.headers.accept;\n ret.transformResponse = [];\n if (type === 'application/json') {\n ret.responseType = 'json';\n } else if (type === 'text/plain') {\n ret.responseType = 'text';\n } else if (type === 'application/xml') {\n ret.responseType = 'text';\n } else {\n throw new OnmsError_1.OnmsError('Unhandled \"Accept\" header: ' + type);\n }\n if (allOptions.parameters) {\n ret.params = clonedeep(allOptions.parameters);\n }\n if (allOptions.data) {\n ret.data = clonedeep(allOptions.data);\n }\n return ret;\n }\n /**\n * Internal method for getting/constructing an Axios object on-demand,\n * based on the current server configuration.\n * @hidden\n */\n\n }, {\n key: \"getImpl\",\n value: function getImpl(options) {\n if (!this.axiosObj) {\n var server = this.getServer(options);\n if (!server) {\n throw new OnmsError_1.OnmsError('You must set a server before attempting to make queries using Axios!');\n }\n var allOptions = this.getOptions(options);\n var axiosOpts = {\n auth: {\n password: allOptions.auth.password,\n username: allOptions.auth.username\n },\n baseURL: server.url,\n timeout: allOptions.timeout,\n withCredentials: true\n };\n if (typeof XMLHttpRequest !== 'undefined') {\n axiosOpts.adapter = require('axios/lib/adapters/xhr.js');\n } else if (typeof process !== 'undefined') {\n axiosOpts.adapter = require('axios/lib/adapters/http.js');\n }\n this.axiosObj = this.axiosImpl.create(axiosOpts);\n }\n return this.axiosObj;\n }\n }]);\n\n return AxiosHTTP;\n}(AbstractHTTP_1.AbstractHTTP);\n\nexports.AxiosHTTP = AxiosHTTP;",{"version":3,"file":"/data/src/rest/AxiosHTTP.ts","sourceRoot":"","sources":["/data/src/rest/AxiosHTTP.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,sBAA0B;AAG1B,wBAA8C;AAE9C,AAAc;AACd,AAA2B;AAC3B,IAAM,AAAG,MAAG,AAAO,QAAC,AAAO,AAAC,AAAC;AAE7B,6BAA4C;AAC5C,0BAA2C;AAE3C,2BAA6C;AAG7C,oBAAwC;AACxC,mCAA4C;AAG5C,AAAc;AACd,IAAM,AAAQ,WAAG,IAAI,qBAAQ,SAAC,AAAO,SAAE,MAAO,AAAC,AAAC;AAEhD,AAIG,AACH;;;;;;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,0BAAM,IAAI,YAAS,UAAC,AAAsE,AAAC,AAAC,AAC9F;AAAC;AACD,oBAAM,AAAU,aAAG,AAAI,KAAC,AAAU,WAAC,AAAO,AAAC,AAAC;AAE5C,oBAAM,AAAS;AACb,AAAI;AACF,AAAQ,kCAAE,AAAU,WAAC,AAAI,KAAC,AAAQ;AAClC,AAAQ,kCAAE,AAAU,WAAC,AAAI,KAAC,AAAQ,AACnC;AAHK;AAIN,AAAO,6BAAE,AAAM,OAAC,AAAG;AACnB,AAAO,6BAAE,AAAU,WAAC,AAAO;AAC3B,AAAe,qCAAE,AAAI,AACA,AAAC;AARN;AAUlB,AAAE,AAAC,oBAAC,OAAO,AAAc,mBAAK,AAAW,AAAC,aAAC,AAAC;AAC1C,AAAS,8BAAC,AAAO,UAAG,AAAO,QAAC,AAA2B,AAAC,AAAC,AAC3D;AAAC,AAAC,AAAI,uBAAC,AAAE,AAAC,IAAC,OAAO,AAAO,YAAK,AAAW,AAAC,aAAC,AAAC;AAC1C,AAAS,8BAAC,AAAO,UAAG,AAAO,QAAC,AAA4B,AAAC,AAAC,AAC5D;AAAC;AAED,AAAI,qBAAC,AAAQ,WAAG,AAAI,KAAC,AAAS,UAAC,AAAM,OAAC,AAAS,AAAC,AAAC,AACnD;AAAC;AACD,AAAM,mBAAC,AAAI,KAAC,AAAQ,AAAC,AACvB;AAAC,AAEF;;;;EApO8B,eAAY;;AAA3C,oBAoOC","sourcesContent":["import axios from 'axios';\nimport {AxiosStatic, AxiosInstance, AxiosResponse, AxiosRequestConfig} from 'axios';\nimport * as qs from 'qs';\nimport * as clonedeep from 'lodash.clonedeep';\n\n/** @hidden */\n// tslint:disable-next-line\nconst URI = require('urijs');\n\nimport {AbstractHTTP} from './AbstractHTTP';\nimport {OnmsError} from '../api/OnmsError';\nimport {OnmsHTTPOptions} from '../api/OnmsHTTPOptions';\nimport {OnmsResult} from '../api/OnmsResult';\nimport {OnmsServer} from '../api/OnmsServer';\n\nimport {log, catRest} from '../api/Log';\nimport {Category} from 'typescript-logging';\nimport {Util} from '../internal/Util';\n\n/** @hidden */\nconst catAxios = new Category('axios', catRest);\n\n/**\n * Implementation of the [[IOnmsHTTP]] interface using Axios: https://github.com/mzabriskie/axios\n * @module AxiosHTTP\n * @implements IOnmsHTTP\n */\nexport class AxiosHTTP extends AbstractHTTP {\n /**\n * The Axios implementation class we'll use for making ReST calls. This is necessary\n * to make sure we end up with the correct backend (XMLHttpRequest or Node.js 'http')\n * at runtime.\n * @hidden\n */\n private axiosImpl: AxiosStatic;\n\n /**\n * The Axios instance we'll use for making ReST calls. This will be reinitialized whenever\n * the server configuration changes.\n */\n private axiosObj: AxiosInstance;\n\n /**\n * Construct an AxiosHTTP instance.\n * @param server - The server to connect to.\n * @param axiosImpl - The Axios implementation class to use.\n * @param timeout - The default timeout for ReST connections.\n */\n constructor(server?: OnmsServer, axiosImpl?: AxiosStatic, timeout = 10000) {\n super(server, timeout);\n this.axiosImpl = axiosImpl || axios;\n }\n\n /**\n * Make an HTTP GET call using `axios.request({method:'get'})`.\n */\n public get(url: string, options?: OnmsHTTPOptions) {\n const realUrl = this.getServer(options).resolveURL(url);\n const opts = this.getConfig(options);\n\n const urlObj = new URI(realUrl);\n urlObj.search(opts.params);\n log.debug('GET ' + urlObj.toString(), catAxios);\n\n opts.method = 'get';\n opts.url = realUrl;\n\n return this.getImpl(options).request(opts).then((response) => {\n let type;\n if (response.headers && response.headers['content-type']) {\n type = response.headers['content-type'];\n }\n return OnmsResult.ok(this.getData(response), undefined, response.status, type);\n }).catch((err) => {\n throw this.handleError(err, opts);\n });\n }\n\n /**\n * Make an HTTP PUT call using `axios.request({method:'put'})`.\n */\n public put(url: string, options?: OnmsHTTPOptions) {\n const realUrl = this.getServer(options).resolveURL(url);\n const opts = this.getConfig(options);\n\n const urlObj = new URI(realUrl);\n urlObj.search(opts.params);\n log.debug('PUT ' + urlObj.toString(), catAxios);\n\n opts.data = Object.apply({}, opts.params);\n opts.method = 'put';\n opts.url = realUrl;\n\n return this.getImpl(options).request(opts).then((response) => {\n let type;\n if (response.headers && response.headers['content-type']) {\n type = response.headers['content-type'];\n }\n return OnmsResult.ok(this.getData(response), undefined, response.status, type);\n }).catch((err) => {\n throw this.handleError(err, opts);\n });\n }\n\n /**\n * Make an HTTP POST call using `axios.request({method:'post'})`.\n */\n public post(url: string, options?: OnmsHTTPOptions) {\n const realUrl = this.getServer(options).resolveURL(url);\n const opts = this.getConfig(options);\n\n const urlObj = new URI(realUrl);\n urlObj.search(opts.params);\n log.debug('POST ' + urlObj.toString(), catAxios);\n\n opts.method = 'post';\n opts.url = realUrl;\n\n return this.getImpl(options).request(opts).then((response) => {\n let type;\n if (response.headers && response.headers['content-type']) {\n type = response.headers['content-type'];\n }\n return OnmsResult.ok(this.getData(response), undefined, response.status, type);\n }).catch((err) => {\n throw this.handleError(err, opts);\n });\n }\n\n /**\n * Make an HTTP DELETE call using `axios.request({method:'delete'})`.\n */\n public httpDelete(url: string, options?: OnmsHTTPOptions) {\n const realUrl = this.getServer(options).resolveURL(url);\n const opts = this.getConfig(options);\n\n const urlObj = new URI(realUrl);\n urlObj.search(opts.params);\n log.debug('DELETE ' + urlObj.toString(), catAxios);\n\n opts.method = 'delete';\n opts.url = realUrl;\n\n return this.getImpl(options).request(opts).then((response) => {\n let type;\n if (response.headers && response.headers['content-type']) {\n type = response.headers['content-type'];\n }\n return OnmsResult.ok(this.getData(response), undefined, response.status, type);\n }).catch((err) => {\n throw this.handleError(err, opts);\n });\n }\n\n /**\n * Clear the current [[AxiosInstance]] so it is recreated on next request with the\n * new server configuration.\n */\n protected onSetServer() {\n super.onSetServer();\n this.axiosObj = undefined;\n }\n\n /**\n * Internal method to turn [[OnmsHTTPOptions]] into an [[AxiosRequestConfig]] object.\n * @hidden\n */\n private getConfig(options?: OnmsHTTPOptions): AxiosRequestConfig {\n const allOptions = this.getOptions(options);\n\n const ret = {\n transformResponse: [], // we do this so we can post-process only on success\n } as AxiosRequestConfig;\n\n if (allOptions.auth && allOptions.auth.username && allOptions.auth.password) {\n ret.auth = {\n password: allOptions.auth.password,\n username: allOptions.auth.username,\n };\n }\n\n if (allOptions.timeout) {\n ret.timeout = allOptions.timeout;\n }\n\n if (allOptions.headers) {\n ret.headers = clonedeep(allOptions.headers);\n } else {\n ret.headers = {};\n }\n\n if (!ret.headers.accept) {\n ret.headers.accept = 'application/json';\n }\n if (!ret.headers['content-type']) {\n ret.headers['content-type'] = 'application/json;charset=utf-8';\n }\n\n const type = ret.headers.accept;\n ret.transformResponse = [];\n if (type === 'application/json') {\n ret.responseType = 'json';\n } else if (type === 'text/plain') {\n ret.responseType = 'text';\n } else if (type === 'application/xml') {\n ret.responseType = 'text';\n } else {\n throw new OnmsError('Unhandled \"Accept\" header: ' + type);\n }\n\n if (allOptions.parameters) {\n ret.params = clonedeep(allOptions.parameters);\n }\n\n if (allOptions.data) {\n ret.data = clonedeep(allOptions.data);\n }\n\n return ret;\n }\n\n /**\n * Internal method for getting/constructing an Axios object on-demand,\n * based on the current server configuration.\n * @hidden\n */\n private getImpl(options?: OnmsHTTPOptions) {\n if (!this.axiosObj) {\n const server = this.getServer(options);\n if (!server) {\n throw new OnmsError('You must set a server before attempting to make queries using Axios!');\n }\n const allOptions = this.getOptions(options);\n\n const axiosOpts = {\n auth: {\n password: allOptions.auth.password,\n username: allOptions.auth.username,\n },\n baseURL: server.url,\n timeout: allOptions.timeout,\n withCredentials: true,\n } as AxiosRequestConfig;\n\n if (typeof XMLHttpRequest !== 'undefined') {\n axiosOpts.adapter = require('axios/lib/adapters/xhr.js');\n } else if (typeof process !== 'undefined') {\n axiosOpts.adapter = require('axios/lib/adapters/http.js');\n }\n\n this.axiosObj = this.axiosImpl.create(axiosOpts);\n }\n return this.axiosObj;\n }\n\n}\n"]}]}