UNPKG

@datocms/cma-client

Version:
254 lines 8.37 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource'; var Role = /** @class */ (function (_super) { __extends(Role, _super); function Role() { return _super !== null && _super.apply(this, arguments) || this; } /** * Create a new role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/create * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.create = function (body) { return this.rawCreate(Utils.serializeRequestBody(body, { type: 'role', attributes: [ 'name', 'can_edit_favicon', 'can_edit_site', 'can_edit_schema', 'can_manage_menu', 'can_edit_environment', 'can_promote_environments', 'environments_access', 'can_manage_users', 'can_manage_shared_filters', 'can_manage_upload_collections', 'can_manage_build_triggers', 'can_manage_webhooks', 'can_manage_environments', 'can_manage_sso', 'can_access_audit_log', 'can_manage_workflows', 'can_manage_access_tokens', 'can_perform_site_search', 'can_access_build_events_log', 'positive_item_type_permissions', 'negative_item_type_permissions', 'positive_upload_permissions', 'negative_upload_permissions', 'positive_build_trigger_permissions', 'negative_build_trigger_permissions', ], relationships: ['inherits_permissions_from'], })).then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Create a new role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/create * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.rawCreate = function (body) { return this.client.request({ method: 'POST', url: '/roles', body: body, }); }; /** * Update a role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/update * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.update = function (roleId, body) { return this.rawUpdate(Utils.toId(roleId), Utils.serializeRequestBody(body, { id: Utils.toId(roleId), type: 'role', attributes: [ 'name', 'can_edit_favicon', 'can_edit_site', 'can_edit_schema', 'can_manage_menu', 'can_edit_environment', 'can_promote_environments', 'environments_access', 'can_manage_users', 'can_manage_shared_filters', 'can_manage_upload_collections', 'can_manage_build_triggers', 'can_manage_webhooks', 'can_manage_environments', 'can_manage_sso', 'can_access_audit_log', 'can_manage_workflows', 'can_manage_access_tokens', 'can_perform_site_search', 'can_access_build_events_log', 'positive_item_type_permissions', 'negative_item_type_permissions', 'positive_upload_permissions', 'negative_upload_permissions', 'positive_build_trigger_permissions', 'negative_build_trigger_permissions', ], relationships: ['inherits_permissions_from'], })).then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Update a role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/update * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.rawUpdate = function (roleId, body) { return this.client.request({ method: 'PUT', url: "/roles/".concat(roleId), body: body, }); }; /** * List all roles * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/instances * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.list = function () { return this.rawList().then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * List all roles * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/instances * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.rawList = function () { return this.client.request({ method: 'GET', url: '/roles', }); }; /** * Retrieve a role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/self * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.find = function (roleId) { return this.rawFind(Utils.toId(roleId)).then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Retrieve a role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/self * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.rawFind = function (roleId) { return this.client.request({ method: 'GET', url: "/roles/".concat(roleId), }); }; /** * Delete a role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/destroy * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.destroy = function (roleId) { return this.rawDestroy(Utils.toId(roleId)).then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Delete a role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/destroy * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.rawDestroy = function (roleId) { return this.client.request({ method: 'DELETE', url: "/roles/".concat(roleId), }); }; /** * Duplicate a role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/duplicate * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.duplicate = function (roleId) { return this.rawDuplicate(Utils.toId(roleId)).then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Duplicate a role * * Read more: https://www.datocms.com/docs/content-management-api/resources/role/duplicate * * @throws {ApiError} * @throws {TimeoutError} */ Role.prototype.rawDuplicate = function (roleId) { return this.client.request({ method: 'POST', url: "/roles/".concat(roleId, "/duplicate"), }); }; Role.TYPE = 'role'; return Role; }(BaseResource)); export default Role; //# sourceMappingURL=Role.js.map