@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
229 lines • 7.22 kB
JavaScript
import * as Utils from '@datocms/rest-client-utils';
import BaseResource from '../../BaseResource';
export default class Role extends BaseResource {
/**
* Create a new role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
create(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_search_indexes',
'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',
'can_access_search_index_events_log',
'positive_item_type_permissions',
'negative_item_type_permissions',
'positive_upload_permissions',
'negative_upload_permissions',
'positive_build_trigger_permissions',
'negative_build_trigger_permissions',
'positive_search_index_permissions',
'negative_search_index_permissions',
],
relationships: ['inherits_permissions_from'],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Create a new role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawCreate(body) {
return this.client.request({
method: 'POST',
url: '/roles',
body,
});
}
/**
* Update a role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
update(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_search_indexes',
'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',
'can_access_search_index_events_log',
'positive_item_type_permissions',
'negative_item_type_permissions',
'positive_upload_permissions',
'negative_upload_permissions',
'positive_build_trigger_permissions',
'negative_build_trigger_permissions',
'positive_search_index_permissions',
'negative_search_index_permissions',
],
relationships: ['inherits_permissions_from'],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Update a role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawUpdate(roleId, body) {
return this.client.request({
method: 'PUT',
url: `/roles/${roleId}`,
body,
});
}
/**
* List all roles
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
list() {
return this.rawList().then((body) => Utils.deserializeResponseBody(body));
}
/**
* List all roles
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawList() {
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}
*/
find(roleId) {
return this.rawFind(Utils.toId(roleId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Retrieve a role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawFind(roleId) {
return this.client.request({
method: 'GET',
url: `/roles/${roleId}`,
});
}
/**
* Delete a role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
destroy(roleId) {
return this.rawDestroy(Utils.toId(roleId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Delete a role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawDestroy(roleId) {
return this.client.request({
method: 'DELETE',
url: `/roles/${roleId}`,
});
}
/**
* Duplicate a role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/duplicate
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
duplicate(roleId) {
return this.rawDuplicate(Utils.toId(roleId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Duplicate a role
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/duplicate
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawDuplicate(roleId) {
return this.client.request({
method: 'POST',
url: `/roles/${roleId}/duplicate`,
});
}
}
Role.TYPE = 'role';
//# sourceMappingURL=Role.js.map