@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
184 lines • 5.15 kB
JavaScript
import * as Utils from '@datocms/rest-client-utils';
import BaseResource from '../../BaseResource';
export default class Plugin extends BaseResource {
/**
* Create a new plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
create(body) {
return this.rawCreate(Utils.serializeRequestBody(body, {
type: 'plugin',
attributes: [
'package_name',
'name',
'description',
'url',
'permissions',
'plugin_type',
'field_types',
'parameter_definitions',
'package_version',
],
relationships: [],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Create a new plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawCreate(body) {
return this.client.request({
method: 'POST',
url: '/plugins',
body,
});
}
/**
* Update a plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
update(pluginId, body) {
return this.rawUpdate(Utils.toId(pluginId), Utils.serializeRequestBody(body, {
id: Utils.toId(pluginId),
type: 'plugin',
attributes: [
'name',
'description',
'url',
'parameters',
'package_version',
'permissions',
],
relationships: [],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Update a plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawUpdate(pluginId, body) {
return this.client.request({
method: 'PUT',
url: `/plugins/${pluginId}`,
body,
});
}
/**
* List all plugins
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
list() {
return this.rawList().then((body) => Utils.deserializeResponseBody(body));
}
/**
* List all plugins
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawList() {
return this.client.request({
method: 'GET',
url: '/plugins',
});
}
/**
* Retrieve a plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
find(pluginId) {
return this.rawFind(Utils.toId(pluginId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Retrieve a plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawFind(pluginId) {
return this.client.request({
method: 'GET',
url: `/plugins/${pluginId}`,
});
}
/**
* Delete a plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
destroy(pluginId) {
return this.rawDestroy(Utils.toId(pluginId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Delete a plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawDestroy(pluginId) {
return this.client.request({
method: 'DELETE',
url: `/plugins/${pluginId}`,
});
}
/**
* Retrieve all fields using the plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/fields
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
fields(pluginId) {
return this.rawFields(Utils.toId(pluginId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Retrieve all fields using the plugin
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/plugin/fields
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawFields(pluginId) {
return this.client.request({
method: 'GET',
url: `/plugins/${pluginId}/fields`,
});
}
}
Plugin.TYPE = 'plugin';
//# sourceMappingURL=Plugin.js.map