UNPKG

@kineticdata/react

Version:
96 lines (92 loc) 3.95 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"]; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateOAuthClient = exports.fetchOAuthClients = exports.fetchOAuthClient = exports.deleteOAuthClient = exports.createOAuthClient = void 0; var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2")); var _axios = _interopRequireDefault(require("axios")); var _helpers = require("../../helpers"); var _http = require("../http"); var buildEndpoint = function buildEndpoint(_ref) { var clientId = _ref.clientId; return clientId ? "".concat(_helpers.bundle.apiLocation(), "/oauthClients/").concat(encodeURIComponent(clientId)) : "".concat(_helpers.bundle.apiLocation(), "/oauthClients"); }; var fetchOAuthClients = exports.fetchOAuthClients = function fetchOAuthClients() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return _axios["default"].get(buildEndpoint(options), { params: (0, _objectSpread2["default"])({}, (0, _http.paramBuilder)(options)), headers: (0, _http.headerBuilder)(options) }).then(function (response) { return { oauthClients: response.data.oauthClients }; })["catch"](_http.handleErrors); }; var fetchOAuthClient = exports.fetchOAuthClient = function fetchOAuthClient() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var clientId = options.clientId; if (!clientId) { throw new Error('fetchOAuthClient failed! The option "clientId" is required.'); } return _axios["default"].get(buildEndpoint(options), { params: (0, _objectSpread2["default"])({}, (0, _http.paramBuilder)(options)), headers: (0, _http.headerBuilder)(options) }).then(function (response) { return { client: response.data.client }; })["catch"](_http.handleErrors); }; var updateOAuthClient = exports.updateOAuthClient = function updateOAuthClient() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var clientId = options.clientId, client = options.client; if (!clientId) { throw new Error('updateOAuthClient failed! The option "clientId" is required.'); } if (!client) { throw new Error('updateOAuthClient failed! The option "client" is required.'); } // Build URL and fetch the space. return _axios["default"].put(buildEndpoint(options), client, { params: (0, _http.paramBuilder)(options), headers: (0, _http.headerBuilder)(options) }).then(function (response) { return { client: response.data.client }; })["catch"](_http.handleErrors); }; var createOAuthClient = exports.createOAuthClient = function createOAuthClient() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var client = options.client; if (!client) { throw new Error('updateOAuthClient failed! The option "client" is required.'); } // Build URL and fetch the space. return _axios["default"].post(buildEndpoint(options), client, { params: (0, _http.paramBuilder)(options), headers: (0, _http.headerBuilder)(options) }).then(function (response) { return { client: response.data.client }; })["catch"](_http.handleErrors); }; var deleteOAuthClient = exports.deleteOAuthClient = function deleteOAuthClient() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var clientId = options.clientId; if (!clientId) { throw new Error('deleteOAuthClient failed! The option "clientId" is required.'); } // Build URL and fetch the space. return _axios["default"]["delete"](buildEndpoint(options), { params: (0, _http.paramBuilder)(options), headers: (0, _http.headerBuilder)(options) }).then(function (response) { return { client: response.data.client }; })["catch"](_http.handleErrors); };