@yext/search-core
Version:
Typescript Networking Library for the Yext Search API
44 lines • 1.79 kB
JavaScript
import { SearchError } from '../../models/searchapi/SearchError';
import { createAutocompleteResult } from './createAutocompleteResult';
export function createAutocompleteResponse(data) {
var _a, _b;
if (!data.response) {
throw new Error('The autocomplete data does not contain a response property');
}
if (!Object.keys(data.response).length) {
throw new Error('The autocomplete response is empty');
}
var response = data.response;
var responseResults = response.results.map(createAutocompleteResult);
var inputIntents = (_b = (_a = response.input) === null || _a === void 0 ? void 0 : _a.queryIntents) !== null && _b !== void 0 ? _b : [];
return {
results: responseResults,
queryId: response.queryId,
inputIntents: inputIntents || [],
uuid: data.meta.uuid
};
}
export function createFilterSearchResponse(data) {
if (!data.response) {
throw new Error('The autocomplete data does not contain a response property');
}
if (!Object.keys(data.response).length) {
throw new Error('The autocomplete response is empty');
}
var response = data.response;
if (response.failedVerticals && response.failedVerticals.length != 0) {
var error = response.failedVerticals[0];
throw new SearchError(error.details.description, error.details.responseCode, error.errorType);
}
var sections = response.sections.map(function (section) { return ({
label: section.label,
results: section.results.map(createAutocompleteResult)
}); });
return {
sections: sections,
queryId: response.queryId,
businessId: response.businessId,
uuid: data.meta.uuid
};
}
//# sourceMappingURL=createAutocompleteResponse.js.map