UNPKG

opennms

Version:

Client API for the OpenNMS network monitoring platform

1 lines 29.4 kB
{"remainingRequest":"/data/node_modules/babel-loader/lib/index.js!/data/node_modules/ts-loader/index.js!/data/node_modules/tslint-loader/index.js??ref--4-0!/data/src/rest/GrafanaHTTP.ts","dependencies":[{"path":"/data/src/rest/GrafanaHTTP.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/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/node_modules/lodash.clonedeep/index.js","mtime":1553611386624},{"path":"/data/src/rest/GrafanaError.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},{"path":"/data/node_modules/tslint-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\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 AbstractHTTP_1 = require(\"./AbstractHTTP\");\nvar OnmsResult_1 = require(\"../api/OnmsResult\");\nvar Log_1 = require(\"../api/Log\");\nvar typescript_logging_1 = require(\"typescript-logging\");\nvar clonedeep = require(\"lodash.clonedeep\");\nvar GrafanaError_1 = require(\"./GrafanaError\");\n/** @hidden */\nvar catGrafana = new typescript_logging_1.Category('grafana', Log_1.catRest);\n/**\n * Implementation of the [[IOnmsHTTP]] interface for Grafana.\n * @module GrafanaHTTP\n * @implements IOnmsHTTP\n */\n\nvar GrafanaHTTP = function (_AbstractHTTP_1$Abstr) {\n _inherits(GrafanaHTTP, _AbstractHTTP_1$Abstr);\n\n /**\n * Construct a new GrafanaHTTP implementation.\n * @constructor\n * @param backendSrv - The Grafana BackendSrv object to use for requests.\n * @param server - The OpenNMS server to make requests to.\n */\n function GrafanaHTTP(backendSrv, server, timeout) {\n _classCallCheck(this, GrafanaHTTP);\n\n var _this = _possibleConstructorReturn(this, (GrafanaHTTP.__proto__ || Object.getPrototypeOf(GrafanaHTTP)).call(this, server, timeout));\n\n _this.backendSrv = backendSrv;\n return _this;\n }\n /** Make an HTTP GET call using the Grafana `BackendSrv`. */\n\n\n _createClass(GrafanaHTTP, [{\n key: \"get\",\n value: function get(url, options) {\n var _this2 = this;\n\n var realUrl = this.getServer(options).resolveURL(url);\n Log_1.log.debug('GET ' + realUrl);\n var query = this.getConfig(options);\n query.method = 'GET';\n query.url = realUrl;\n return this.backendSrv.datasourceRequest(query).then(function (response) {\n var type = 'application/xml';\n if (query && query.headers && query.headers.accept) {\n type = query.headers.accept;\n }\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 (e) {\n _this2.handleError(e, query);\n });\n }\n /** Make an HTTP PUT call using the Grafana `BackendSrv`. */\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 Log_1.log.debug('PUT ' + realUrl);\n var query = this.getConfig(options);\n query.method = 'PUT';\n query.url = realUrl;\n query.data = Object.apply({}, query.parameters);\n return this.backendSrv.datasourceRequest(query).then(function (response) {\n var type = 'application/xml';\n if (query && query.headers && query.headers.accept) {\n type = query.headers.accept;\n }\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 (e) {\n _this3.handleError(e, query);\n });\n }\n /** Make an HTTP POST call using the Grafana `BackendSrv`. */\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 Log_1.log.debug('POST ' + realUrl);\n var query = this.getConfig(options);\n query.method = 'POST';\n query.url = realUrl;\n return this.backendSrv.datasourceRequest(query).then(function (response) {\n var type = 'application/xml';\n if (query && query.headers && query.headers.accept) {\n type = query.headers.accept;\n }\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 (e) {\n _this4.handleError(e, query);\n });\n }\n /** Make an HTTP DELETE call using the Grafana `BackendSrv`. */\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 Log_1.log.debug('DELETE ' + realUrl);\n var query = this.getConfig(options);\n query.method = 'DELETE';\n query.url = realUrl;\n return this.backendSrv.datasourceRequest(query).then(function (response) {\n var type = 'application/xml';\n if (query && query.headers && query.headers.accept) {\n type = query.headers.accept;\n }\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 (e) {\n _this5.handleError(e, query);\n });\n }\n /**\n * A callback to handle any request errors.\n * @hidden\n */\n\n }, {\n key: \"handleError\",\n value: function handleError(err, options) {\n var message = AbstractHTTP_1.AbstractHTTP.extractMessage(err);\n if (err && err.data && err.data.response && typeof err.data.response === 'string') {\n message = err.data.response;\n }\n var status = AbstractHTTP_1.AbstractHTTP.extractStatus(err);\n throw new GrafanaError_1.GrafanaError(message, status, options, err);\n }\n /**\n * Internal method to turn [[OnmsHTTPOptions]] into a Grafana `BackendSrv` request object.\n * @hidden\n */\n\n }, {\n key: \"getConfig\",\n value: function getConfig(options) {\n var allOptions = this.getOptions(options);\n var ret = clonedeep(allOptions.toJSON());\n ret.transformResponse = []; // we do this so we can post-process only on success\n if (allOptions.headers) {\n ret.headers = clonedeep(allOptions.headers);\n } else {\n ret.headers = {};\n }\n if (allOptions.auth && allOptions.auth.username && allOptions.auth.password) {\n ret.withCredentials = true;\n ret.headers.Authorization = 'Basic ' + btoa(allOptions.auth.username + ':' + allOptions.auth.password);\n }\n // Enforce Accept-Header\n if (!ret.headers.accept) {\n ret.headers.accept = 'application/json';\n }\n // Enforce Content-Type-Header when data is being sent\n if (ret.data && !ret.headers['content-type']) {\n ret.headers['content-type'] = 'application/json;charset=utf-8';\n }\n if (ret.parameters && Object.keys(ret.parameters).length > 0) {\n ret.params = ret.parameters;\n delete ret.parameters;\n }\n return ret;\n }\n }]);\n\n return GrafanaHTTP;\n}(AbstractHTTP_1.AbstractHTTP);\n\nexports.GrafanaHTTP = GrafanaHTTP;",{"version":3,"file":"/data/src/rest/GrafanaHTTP.ts","sourceRoot":"","sources":["/data/node_modules/tslint-loader/index.js??ref--4-0!/data/src/rest/GrafanaHTTP.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA4C;AAG5C,2BAA6C;AAG7C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AG,AAAE,AAAC,AACnB;AAAC;AAED,AAAE,AAAC,gBAAC,AAAU,WAAC,AAAI,QAAI,AAAU,WAAC,AAAI,KAAC,AAAQ,YAAI,AAAU,WAAC,AAAI,KAAC,AAAQ,AAAC,UAAC,AAAC;AAC5E,AAAG,oBAAC,AAAe,kBAAG,AAAI,AAAC;AAC3B,AAAG,oBAAC,AAAO,QAAC,AAAa,gBAAG,AAAQ,WAAG,AAAI,KAAC,AAAU,WAAC,AAAI,KAAC,AAAQ,WAAG,AAAG,MAAG,AAAU,WAAC,AAAI,KAAC,AAAQ,AAAC,AAAC,AACzG;AAAC;AAED,AAAwB;AACxB,AAAE,AAAC,gBAAC,CAAC,AAAG,IAAC,AAAO,QAAC,AAAM,AAAC,QAAC,AAAC;AACxB,AAAG,oBAAC,AAAO,QAAC,AAAM,SAAG,AAAkB,AAAC,AAC1C;AAAC;AACD,AAAsD;AACtD,AAAE,AAAC,gBAAC,AAAG,IAAC,AAAI,QAAI,CAAC,AAAG,IAAC,AAAO,QAAC,AAAc,AAAC,AAAC,iBAAC,AAAC;AAC7C,AAAG,oBAAC,AAAO,QAAC,AAAc,AAAC,kBAAG,AAAgC,AAAC,AACjE;AAAC;AACD,AAAE,AAAC,gBAAC,AAAG,IAAC,AAAU,cAAI,AAAM,OAAC,AAAI,KAAC,AAAG,IAAC,AAAU,AAAC,YAAC,AAAM,SAAG,AAAC,AAAC,GAAC,AAAC;AAC7D,AAAG,oBAAC,AAAM,SAAG,AAAG,IAAC,AAAU,AAAC;AAC5B,uBAAO,AAAG,IAAC,AAAU,AAAC,AACxB;AAAC;AACD,AAAM,mBAAC,AAAG,AAAC,AACb;AAAC,AAEF;;;;EAvJgC,eAAY;;AAA7C,sBAuJC","sourcesContent":["import {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';\n\nimport * as clonedeep from 'lodash.clonedeep';\nimport {GrafanaError} from './GrafanaError';\n\n/** @hidden */\nconst catGrafana = new Category('grafana', catRest);\n\n/**\n * Implementation of the [[IOnmsHTTP]] interface for Grafana.\n * @module GrafanaHTTP\n * @implements IOnmsHTTP\n */\nexport class GrafanaHTTP extends AbstractHTTP {\n /**\n * The Grafana backend object we'll use for making ReST calls.\n * @hidden\n */\n private backendSrv: any;\n\n /**\n * Construct a new GrafanaHTTP implementation.\n * @constructor\n * @param backendSrv - The Grafana BackendSrv object to use for requests.\n * @param server - The OpenNMS server to make requests to.\n */\n constructor(backendSrv: any, server?: OnmsServer, timeout?: number) {\n super(server, timeout);\n this.backendSrv = backendSrv;\n }\n\n /** Make an HTTP GET call using the Grafana `BackendSrv`. */\n public get(url: string, options?: OnmsHTTPOptions) {\n const realUrl = this.getServer(options).resolveURL(url);\n log.debug('GET ' + realUrl);\n const query = this.getConfig(options);\n query.method = 'GET';\n query.url = realUrl;\n return this.backendSrv.datasourceRequest(query).then((response) => {\n let type = 'application/xml';\n if (query && query.headers && query.headers.accept) {\n type = query.headers.accept;\n }\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((e) => {\n this.handleError(e, query);\n });\n }\n\n /** Make an HTTP PUT call using the Grafana `BackendSrv`. */\n public put(url: string, options?: OnmsHTTPOptions) {\n const realUrl = this.getServer(options).resolveURL(url);\n log.debug('PUT ' + realUrl);\n const query = this.getConfig(options);\n query.method = 'PUT';\n query.url = realUrl;\n query.data = Object.apply({}, query.parameters);\n return this.backendSrv.datasourceRequest(query).then((response) => {\n let type = 'application/xml';\n if (query && query.headers && query.headers.accept) {\n type = query.headers.accept;\n }\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((e) => {\n this.handleError(e, query);\n });\n }\n\n /** Make an HTTP POST call using the Grafana `BackendSrv`. */\n public post(url: string, options?: OnmsHTTPOptions) {\n const realUrl = this.getServer(options).resolveURL(url);\n log.debug('POST ' + realUrl);\n const query = this.getConfig(options);\n query.method = 'POST';\n query.url = realUrl;\n return this.backendSrv.datasourceRequest(query).then((response) => {\n let type = 'application/xml';\n if (query && query.headers && query.headers.accept) {\n type = query.headers.accept;\n }\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((e) => {\n this.handleError(e, query);\n });\n }\n\n /** Make an HTTP DELETE call using the Grafana `BackendSrv`. */\n public httpDelete(url: string, options?: OnmsHTTPOptions) {\n const realUrl = this.getServer(options).resolveURL(url);\n log.debug('DELETE ' + realUrl);\n const query = this.getConfig(options);\n query.method = 'DELETE';\n query.url = realUrl;\n return this.backendSrv.datasourceRequest(query).then((response) => {\n let type = 'application/xml';\n if (query && query.headers && query.headers.accept) {\n type = query.headers.accept;\n }\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((e) => {\n this.handleError(e, query);\n });\n }\n\n /**\n * A callback to handle any request errors.\n * @hidden\n */\n protected handleError(err: any, options?: any): never {\n let message = AbstractHTTP.extractMessage(err);\n if (err && err.data && err.data.response && (typeof (err.data.response) === 'string')) {\n message = err.data.response;\n }\n const status = AbstractHTTP.extractStatus(err);\n throw new GrafanaError(message, status, options, err);\n }\n\n /**\n * Internal method to turn [[OnmsHTTPOptions]] into a Grafana `BackendSrv` request object.\n * @hidden\n */\n private getConfig(options?: OnmsHTTPOptions): any {\n const allOptions = this.getOptions(options);\n const ret = clonedeep(allOptions.toJSON());\n ret.transformResponse = []; // we do this so we can post-process only on success\n\n if (allOptions.headers) {\n ret.headers = clonedeep(allOptions.headers);\n } else {\n ret.headers = {};\n }\n\n if (allOptions.auth && allOptions.auth.username && allOptions.auth.password) {\n ret.withCredentials = true;\n ret.headers.Authorization = 'Basic ' + btoa(allOptions.auth.username + ':' + allOptions.auth.password);\n }\n\n // Enforce Accept-Header\n if (!ret.headers.accept) {\n ret.headers.accept = 'application/json';\n }\n // Enforce Content-Type-Header when data is being sent\n if (ret.data && !ret.headers['content-type']) {\n ret.headers['content-type'] = 'application/json;charset=utf-8';\n }\n if (ret.parameters && Object.keys(ret.parameters).length > 0) {\n ret.params = ret.parameters;\n delete ret.parameters;\n }\n return ret;\n }\n\n}\n"]}]}