UNPKG

@datocms/cma-client

Version:
548 lines 18.4 kB
var __asyncValues = (this && this.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } }; import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource'; export default class Item extends BaseResource { /** * List all records * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/instances * * @throws {ApiError} * @throws {TimeoutError} */ list(queryParams) { return this.rawList(queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * List all records * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/instances * * @throws {ApiError} * @throws {TimeoutError} */ rawList(queryParams) { return this.client .request({ method: 'GET', url: '/items', queryParams, }) .then(Utils.deserializeRawResponseBodyWithItems); } listPagedIterator(queryParams, iteratorOptions) { return __asyncGenerator(this, arguments, function* listPagedIterator_1() { var _a, e_1, _b, _c; try { for (var _d = true, _e = __asyncValues(this.rawListPagedIterator(queryParams, iteratorOptions)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a;) { _c = _f.value; _d = false; try { const element = _c; yield yield __await(Utils.deserializeJsonEntity(element)); } finally { _d = true; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e)); } finally { if (e_1) throw e_1.error; } } }); } rawListPagedIterator(queryParams, iteratorOptions) { Utils.warnOnPageQueryParam(queryParams); return Utils.rawPageIterator({ defaultLimit: 30, maxLimit: 500, }, (page) => this.rawList(Object.assign(Object.assign({}, queryParams), { page })), iteratorOptions, true); } /** * Validates an existing record field * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/validate_existing * * @throws {ApiError} * @throws {TimeoutError} * * @deprecated This API call is to be considered private and might change without notice */ validateExisting(itemId, body) { return this.rawValidateExisting(Utils.toId(itemId), Utils.serializeRequestBody(body, { id: Utils.toId(itemId), type: 'item', attributes: '*', relationships: ['item_type', 'creator'], })); } /** * Validates an existing record field * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/validate_existing * * @throws {ApiError} * @throws {TimeoutError} * * @deprecated This API call is to be considered private and might change without notice */ rawValidateExisting(itemId, body) { return this.client.request({ method: 'POST', url: `/items/${itemId}/validate`, body: Utils.serializeRawRequestBodyWithItems(body), }); } /** * Validates a record field * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/validate_new * * @throws {ApiError} * @throws {TimeoutError} * * @deprecated This API call is to be considered private and might change without notice */ validateNew(body) { return this.rawValidateNew(Utils.serializeRequestBody(body, { type: 'item', attributes: '*', relationships: ['item_type', 'creator'], })); } /** * Validates a record field * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/validate_new * * @throws {ApiError} * @throws {TimeoutError} * * @deprecated This API call is to be considered private and might change without notice */ rawValidateNew(body) { return this.client.request({ method: 'POST', url: '/items/validate', body: Utils.serializeRawRequestBodyWithItems(body), }); } /** * Create a new record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/create * * @throws {ApiError} * @throws {TimeoutError} */ create(body) { return this.rawCreate(Utils.serializeRequestBody(body, { type: 'item', attributes: '*', relationships: ['item_type', 'creator'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Create a new record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/create * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate(body) { return this.client .request({ method: 'POST', url: '/items', body: Utils.serializeRawRequestBodyWithItems(body), }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Duplicate a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/duplicate * * @throws {ApiError} * @throws {TimeoutError} */ duplicate(itemId) { return this.rawDuplicate(Utils.toId(itemId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Duplicate a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/duplicate * * @throws {ApiError} * @throws {TimeoutError} */ rawDuplicate(itemId) { return this.client .request({ method: 'POST', url: `/items/${itemId}/duplicate`, }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Update a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/update * * @throws {ApiError} * @throws {TimeoutError} */ update(itemId, body) { return this.rawUpdate(Utils.toId(itemId), Utils.serializeRequestBody(body, { id: Utils.toId(itemId), type: 'item', attributes: '*', relationships: ['item_type', 'creator'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Update a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/update * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate(itemId, body) { return this.client .request({ method: 'PUT', url: `/items/${itemId}`, body: Utils.serializeRawRequestBodyWithItems(body), }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Referenced records * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/references * * @throws {ApiError} * @throws {TimeoutError} */ references(itemId, queryParams) { return this.rawReferences(Utils.toId(itemId), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Referenced records * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/references * * @throws {ApiError} * @throws {TimeoutError} */ rawReferences(itemId, queryParams) { return this.client .request({ method: 'GET', url: `/items/${itemId}/references`, queryParams, }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Retrieve a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/self * * @throws {ApiError} * @throws {TimeoutError} */ find(itemId, queryParams) { return this.rawFind(Utils.toId(itemId), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/self * * @throws {ApiError} * @throws {TimeoutError} */ rawFind(itemId, queryParams) { return this.client .request({ method: 'GET', url: `/items/${itemId}`, queryParams, }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Retrieve information regarding changes between current and published versions of the record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/current_vs_published_state * * @throws {ApiError} * @throws {TimeoutError} * * @deprecated This API call is to be considered private and might change without notice */ currentVsPublishedState(itemId) { return this.rawCurrentVsPublishedState(Utils.toId(itemId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve information regarding changes between current and published versions of the record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/current_vs_published_state * * @throws {ApiError} * @throws {TimeoutError} * * @deprecated This API call is to be considered private and might change without notice */ rawCurrentVsPublishedState(itemId) { return this.client.request({ method: 'GET', url: `/items/${itemId}/current-vs-published-state`, }); } /** * Delete a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/destroy * * @throws {ApiError} * @throws {TimeoutError} */ destroy(itemId) { return this.rawDestroy(Utils.toId(itemId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Delete a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy(itemId) { return this.client .request({ method: 'DELETE', url: `/items/${itemId}`, }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Publish a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/publish * * @throws {ApiError} * @throws {TimeoutError} */ publish(itemId, body, queryParams) { return this.rawPublish(Utils.toId(itemId), body ? Utils.serializeRequestBody(body, { type: 'selective_publish_operation', attributes: ['content_in_locales', 'non_localized_content'], relationships: [], }) : null, queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Publish a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/publish * * @throws {ApiError} * @throws {TimeoutError} */ rawPublish(itemId, body, queryParams) { return this.client .request({ method: 'PUT', url: `/items/${itemId}/publish`, body, queryParams, }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Unpublish a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/unpublish * * @throws {ApiError} * @throws {TimeoutError} */ unpublish(itemId, body, queryParams) { return this.rawUnpublish(Utils.toId(itemId), body ? Utils.serializeRequestBody(body, { type: 'selective_unpublish_operation', attributes: ['content_in_locales'], relationships: [], }) : null, queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Unpublish a record * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/unpublish * * @throws {ApiError} * @throws {TimeoutError} */ rawUnpublish(itemId, body, queryParams) { return this.client .request({ method: 'PUT', url: `/items/${itemId}/unpublish`, body, queryParams, }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Publish items in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/bulk_publish * * @throws {ApiError} * @throws {TimeoutError} */ bulkPublish(body) { return this.rawBulkPublish(Utils.serializeRequestBody(body, { type: 'item_bulk_publish_operation', attributes: [], relationships: ['items'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Publish items in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/bulk_publish * * @throws {ApiError} * @throws {TimeoutError} */ rawBulkPublish(body) { return this.client.request({ method: 'POST', url: '/items/bulk/publish', body, }); } /** * Unpublish items in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/bulk_unpublish * * @throws {ApiError} * @throws {TimeoutError} */ bulkUnpublish(body) { return this.rawBulkUnpublish(Utils.serializeRequestBody(body, { type: 'item_bulk_unpublish_operation', attributes: [], relationships: ['items'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Unpublish items in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/bulk_unpublish * * @throws {ApiError} * @throws {TimeoutError} */ rawBulkUnpublish(body) { return this.client.request({ method: 'POST', url: '/items/bulk/unpublish', body, }); } /** * Destroy items in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/bulk_destroy * * @throws {ApiError} * @throws {TimeoutError} */ bulkDestroy(body) { return this.rawBulkDestroy(Utils.serializeRequestBody(body, { type: 'item_bulk_destroy_operation', attributes: [], relationships: ['items'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Destroy items in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/bulk_destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawBulkDestroy(body) { return this.client.request({ method: 'POST', url: '/items/bulk/destroy', body, }); } /** * Move items to stage in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/bulk_move_to_stage * * @throws {ApiError} * @throws {TimeoutError} */ bulkMoveToStage(body) { return this.rawBulkMoveToStage(Utils.serializeRequestBody(body, { type: 'item_bulk_move_to_stage_operation', attributes: ['stage'], relationships: ['items'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Move items to stage in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/item/bulk_move_to_stage * * @throws {ApiError} * @throws {TimeoutError} */ rawBulkMoveToStage(body) { return this.client.request({ method: 'POST', url: '/items/bulk/move-to-stage', body, }); } } Item.TYPE = 'item'; //# sourceMappingURL=Item.js.map