"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _Module2 = _interopRequireDefault(require("../Module")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function checkIt(resp) { if (parseInt(resp.status / 100, 10) === 2) { return resp; } else { throw resp; } } function catchIt(err) { if (parseInt(err.status / 500, 10) === 5) { return err; } else { return err; } } var APIService = /*#__PURE__*/ function () { function APIService(baseURL) { _classCallCheck(this, APIService); this.baseURL = baseURL; } _createClass(APIService, [{ key: "get", value: function get(url) { url = this.baseURL + url; return window.fetch(url, { method: 'GET' }).then(checkIt).then(function (r) { return r.json(); }).catch(catchIt); } }, { key: "post", value: function post(url, body) { var urb = this.baseURL + url; return window.fetch(urb, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Token': '' }, body: JSON.stringify(body) }).then(checkIt).then(function (r) { return r.json(); }).catch(catchIt); } }]); return APIService; }(); var API = /*#__PURE__*/ function (_Module) { _inherits(API, _Module); function API(props) { var _this; _classCallCheck(this, API); _this = _possibleConstructorReturn(this, _getPrototypeOf(API).call(this, props)); _this.baseURL.onUpdate(function (v) { return _this.setAPI(v); }); _this.setAPI(_this.baseURL.value); return _this; } _createClass(API, [{ key: "setAPI", value: function setAPI(v) { var temp = new APIService(v); this.api.set(temp); } }, { key: "render", value: function render() { return _get(_getPrototypeOf(API.prototype), "render", this).call(this); } }]); return API; }(_Module2.default); API.Inputs = { baseURL: { type: _Module2.default.Types.Text, required: true, comment: "API URL", defaultValue: '/' } }; API.Outputs = { api: {} }; API.Category = "Services"; var _default = API; exports.default = _default;