UNPKG

@kineticdata/react

Version:
45 lines (42 loc) 1.67 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"]; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateProfile = exports.fetchProfile = void 0; var _axios = _interopRequireDefault(require("axios")); var _helpers = require("../../helpers"); var _http = require("../http"); var getProfileEndpoint = function getProfileEndpoint() { return "".concat(_helpers.bundle.apiLocation(), "/me"); }; // Extract the profile from the data and return it. // If there are any errors clean them up and return them instead. var fetchProfile = exports.fetchProfile = function fetchProfile() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; // Build URL and fetch the space. return _axios["default"].get(getProfileEndpoint(), { params: (0, _http.paramBuilder)(options), headers: (0, _http.headerBuilder)(options) }).then(function (response) { return { profile: response.data }; })["catch"](_http.handleErrors); }; var updateProfile = exports.updateProfile = function updateProfile() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var profile = options.profile; if (!profile) { throw new Error('updateProfile failed! The option "profile" is required.'); } // Build URL and fetch the space. return _axios["default"].put(getProfileEndpoint(), profile, { params: (0, _http.paramBuilder)(options), headers: (0, _http.headerBuilder)(options) }).then(function (response) { return { profile: response.data.user }; })["catch"](_http.handleErrors); };