@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
296 lines • 10.1 kB
JavaScript
;
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 __());
};
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var Utils = __importStar(require("@datocms/rest-client-utils"));
var BaseResource_1 = __importDefault(require("../../BaseResource"));
var ItemType = /** @class */ (function (_super) {
__extends(ItemType, _super);
function ItemType() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Create a new model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.create = function (body, queryParams) {
return this.rawCreate(Utils.serializeRequestBody(body, {
type: 'item_type',
attributes: [
'name',
'api_key',
'singleton',
'all_locales_required',
'sortable',
'modular_block',
'draft_mode_active',
'draft_saving_active',
'tree',
'ordering_direction',
'ordering_meta',
'collection_appeareance',
'collection_appearance',
'hint',
'inverse_relationships_enabled',
],
relationships: [
'ordering_field',
'presentation_title_field',
'presentation_image_field',
'title_field',
'image_preview_field',
'excerpt_field',
'workflow',
],
}), queryParams).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Create a new model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.rawCreate = function (body, queryParams) {
return this.client.request({
method: 'POST',
url: '/item-types',
body: body,
queryParams: queryParams,
});
};
/**
* Update a model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.update = function (itemTypeId, body) {
return this.rawUpdate(Utils.toId(itemTypeId), Utils.serializeRequestBody(body, {
id: Utils.toId(itemTypeId),
type: 'item_type',
attributes: [
'name',
'api_key',
'collection_appeareance',
'collection_appearance',
'singleton',
'all_locales_required',
'sortable',
'modular_block',
'draft_mode_active',
'draft_saving_active',
'tree',
'ordering_direction',
'ordering_meta',
'has_singleton_item',
'hint',
'inverse_relationships_enabled',
],
relationships: [
'ordering_field',
'presentation_title_field',
'presentation_image_field',
'title_field',
'image_preview_field',
'excerpt_field',
'workflow',
],
})).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Update a model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.rawUpdate = function (itemTypeId, body) {
return this.client.request({
method: 'PUT',
url: "/item-types/".concat(itemTypeId),
body: body,
});
};
/**
* List all models
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.list = function () {
return this.rawList().then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* List all models
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.rawList = function () {
return this.client.request({
method: 'GET',
url: '/item-types',
});
};
/**
* Retrieve a model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.find = function (itemTypeId) {
return this.rawFind(Utils.toId(itemTypeId)).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Retrieve a model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.rawFind = function (itemTypeId) {
return this.client.request({
method: 'GET',
url: "/item-types/".concat(itemTypeId),
});
};
/**
* Duplicate model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/duplicate
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.duplicate = function (itemTypeId) {
return this.rawDuplicate(Utils.toId(itemTypeId)).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Duplicate model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/duplicate
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.rawDuplicate = function (itemTypeId) {
return this.client.request({
method: 'POST',
url: "/item-types/".concat(itemTypeId, "/duplicate"),
});
};
/**
* Delete a model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.destroy = function (itemTypeId, queryParams) {
return this.rawDestroy(Utils.toId(itemTypeId), queryParams).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Delete a model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
ItemType.prototype.rawDestroy = function (itemTypeId, queryParams) {
return this.client.request({
method: 'DELETE',
url: "/item-types/".concat(itemTypeId),
queryParams: queryParams,
});
};
/**
* Reorders a set of fields and fieldsets within the model
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/reorder_fields_and_fieldsets
*
* @throws {ApiError}
* @throws {TimeoutError}
*
* @deprecated This API call is to be considered private and might change without notice
*/
ItemType.prototype.rawReorderFieldsAndFieldsets = function (itemTypeId, body) {
return this.client.request({
method: 'POST',
url: "/item-types/".concat(itemTypeId, "/reorder-fields-and-fieldsets"),
body: body,
});
};
ItemType.TYPE = 'item_type';
return ItemType;
}(BaseResource_1.default));
exports.default = ItemType;
//# sourceMappingURL=ItemType.js.map