UNPKG

@contentstack/management

Version:

The Content Management API is used to manage the content of your Contentstack account

187 lines (185 loc) 6.57 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; /** * @namespace StackRoleMappings */ import cloneDeep from 'lodash/cloneDeep'; import { deleteEntity } from '../../../entity'; import error from '../../../core/contentstackError'; export function StackRoleMappings(http, data) { var _this = this; var _urlPath = "/organizations/".concat(data.organizationUid, "/teams/").concat(data.teamUid, "/stack_role_mappings"); if (data && data.stackApiKey) { Object.assign(this, cloneDeep(data)); if (this.organizationUid) this.urlPath = "".concat(_urlPath, "/").concat(this.stackApiKey); /** * @description The update stackRoleMappings call is used to update the roles. * @memberof StackRoleMappings * @func update * @param {Object} updateData - The data to update stack role mappings * @returns {Promise<Object>} Response Object. * @example * import * as contentstack from '@contentstack/management' * const client = contentstack.client() * const updateRoles = { * roles: [ * 'roles_uid1', * 'roles_uid2' * ] * } * client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').update(updateRoles) * .then((response) => console.log(response)) */ this.update = /*#__PURE__*/function () { var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(updateData) { var params, response, _args = arguments, _t; return _regeneratorRuntime.wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: params = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}; _context.prev = 1; _context.next = 2; return http.put(_this.urlPath, updateData, { params: params }); case 2: response = _context.sent; if (!response.data) { _context.next = 3; break; } return _context.abrupt("return", response.data); case 3: _context.next = 5; break; case 4: _context.prev = 4; _t = _context["catch"](1); throw error(_t); case 5: case "end": return _context.stop(); } }, _callee, null, [[1, 4]]); })); return function (_x) { return _ref.apply(this, arguments); }; }(); /** * @description The delete stackRoleMappings call is used to delete the roles. * @memberof StackRoleMappings * @func delete * @returns {Promise<Object>} Response Object. * @example * import * as contentstack from '@contentstack/management' * const client = contentstack.client() * * client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').delete() * .then((response) => console.log(response)) */ this["delete"] = deleteEntity(http); } else { this.urlPath = _urlPath; /** * @description The add stackRoleMappings call is used to add the roles. * @memberof StackRoleMappings * @func add * @returns {Promise<Object>} Response Object. * @example * import * as contentstack from '@contentstack/management' * const client = contentstack.client() * * const addRole = { * 'stackApiKey': 'stackApiKey', * 'roles': [ * 'role_uid' * ] * } * client.organization('organizationUid').teams('teamUid').stackRoleMappings().add(addRole) * .then((response) => console.log(response)) */ this.add = /*#__PURE__*/function () { var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(updateData) { var params, response, _args2 = arguments, _t2; return _regeneratorRuntime.wrap(function (_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: params = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}; _context2.prev = 1; _context2.next = 2; return http.post(_this.urlPath, updateData, { params: params }); case 2: response = _context2.sent; if (!response.data) { _context2.next = 3; break; } return _context2.abrupt("return", response.data); case 3: _context2.next = 5; break; case 4: _context2.prev = 4; _t2 = _context2["catch"](1); throw error(_t2); case 5: case "end": return _context2.stop(); } }, _callee2, null, [[1, 4]]); })); return function (_x2) { return _ref2.apply(this, arguments); }; }(); /** * @description The fetchAll stackRoleMappings call is used to fetchAll the roles. * @memberof StackRoleMappings * @func fetchAll * @returns {Promise<Object>} Response Object. * @example * import * as contentstack from '@contentstack/management' * const client = contentstack.client() * * client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll() * .then((response) => console.log(response)) */ this.fetchAll = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var response, _t3; return _regeneratorRuntime.wrap(function (_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _context3.prev = 0; _context3.next = 1; return http.get(_this.urlPath); case 1: response = _context3.sent; if (!response.data) { _context3.next = 2; break; } return _context3.abrupt("return", response.data); case 2: _context3.next = 4; break; case 3: _context3.prev = 3; _t3 = _context3["catch"](0); throw error(_t3); case 4: case "end": return _context3.stop(); } }, _callee3, null, [[0, 3]]); })); } }