@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
140 lines • 3.98 kB
JavaScript
import * as Utils from '@datocms/rest-client-utils';
import BaseResource from '../../BaseResource';
export default class User extends BaseResource {
/**
* Update a collaborator
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
update(userId, body) {
return this.rawUpdate(Utils.toId(userId), Utils.serializeRequestBody(body, {
id: Utils.toId(userId),
type: 'user',
attributes: ['is_active'],
relationships: ['role'],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Update a collaborator
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawUpdate(userId, body) {
return this.client.request({
method: 'PUT',
url: `/users/${userId}`,
body,
});
}
/**
* List all collaborators
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
list() {
return this.rawList().then((body) => Utils.deserializeResponseBody(body));
}
/**
* List all collaborators
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawList() {
return this.client.request({
method: 'GET',
url: '/users',
});
}
/**
* Retrieve a collaborator
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
find(userId, queryParams) {
return this.rawFind(Utils.toId(userId), queryParams).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Retrieve a collaborator
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawFind(userId, queryParams) {
return this.client.request({
method: 'GET',
url: `/users/${userId}`,
queryParams,
});
}
/**
* Retrieve current signed-in user
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/me
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
findMe(queryParams) {
return this.rawFindMe(queryParams).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Retrieve current signed-in user
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/me
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawFindMe(queryParams) {
return this.client.request({
method: 'GET',
url: '/users/me',
queryParams,
});
}
/**
* Delete a collaborator
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
destroy(userId, queryParams) {
return this.rawDestroy(Utils.toId(userId), queryParams).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Delete a collaborator
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/user/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawDestroy(userId, queryParams) {
return this.client.request({
method: 'DELETE',
url: `/users/${userId}`,
queryParams,
});
}
}
User.TYPE = 'user';
//# sourceMappingURL=User.js.map