UNPKG

@coveo/platform-client

Version:

The main goal of this package is to provide an easy to configure and straightforward way of querying Coveo Cloud APIs using JavaScript.

99 lines 4.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const APICore_js_1 = tslib_1.__importDefault(require("../../APICore.js")); const Resource_js_1 = tslib_1.__importDefault(require("../Resource.js")); class Search extends Resource_js_1.default { static baseUrl = `/rest/search/v2`; createToken(tokenParams) { return this.api.post(`${Search.baseUrl}/token?organizationId=${APICore_js_1.default.orgPlaceholder}`, tokenParams); } listFields(params) { return this.api.get(this.buildPath(`${Search.baseUrl}/fields`, { ...params, organizationId: params?.organizationId ?? this.api.organizationId, }, { skipEmptyString: false })); } getFieldValues(fieldName, params) { return this.api.get(this.buildPath(`${Search.baseUrl}/values`, { field: encodeURI(`${fieldName}`), ...params, organizationId: params?.organizationId ?? this.api.organizationId, })); } // For more info about restQueryParameters values available // See: https://platform.cloud.coveo.com/docs?api=SearchApi#!/Search/post_rest_search_v2 // or : https://docs.coveo.com/en/13/cloud-v2-api-reference/search-api#operation/searchUsingGet query(restQueryParameters) { const { viewAllContent, ...bodyParameters } = restQueryParameters; return this.api.post(this.buildPath(Search.baseUrl, { organizationId: this.api.organizationId, viewAllContent: viewAllContent ? 1 : undefined, }), bodyParameters); } /** * Exports search results to a Microsoft Excel™ spreadsheet * @param restQueryParameters Parameters of the query * @returns A .xlsx file containing the search results of the specified query */ exportQuery(restQueryParameters) { const { viewAllContent, ...bodyParameters } = restQueryParameters; return this.api.post(this.buildPath(Search.baseUrl, { organizationId: this.api.organizationId, viewAllContent: viewAllContent ? 1 : undefined, }), { ...bodyParameters, format: 'xlsx' }, { responseBodyFormat: 'blob' }); } querySuggestPost(restQuerySuggestParameters) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return this.api.post(this.buildPath(`${Search.baseUrl}/querySuggest`, { organizationId: this.api.organizationId, }), restQuerySuggestParameters); } /** * Get an item's preview in HTML format * @param root0 * @param root0.enableNavigation * @param root0.findNext * @param root0.findPrevious * @param root0.organizationId * @param root0.page * @param root0.requestedOutputSize * @param root0.uniqueId * @param root0.viewAllContent */ previewHTML({ enableNavigation, findNext, findPrevious, organizationId, page, requestedOutputSize, uniqueId, viewAllContent, ...body }) { return this.api.post(this.buildPath(`${Search.baseUrl}/html`, { enableNavigation, findNext, findPrevious, page, requestedOutputSize, uniqueId, viewAllContent, organizationId: organizationId ?? this.api.organizationId, }), body, { responseBodyFormat: 'text' }); } /** * Get item in JSON format * @param params */ getDocument(params) { return this.api.get(this.buildPath(`${Search.baseUrl}/document`, { ...params, organizationId: params.organizationId ?? this.api.organizationId, }, { skipEmptyString: false })); } /** * Executes a facet search request. * @param params */ searchFacet(params) { const { viewAllContent, organizationId, ...bodyParameters } = params; return this.api.post(this.buildPath(`${Search.baseUrl}/facet`, { organizationId: organizationId ?? this.api.organizationId, viewAllContent, }), bodyParameters); } } exports.default = Search; //# sourceMappingURL=Search.js.map