UNPKG

@datocms/cma-client

Version:
221 lines 7.13 kB
"use strict"; 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 }); const Utils = __importStar(require("@datocms/rest-client-utils")); const BaseResource_1 = __importDefault(require("../../BaseResource")); class SearchIndex extends BaseResource_1.default { /** * 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}`, }); } } exports.default = SearchIndex; SearchIndex.TYPE = 'search_index'; //# sourceMappingURL=SearchIndex.js.map