UNPKG

@datocms/cma-client

Version:
192 lines 5.82 kB
import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource'; export default class SearchIndex extends BaseResource { /** * List all search indexes for a site * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/instances * * @throws {ApiError} * @throws {TimeoutError} */ list() { return this.rawList().then((body) => Utils.deserializeResponseBody(body)); } /** * List all search indexes for a site * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/instances * * @throws {ApiError} * @throws {TimeoutError} */ rawList() { return this.client.request({ method: 'GET', url: '/search-indexes', }); } /** * Retrieve a search index * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/self * * @throws {ApiError} * @throws {TimeoutError} */ find(searchIndexId) { return this.rawFind(Utils.toId(searchIndexId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve a search index * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/self * * @throws {ApiError} * @throws {TimeoutError} */ rawFind(searchIndexId) { return this.client.request({ method: 'GET', url: `/search-indexes/${searchIndexId}`, }); } /** * Create a search index * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/create * * @throws {ApiError} * @throws {TimeoutError} */ create(body) { return this.rawCreate(Utils.serializeRequestBody(body, { type: 'search_index', attributes: ['name', 'enabled', 'frontend_url', 'user_agent_suffix'], relationships: ['build_triggers'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Create a search index * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/create * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate(body) { return this.client.request({ method: 'POST', url: '/search-indexes', body, }); } /** * Update a search index * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/update * * @throws {ApiError} * @throws {TimeoutError} */ update(searchIndexId, body) { return this.rawUpdate(Utils.toId(searchIndexId), Utils.serializeRequestBody(body, { id: Utils.toId(searchIndexId), type: 'search_index', attributes: ['name', 'enabled', 'frontend_url', 'user_agent_suffix'], relationships: ['build_triggers'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Update a search index * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/update * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate(searchIndexId, body) { return this.client.request({ method: 'PUT', url: `/search-indexes/${searchIndexId}`, body, }); } /** * Trigger the indexing process * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/trigger * * @throws {ApiError} * @throws {TimeoutError} */ trigger(searchIndexId) { return this.rawTrigger(Utils.toId(searchIndexId)); } /** * Trigger the indexing process * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/trigger * * @throws {ApiError} * @throws {TimeoutError} */ rawTrigger(searchIndexId) { return this.client.request({ method: 'POST', url: `/search-indexes/${searchIndexId}/trigger`, }); } /** * Abort a the current indexing process and mark it as failed * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/abort * * @throws {ApiError} * @throws {TimeoutError} */ abort(searchIndexId) { return this.rawAbort(Utils.toId(searchIndexId)); } /** * Abort a the current indexing process and mark it as failed * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/abort * * @throws {ApiError} * @throws {TimeoutError} */ rawAbort(searchIndexId) { return this.client.request({ method: 'DELETE', url: `/search-indexes/${searchIndexId}/abort`, }); } /** * Delete a search index * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/destroy * * @throws {ApiError} * @throws {TimeoutError} */ destroy(searchIndexId) { return this.rawDestroy(Utils.toId(searchIndexId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Delete a search index * * Read more: https://www.datocms.com/docs/content-management-api/resources/search-index/destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy(searchIndexId) { return this.client.request({ method: 'DELETE', url: `/search-indexes/${searchIndexId}`, }); } } SearchIndex.TYPE = 'search_index'; //# sourceMappingURL=SearchIndex.js.map