Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@searchkit/api

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@searchkit/api - npm Package Compare versions

Comparing version
4.0.0-next.5
to
4.0.0-next.6
+7
-3
dist/index.d.ts

@@ -79,7 +79,11 @@ import { MultipleQueriesQuery } from '@algolia/client-search';

}
interface AppSettings {
debug: boolean;
}
declare class Client {
private config;
private settings;
transporter: Transporter;
constructor(config: ClientConfig);
constructor(config: ClientConfig, settings?: AppSettings);
private performSearch;

@@ -165,4 +169,4 @@ handleRequest(body: any, requestOptions?: RequestOptions): Promise<{

}
declare const createClient: (config: ClientConfig) => Client;
declare const createClient: (config: ClientConfig, settings?: AppSettings) => Client;
export { ClientConfig, ClientConfigConnection, ElasticsearchHit, ElasticsearchQuery, ElasticsearchResponseBody, FacetAttribute, FacetFieldConfig, QueryRule, QueryRuleAction, QueryRuleCondition, RequestOptions, SearchRequest, SearchSettingsConfig, Transporter, createClient as default };
export { AppSettings, ClientConfig, ClientConfigConnection, ElasticsearchHit, ElasticsearchQuery, ElasticsearchResponseBody, FacetAttribute, FacetFieldConfig, QueryRule, QueryRuleAction, QueryRuleCondition, RequestOptions, SearchRequest, SearchSettingsConfig, Transporter, createClient as default };

@@ -583,15 +583,19 @@ "use strict";

function transformResponse(response, instantsearchRequest, config, queryRuleActions) {
return {
exhaustiveNbHits: true,
exhaustiveFacetsCount: true,
exhaustiveTypo: true,
exhaustive: { facetsCount: true, nbHits: true, typo: true },
...getPageDetails(response, instantsearchRequest, config),
...getRenderingContent(config, queryRuleActions),
...getFacets(response, config),
hits: getHits(response, config),
index: instantsearchRequest.indexName,
params: (0, import_querystring.stringify)(instantsearchRequest.params),
...queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {}
};
try {
return {
exhaustiveNbHits: true,
exhaustiveFacetsCount: true,
exhaustiveTypo: true,
exhaustive: { facetsCount: true, nbHits: true, typo: true },
...getPageDetails(response, instantsearchRequest, config),
...getRenderingContent(config, queryRuleActions),
...getFacets(response, config),
hits: getHits(response, config),
index: instantsearchRequest.indexName,
params: (0, import_querystring.stringify)(instantsearchRequest.params),
...queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {}
};
} catch (e) {
throw new Error(`Error transforming Elasticsearch response for index`);
}
}

@@ -620,21 +624,47 @@ var transformFacetValuesResponse = (response, instantsearchRequest) => {

async msearch(requests) {
const response = await fetch(`${this.config.host}/_msearch`, {
headers: {
...this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {},
"content-type": "application/json"
},
body: requests.reduce(
(sum, request) => [
...sum,
JSON.stringify({ index: request.indexName }),
"\n",
JSON.stringify(request.body),
"\n"
],
[]
).join(""),
method: "POST"
});
const responses = await response.json();
return responses.responses;
var _a, _b, _c, _d;
try {
const response = await fetch(`${this.config.host}/_msearch`, {
headers: {
...this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {},
"content-type": "application/json"
},
body: requests.reduce(
(sum, request) => [
...sum,
JSON.stringify({ index: request.indexName }),
"\n",
JSON.stringify(request.body),
"\n"
],
[]
).join(""),
method: "POST"
});
const responses = await response.json();
if (responses.status >= 500) {
throw new Error(
"Elasticsearch Internal Error: Check your elasticsearch instance to make sure it can recieve requests."
);
} else if (responses.status === 401) {
throw new Error(
"Cannot connect to Elasticsearch. Check your connection host and API Key. You can also provide a custom Elasticsearch transporter to the API Client. See docs for more information."
);
} else if (((_b = (_a = responses.responses) == null ? void 0 : _a[0]) == null ? void 0 : _b.status) === 403) {
throw new Error(
"Auth Error: You do not have permission to access this index. Check you are calling the right index (specified in frontend) and your API Key permissions has access to the index."
);
} else if (responses.status === 404 || ((_d = (_c = responses.responses) == null ? void 0 : _c[0]) == null ? void 0 : _d.status) === 404) {
throw new Error(
"Elasticsearch index not found. Check your index name and make sure it exists."
);
} else if (responses.status === 400) {
throw new Error(
"Elasticsearch Bad Request. Check your query and make sure it is valid. Turn on debug mode to see the Elasticsearch query."
);
}
return responses.responses;
} catch (error) {
throw error;
}
}

@@ -699,7 +729,12 @@ };

var Client = class {
constructor(config) {
constructor(config, settings = { debug: false }) {
this.config = config;
this.settings = settings;
this.transporter = "msearch" in config.connection ? config.connection : new ESTransporter(config.connection);
}
async performSearch(requests) {
if (this.settings.debug) {
console.log("Performing search with requests:");
console.log(JSON.stringify(requests, null, 2));
}
const responses = await this.transporter.msearch(requests);

@@ -748,3 +783,3 @@ return responses;

};
var createClient = (config) => new Client(config);
var createClient = (config, settings) => new Client(config, settings);
var src_default = createClient;

@@ -751,0 +786,0 @@ // Annotate the CommonJS export names for ESM import in node:

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/index.ts","../src/transformRequest.ts","../src/utils.ts","../src/transformResponse.ts","../src/highlightUtils.ts","../src/Transporter.ts","../src/queryRules.ts"],"sourcesContent":["import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search'\nimport { transformRequest } from './transformRequest'\nimport transformResponse, { transformFacetValuesResponse } from './transformResponse'\nimport { ClientConfig, SearchRequest, RequestOptions, Transporter, QueryRuleAction } from './types'\nimport { ESTransporter } from './Transporter'\nimport { getQueryRulesActionsFromRequest, QueryRuleActions } from './queryRules'\nexport * from './types'\n\nclass Client {\n transporter: Transporter\n\n constructor(private config: ClientConfig) {\n this.transporter =\n 'msearch' in config.connection ? config.connection : new ESTransporter(config.connection)\n }\n\n private async performSearch(requests: SearchRequest[]) {\n const responses = await this.transporter.msearch(requests)\n return responses\n }\n\n async handleRequest(body: any, requestOptions?: RequestOptions) {\n const instantsearchRequests = body as AlgoliaMultipleQueriesQuery[]\n\n const instantsearchResponses = this.handleInstantSearchRequests(\n instantsearchRequests,\n requestOptions\n )\n\n return instantsearchResponses\n }\n\n async handleInstantSearchRequests(\n instantsearchRequests: AlgoliaMultipleQueriesQuery[],\n requestOptions?: RequestOptions\n ) {\n const queryRules = this.config.search_settings.query_rules || []\n\n const requestQueryRuleActions: QueryRuleActions[] = instantsearchRequests.map((request) => {\n return getQueryRulesActionsFromRequest(queryRules, request)\n })\n\n const esRequests: SearchRequest[] = instantsearchRequests.map((request, i) => ({\n body: transformRequest(\n request,\n this.config.search_settings,\n requestQueryRuleActions[i],\n requestOptions\n ),\n indexName: request.indexName\n }))\n\n const esResponses = await this.performSearch(esRequests)\n\n const instantsearchResponses = esResponses.map((response, i) => {\n // @ts-ignore\n if (instantsearchRequests[i].params?.facetName) {\n return transformFacetValuesResponse(response, instantsearchRequests[i])\n }\n return transformResponse(\n response,\n instantsearchRequests[i],\n this.config.search_settings,\n requestQueryRuleActions[i]\n )\n })\n\n return {\n results: instantsearchResponses\n }\n }\n}\n\nconst createClient = (config: ClientConfig) => new Client(config)\n\nexport default createClient\n","import deepmerge from 'deepmerge'\nimport { QueryRuleActions } from './queryRules'\nimport { FacetAttribute, RequestOptions, SearchSettingsConfig } from './types'\nimport {\n AlgoliaMultipleQueriesQuery,\n ElasticsearchQuery,\n ElasticsearchSearchRequest\n} from './types'\nimport { getFacet, getFacetAttribute } from './utils'\n\nexport const createRegexQuery = (queryString: string) => {\n let query = queryString.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n query = query\n .split('')\n .map((char) => {\n if (/[a-z]/.test(char)) {\n return `[${char}${char.toUpperCase()}]`\n }\n return char\n })\n .join('')\n query = `${query}.*`\n if (queryString.length > 2) {\n query = `([a-zA-Z]+ )+?${query}`\n }\n return query\n}\n\nconst transformNumericFilters = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n): ElasticsearchQuery[] => {\n const { params = {} } = request\n const { numericFilters } = params\n\n if (!Array.isArray(numericFilters)) {\n return []\n }\n\n return numericFilters.reduce((sum, filter) => {\n const [match, field, operator, value] = filter.match(\n /([\\w\\.\\_\\-]+)(\\=|\\!\\=|\\>|\\>\\=|\\<|\\<\\=)(\\d+)/\n )\n const fieldConfig = getFacet(config.facet_attributes || [], field)\n\n if (!match) return sum\n\n const getFilter = (operator: string, value: string) => {\n if (operator === '=') {\n return {\n term: {\n [field]: value\n }\n }\n } else if (operator === '!=') {\n return {\n bool: {\n must_not: {\n term: {\n [field]: value\n }\n }\n }\n }\n } else if (operator === '>') {\n return {\n range: {\n [field]: {\n gt: value\n }\n }\n }\n } else if (operator === '>=') {\n return {\n range: {\n [field]: {\n gte: value\n }\n }\n }\n } else if (operator === '<') {\n return {\n range: {\n [field]: {\n lt: value\n }\n }\n }\n } else if (operator === '<=') {\n return {\n range: {\n [field]: {\n lte: value\n }\n }\n }\n }\n }\n\n const esFilter = []\n\n if (typeof fieldConfig !== 'string' && fieldConfig.nestedPath) {\n esFilter.push({\n nested: {\n path: fieldConfig.nestedPath,\n query: {\n bool: {\n filter: [getFilter(operator, value)]\n }\n }\n }\n })\n } else {\n esFilter.push(getFilter(operator, value))\n }\n\n return [...sum, ...esFilter]\n }, [])\n}\n\nconst termFilter = (field: string, value: string) => {\n return { term: { [field]: value } }\n}\n\nconst transformFacetFilters = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n): ElasticsearchQuery[] => {\n const { params = {} } = request\n const { facetFilters } = params\n\n if (!Array.isArray(facetFilters)) {\n return []\n }\n\n return facetFilters.reduce((sum, filter) => {\n if (Array.isArray(filter)) {\n return [\n ...sum,\n {\n bool: {\n should: filter.reduce((sum, filter) => {\n const [facet, value] = filter.split(':')\n const facetAttribute = getFacetAttribute(facet)\n const facetConfig = getFacet(config.facet_attributes || [], facetAttribute)\n const field = typeof facetConfig === 'string' ? facetConfig : facetConfig.field\n\n if (\n typeof facetConfig !== 'string' &&\n isNestedFacet(facetConfig) &&\n facetConfig.nestedPath\n ) {\n // detect if there is a nested filter in sum\n // if one doesn't exist, add one\n // if one does exist, add to it\n const nestedFilter = sum.find((filter: any) => {\n return filter.nested && filter.nested.path === facetConfig.nestedPath\n })\n\n if (nestedFilter) {\n nestedFilter.nested.query.bool.should.push(\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n )\n return sum\n } else {\n return [\n ...sum,\n {\n nested: {\n path: facetConfig.nestedPath,\n query: {\n bool: {\n should: [\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n ]\n }\n }\n }\n }\n ]\n }\n }\n return [...sum, termFilter(field, value)]\n }, [])\n }\n }\n ]\n } else if (typeof filter === 'string') {\n const [facet, value] = filter.split(':')\n const facetAttribute = getFacetAttribute(facet)\n const facetConfig = getFacet(config.facet_attributes || [], facetAttribute)\n const field = typeof facetConfig === 'string' ? facetConfig : facetConfig.field\n\n if (typeof facetConfig !== 'string' && isNestedFacet(facetConfig) && facetConfig.nestedPath) {\n // detect if there is a nested filter in sum\n // if one doesn't exist, add one\n // if one does exist, add to it\n const nestedFilter = sum.find((filter: any) => {\n return filter.nested && filter.nested.path === facetConfig.nestedPath + '.'\n })\n\n if (nestedFilter) {\n nestedFilter.nested.query.bool.should.push(\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n )\n return sum\n } else {\n return [\n ...sum,\n {\n nested: {\n path: facetConfig.nestedPath,\n query: {\n bool: {\n should: [termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)]\n }\n }\n }\n }\n ]\n }\n }\n return [...sum, termFilter(field, value)]\n }\n }, [])\n}\n\nconst isNestedFacet = (facet: FacetAttribute): boolean => {\n return typeof facet !== 'string' && !!facet.nestedPath\n}\n\nconst getTermAggregation = (facet: FacetAttribute, size: number, search: string) => {\n const searchInclude = search && search.length > 0 ? { include: createRegexQuery(search) } : {}\n let aggEntries = {}\n\n const getInnerAggs = (facetName: string, field: string): any => {\n if (typeof facet === 'string' || facet.type === 'string') {\n aggEntries = {\n [facetName]: {\n terms: {\n field: field,\n size,\n ...searchInclude\n }\n }\n }\n } else if (facet.type === 'numeric') {\n aggEntries = {\n [facetName + '$_stats']: {\n stats: {\n field: field\n }\n },\n [facetName + '$_entries']: {\n terms: {\n field: field,\n size: size\n }\n }\n }\n }\n return aggEntries\n }\n\n if (typeof facet === 'string') {\n return getInnerAggs(facet, facet)\n } else if (isNestedFacet(facet)) {\n return {\n [`${facet.nestedPath}.`]: {\n nested: {\n path: facet.nestedPath\n },\n aggs: getInnerAggs(facet.attribute, `${facet.nestedPath}.${facet.field}`)\n }\n }\n } else {\n return getInnerAggs(facet.attribute, facet.field)\n }\n}\n\nexport const getAggs = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions\n) => {\n const { params = {}, type } = request\n // @ts-ignore\n const { facets, maxValuesPerFacet, facetName, facetQuery } = params\n const maxFacetSize = maxValuesPerFacet || 10\n const facetAttributes = config.facet_attributes || []\n\n if (facetName) {\n return getTermAggregation(getFacet(facetAttributes, facetName), maxFacetSize, facetQuery)\n } else if (Array.isArray(facets)) {\n let facetAttibutes = config.facet_attributes || []\n\n if (queryRuleActions.facetAttributesOrder) {\n facetAttibutes = queryRuleActions.facetAttributesOrder.map((attribute) => {\n return getFacet(config.facet_attributes || [], attribute)\n })\n }\n\n const facetAttributes: FacetAttribute[] =\n facets[0] === '*'\n ? facetAttibutes\n : facets.map((facetAttribute) => {\n return getFacet(config.facet_attributes || [], facetAttribute)\n })\n return (\n facetAttributes.reduce((sum, facet) => {\n return deepmerge(sum, getTermAggregation(facet, maxFacetSize, ''))\n }, {}) || {}\n )\n } else if (typeof facets === 'string') {\n const field = getFacet(config.facet_attributes || [], facets)\n return getTermAggregation(field, maxFacetSize, '')\n }\n}\n\nexport function RelevanceQueryMatch(\n query: string,\n search_attributes: string[],\n queryRuleActions: QueryRuleActions\n) {\n if (queryRuleActions) {\n return {\n function_score: {\n query: {\n pinned: {\n ids: queryRuleActions.pinnedDocs,\n organic: {\n combined_fields: {\n query: queryRuleActions.query,\n fields: search_attributes\n }\n }\n }\n },\n functions: queryRuleActions.boostFunctions\n }\n }\n }\n return {\n combined_fields: { query: query, fields: search_attributes }\n }\n}\n\nconst getQuery = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions,\n requestOptions?: RequestOptions\n) => {\n const { params = {} } = request\n const { query } = params\n\n const searchAttributes = config.search_attributes\n\n const filters = [\n ...transformFacetFilters(request, config),\n ...transformNumericFilters(request, config),\n ...(requestOptions?.getBaseFilters?.() || [])\n ]\n\n return {\n bool: {\n filter: filters,\n must:\n typeof query === 'string' && query !== ''\n ? requestOptions?.getQuery\n ? requestOptions.getQuery(query, searchAttributes, config)\n : RelevanceQueryMatch(query, searchAttributes, queryRuleActions)\n : []\n }\n }\n}\n\nconst getResultsSize = (request: AlgoliaMultipleQueriesQuery, config: SearchSettingsConfig) => {\n const { params = {} } = request\n const hitsPerPage = params.hitsPerPage || 20\n\n return {\n size: hitsPerPage,\n from: (params.page || 0) * hitsPerPage\n }\n}\n\nexport const getHitFields = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { attributesToRetrieve } = params\n // ignoring attributesToRetrieve for now\n\n return {\n _source: {\n includes: config.result_attributes\n }\n }\n}\n\nexport const getHighlightFields = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { attributesToHighlight } = params\n // ignoring attributesToHighlight for now\n return {\n highlight: {\n pre_tags: [params.highlightPreTag || '<ais-highlight-0000000000>'],\n post_tags: [params.highlightPostTag || '</ais-highlight-0000000000>'],\n fields:\n config.highlight_attributes?.reduce(\n (sum, field) => ({\n ...sum,\n [field]: {}\n }),\n {}\n ) || {}\n }\n }\n}\n\nexport function transformRequest(\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions,\n requestOptions?: RequestOptions\n): ElasticsearchSearchRequest {\n const body: ElasticsearchSearchRequest = {\n aggs: getAggs(request, config, queryRuleActions),\n query: getQuery(request, config, queryRuleActions, requestOptions),\n ...getResultsSize(request, config),\n ...getHitFields(request, config),\n ...getHighlightFields(request, config)\n }\n\n return body\n}\n","import { FacetAttribute, FacetFieldConfig } from './types'\n\nexport const createRegexQuery = (queryString: string) => {\n let query = queryString.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n query = query\n .split('')\n .map((char) => {\n if (/[a-z]/.test(char)) {\n return `[${char}${char.toUpperCase()}]`\n }\n return char\n })\n .join('')\n query = `${query}.*`\n if (queryString.length > 2) {\n query = `([a-zA-Z]+ )+?${query}`\n }\n return query\n}\n\nexport const getFacet = (\n facet_attributes: FacetAttribute[],\n attributeName: string\n): FacetAttribute => {\n const f = facet_attributes.find((a) => {\n if (typeof a === 'string') {\n return a === attributeName\n }\n return a.attribute === attributeName\n })\n return f || attributeName\n}\n\nexport const getFacetField = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): string => {\n const attributeKey = typeof attribute === 'string' ? attribute : attribute.attribute\n\n if (facet_attributes.includes(attributeKey)) {\n return attributeKey\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a.attribute === attributeKey)?.field || attributeKey\n )\n}\n\nexport const getFacetByAttribute = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): string => {\n const attributeKey = getFacetAttribute(attribute)\n\n if (facet_attributes.includes(attributeKey)) {\n return attributeKey\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a.attribute === attributeKey)?.attribute || attributeKey\n )\n}\n\nexport const getFacetAttribute = (facetAttribute: FacetAttribute): string => {\n return typeof facetAttribute === 'string' ? facetAttribute : facetAttribute.attribute\n}\n\nexport const getFacetFieldType = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): FacetFieldConfig['type'] => {\n const attributeKey = typeof attribute === 'string' ? attribute : attribute.attribute\n\n if (facet_attributes.includes(attributeKey)) {\n return 'string'\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a?.attribute === attributeKey)?.type || 'string'\n )\n}\n","import { stringify } from 'querystring'\nimport { SearchSettingsConfig } from './types'\nimport { getHighlightFields, highlightTerm } from './highlightUtils'\nimport { AlgoliaMultipleQueriesQuery, ElasticsearchResponseBody } from './types'\nimport { getFacetFieldType } from './utils'\nimport { QueryRuleActions } from './queryRules'\n\ntype FacetsList = Record<string, Record<string, number>>\ntype FacetsStats = Record<string, { min: number; max: number; avg: number; sum: number }>\n\nconst getHits = (response: ElasticsearchResponseBody, config: SearchSettingsConfig) => {\n const { hits } = response\n\n return hits.hits.map((hit) => ({\n objectID: hit._id,\n ...(hit._source || {}),\n _highlightResult: getHighlightFields(hit)\n }))\n}\n\nconst getFacets = (response: ElasticsearchResponseBody, config: SearchSettingsConfig) => {\n if (!response?.aggregations) {\n return {}\n }\n\n // flattening for nested facets\n const aggregations = Object.keys(response.aggregations).reduce<Record<string, any>>(\n (sum, key) => {\n const value = (response.aggregations || {})[key] as any\n\n if (key.endsWith('.')) {\n const { doc_count, ...nestedAggregations } = value\n return {\n ...sum,\n ...nestedAggregations\n }\n }\n\n return {\n ...sum,\n [key]: value\n }\n },\n {}\n )\n\n return Object.keys(aggregations).reduce<{\n facets: FacetsList\n facets_stats: FacetsStats\n }>(\n (sum, f) => {\n const facet = f.split('$')[0]\n const fieldType = getFacetFieldType(config.facet_attributes || [], facet)\n\n if (fieldType === 'numeric') {\n const facetValues = aggregations[facet + '$_stats'] as any\n const { buckets } = aggregations[facet + '$_entries'] as {\n buckets: any[]\n }\n\n return {\n ...sum,\n facets: {\n ...sum.facets,\n [facet]: buckets.reduce<Record<string, number>>(\n (sum, bucket) => ({\n ...sum,\n [bucket.key]: bucket.doc_count\n }),\n {}\n )\n },\n facets_stats: {\n ...sum.facets_stats,\n [facet]: {\n min: facetValues.min,\n avg: facetValues.avg,\n max: facetValues.max,\n sum: facetValues.sum\n }\n }\n }\n }\n\n const { buckets } = aggregations[facet] as { buckets: any[] }\n\n return {\n ...sum,\n facets: {\n ...sum.facets,\n [facet]: buckets.reduce<Record<string, number>>(\n (sum, bucket) => ({\n ...sum,\n [bucket.key]: bucket.doc_count\n }),\n {}\n )\n }\n }\n },\n {\n facets: {},\n facets_stats: {}\n }\n )\n}\n\nconst getRenderingContent = (config: SearchSettingsConfig, queryRuleActions: QueryRuleActions) => {\n const defaultOrder = config.facet_attributes?.map((facet) =>\n typeof facet === 'string' ? facet : facet.attribute\n )\n\n return {\n renderingContent: {\n facetOrdering: {\n facets: {\n order: queryRuleActions.facetAttributesOrder || defaultOrder || []\n },\n values: config.facet_attributes?.reduce<Record<string, { sortRemainingBy: 'count' }>>(\n (sum, facet) => {\n const facetName = typeof facet === 'string' ? facet : facet.attribute\n\n // If request has explicit facet orders and the facet is not\n // in the query rule actions, we don't want to sort it\n if (\n queryRuleActions.facetAttributesOrder &&\n !queryRuleActions.facetAttributesOrder.includes(facetName)\n ) {\n return sum\n }\n\n return {\n ...sum,\n [facetName]: {\n sortRemainingBy: 'count'\n }\n }\n },\n {}\n )\n }\n }\n }\n}\n\nconst getPageDetails = (\n response: ElasticsearchResponseBody,\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { hitsPerPage = 20, page = 0, query = '' } = params\n\n const { total } = response.hits\n const totalHits = typeof total === 'number' ? total : total?.value\n const nbPages = Math.ceil((typeof total === 'number' ? total : total?.value || 0) / hitsPerPage)\n\n return {\n hitsPerPage,\n processingTimeMS: response.took,\n nbHits: totalHits,\n page: page,\n nbPages,\n query\n }\n}\n\nexport default function transformResponse(\n response: ElasticsearchResponseBody,\n instantsearchRequest: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions\n) {\n return {\n exhaustiveNbHits: true,\n exhaustiveFacetsCount: true,\n exhaustiveTypo: true,\n exhaustive: { facetsCount: true, nbHits: true, typo: true },\n ...getPageDetails(response, instantsearchRequest, config),\n ...getRenderingContent(config, queryRuleActions),\n ...getFacets(response, config),\n hits: getHits(response, config),\n index: instantsearchRequest.indexName,\n params: stringify(instantsearchRequest.params as any),\n ...(queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {})\n }\n}\n\nexport const transformFacetValuesResponse = (\n response: ElasticsearchResponseBody,\n instantsearchRequest: AlgoliaMultipleQueriesQuery\n) => {\n const aggregations = response.aggregations || {}\n return {\n facetHits: (aggregations[Object.keys(aggregations)[0]] as any).buckets.map((entry: any) => ({\n value: entry.key,\n highlighted: highlightTerm(\n entry.key,\n // @ts-ignore\n instantsearchRequest.params.facetQuery || ''\n ),\n count: entry.doc_count\n })),\n exhaustiveFacetsCount: true,\n processingTimeMS: response.took\n }\n}\n","import type { ElasticsearchHit } from './types'\n\nexport function highlightTerm(value: string, query: string): string {\n const regex = new RegExp(query, 'gi')\n return value.replace(\n regex,\n (match) => `<ais-highlight-0000000000>${match}</ais-highlight-0000000000>`\n )\n}\n\nexport function getHighlightFields(hit: ElasticsearchHit) {\n const { _source = {}, highlight = {} } = hit\n\n const hitHighlights = Object.keys(_source).reduce<Record<string, any>>((sum, fieldKey) => {\n const fieldValue: any = _source[fieldKey]\n const highlightedMatch = highlight[fieldKey] || null\n\n if (Array.isArray(fieldValue) && !highlightedMatch) {\n return {\n ...sum,\n [fieldKey]: fieldValue.map((value) => ({\n matchLevel: 'none',\n matchedWords: [],\n value: value\n }))\n }\n } else if (Array.isArray(highlightedMatch)) {\n // TODO: needs to return all non matches values too\n return {\n ...sum,\n [fieldKey]: highlightedMatch.map((highlightedMatch) => {\n const matchWords = Array.from(\n highlightedMatch.matchAll(\n /\\<ais-highlight-0000000000\\>(.*?)\\<\\/ais-highlight-0000000000\\>/g\n )\n ).map((match) => match[1])\n return {\n fullyHighlighted: false,\n matchLevel: 'full',\n matchedWords: matchWords,\n value: highlightedMatch\n }\n })\n }\n }\n\n return {\n ...sum,\n [fieldKey]: {\n matchLevel: 'none',\n matchedWords: [],\n value: fieldValue\n }\n }\n }, {})\n\n return hitHighlights\n}\n","import { ClientConfigConnection, SearchRequest } from './types'\nimport { ElasticsearchResponseBody, Transporter } from './types'\n\nexport class ESTransporter implements Transporter {\n constructor(public config: ClientConfigConnection) {}\n\n async msearch(requests: SearchRequest[]): Promise<ElasticsearchResponseBody[]> {\n // @ts-ignore\n const response = await fetch(`${this.config.host}/_msearch`, {\n headers: {\n ...(this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {}),\n 'content-type': 'application/json'\n },\n body: requests\n .reduce<string[]>(\n (sum, request) => [\n ...sum,\n JSON.stringify({ index: request.indexName }),\n '\\n',\n JSON.stringify(request.body),\n '\\n'\n ],\n []\n )\n .join(''),\n method: 'POST'\n })\n\n const responses = await response.json()\n return responses.responses\n }\n}\n","import { AlgoliaMultipleQueriesQuery, QueryRule, SearchSettingsConfig } from './types'\n\nexport interface QueryContext {\n query: string\n}\n\nexport interface QueryRuleActions {\n pinnedDocs: string[]\n boostFunctions: any[]\n query: string\n userData: unknown[]\n facetAttributesOrder: string[] | undefined\n}\n\nexport const getQueryRulesActionsFromRequest = (\n queryRules: QueryRule[],\n request: AlgoliaMultipleQueriesQuery\n) => {\n const queryContext: QueryContext = {\n query: request.params?.query || ''\n }\n\n const satisfiedRules = getSatisfiedRules(queryContext, queryRules || [])\n\n const actions = satisfiedRules.reduce<QueryRuleActions>(\n (sum, rule) => {\n rule.actions.map((action) => {\n if (action.action === 'PinnedResult') {\n sum.pinnedDocs.push(...action.documentIds)\n } else if (action.action === 'QueryRewrite') {\n sum.query = action.query\n } else if (action.action === 'QueryAttributeBoost') {\n sum.boostFunctions.push({\n filter: {\n match: { [action.attribute]: { query: action.value } }\n },\n weight: action.boost\n })\n } else if (action.action === 'RenderUserData') {\n sum.userData.push(JSON.parse(action.userData))\n } else if (action.action === 'RenderFacetsOrder') {\n sum.facetAttributesOrder = action.facetAttributesOrder\n }\n })\n return sum\n },\n {\n pinnedDocs: [],\n boostFunctions: [],\n query: queryContext.query,\n userData: [],\n facetAttributesOrder: undefined\n }\n )\n return actions\n}\n\nexport const getSatisfiedRules = (queryContext: QueryContext, rules: QueryRule[]) =>\n rules.filter(\n (rule) =>\n rule.conditions.filter((condition) => {\n if (condition.context === 'query' && condition.match_type === 'exact') {\n return condition.value === queryContext.query\n }\n if (condition.context === 'query' && condition.match_type === 'contains') {\n return queryContext.query.includes(condition.value)\n }\n if (condition.context === 'query' && condition.match_type === 'prefix') {\n return queryContext.query.startsWith(condition.value)\n }\n\n return false\n }).length > 0\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAsB;;;ACoBf,IAAM,WAAW,CACtB,kBACA,kBACmB;AACnB,QAAM,IAAI,iBAAiB,KAAK,CAAC,MAAM;AACrC,QAAI,OAAO,MAAM,UAAU;AACzB,aAAO,MAAM;AAAA,IACf;AACA,WAAO,EAAE,cAAc;AAAA,EACzB,CAAC;AACD,SAAO,KAAK;AACd;AAkCO,IAAM,oBAAoB,CAAC,mBAA2C;AAC3E,SAAO,OAAO,mBAAmB,WAAW,iBAAiB,eAAe;AAC9E;AAEO,IAAM,oBAAoB,CAC/B,kBACA,cAC6B;AAxE/B;AAyEE,QAAM,eAAe,OAAO,cAAc,WAAW,YAAY,UAAU;AAE3E,MAAI,iBAAiB,SAAS,YAAY,GAAG;AAC3C,WAAO;AAAA,EACT;AACA,WACE,sBAEG,KAAK,CAAC,OAAM,uBAAG,eAAc,YAAY,MAF5C,mBAE+C,SAAQ;AAE3D;;;ADzEO,IAAM,mBAAmB,CAAC,gBAAwB;AACvD,MAAI,QAAQ,YAAY,QAAQ,uCAAuC,MAAM;AAC7E,UAAQ,MACL,MAAM,EAAE,EACR,IAAI,CAAC,SAAS;AACb,QAAI,QAAQ,KAAK,IAAI,GAAG;AACtB,aAAO,IAAI,OAAO,KAAK,YAAY;AAAA,IACrC;AACA,WAAO;AAAA,EACT,CAAC,EACA,KAAK,EAAE;AACV,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AA,MACA,WAAW,QAAQ;AAAA,IACrB,EAAE;AAEF,UAAM,cAAc,MAAM,KAAK,cAAc,UAAU;AAEvD,UAAM,yBAAyB,YAAY,IAAI,CAAC,UAAU,MAAM;AAtDpE;AAwDM,WAAI,2BAAsB,GAAG,WAAzB,mBAAiC,WAAW;AAC9C,eAAO,6BAA6B,UAAU,sBAAsB,EAAE;AAAA,MACxE;AACA,aAAO;AAAA,QACL;AAAA,QACA,sBAAsB;AAAA,QACtB,KAAK,OAAO;AAAA,QACZ,wBAAwB;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,SAAS;AAAA,IACX;AAAA,EACF;AACF;AAEA,IAAM,eAAe,CAAC,WAAyB,IAAI,OAAO,MAAM;AAEhE,IAAO,cAAQ;","names":["operator","value","sum","filter","facetAttributes","deepmerge","getHighlightFields","highlightedMatch","getHighlightFields","buckets","sum"]}
{"version":3,"sources":["../src/index.ts","../src/transformRequest.ts","../src/utils.ts","../src/transformResponse.ts","../src/highlightUtils.ts","../src/Transporter.ts","../src/queryRules.ts"],"sourcesContent":["import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search'\nimport { transformRequest } from './transformRequest'\nimport transformResponse, { transformFacetValuesResponse } from './transformResponse'\nimport {\n ClientConfig,\n SearchRequest,\n RequestOptions,\n Transporter,\n QueryRuleAction,\n AppSettings\n} from './types'\nimport { ESTransporter } from './Transporter'\nimport { getQueryRulesActionsFromRequest, QueryRuleActions } from './queryRules'\nexport * from './types'\n\nclass Client {\n transporter: Transporter\n\n constructor(private config: ClientConfig, private settings: AppSettings = { debug: false }) {\n this.transporter =\n 'msearch' in config.connection ? config.connection : new ESTransporter(config.connection)\n }\n\n private async performSearch(requests: SearchRequest[]) {\n if (this.settings.debug) {\n console.log('Performing search with requests:')\n console.log(JSON.stringify(requests, null, 2))\n }\n const responses = await this.transporter.msearch(requests)\n return responses\n }\n\n async handleRequest(body: any, requestOptions?: RequestOptions) {\n const instantsearchRequests = body as AlgoliaMultipleQueriesQuery[]\n\n const instantsearchResponses = this.handleInstantSearchRequests(\n instantsearchRequests,\n requestOptions\n )\n\n return instantsearchResponses\n }\n\n async handleInstantSearchRequests(\n instantsearchRequests: AlgoliaMultipleQueriesQuery[],\n requestOptions?: RequestOptions\n ) {\n const queryRules = this.config.search_settings.query_rules || []\n\n const requestQueryRuleActions: QueryRuleActions[] = instantsearchRequests.map((request) => {\n return getQueryRulesActionsFromRequest(queryRules, request)\n })\n\n const esRequests: SearchRequest[] = instantsearchRequests.map((request, i) => ({\n body: transformRequest(\n request,\n this.config.search_settings,\n requestQueryRuleActions[i],\n requestOptions\n ),\n indexName: request.indexName\n }))\n\n const esResponses = await this.performSearch(esRequests)\n\n const instantsearchResponses = esResponses.map((response, i) => {\n // @ts-ignore\n if (instantsearchRequests[i].params?.facetName) {\n return transformFacetValuesResponse(response, instantsearchRequests[i])\n }\n return transformResponse(\n response,\n instantsearchRequests[i],\n this.config.search_settings,\n requestQueryRuleActions[i]\n )\n })\n\n return {\n results: instantsearchResponses\n }\n }\n}\n\nconst createClient = (config: ClientConfig, settings?: AppSettings) => new Client(config, settings)\n\nexport default createClient\n","import deepmerge from 'deepmerge'\nimport { QueryRuleActions } from './queryRules'\nimport { FacetAttribute, RequestOptions, SearchSettingsConfig } from './types'\nimport {\n AlgoliaMultipleQueriesQuery,\n ElasticsearchQuery,\n ElasticsearchSearchRequest\n} from './types'\nimport { getFacet, getFacetAttribute } from './utils'\n\nexport const createRegexQuery = (queryString: string) => {\n let query = queryString.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n query = query\n .split('')\n .map((char) => {\n if (/[a-z]/.test(char)) {\n return `[${char}${char.toUpperCase()}]`\n }\n return char\n })\n .join('')\n query = `${query}.*`\n if (queryString.length > 2) {\n query = `([a-zA-Z]+ )+?${query}`\n }\n return query\n}\n\nconst transformNumericFilters = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n): ElasticsearchQuery[] => {\n const { params = {} } = request\n const { numericFilters } = params\n\n if (!Array.isArray(numericFilters)) {\n return []\n }\n\n return numericFilters.reduce((sum, filter) => {\n const [match, field, operator, value] = filter.match(\n /([\\w\\.\\_\\-]+)(\\=|\\!\\=|\\>|\\>\\=|\\<|\\<\\=)(\\d+)/\n )\n const fieldConfig = getFacet(config.facet_attributes || [], field)\n\n if (!match) return sum\n\n const getFilter = (operator: string, value: string) => {\n if (operator === '=') {\n return {\n term: {\n [field]: value\n }\n }\n } else if (operator === '!=') {\n return {\n bool: {\n must_not: {\n term: {\n [field]: value\n }\n }\n }\n }\n } else if (operator === '>') {\n return {\n range: {\n [field]: {\n gt: value\n }\n }\n }\n } else if (operator === '>=') {\n return {\n range: {\n [field]: {\n gte: value\n }\n }\n }\n } else if (operator === '<') {\n return {\n range: {\n [field]: {\n lt: value\n }\n }\n }\n } else if (operator === '<=') {\n return {\n range: {\n [field]: {\n lte: value\n }\n }\n }\n }\n }\n\n const esFilter = []\n\n if (typeof fieldConfig !== 'string' && fieldConfig.nestedPath) {\n esFilter.push({\n nested: {\n path: fieldConfig.nestedPath,\n query: {\n bool: {\n filter: [getFilter(operator, value)]\n }\n }\n }\n })\n } else {\n esFilter.push(getFilter(operator, value))\n }\n\n return [...sum, ...esFilter]\n }, [])\n}\n\nconst termFilter = (field: string, value: string) => {\n return { term: { [field]: value } }\n}\n\nconst transformFacetFilters = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n): ElasticsearchQuery[] => {\n const { params = {} } = request\n const { facetFilters } = params\n\n if (!Array.isArray(facetFilters)) {\n return []\n }\n\n return facetFilters.reduce((sum, filter) => {\n if (Array.isArray(filter)) {\n return [\n ...sum,\n {\n bool: {\n should: filter.reduce((sum, filter) => {\n const [facet, value] = filter.split(':')\n const facetAttribute = getFacetAttribute(facet)\n const facetConfig = getFacet(config.facet_attributes || [], facetAttribute)\n const field = typeof facetConfig === 'string' ? facetConfig : facetConfig.field\n\n if (\n typeof facetConfig !== 'string' &&\n isNestedFacet(facetConfig) &&\n facetConfig.nestedPath\n ) {\n // detect if there is a nested filter in sum\n // if one doesn't exist, add one\n // if one does exist, add to it\n const nestedFilter = sum.find((filter: any) => {\n return filter.nested && filter.nested.path === facetConfig.nestedPath\n })\n\n if (nestedFilter) {\n nestedFilter.nested.query.bool.should.push(\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n )\n return sum\n } else {\n return [\n ...sum,\n {\n nested: {\n path: facetConfig.nestedPath,\n query: {\n bool: {\n should: [\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n ]\n }\n }\n }\n }\n ]\n }\n }\n return [...sum, termFilter(field, value)]\n }, [])\n }\n }\n ]\n } else if (typeof filter === 'string') {\n const [facet, value] = filter.split(':')\n const facetAttribute = getFacetAttribute(facet)\n const facetConfig = getFacet(config.facet_attributes || [], facetAttribute)\n const field = typeof facetConfig === 'string' ? facetConfig : facetConfig.field\n\n if (typeof facetConfig !== 'string' && isNestedFacet(facetConfig) && facetConfig.nestedPath) {\n // detect if there is a nested filter in sum\n // if one doesn't exist, add one\n // if one does exist, add to it\n const nestedFilter = sum.find((filter: any) => {\n return filter.nested && filter.nested.path === facetConfig.nestedPath + '.'\n })\n\n if (nestedFilter) {\n nestedFilter.nested.query.bool.should.push(\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n )\n return sum\n } else {\n return [\n ...sum,\n {\n nested: {\n path: facetConfig.nestedPath,\n query: {\n bool: {\n should: [termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)]\n }\n }\n }\n }\n ]\n }\n }\n return [...sum, termFilter(field, value)]\n }\n }, [])\n}\n\nconst isNestedFacet = (facet: FacetAttribute): boolean => {\n return typeof facet !== 'string' && !!facet.nestedPath\n}\n\nconst getTermAggregation = (facet: FacetAttribute, size: number, search: string) => {\n const searchInclude = search && search.length > 0 ? { include: createRegexQuery(search) } : {}\n let aggEntries = {}\n\n const getInnerAggs = (facetName: string, field: string): any => {\n if (typeof facet === 'string' || facet.type === 'string') {\n aggEntries = {\n [facetName]: {\n terms: {\n field: field,\n size,\n ...searchInclude\n }\n }\n }\n } else if (facet.type === 'numeric') {\n aggEntries = {\n [facetName + '$_stats']: {\n stats: {\n field: field\n }\n },\n [facetName + '$_entries']: {\n terms: {\n field: field,\n size: size\n }\n }\n }\n }\n return aggEntries\n }\n\n if (typeof facet === 'string') {\n return getInnerAggs(facet, facet)\n } else if (isNestedFacet(facet)) {\n return {\n [`${facet.nestedPath}.`]: {\n nested: {\n path: facet.nestedPath\n },\n aggs: getInnerAggs(facet.attribute, `${facet.nestedPath}.${facet.field}`)\n }\n }\n } else {\n return getInnerAggs(facet.attribute, facet.field)\n }\n}\n\nexport const getAggs = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions\n) => {\n const { params = {}, type } = request\n // @ts-ignore\n const { facets, maxValuesPerFacet, facetName, facetQuery } = params\n const maxFacetSize = maxValuesPerFacet || 10\n const facetAttributes = config.facet_attributes || []\n\n if (facetName) {\n return getTermAggregation(getFacet(facetAttributes, facetName), maxFacetSize, facetQuery)\n } else if (Array.isArray(facets)) {\n let facetAttibutes = config.facet_attributes || []\n\n if (queryRuleActions.facetAttributesOrder) {\n facetAttibutes = queryRuleActions.facetAttributesOrder.map((attribute) => {\n return getFacet(config.facet_attributes || [], attribute)\n })\n }\n\n const facetAttributes: FacetAttribute[] =\n facets[0] === '*'\n ? facetAttibutes\n : facets.map((facetAttribute) => {\n return getFacet(config.facet_attributes || [], facetAttribute)\n })\n return (\n facetAttributes.reduce((sum, facet) => {\n return deepmerge(sum, getTermAggregation(facet, maxFacetSize, ''))\n }, {}) || {}\n )\n } else if (typeof facets === 'string') {\n const field = getFacet(config.facet_attributes || [], facets)\n return getTermAggregation(field, maxFacetSize, '')\n }\n}\n\nexport function RelevanceQueryMatch(\n query: string,\n search_attributes: string[],\n queryRuleActions: QueryRuleActions\n) {\n if (queryRuleActions) {\n return {\n function_score: {\n query: {\n pinned: {\n ids: queryRuleActions.pinnedDocs,\n organic: {\n combined_fields: {\n query: queryRuleActions.query,\n fields: search_attributes\n }\n }\n }\n },\n functions: queryRuleActions.boostFunctions\n }\n }\n }\n return {\n combined_fields: { query: query, fields: search_attributes }\n }\n}\n\nconst getQuery = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions,\n requestOptions?: RequestOptions\n) => {\n const { params = {} } = request\n const { query } = params\n\n const searchAttributes = config.search_attributes\n\n const filters = [\n ...transformFacetFilters(request, config),\n ...transformNumericFilters(request, config),\n ...(requestOptions?.getBaseFilters?.() || [])\n ]\n\n return {\n bool: {\n filter: filters,\n must:\n typeof query === 'string' && query !== ''\n ? requestOptions?.getQuery\n ? requestOptions.getQuery(query, searchAttributes, config)\n : RelevanceQueryMatch(query, searchAttributes, queryRuleActions)\n : []\n }\n }\n}\n\nconst getResultsSize = (request: AlgoliaMultipleQueriesQuery, config: SearchSettingsConfig) => {\n const { params = {} } = request\n const hitsPerPage = params.hitsPerPage || 20\n\n return {\n size: hitsPerPage,\n from: (params.page || 0) * hitsPerPage\n }\n}\n\nexport const getHitFields = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { attributesToRetrieve } = params\n // ignoring attributesToRetrieve for now\n\n return {\n _source: {\n includes: config.result_attributes\n }\n }\n}\n\nexport const getHighlightFields = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { attributesToHighlight } = params\n // ignoring attributesToHighlight for now\n return {\n highlight: {\n pre_tags: [params.highlightPreTag || '<ais-highlight-0000000000>'],\n post_tags: [params.highlightPostTag || '</ais-highlight-0000000000>'],\n fields:\n config.highlight_attributes?.reduce(\n (sum, field) => ({\n ...sum,\n [field]: {}\n }),\n {}\n ) || {}\n }\n }\n}\n\nexport function transformRequest(\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions,\n requestOptions?: RequestOptions\n): ElasticsearchSearchRequest {\n const body: ElasticsearchSearchRequest = {\n aggs: getAggs(request, config, queryRuleActions),\n query: getQuery(request, config, queryRuleActions, requestOptions),\n ...getResultsSize(request, config),\n ...getHitFields(request, config),\n ...getHighlightFields(request, config)\n }\n\n return body\n}\n","import { FacetAttribute, FacetFieldConfig } from './types'\n\nexport const createRegexQuery = (queryString: string) => {\n let query = queryString.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n query = query\n .split('')\n .map((char) => {\n if (/[a-z]/.test(char)) {\n return `[${char}${char.toUpperCase()}]`\n }\n return char\n })\n .join('')\n query = `${query}.*`\n if (queryString.length > 2) {\n query = `([a-zA-Z]+ )+?${query}`\n }\n return query\n}\n\nexport const getFacet = (\n facet_attributes: FacetAttribute[],\n attributeName: string\n): FacetAttribute => {\n const f = facet_attributes.find((a) => {\n if (typeof a === 'string') {\n return a === attributeName\n }\n return a.attribute === attributeName\n })\n return f || attributeName\n}\n\nexport const getFacetField = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): string => {\n const attributeKey = typeof attribute === 'string' ? attribute : attribute.attribute\n\n if (facet_attributes.includes(attributeKey)) {\n return attributeKey\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a.attribute === attributeKey)?.field || attributeKey\n )\n}\n\nexport const getFacetByAttribute = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): string => {\n const attributeKey = getFacetAttribute(attribute)\n\n if (facet_attributes.includes(attributeKey)) {\n return attributeKey\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a.attribute === attributeKey)?.attribute || attributeKey\n )\n}\n\nexport const getFacetAttribute = (facetAttribute: FacetAttribute): string => {\n return typeof facetAttribute === 'string' ? facetAttribute : facetAttribute.attribute\n}\n\nexport const getFacetFieldType = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): FacetFieldConfig['type'] => {\n const attributeKey = typeof attribute === 'string' ? attribute : attribute.attribute\n\n if (facet_attributes.includes(attributeKey)) {\n return 'string'\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a?.attribute === attributeKey)?.type || 'string'\n )\n}\n","import { stringify } from 'querystring'\nimport { SearchSettingsConfig } from './types'\nimport { getHighlightFields, highlightTerm } from './highlightUtils'\nimport { AlgoliaMultipleQueriesQuery, ElasticsearchResponseBody } from './types'\nimport { getFacetFieldType } from './utils'\nimport { QueryRuleActions } from './queryRules'\n\ntype FacetsList = Record<string, Record<string, number>>\ntype FacetsStats = Record<string, { min: number; max: number; avg: number; sum: number }>\n\nconst getHits = (response: ElasticsearchResponseBody, config: SearchSettingsConfig) => {\n const { hits } = response\n\n return hits.hits.map((hit) => ({\n objectID: hit._id,\n ...(hit._source || {}),\n _highlightResult: getHighlightFields(hit)\n }))\n}\n\nconst getFacets = (response: ElasticsearchResponseBody, config: SearchSettingsConfig) => {\n if (!response?.aggregations) {\n return {}\n }\n\n // flattening for nested facets\n const aggregations = Object.keys(response.aggregations).reduce<Record<string, any>>(\n (sum, key) => {\n const value = (response.aggregations || {})[key] as any\n\n if (key.endsWith('.')) {\n const { doc_count, ...nestedAggregations } = value\n return {\n ...sum,\n ...nestedAggregations\n }\n }\n\n return {\n ...sum,\n [key]: value\n }\n },\n {}\n )\n\n return Object.keys(aggregations).reduce<{\n facets: FacetsList\n facets_stats: FacetsStats\n }>(\n (sum, f) => {\n const facet = f.split('$')[0]\n const fieldType = getFacetFieldType(config.facet_attributes || [], facet)\n\n if (fieldType === 'numeric') {\n const facetValues = aggregations[facet + '$_stats'] as any\n const { buckets } = aggregations[facet + '$_entries'] as {\n buckets: any[]\n }\n\n return {\n ...sum,\n facets: {\n ...sum.facets,\n [facet]: buckets.reduce<Record<string, number>>(\n (sum, bucket) => ({\n ...sum,\n [bucket.key]: bucket.doc_count\n }),\n {}\n )\n },\n facets_stats: {\n ...sum.facets_stats,\n [facet]: {\n min: facetValues.min,\n avg: facetValues.avg,\n max: facetValues.max,\n sum: facetValues.sum\n }\n }\n }\n }\n\n const { buckets } = aggregations[facet] as { buckets: any[] }\n\n return {\n ...sum,\n facets: {\n ...sum.facets,\n [facet]: buckets.reduce<Record<string, number>>(\n (sum, bucket) => ({\n ...sum,\n [bucket.key]: bucket.doc_count\n }),\n {}\n )\n }\n }\n },\n {\n facets: {},\n facets_stats: {}\n }\n )\n}\n\nconst getRenderingContent = (config: SearchSettingsConfig, queryRuleActions: QueryRuleActions) => {\n const defaultOrder = config.facet_attributes?.map((facet) =>\n typeof facet === 'string' ? facet : facet.attribute\n )\n\n return {\n renderingContent: {\n facetOrdering: {\n facets: {\n order: queryRuleActions.facetAttributesOrder || defaultOrder || []\n },\n values: config.facet_attributes?.reduce<Record<string, { sortRemainingBy: 'count' }>>(\n (sum, facet) => {\n const facetName = typeof facet === 'string' ? facet : facet.attribute\n\n // If request has explicit facet orders and the facet is not\n // in the query rule actions, we don't want to sort it\n if (\n queryRuleActions.facetAttributesOrder &&\n !queryRuleActions.facetAttributesOrder.includes(facetName)\n ) {\n return sum\n }\n\n return {\n ...sum,\n [facetName]: {\n sortRemainingBy: 'count'\n }\n }\n },\n {}\n )\n }\n }\n }\n}\n\nconst getPageDetails = (\n response: ElasticsearchResponseBody,\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { hitsPerPage = 20, page = 0, query = '' } = params\n\n const { total } = response.hits\n const totalHits = typeof total === 'number' ? total : total?.value\n const nbPages = Math.ceil((typeof total === 'number' ? total : total?.value || 0) / hitsPerPage)\n\n return {\n hitsPerPage,\n processingTimeMS: response.took,\n nbHits: totalHits,\n page: page,\n nbPages,\n query\n }\n}\n\nexport default function transformResponse(\n response: ElasticsearchResponseBody,\n instantsearchRequest: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions\n) {\n try {\n return {\n exhaustiveNbHits: true,\n exhaustiveFacetsCount: true,\n exhaustiveTypo: true,\n exhaustive: { facetsCount: true, nbHits: true, typo: true },\n ...getPageDetails(response, instantsearchRequest, config),\n ...getRenderingContent(config, queryRuleActions),\n ...getFacets(response, config),\n hits: getHits(response, config),\n index: instantsearchRequest.indexName,\n params: stringify(instantsearchRequest.params as any),\n ...(queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {})\n }\n } catch (e) {\n throw new Error(`Error transforming Elasticsearch response for index`)\n }\n}\n\nexport const transformFacetValuesResponse = (\n response: ElasticsearchResponseBody,\n instantsearchRequest: AlgoliaMultipleQueriesQuery\n) => {\n const aggregations = response.aggregations || {}\n return {\n facetHits: (aggregations[Object.keys(aggregations)[0]] as any).buckets.map((entry: any) => ({\n value: entry.key,\n highlighted: highlightTerm(\n entry.key,\n // @ts-ignore\n instantsearchRequest.params.facetQuery || ''\n ),\n count: entry.doc_count\n })),\n exhaustiveFacetsCount: true,\n processingTimeMS: response.took\n }\n}\n","import type { ElasticsearchHit } from './types'\n\nexport function highlightTerm(value: string, query: string): string {\n const regex = new RegExp(query, 'gi')\n return value.replace(\n regex,\n (match) => `<ais-highlight-0000000000>${match}</ais-highlight-0000000000>`\n )\n}\n\nexport function getHighlightFields(hit: ElasticsearchHit) {\n const { _source = {}, highlight = {} } = hit\n\n const hitHighlights = Object.keys(_source).reduce<Record<string, any>>((sum, fieldKey) => {\n const fieldValue: any = _source[fieldKey]\n const highlightedMatch = highlight[fieldKey] || null\n\n if (Array.isArray(fieldValue) && !highlightedMatch) {\n return {\n ...sum,\n [fieldKey]: fieldValue.map((value) => ({\n matchLevel: 'none',\n matchedWords: [],\n value: value\n }))\n }\n } else if (Array.isArray(highlightedMatch)) {\n // TODO: needs to return all non matches values too\n return {\n ...sum,\n [fieldKey]: highlightedMatch.map((highlightedMatch) => {\n const matchWords = Array.from(\n highlightedMatch.matchAll(\n /\\<ais-highlight-0000000000\\>(.*?)\\<\\/ais-highlight-0000000000\\>/g\n )\n ).map((match) => match[1])\n return {\n fullyHighlighted: false,\n matchLevel: 'full',\n matchedWords: matchWords,\n value: highlightedMatch\n }\n })\n }\n }\n\n return {\n ...sum,\n [fieldKey]: {\n matchLevel: 'none',\n matchedWords: [],\n value: fieldValue\n }\n }\n }, {})\n\n return hitHighlights\n}\n","import { ClientConfigConnection, SearchRequest } from './types'\nimport { ElasticsearchResponseBody, Transporter } from './types'\n\nexport class ESTransporter implements Transporter {\n constructor(public config: ClientConfigConnection) {}\n\n async msearch(requests: SearchRequest[]): Promise<ElasticsearchResponseBody[]> {\n // @ts-ignore\n try {\n const response = await fetch(`${this.config.host}/_msearch`, {\n headers: {\n ...(this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {}),\n 'content-type': 'application/json'\n },\n body: requests\n .reduce<string[]>(\n (sum, request) => [\n ...sum,\n JSON.stringify({ index: request.indexName }),\n '\\n',\n JSON.stringify(request.body),\n '\\n'\n ],\n []\n )\n .join(''),\n method: 'POST'\n })\n\n const responses = await response.json()\n\n if (responses.status >= 500) {\n throw new Error(\n 'Elasticsearch Internal Error: Check your elasticsearch instance to make sure it can recieve requests.'\n )\n } else if (responses.status === 401) {\n throw new Error(\n 'Cannot connect to Elasticsearch. Check your connection host and API Key. You can also provide a custom Elasticsearch transporter to the API Client. See docs for more information.'\n )\n } else if (responses.responses?.[0]?.status === 403) {\n throw new Error(\n 'Auth Error: You do not have permission to access this index. Check you are calling the right index (specified in frontend) and your API Key permissions has access to the index.'\n )\n } else if (responses.status === 404 || responses.responses?.[0]?.status === 404) {\n throw new Error(\n 'Elasticsearch index not found. Check your index name and make sure it exists.'\n )\n } else if (responses.status === 400) {\n throw new Error(\n 'Elasticsearch Bad Request. Check your query and make sure it is valid. Turn on debug mode to see the Elasticsearch query.'\n )\n }\n return responses.responses\n } catch (error) {\n throw error\n }\n }\n}\n","import { AlgoliaMultipleQueriesQuery, QueryRule, SearchSettingsConfig } from './types'\n\nexport interface QueryContext {\n query: string\n}\n\nexport interface QueryRuleActions {\n pinnedDocs: string[]\n boostFunctions: any[]\n query: string\n userData: unknown[]\n facetAttributesOrder: string[] | undefined\n}\n\nexport const getQueryRulesActionsFromRequest = (\n queryRules: QueryRule[],\n request: AlgoliaMultipleQueriesQuery\n) => {\n const queryContext: QueryContext = {\n query: request.params?.query || ''\n }\n\n const satisfiedRules = getSatisfiedRules(queryContext, queryRules || [])\n\n const actions = satisfiedRules.reduce<QueryRuleActions>(\n (sum, rule) => {\n rule.actions.map((action) => {\n if (action.action === 'PinnedResult') {\n sum.pinnedDocs.push(...action.documentIds)\n } else if (action.action === 'QueryRewrite') {\n sum.query = action.query\n } else if (action.action === 'QueryAttributeBoost') {\n sum.boostFunctions.push({\n filter: {\n match: { [action.attribute]: { query: action.value } }\n },\n weight: action.boost\n })\n } else if (action.action === 'RenderUserData') {\n sum.userData.push(JSON.parse(action.userData))\n } else if (action.action === 'RenderFacetsOrder') {\n sum.facetAttributesOrder = action.facetAttributesOrder\n }\n })\n return sum\n },\n {\n pinnedDocs: [],\n boostFunctions: [],\n query: queryContext.query,\n userData: [],\n facetAttributesOrder: undefined\n }\n )\n return actions\n}\n\nexport const getSatisfiedRules = (queryContext: QueryContext, rules: QueryRule[]) =>\n rules.filter(\n (rule) =>\n rule.conditions.filter((condition) => {\n if (condition.context === 'query' && condition.match_type === 'exact') {\n return condition.value === queryContext.query\n }\n if (condition.context === 'query' && condition.match_type === 'contains') {\n return queryContext.query.includes(condition.value)\n }\n if (condition.context === 'query' && condition.match_type === 'prefix') {\n return queryContext.query.startsWith(condition.value)\n }\n\n return false\n }).length > 0\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAsB;;;ACoBf,IAAM,WAAW,CACtB,kBACA,kBACmB;AACnB,QA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;AACA,UAAM,aAAa,KAAK,OAAO,gBAAgB,eAAe,CAAC;AAE/D,UAAM,0BAA8C,sBAAsB,IAAI,CAAC,YAAY;AACzF,aAAO,gCAAgC,YAAY,OAAO;AAAA,IAC5D,CAAC;AAED,UAAM,aAA8B,sBAAsB,IAAI,CAAC,SAAS,OAAO;AAAA,MAC7E,MAAM;AAAA,QACJ;AAAA,QACA,KAAK,OAAO;AAAA,QACZ,wBAAwB;AAAA,QACxB;AAAA,MACF;AAAA,MACA,WAAW,QAAQ;AAAA,IACrB,EAAE;AAEF,UAAM,cAAc,MAAM,KAAK,cAAc,UAAU;AAEvD,UAAM,yBAAyB,YAAY,IAAI,CAAC,UAAU,MAAM;AAjEpE;AAmEM,WAAI,2BAAsB,GAAG,WAAzB,mBAAiC,WAAW;AAC9C,eAAO,6BAA6B,UAAU,sBAAsB,EAAE;AAAA,MACxE;AACA,aAAO;AAAA,QACL;AAAA,QACA,sBAAsB;AAAA,QACtB,KAAK,OAAO;AAAA,QACZ,wBAAwB;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,SAAS;AAAA,IACX;AAAA,EACF;AACF;AAEA,IAAM,eAAe,CAAC,QAAsB,aAA2B,IAAI,OAAO,QAAQ,QAAQ;AAElG,IAAO,cAAQ;","names":["operator","value","sum","filter","facetAttributes","deepmerge","getHighlightFields","highlightedMatch","getHighlightFields","buckets","sum"]}

@@ -551,15 +551,19 @@ // src/transformRequest.ts

function transformResponse(response, instantsearchRequest, config, queryRuleActions) {
return {
exhaustiveNbHits: true,
exhaustiveFacetsCount: true,
exhaustiveTypo: true,
exhaustive: { facetsCount: true, nbHits: true, typo: true },
...getPageDetails(response, instantsearchRequest, config),
...getRenderingContent(config, queryRuleActions),
...getFacets(response, config),
hits: getHits(response, config),
index: instantsearchRequest.indexName,
params: stringify(instantsearchRequest.params),
...queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {}
};
try {
return {
exhaustiveNbHits: true,
exhaustiveFacetsCount: true,
exhaustiveTypo: true,
exhaustive: { facetsCount: true, nbHits: true, typo: true },
...getPageDetails(response, instantsearchRequest, config),
...getRenderingContent(config, queryRuleActions),
...getFacets(response, config),
hits: getHits(response, config),
index: instantsearchRequest.indexName,
params: stringify(instantsearchRequest.params),
...queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {}
};
} catch (e) {
throw new Error(`Error transforming Elasticsearch response for index`);
}
}

@@ -588,21 +592,47 @@ var transformFacetValuesResponse = (response, instantsearchRequest) => {

async msearch(requests) {
const response = await fetch(`${this.config.host}/_msearch`, {
headers: {
...this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {},
"content-type": "application/json"
},
body: requests.reduce(
(sum, request) => [
...sum,
JSON.stringify({ index: request.indexName }),
"\n",
JSON.stringify(request.body),
"\n"
],
[]
).join(""),
method: "POST"
});
const responses = await response.json();
return responses.responses;
var _a, _b, _c, _d;
try {
const response = await fetch(`${this.config.host}/_msearch`, {
headers: {
...this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {},
"content-type": "application/json"
},
body: requests.reduce(
(sum, request) => [
...sum,
JSON.stringify({ index: request.indexName }),
"\n",
JSON.stringify(request.body),
"\n"
],
[]
).join(""),
method: "POST"
});
const responses = await response.json();
if (responses.status >= 500) {
throw new Error(
"Elasticsearch Internal Error: Check your elasticsearch instance to make sure it can recieve requests."
);
} else if (responses.status === 401) {
throw new Error(
"Cannot connect to Elasticsearch. Check your connection host and API Key. You can also provide a custom Elasticsearch transporter to the API Client. See docs for more information."
);
} else if (((_b = (_a = responses.responses) == null ? void 0 : _a[0]) == null ? void 0 : _b.status) === 403) {
throw new Error(
"Auth Error: You do not have permission to access this index. Check you are calling the right index (specified in frontend) and your API Key permissions has access to the index."
);
} else if (responses.status === 404 || ((_d = (_c = responses.responses) == null ? void 0 : _c[0]) == null ? void 0 : _d.status) === 404) {
throw new Error(
"Elasticsearch index not found. Check your index name and make sure it exists."
);
} else if (responses.status === 400) {
throw new Error(
"Elasticsearch Bad Request. Check your query and make sure it is valid. Turn on debug mode to see the Elasticsearch query."
);
}
return responses.responses;
} catch (error) {
throw error;
}
}

@@ -667,7 +697,12 @@ };

var Client = class {
constructor(config) {
constructor(config, settings = { debug: false }) {
this.config = config;
this.settings = settings;
this.transporter = "msearch" in config.connection ? config.connection : new ESTransporter(config.connection);
}
async performSearch(requests) {
if (this.settings.debug) {
console.log("Performing search with requests:");
console.log(JSON.stringify(requests, null, 2));
}
const responses = await this.transporter.msearch(requests);

@@ -716,3 +751,3 @@ return responses;

};
var createClient = (config) => new Client(config);
var createClient = (config, settings) => new Client(config, settings);
var src_default = createClient;

@@ -719,0 +754,0 @@ export {

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/transformRequest.ts","../src/utils.ts","../src/transformResponse.ts","../src/highlightUtils.ts","../src/Transporter.ts","../src/queryRules.ts","../src/index.ts"],"sourcesContent":["import deepmerge from 'deepmerge'\nimport { QueryRuleActions } from './queryRules'\nimport { FacetAttribute, RequestOptions, SearchSettingsConfig } from './types'\nimport {\n AlgoliaMultipleQueriesQuery,\n ElasticsearchQuery,\n ElasticsearchSearchRequest\n} from './types'\nimport { getFacet, getFacetAttribute } from './utils'\n\nexport const createRegexQuery = (queryString: string) => {\n let query = queryString.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n query = query\n .split('')\n .map((char) => {\n if (/[a-z]/.test(char)) {\n return `[${char}${char.toUpperCase()}]`\n }\n return char\n })\n .join('')\n query = `${query}.*`\n if (queryString.length > 2) {\n query = `([a-zA-Z]+ )+?${query}`\n }\n return query\n}\n\nconst transformNumericFilters = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n): ElasticsearchQuery[] => {\n const { params = {} } = request\n const { numericFilters } = params\n\n if (!Array.isArray(numericFilters)) {\n return []\n }\n\n return numericFilters.reduce((sum, filter) => {\n const [match, field, operator, value] = filter.match(\n /([\\w\\.\\_\\-]+)(\\=|\\!\\=|\\>|\\>\\=|\\<|\\<\\=)(\\d+)/\n )\n const fieldConfig = getFacet(config.facet_attributes || [], field)\n\n if (!match) return sum\n\n const getFilter = (operator: string, value: string) => {\n if (operator === '=') {\n return {\n term: {\n [field]: value\n }\n }\n } else if (operator === '!=') {\n return {\n bool: {\n must_not: {\n term: {\n [field]: value\n }\n }\n }\n }\n } else if (operator === '>') {\n return {\n range: {\n [field]: {\n gt: value\n }\n }\n }\n } else if (operator === '>=') {\n return {\n range: {\n [field]: {\n gte: value\n }\n }\n }\n } else if (operator === '<') {\n return {\n range: {\n [field]: {\n lt: value\n }\n }\n }\n } else if (operator === '<=') {\n return {\n range: {\n [field]: {\n lte: value\n }\n }\n }\n }\n }\n\n const esFilter = []\n\n if (typeof fieldConfig !== 'string' && fieldConfig.nestedPath) {\n esFilter.push({\n nested: {\n path: fieldConfig.nestedPath,\n query: {\n bool: {\n filter: [getFilter(operator, value)]\n }\n }\n }\n })\n } else {\n esFilter.push(getFilter(operator, value))\n }\n\n return [...sum, ...esFilter]\n }, [])\n}\n\nconst termFilter = (field: string, value: string) => {\n return { term: { [field]: value } }\n}\n\nconst transformFacetFilters = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n): ElasticsearchQuery[] => {\n const { params = {} } = request\n const { facetFilters } = params\n\n if (!Array.isArray(facetFilters)) {\n return []\n }\n\n return facetFilters.reduce((sum, filter) => {\n if (Array.isArray(filter)) {\n return [\n ...sum,\n {\n bool: {\n should: filter.reduce((sum, filter) => {\n const [facet, value] = filter.split(':')\n const facetAttribute = getFacetAttribute(facet)\n const facetConfig = getFacet(config.facet_attributes || [], facetAttribute)\n const field = typeof facetConfig === 'string' ? facetConfig : facetConfig.field\n\n if (\n typeof facetConfig !== 'string' &&\n isNestedFacet(facetConfig) &&\n facetConfig.nestedPath\n ) {\n // detect if there is a nested filter in sum\n // if one doesn't exist, add one\n // if one does exist, add to it\n const nestedFilter = sum.find((filter: any) => {\n return filter.nested && filter.nested.path === facetConfig.nestedPath\n })\n\n if (nestedFilter) {\n nestedFilter.nested.query.bool.should.push(\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n )\n return sum\n } else {\n return [\n ...sum,\n {\n nested: {\n path: facetConfig.nestedPath,\n query: {\n bool: {\n should: [\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n ]\n }\n }\n }\n }\n ]\n }\n }\n return [...sum, termFilter(field, value)]\n }, [])\n }\n }\n ]\n } else if (typeof filter === 'string') {\n const [facet, value] = filter.split(':')\n const facetAttribute = getFacetAttribute(facet)\n const facetConfig = getFacet(config.facet_attributes || [], facetAttribute)\n const field = typeof facetConfig === 'string' ? facetConfig : facetConfig.field\n\n if (typeof facetConfig !== 'string' && isNestedFacet(facetConfig) && facetConfig.nestedPath) {\n // detect if there is a nested filter in sum\n // if one doesn't exist, add one\n // if one does exist, add to it\n const nestedFilter = sum.find((filter: any) => {\n return filter.nested && filter.nested.path === facetConfig.nestedPath + '.'\n })\n\n if (nestedFilter) {\n nestedFilter.nested.query.bool.should.push(\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n )\n return sum\n } else {\n return [\n ...sum,\n {\n nested: {\n path: facetConfig.nestedPath,\n query: {\n bool: {\n should: [termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)]\n }\n }\n }\n }\n ]\n }\n }\n return [...sum, termFilter(field, value)]\n }\n }, [])\n}\n\nconst isNestedFacet = (facet: FacetAttribute): boolean => {\n return typeof facet !== 'string' && !!facet.nestedPath\n}\n\nconst getTermAggregation = (facet: FacetAttribute, size: number, search: string) => {\n const searchInclude = search && search.length > 0 ? { include: createRegexQuery(search) } : {}\n let aggEntries = {}\n\n const getInnerAggs = (facetName: string, field: string): any => {\n if (typeof facet === 'string' || facet.type === 'string') {\n aggEntries = {\n [facetName]: {\n terms: {\n field: field,\n size,\n ...searchInclude\n }\n }\n }\n } else if (facet.type === 'numeric') {\n aggEntries = {\n [facetName + '$_stats']: {\n stats: {\n field: field\n }\n },\n [facetName + '$_entries']: {\n terms: {\n field: field,\n size: size\n }\n }\n }\n }\n return aggEntries\n }\n\n if (typeof facet === 'string') {\n return getInnerAggs(facet, facet)\n } else if (isNestedFacet(facet)) {\n return {\n [`${facet.nestedPath}.`]: {\n nested: {\n path: facet.nestedPath\n },\n aggs: getInnerAggs(facet.attribute, `${facet.nestedPath}.${facet.field}`)\n }\n }\n } else {\n return getInnerAggs(facet.attribute, facet.field)\n }\n}\n\nexport const getAggs = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions\n) => {\n const { params = {}, type } = request\n // @ts-ignore\n const { facets, maxValuesPerFacet, facetName, facetQuery } = params\n const maxFacetSize = maxValuesPerFacet || 10\n const facetAttributes = config.facet_attributes || []\n\n if (facetName) {\n return getTermAggregation(getFacet(facetAttributes, facetName), maxFacetSize, facetQuery)\n } else if (Array.isArray(facets)) {\n let facetAttibutes = config.facet_attributes || []\n\n if (queryRuleActions.facetAttributesOrder) {\n facetAttibutes = queryRuleActions.facetAttributesOrder.map((attribute) => {\n return getFacet(config.facet_attributes || [], attribute)\n })\n }\n\n const facetAttributes: FacetAttribute[] =\n facets[0] === '*'\n ? facetAttibutes\n : facets.map((facetAttribute) => {\n return getFacet(config.facet_attributes || [], facetAttribute)\n })\n return (\n facetAttributes.reduce((sum, facet) => {\n return deepmerge(sum, getTermAggregation(facet, maxFacetSize, ''))\n }, {}) || {}\n )\n } else if (typeof facets === 'string') {\n const field = getFacet(config.facet_attributes || [], facets)\n return getTermAggregation(field, maxFacetSize, '')\n }\n}\n\nexport function RelevanceQueryMatch(\n query: string,\n search_attributes: string[],\n queryRuleActions: QueryRuleActions\n) {\n if (queryRuleActions) {\n return {\n function_score: {\n query: {\n pinned: {\n ids: queryRuleActions.pinnedDocs,\n organic: {\n combined_fields: {\n query: queryRuleActions.query,\n fields: search_attributes\n }\n }\n }\n },\n functions: queryRuleActions.boostFunctions\n }\n }\n }\n return {\n combined_fields: { query: query, fields: search_attributes }\n }\n}\n\nconst getQuery = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions,\n requestOptions?: RequestOptions\n) => {\n const { params = {} } = request\n const { query } = params\n\n const searchAttributes = config.search_attributes\n\n const filters = [\n ...transformFacetFilters(request, config),\n ...transformNumericFilters(request, config),\n ...(requestOptions?.getBaseFilters?.() || [])\n ]\n\n return {\n bool: {\n filter: filters,\n must:\n typeof query === 'string' && query !== ''\n ? requestOptions?.getQuery\n ? requestOptions.getQuery(query, searchAttributes, config)\n : RelevanceQueryMatch(query, searchAttributes, queryRuleActions)\n : []\n }\n }\n}\n\nconst getResultsSize = (request: AlgoliaMultipleQueriesQuery, config: SearchSettingsConfig) => {\n const { params = {} } = request\n const hitsPerPage = params.hitsPerPage || 20\n\n return {\n size: hitsPerPage,\n from: (params.page || 0) * hitsPerPage\n }\n}\n\nexport const getHitFields = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { attributesToRetrieve } = params\n // ignoring attributesToRetrieve for now\n\n return {\n _source: {\n includes: config.result_attributes\n }\n }\n}\n\nexport const getHighlightFields = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { attributesToHighlight } = params\n // ignoring attributesToHighlight for now\n return {\n highlight: {\n pre_tags: [params.highlightPreTag || '<ais-highlight-0000000000>'],\n post_tags: [params.highlightPostTag || '</ais-highlight-0000000000>'],\n fields:\n config.highlight_attributes?.reduce(\n (sum, field) => ({\n ...sum,\n [field]: {}\n }),\n {}\n ) || {}\n }\n }\n}\n\nexport function transformRequest(\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions,\n requestOptions?: RequestOptions\n): ElasticsearchSearchRequest {\n const body: ElasticsearchSearchRequest = {\n aggs: getAggs(request, config, queryRuleActions),\n query: getQuery(request, config, queryRuleActions, requestOptions),\n ...getResultsSize(request, config),\n ...getHitFields(request, config),\n ...getHighlightFields(request, config)\n }\n\n return body\n}\n","import { FacetAttribute, FacetFieldConfig } from './types'\n\nexport const createRegexQuery = (queryString: string) => {\n let query = queryString.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n query = query\n .split('')\n .map((char) => {\n if (/[a-z]/.test(char)) {\n return `[${char}${char.toUpperCase()}]`\n }\n return char\n })\n .join('')\n query = `${query}.*`\n if (queryString.length > 2) {\n query = `([a-zA-Z]+ )+?${query}`\n }\n return query\n}\n\nexport const getFacet = (\n facet_attributes: FacetAttribute[],\n attributeName: string\n): FacetAttribute => {\n const f = facet_attributes.find((a) => {\n if (typeof a === 'string') {\n return a === attributeName\n }\n return a.attribute === attributeName\n })\n return f || attributeName\n}\n\nexport const getFacetField = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): string => {\n const attributeKey = typeof attribute === 'string' ? attribute : attribute.attribute\n\n if (facet_attributes.includes(attributeKey)) {\n return attributeKey\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a.attribute === attributeKey)?.field || attributeKey\n )\n}\n\nexport const getFacetByAttribute = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): string => {\n const attributeKey = getFacetAttribute(attribute)\n\n if (facet_attributes.includes(attributeKey)) {\n return attributeKey\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a.attribute === attributeKey)?.attribute || attributeKey\n )\n}\n\nexport const getFacetAttribute = (facetAttribute: FacetAttribute): string => {\n return typeof facetAttribute === 'string' ? facetAttribute : facetAttribute.attribute\n}\n\nexport const getFacetFieldType = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): FacetFieldConfig['type'] => {\n const attributeKey = typeof attribute === 'string' ? attribute : attribute.attribute\n\n if (facet_attributes.includes(attributeKey)) {\n return 'string'\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a?.attribute === attributeKey)?.type || 'string'\n )\n}\n","import { stringify } from 'querystring'\nimport { SearchSettingsConfig } from './types'\nimport { getHighlightFields, highlightTerm } from './highlightUtils'\nimport { AlgoliaMultipleQueriesQuery, ElasticsearchResponseBody } from './types'\nimport { getFacetFieldType } from './utils'\nimport { QueryRuleActions } from './queryRules'\n\ntype FacetsList = Record<string, Record<string, number>>\ntype FacetsStats = Record<string, { min: number; max: number; avg: number; sum: number }>\n\nconst getHits = (response: ElasticsearchResponseBody, config: SearchSettingsConfig) => {\n const { hits } = response\n\n return hits.hits.map((hit) => ({\n objectID: hit._id,\n ...(hit._source || {}),\n _highlightResult: getHighlightFields(hit)\n }))\n}\n\nconst getFacets = (response: ElasticsearchResponseBody, config: SearchSettingsConfig) => {\n if (!response?.aggregations) {\n return {}\n }\n\n // flattening for nested facets\n const aggregations = Object.keys(response.aggregations).reduce<Record<string, any>>(\n (sum, key) => {\n const value = (response.aggregations || {})[key] as any\n\n if (key.endsWith('.')) {\n const { doc_count, ...nestedAggregations } = value\n return {\n ...sum,\n ...nestedAggregations\n }\n }\n\n return {\n ...sum,\n [key]: value\n }\n },\n {}\n )\n\n return Object.keys(aggregations).reduce<{\n facets: FacetsList\n facets_stats: FacetsStats\n }>(\n (sum, f) => {\n const facet = f.split('$')[0]\n const fieldType = getFacetFieldType(config.facet_attributes || [], facet)\n\n if (fieldType === 'numeric') {\n const facetValues = aggregations[facet + '$_stats'] as any\n const { buckets } = aggregations[facet + '$_entries'] as {\n buckets: any[]\n }\n\n return {\n ...sum,\n facets: {\n ...sum.facets,\n [facet]: buckets.reduce<Record<string, number>>(\n (sum, bucket) => ({\n ...sum,\n [bucket.key]: bucket.doc_count\n }),\n {}\n )\n },\n facets_stats: {\n ...sum.facets_stats,\n [facet]: {\n min: facetValues.min,\n avg: facetValues.avg,\n max: facetValues.max,\n sum: facetValues.sum\n }\n }\n }\n }\n\n const { buckets } = aggregations[facet] as { buckets: any[] }\n\n return {\n ...sum,\n facets: {\n ...sum.facets,\n [facet]: buckets.reduce<Record<string, number>>(\n (sum, bucket) => ({\n ...sum,\n [bucket.key]: bucket.doc_count\n }),\n {}\n )\n }\n }\n },\n {\n facets: {},\n facets_stats: {}\n }\n )\n}\n\nconst getRenderingContent = (config: SearchSettingsConfig, queryRuleActions: QueryRuleActions) => {\n const defaultOrder = config.facet_attributes?.map((facet) =>\n typeof facet === 'string' ? facet : facet.attribute\n )\n\n return {\n renderingContent: {\n facetOrdering: {\n facets: {\n order: queryRuleActions.facetAttributesOrder || defaultOrder || []\n },\n values: config.facet_attributes?.reduce<Record<string, { sortRemainingBy: 'count' }>>(\n (sum, facet) => {\n const facetName = typeof facet === 'string' ? facet : facet.attribute\n\n // If request has explicit facet orders and the facet is not\n // in the query rule actions, we don't want to sort it\n if (\n queryRuleActions.facetAttributesOrder &&\n !queryRuleActions.facetAttributesOrder.includes(facetName)\n ) {\n return sum\n }\n\n return {\n ...sum,\n [facetName]: {\n sortRemainingBy: 'count'\n }\n }\n },\n {}\n )\n }\n }\n }\n}\n\nconst getPageDetails = (\n response: ElasticsearchResponseBody,\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { hitsPerPage = 20, page = 0, query = '' } = params\n\n const { total } = response.hits\n const totalHits = typeof total === 'number' ? total : total?.value\n const nbPages = Math.ceil((typeof total === 'number' ? total : total?.value || 0) / hitsPerPage)\n\n return {\n hitsPerPage,\n processingTimeMS: response.took,\n nbHits: totalHits,\n page: page,\n nbPages,\n query\n }\n}\n\nexport default function transformResponse(\n response: ElasticsearchResponseBody,\n instantsearchRequest: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions\n) {\n return {\n exhaustiveNbHits: true,\n exhaustiveFacetsCount: true,\n exhaustiveTypo: true,\n exhaustive: { facetsCount: true, nbHits: true, typo: true },\n ...getPageDetails(response, instantsearchRequest, config),\n ...getRenderingContent(config, queryRuleActions),\n ...getFacets(response, config),\n hits: getHits(response, config),\n index: instantsearchRequest.indexName,\n params: stringify(instantsearchRequest.params as any),\n ...(queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {})\n }\n}\n\nexport const transformFacetValuesResponse = (\n response: ElasticsearchResponseBody,\n instantsearchRequest: AlgoliaMultipleQueriesQuery\n) => {\n const aggregations = response.aggregations || {}\n return {\n facetHits: (aggregations[Object.keys(aggregations)[0]] as any).buckets.map((entry: any) => ({\n value: entry.key,\n highlighted: highlightTerm(\n entry.key,\n // @ts-ignore\n instantsearchRequest.params.facetQuery || ''\n ),\n count: entry.doc_count\n })),\n exhaustiveFacetsCount: true,\n processingTimeMS: response.took\n }\n}\n","import type { ElasticsearchHit } from './types'\n\nexport function highlightTerm(value: string, query: string): string {\n const regex = new RegExp(query, 'gi')\n return value.replace(\n regex,\n (match) => `<ais-highlight-0000000000>${match}</ais-highlight-0000000000>`\n )\n}\n\nexport function getHighlightFields(hit: ElasticsearchHit) {\n const { _source = {}, highlight = {} } = hit\n\n const hitHighlights = Object.keys(_source).reduce<Record<string, any>>((sum, fieldKey) => {\n const fieldValue: any = _source[fieldKey]\n const highlightedMatch = highlight[fieldKey] || null\n\n if (Array.isArray(fieldValue) && !highlightedMatch) {\n return {\n ...sum,\n [fieldKey]: fieldValue.map((value) => ({\n matchLevel: 'none',\n matchedWords: [],\n value: value\n }))\n }\n } else if (Array.isArray(highlightedMatch)) {\n // TODO: needs to return all non matches values too\n return {\n ...sum,\n [fieldKey]: highlightedMatch.map((highlightedMatch) => {\n const matchWords = Array.from(\n highlightedMatch.matchAll(\n /\\<ais-highlight-0000000000\\>(.*?)\\<\\/ais-highlight-0000000000\\>/g\n )\n ).map((match) => match[1])\n return {\n fullyHighlighted: false,\n matchLevel: 'full',\n matchedWords: matchWords,\n value: highlightedMatch\n }\n })\n }\n }\n\n return {\n ...sum,\n [fieldKey]: {\n matchLevel: 'none',\n matchedWords: [],\n value: fieldValue\n }\n }\n }, {})\n\n return hitHighlights\n}\n","import { ClientConfigConnection, SearchRequest } from './types'\nimport { ElasticsearchResponseBody, Transporter } from './types'\n\nexport class ESTransporter implements Transporter {\n constructor(public config: ClientConfigConnection) {}\n\n async msearch(requests: SearchRequest[]): Promise<ElasticsearchResponseBody[]> {\n // @ts-ignore\n const response = await fetch(`${this.config.host}/_msearch`, {\n headers: {\n ...(this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {}),\n 'content-type': 'application/json'\n },\n body: requests\n .reduce<string[]>(\n (sum, request) => [\n ...sum,\n JSON.stringify({ index: request.indexName }),\n '\\n',\n JSON.stringify(request.body),\n '\\n'\n ],\n []\n )\n .join(''),\n method: 'POST'\n })\n\n const responses = await response.json()\n return responses.responses\n }\n}\n","import { AlgoliaMultipleQueriesQuery, QueryRule, SearchSettingsConfig } from './types'\n\nexport interface QueryContext {\n query: string\n}\n\nexport interface QueryRuleActions {\n pinnedDocs: string[]\n boostFunctions: any[]\n query: string\n userData: unknown[]\n facetAttributesOrder: string[] | undefined\n}\n\nexport const getQueryRulesActionsFromRequest = (\n queryRules: QueryRule[],\n request: AlgoliaMultipleQueriesQuery\n) => {\n const queryContext: QueryContext = {\n query: request.params?.query || ''\n }\n\n const satisfiedRules = getSatisfiedRules(queryContext, queryRules || [])\n\n const actions = satisfiedRules.reduce<QueryRuleActions>(\n (sum, rule) => {\n rule.actions.map((action) => {\n if (action.action === 'PinnedResult') {\n sum.pinnedDocs.push(...action.documentIds)\n } else if (action.action === 'QueryRewrite') {\n sum.query = action.query\n } else if (action.action === 'QueryAttributeBoost') {\n sum.boostFunctions.push({\n filter: {\n match: { [action.attribute]: { query: action.value } }\n },\n weight: action.boost\n })\n } else if (action.action === 'RenderUserData') {\n sum.userData.push(JSON.parse(action.userData))\n } else if (action.action === 'RenderFacetsOrder') {\n sum.facetAttributesOrder = action.facetAttributesOrder\n }\n })\n return sum\n },\n {\n pinnedDocs: [],\n boostFunctions: [],\n query: queryContext.query,\n userData: [],\n facetAttributesOrder: undefined\n }\n )\n return actions\n}\n\nexport const getSatisfiedRules = (queryContext: QueryContext, rules: QueryRule[]) =>\n rules.filter(\n (rule) =>\n rule.conditions.filter((condition) => {\n if (condition.context === 'query' && condition.match_type === 'exact') {\n return condition.value === queryContext.query\n }\n if (condition.context === 'query' && condition.match_type === 'contains') {\n return queryContext.query.includes(condition.value)\n }\n if (condition.context === 'query' && condition.match_type === 'prefix') {\n return queryContext.query.startsWith(condition.value)\n }\n\n return false\n }).length > 0\n )\n","import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search'\nimport { transformRequest } from './transformRequest'\nimport transformResponse, { transformFacetValuesResponse } from './transformResponse'\nimport { ClientConfig, SearchRequest, RequestOptions, Transporter, QueryRuleAction } from './types'\nimport { ESTransporter } from './Transporter'\nimport { getQueryRulesActionsFromRequest, QueryRuleActions } from './queryRules'\nexport * from './types'\n\nclass Client {\n transporter: Transporter\n\n constructor(private config: ClientConfig) {\n this.transporter =\n 'msearch' in config.connection ? config.connection : new ESTransporter(config.connection)\n }\n\n private async performSearch(requests: SearchRequest[]) {\n const responses = await this.transporter.msearch(requests)\n return responses\n }\n\n async handleRequest(body: any, requestOptions?: RequestOptions) {\n const instantsearchRequests = body as AlgoliaMultipleQueriesQuery[]\n\n const instantsearchResponses = this.handleInstantSearchRequests(\n instantsearchRequests,\n requestOptions\n )\n\n return instantsearchResponses\n }\n\n async handleInstantSearchRequests(\n instantsearchRequests: AlgoliaMultipleQueriesQuery[],\n requestOptions?: RequestOptions\n ) {\n const queryRules = this.config.search_settings.query_rules || []\n\n const requestQueryRuleActions: QueryRuleActions[] = instantsearchRequests.map((request) => {\n return getQueryRulesActionsFromRequest(queryRules, request)\n })\n\n const esRequests: SearchRequest[] = instantsearchRequests.map((request, i) => ({\n body: transformRequest(\n request,\n this.config.search_settings,\n requestQueryRuleActions[i],\n requestOptions\n ),\n indexName: request.indexName\n }))\n\n const esResponses = await this.performSearch(esRequests)\n\n const instantsearchResponses = esResponses.map((response, i) => {\n // @ts-ignore\n if (instantsearchRequests[i].params?.facetName) {\n return transformFacetValuesResponse(response, instantsearchRequests[i])\n }\n return transformResponse(\n response,\n instantsearchRequests[i],\n this.config.search_settings,\n requestQueryRuleActions[i]\n )\n })\n\n return {\n results: instantsearchResponses\n }\n }\n}\n\nconst createClient = (config: ClientConfig) => new Client(config)\n\nexport default createClient\n"],"mappings":";AAAA,OAAO,eAAe;;;ACoBf,IAAM,WAAW,CACtB,kBACA,kBACmB;AACnB,QAAM,IAAI,iBAAiB,KAAK,CAAC,MAAM;AACrC,QAAI,OAAO,MAAM,UAAU;AACzB,aAAO,MAAM;AAAA,IACf;AACA,WAAO,EAAE,cAAc;AAAA,EACzB,CAAC;AACD,SAAO,KAAK;AACd;AAkCO,IAAM,oBAAoB,CAAC,mBAA2C;AAC3E,SAAO,OAAO,mBAAmB,WAAW,iBAAiB,eAAe;AAC9E;AAEO,IAAM,oBAAoB,CAC/B,kBACA,cAC6B;AAxE/B;AAyEE,QAAM,eAAe,OAAO,cAAc,WAAW,YAAY,UAAU;AAE3E,MAAI,iBAAiB,SAAS,YAAY,GAAG;AAC3C,WAAO;AAAA,EACT;AACA,WACE,sBAEG,KAAK,CAAC,OAAM,uBAAG,eAAc,YAAY,MAF5C,mBAE+C,SAAQ;AAE3D;;;ADzEO,IAAM,mBAAmB,CAAC,gBAAwB;AACvD,MAAI,QAAQ,YAAY,QAAQ,uCAAuC,MAAM;AAC7E,UAAQ,MACL,MAAM,EAAE,EACR,IAAI,CAAC,SAAS;AACb,QAAI,QAAQ,KAAK,IAAI,GAAG;AACtB,aAAO,IAAI,OAAO,KAAK,YAAY;AAAA,IACrC;AACA,WAAO;AAAA,EACT,CAAC,EACA,KAAK,EAAE;AACV,UAAQ,GAAG;AACX,MAAI,YAAY,SAAS,GAAG;AAC1B,YAAQ,iBAAiB;AAAA,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UAAU;AAEvD,UAAM,yBAAyB,YAAY,IAAI,CAAC,UAAU,MAAM;AAtDpE;AAwDM,WAAI,2BAAsB,GAAG,WAAzB,mBAAiC,WAAW;AAC9C,eAAO,6BAA6B,UAAU,sBAAsB,EAAE;AAAA,MACxE;AACA,aAAO;AAAA,QACL;AAAA,QACA,sBAAsB;AAAA,QACtB,KAAK,OAAO;AAAA,QACZ,wBAAwB;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,SAAS;AAAA,IACX;AAAA,EACF;AACF;AAEA,IAAM,eAAe,CAAC,WAAyB,IAAI,OAAO,MAAM;AAEhE,IAAO,cAAQ;","names":["operator","value","sum","filter","facetAttributes","getHighlightFields","highlightedMatch","getHighlightFields","buckets","sum"]}
{"version":3,"sources":["../src/transformRequest.ts","../src/utils.ts","../src/transformResponse.ts","../src/highlightUtils.ts","../src/Transporter.ts","../src/queryRules.ts","../src/index.ts"],"sourcesContent":["import deepmerge from 'deepmerge'\nimport { QueryRuleActions } from './queryRules'\nimport { FacetAttribute, RequestOptions, SearchSettingsConfig } from './types'\nimport {\n AlgoliaMultipleQueriesQuery,\n ElasticsearchQuery,\n ElasticsearchSearchRequest\n} from './types'\nimport { getFacet, getFacetAttribute } from './utils'\n\nexport const createRegexQuery = (queryString: string) => {\n let query = queryString.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n query = query\n .split('')\n .map((char) => {\n if (/[a-z]/.test(char)) {\n return `[${char}${char.toUpperCase()}]`\n }\n return char\n })\n .join('')\n query = `${query}.*`\n if (queryString.length > 2) {\n query = `([a-zA-Z]+ )+?${query}`\n }\n return query\n}\n\nconst transformNumericFilters = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n): ElasticsearchQuery[] => {\n const { params = {} } = request\n const { numericFilters } = params\n\n if (!Array.isArray(numericFilters)) {\n return []\n }\n\n return numericFilters.reduce((sum, filter) => {\n const [match, field, operator, value] = filter.match(\n /([\\w\\.\\_\\-]+)(\\=|\\!\\=|\\>|\\>\\=|\\<|\\<\\=)(\\d+)/\n )\n const fieldConfig = getFacet(config.facet_attributes || [], field)\n\n if (!match) return sum\n\n const getFilter = (operator: string, value: string) => {\n if (operator === '=') {\n return {\n term: {\n [field]: value\n }\n }\n } else if (operator === '!=') {\n return {\n bool: {\n must_not: {\n term: {\n [field]: value\n }\n }\n }\n }\n } else if (operator === '>') {\n return {\n range: {\n [field]: {\n gt: value\n }\n }\n }\n } else if (operator === '>=') {\n return {\n range: {\n [field]: {\n gte: value\n }\n }\n }\n } else if (operator === '<') {\n return {\n range: {\n [field]: {\n lt: value\n }\n }\n }\n } else if (operator === '<=') {\n return {\n range: {\n [field]: {\n lte: value\n }\n }\n }\n }\n }\n\n const esFilter = []\n\n if (typeof fieldConfig !== 'string' && fieldConfig.nestedPath) {\n esFilter.push({\n nested: {\n path: fieldConfig.nestedPath,\n query: {\n bool: {\n filter: [getFilter(operator, value)]\n }\n }\n }\n })\n } else {\n esFilter.push(getFilter(operator, value))\n }\n\n return [...sum, ...esFilter]\n }, [])\n}\n\nconst termFilter = (field: string, value: string) => {\n return { term: { [field]: value } }\n}\n\nconst transformFacetFilters = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n): ElasticsearchQuery[] => {\n const { params = {} } = request\n const { facetFilters } = params\n\n if (!Array.isArray(facetFilters)) {\n return []\n }\n\n return facetFilters.reduce((sum, filter) => {\n if (Array.isArray(filter)) {\n return [\n ...sum,\n {\n bool: {\n should: filter.reduce((sum, filter) => {\n const [facet, value] = filter.split(':')\n const facetAttribute = getFacetAttribute(facet)\n const facetConfig = getFacet(config.facet_attributes || [], facetAttribute)\n const field = typeof facetConfig === 'string' ? facetConfig : facetConfig.field\n\n if (\n typeof facetConfig !== 'string' &&\n isNestedFacet(facetConfig) &&\n facetConfig.nestedPath\n ) {\n // detect if there is a nested filter in sum\n // if one doesn't exist, add one\n // if one does exist, add to it\n const nestedFilter = sum.find((filter: any) => {\n return filter.nested && filter.nested.path === facetConfig.nestedPath\n })\n\n if (nestedFilter) {\n nestedFilter.nested.query.bool.should.push(\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n )\n return sum\n } else {\n return [\n ...sum,\n {\n nested: {\n path: facetConfig.nestedPath,\n query: {\n bool: {\n should: [\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n ]\n }\n }\n }\n }\n ]\n }\n }\n return [...sum, termFilter(field, value)]\n }, [])\n }\n }\n ]\n } else if (typeof filter === 'string') {\n const [facet, value] = filter.split(':')\n const facetAttribute = getFacetAttribute(facet)\n const facetConfig = getFacet(config.facet_attributes || [], facetAttribute)\n const field = typeof facetConfig === 'string' ? facetConfig : facetConfig.field\n\n if (typeof facetConfig !== 'string' && isNestedFacet(facetConfig) && facetConfig.nestedPath) {\n // detect if there is a nested filter in sum\n // if one doesn't exist, add one\n // if one does exist, add to it\n const nestedFilter = sum.find((filter: any) => {\n return filter.nested && filter.nested.path === facetConfig.nestedPath + '.'\n })\n\n if (nestedFilter) {\n nestedFilter.nested.query.bool.should.push(\n termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)\n )\n return sum\n } else {\n return [\n ...sum,\n {\n nested: {\n path: facetConfig.nestedPath,\n query: {\n bool: {\n should: [termFilter(`${facetConfig.nestedPath}.${facetConfig.field}`, value)]\n }\n }\n }\n }\n ]\n }\n }\n return [...sum, termFilter(field, value)]\n }\n }, [])\n}\n\nconst isNestedFacet = (facet: FacetAttribute): boolean => {\n return typeof facet !== 'string' && !!facet.nestedPath\n}\n\nconst getTermAggregation = (facet: FacetAttribute, size: number, search: string) => {\n const searchInclude = search && search.length > 0 ? { include: createRegexQuery(search) } : {}\n let aggEntries = {}\n\n const getInnerAggs = (facetName: string, field: string): any => {\n if (typeof facet === 'string' || facet.type === 'string') {\n aggEntries = {\n [facetName]: {\n terms: {\n field: field,\n size,\n ...searchInclude\n }\n }\n }\n } else if (facet.type === 'numeric') {\n aggEntries = {\n [facetName + '$_stats']: {\n stats: {\n field: field\n }\n },\n [facetName + '$_entries']: {\n terms: {\n field: field,\n size: size\n }\n }\n }\n }\n return aggEntries\n }\n\n if (typeof facet === 'string') {\n return getInnerAggs(facet, facet)\n } else if (isNestedFacet(facet)) {\n return {\n [`${facet.nestedPath}.`]: {\n nested: {\n path: facet.nestedPath\n },\n aggs: getInnerAggs(facet.attribute, `${facet.nestedPath}.${facet.field}`)\n }\n }\n } else {\n return getInnerAggs(facet.attribute, facet.field)\n }\n}\n\nexport const getAggs = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions\n) => {\n const { params = {}, type } = request\n // @ts-ignore\n const { facets, maxValuesPerFacet, facetName, facetQuery } = params\n const maxFacetSize = maxValuesPerFacet || 10\n const facetAttributes = config.facet_attributes || []\n\n if (facetName) {\n return getTermAggregation(getFacet(facetAttributes, facetName), maxFacetSize, facetQuery)\n } else if (Array.isArray(facets)) {\n let facetAttibutes = config.facet_attributes || []\n\n if (queryRuleActions.facetAttributesOrder) {\n facetAttibutes = queryRuleActions.facetAttributesOrder.map((attribute) => {\n return getFacet(config.facet_attributes || [], attribute)\n })\n }\n\n const facetAttributes: FacetAttribute[] =\n facets[0] === '*'\n ? facetAttibutes\n : facets.map((facetAttribute) => {\n return getFacet(config.facet_attributes || [], facetAttribute)\n })\n return (\n facetAttributes.reduce((sum, facet) => {\n return deepmerge(sum, getTermAggregation(facet, maxFacetSize, ''))\n }, {}) || {}\n )\n } else if (typeof facets === 'string') {\n const field = getFacet(config.facet_attributes || [], facets)\n return getTermAggregation(field, maxFacetSize, '')\n }\n}\n\nexport function RelevanceQueryMatch(\n query: string,\n search_attributes: string[],\n queryRuleActions: QueryRuleActions\n) {\n if (queryRuleActions) {\n return {\n function_score: {\n query: {\n pinned: {\n ids: queryRuleActions.pinnedDocs,\n organic: {\n combined_fields: {\n query: queryRuleActions.query,\n fields: search_attributes\n }\n }\n }\n },\n functions: queryRuleActions.boostFunctions\n }\n }\n }\n return {\n combined_fields: { query: query, fields: search_attributes }\n }\n}\n\nconst getQuery = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions,\n requestOptions?: RequestOptions\n) => {\n const { params = {} } = request\n const { query } = params\n\n const searchAttributes = config.search_attributes\n\n const filters = [\n ...transformFacetFilters(request, config),\n ...transformNumericFilters(request, config),\n ...(requestOptions?.getBaseFilters?.() || [])\n ]\n\n return {\n bool: {\n filter: filters,\n must:\n typeof query === 'string' && query !== ''\n ? requestOptions?.getQuery\n ? requestOptions.getQuery(query, searchAttributes, config)\n : RelevanceQueryMatch(query, searchAttributes, queryRuleActions)\n : []\n }\n }\n}\n\nconst getResultsSize = (request: AlgoliaMultipleQueriesQuery, config: SearchSettingsConfig) => {\n const { params = {} } = request\n const hitsPerPage = params.hitsPerPage || 20\n\n return {\n size: hitsPerPage,\n from: (params.page || 0) * hitsPerPage\n }\n}\n\nexport const getHitFields = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { attributesToRetrieve } = params\n // ignoring attributesToRetrieve for now\n\n return {\n _source: {\n includes: config.result_attributes\n }\n }\n}\n\nexport const getHighlightFields = (\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { attributesToHighlight } = params\n // ignoring attributesToHighlight for now\n return {\n highlight: {\n pre_tags: [params.highlightPreTag || '<ais-highlight-0000000000>'],\n post_tags: [params.highlightPostTag || '</ais-highlight-0000000000>'],\n fields:\n config.highlight_attributes?.reduce(\n (sum, field) => ({\n ...sum,\n [field]: {}\n }),\n {}\n ) || {}\n }\n }\n}\n\nexport function transformRequest(\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions,\n requestOptions?: RequestOptions\n): ElasticsearchSearchRequest {\n const body: ElasticsearchSearchRequest = {\n aggs: getAggs(request, config, queryRuleActions),\n query: getQuery(request, config, queryRuleActions, requestOptions),\n ...getResultsSize(request, config),\n ...getHitFields(request, config),\n ...getHighlightFields(request, config)\n }\n\n return body\n}\n","import { FacetAttribute, FacetFieldConfig } from './types'\n\nexport const createRegexQuery = (queryString: string) => {\n let query = queryString.replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n query = query\n .split('')\n .map((char) => {\n if (/[a-z]/.test(char)) {\n return `[${char}${char.toUpperCase()}]`\n }\n return char\n })\n .join('')\n query = `${query}.*`\n if (queryString.length > 2) {\n query = `([a-zA-Z]+ )+?${query}`\n }\n return query\n}\n\nexport const getFacet = (\n facet_attributes: FacetAttribute[],\n attributeName: string\n): FacetAttribute => {\n const f = facet_attributes.find((a) => {\n if (typeof a === 'string') {\n return a === attributeName\n }\n return a.attribute === attributeName\n })\n return f || attributeName\n}\n\nexport const getFacetField = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): string => {\n const attributeKey = typeof attribute === 'string' ? attribute : attribute.attribute\n\n if (facet_attributes.includes(attributeKey)) {\n return attributeKey\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a.attribute === attributeKey)?.field || attributeKey\n )\n}\n\nexport const getFacetByAttribute = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): string => {\n const attributeKey = getFacetAttribute(attribute)\n\n if (facet_attributes.includes(attributeKey)) {\n return attributeKey\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a.attribute === attributeKey)?.attribute || attributeKey\n )\n}\n\nexport const getFacetAttribute = (facetAttribute: FacetAttribute): string => {\n return typeof facetAttribute === 'string' ? facetAttribute : facetAttribute.attribute\n}\n\nexport const getFacetFieldType = (\n facet_attributes: FacetAttribute[],\n attribute: FacetAttribute\n): FacetFieldConfig['type'] => {\n const attributeKey = typeof attribute === 'string' ? attribute : attribute.attribute\n\n if (facet_attributes.includes(attributeKey)) {\n return 'string'\n }\n return (\n facet_attributes\n // @ts-ignore: object is possibly null\n .find((a) => a?.attribute === attributeKey)?.type || 'string'\n )\n}\n","import { stringify } from 'querystring'\nimport { SearchSettingsConfig } from './types'\nimport { getHighlightFields, highlightTerm } from './highlightUtils'\nimport { AlgoliaMultipleQueriesQuery, ElasticsearchResponseBody } from './types'\nimport { getFacetFieldType } from './utils'\nimport { QueryRuleActions } from './queryRules'\n\ntype FacetsList = Record<string, Record<string, number>>\ntype FacetsStats = Record<string, { min: number; max: number; avg: number; sum: number }>\n\nconst getHits = (response: ElasticsearchResponseBody, config: SearchSettingsConfig) => {\n const { hits } = response\n\n return hits.hits.map((hit) => ({\n objectID: hit._id,\n ...(hit._source || {}),\n _highlightResult: getHighlightFields(hit)\n }))\n}\n\nconst getFacets = (response: ElasticsearchResponseBody, config: SearchSettingsConfig) => {\n if (!response?.aggregations) {\n return {}\n }\n\n // flattening for nested facets\n const aggregations = Object.keys(response.aggregations).reduce<Record<string, any>>(\n (sum, key) => {\n const value = (response.aggregations || {})[key] as any\n\n if (key.endsWith('.')) {\n const { doc_count, ...nestedAggregations } = value\n return {\n ...sum,\n ...nestedAggregations\n }\n }\n\n return {\n ...sum,\n [key]: value\n }\n },\n {}\n )\n\n return Object.keys(aggregations).reduce<{\n facets: FacetsList\n facets_stats: FacetsStats\n }>(\n (sum, f) => {\n const facet = f.split('$')[0]\n const fieldType = getFacetFieldType(config.facet_attributes || [], facet)\n\n if (fieldType === 'numeric') {\n const facetValues = aggregations[facet + '$_stats'] as any\n const { buckets } = aggregations[facet + '$_entries'] as {\n buckets: any[]\n }\n\n return {\n ...sum,\n facets: {\n ...sum.facets,\n [facet]: buckets.reduce<Record<string, number>>(\n (sum, bucket) => ({\n ...sum,\n [bucket.key]: bucket.doc_count\n }),\n {}\n )\n },\n facets_stats: {\n ...sum.facets_stats,\n [facet]: {\n min: facetValues.min,\n avg: facetValues.avg,\n max: facetValues.max,\n sum: facetValues.sum\n }\n }\n }\n }\n\n const { buckets } = aggregations[facet] as { buckets: any[] }\n\n return {\n ...sum,\n facets: {\n ...sum.facets,\n [facet]: buckets.reduce<Record<string, number>>(\n (sum, bucket) => ({\n ...sum,\n [bucket.key]: bucket.doc_count\n }),\n {}\n )\n }\n }\n },\n {\n facets: {},\n facets_stats: {}\n }\n )\n}\n\nconst getRenderingContent = (config: SearchSettingsConfig, queryRuleActions: QueryRuleActions) => {\n const defaultOrder = config.facet_attributes?.map((facet) =>\n typeof facet === 'string' ? facet : facet.attribute\n )\n\n return {\n renderingContent: {\n facetOrdering: {\n facets: {\n order: queryRuleActions.facetAttributesOrder || defaultOrder || []\n },\n values: config.facet_attributes?.reduce<Record<string, { sortRemainingBy: 'count' }>>(\n (sum, facet) => {\n const facetName = typeof facet === 'string' ? facet : facet.attribute\n\n // If request has explicit facet orders and the facet is not\n // in the query rule actions, we don't want to sort it\n if (\n queryRuleActions.facetAttributesOrder &&\n !queryRuleActions.facetAttributesOrder.includes(facetName)\n ) {\n return sum\n }\n\n return {\n ...sum,\n [facetName]: {\n sortRemainingBy: 'count'\n }\n }\n },\n {}\n )\n }\n }\n }\n}\n\nconst getPageDetails = (\n response: ElasticsearchResponseBody,\n request: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig\n) => {\n const { params = {} } = request\n const { hitsPerPage = 20, page = 0, query = '' } = params\n\n const { total } = response.hits\n const totalHits = typeof total === 'number' ? total : total?.value\n const nbPages = Math.ceil((typeof total === 'number' ? total : total?.value || 0) / hitsPerPage)\n\n return {\n hitsPerPage,\n processingTimeMS: response.took,\n nbHits: totalHits,\n page: page,\n nbPages,\n query\n }\n}\n\nexport default function transformResponse(\n response: ElasticsearchResponseBody,\n instantsearchRequest: AlgoliaMultipleQueriesQuery,\n config: SearchSettingsConfig,\n queryRuleActions: QueryRuleActions\n) {\n try {\n return {\n exhaustiveNbHits: true,\n exhaustiveFacetsCount: true,\n exhaustiveTypo: true,\n exhaustive: { facetsCount: true, nbHits: true, typo: true },\n ...getPageDetails(response, instantsearchRequest, config),\n ...getRenderingContent(config, queryRuleActions),\n ...getFacets(response, config),\n hits: getHits(response, config),\n index: instantsearchRequest.indexName,\n params: stringify(instantsearchRequest.params as any),\n ...(queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {})\n }\n } catch (e) {\n throw new Error(`Error transforming Elasticsearch response for index`)\n }\n}\n\nexport const transformFacetValuesResponse = (\n response: ElasticsearchResponseBody,\n instantsearchRequest: AlgoliaMultipleQueriesQuery\n) => {\n const aggregations = response.aggregations || {}\n return {\n facetHits: (aggregations[Object.keys(aggregations)[0]] as any).buckets.map((entry: any) => ({\n value: entry.key,\n highlighted: highlightTerm(\n entry.key,\n // @ts-ignore\n instantsearchRequest.params.facetQuery || ''\n ),\n count: entry.doc_count\n })),\n exhaustiveFacetsCount: true,\n processingTimeMS: response.took\n }\n}\n","import type { ElasticsearchHit } from './types'\n\nexport function highlightTerm(value: string, query: string): string {\n const regex = new RegExp(query, 'gi')\n return value.replace(\n regex,\n (match) => `<ais-highlight-0000000000>${match}</ais-highlight-0000000000>`\n )\n}\n\nexport function getHighlightFields(hit: ElasticsearchHit) {\n const { _source = {}, highlight = {} } = hit\n\n const hitHighlights = Object.keys(_source).reduce<Record<string, any>>((sum, fieldKey) => {\n const fieldValue: any = _source[fieldKey]\n const highlightedMatch = highlight[fieldKey] || null\n\n if (Array.isArray(fieldValue) && !highlightedMatch) {\n return {\n ...sum,\n [fieldKey]: fieldValue.map((value) => ({\n matchLevel: 'none',\n matchedWords: [],\n value: value\n }))\n }\n } else if (Array.isArray(highlightedMatch)) {\n // TODO: needs to return all non matches values too\n return {\n ...sum,\n [fieldKey]: highlightedMatch.map((highlightedMatch) => {\n const matchWords = Array.from(\n highlightedMatch.matchAll(\n /\\<ais-highlight-0000000000\\>(.*?)\\<\\/ais-highlight-0000000000\\>/g\n )\n ).map((match) => match[1])\n return {\n fullyHighlighted: false,\n matchLevel: 'full',\n matchedWords: matchWords,\n value: highlightedMatch\n }\n })\n }\n }\n\n return {\n ...sum,\n [fieldKey]: {\n matchLevel: 'none',\n matchedWords: [],\n value: fieldValue\n }\n }\n }, {})\n\n return hitHighlights\n}\n","import { ClientConfigConnection, SearchRequest } from './types'\nimport { ElasticsearchResponseBody, Transporter } from './types'\n\nexport class ESTransporter implements Transporter {\n constructor(public config: ClientConfigConnection) {}\n\n async msearch(requests: SearchRequest[]): Promise<ElasticsearchResponseBody[]> {\n // @ts-ignore\n try {\n const response = await fetch(`${this.config.host}/_msearch`, {\n headers: {\n ...(this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {}),\n 'content-type': 'application/json'\n },\n body: requests\n .reduce<string[]>(\n (sum, request) => [\n ...sum,\n JSON.stringify({ index: request.indexName }),\n '\\n',\n JSON.stringify(request.body),\n '\\n'\n ],\n []\n )\n .join(''),\n method: 'POST'\n })\n\n const responses = await response.json()\n\n if (responses.status >= 500) {\n throw new Error(\n 'Elasticsearch Internal Error: Check your elasticsearch instance to make sure it can recieve requests.'\n )\n } else if (responses.status === 401) {\n throw new Error(\n 'Cannot connect to Elasticsearch. Check your connection host and API Key. You can also provide a custom Elasticsearch transporter to the API Client. See docs for more information.'\n )\n } else if (responses.responses?.[0]?.status === 403) {\n throw new Error(\n 'Auth Error: You do not have permission to access this index. Check you are calling the right index (specified in frontend) and your API Key permissions has access to the index.'\n )\n } else if (responses.status === 404 || responses.responses?.[0]?.status === 404) {\n throw new Error(\n 'Elasticsearch index not found. Check your index name and make sure it exists.'\n )\n } else if (responses.status === 400) {\n throw new Error(\n 'Elasticsearch Bad Request. Check your query and make sure it is valid. Turn on debug mode to see the Elasticsearch query.'\n )\n }\n return responses.responses\n } catch (error) {\n throw error\n }\n }\n}\n","import { AlgoliaMultipleQueriesQuery, QueryRule, SearchSettingsConfig } from './types'\n\nexport interface QueryContext {\n query: string\n}\n\nexport interface QueryRuleActions {\n pinnedDocs: string[]\n boostFunctions: any[]\n query: string\n userData: unknown[]\n facetAttributesOrder: string[] | undefined\n}\n\nexport const getQueryRulesActionsFromRequest = (\n queryRules: QueryRule[],\n request: AlgoliaMultipleQueriesQuery\n) => {\n const queryContext: QueryContext = {\n query: request.params?.query || ''\n }\n\n const satisfiedRules = getSatisfiedRules(queryContext, queryRules || [])\n\n const actions = satisfiedRules.reduce<QueryRuleActions>(\n (sum, rule) => {\n rule.actions.map((action) => {\n if (action.action === 'PinnedResult') {\n sum.pinnedDocs.push(...action.documentIds)\n } else if (action.action === 'QueryRewrite') {\n sum.query = action.query\n } else if (action.action === 'QueryAttributeBoost') {\n sum.boostFunctions.push({\n filter: {\n match: { [action.attribute]: { query: action.value } }\n },\n weight: action.boost\n })\n } else if (action.action === 'RenderUserData') {\n sum.userData.push(JSON.parse(action.userData))\n } else if (action.action === 'RenderFacetsOrder') {\n sum.facetAttributesOrder = action.facetAttributesOrder\n }\n })\n return sum\n },\n {\n pinnedDocs: [],\n boostFunctions: [],\n query: queryContext.query,\n userData: [],\n facetAttributesOrder: undefined\n }\n )\n return actions\n}\n\nexport const getSatisfiedRules = (queryContext: QueryContext, rules: QueryRule[]) =>\n rules.filter(\n (rule) =>\n rule.conditions.filter((condition) => {\n if (condition.context === 'query' && condition.match_type === 'exact') {\n return condition.value === queryContext.query\n }\n if (condition.context === 'query' && condition.match_type === 'contains') {\n return queryContext.query.includes(condition.value)\n }\n if (condition.context === 'query' && condition.match_type === 'prefix') {\n return queryContext.query.startsWith(condition.value)\n }\n\n return false\n }).length > 0\n )\n","import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search'\nimport { transformRequest } from './transformRequest'\nimport transformResponse, { transformFacetValuesResponse } from './transformResponse'\nimport {\n ClientConfig,\n SearchRequest,\n RequestOptions,\n Transporter,\n QueryRuleAction,\n AppSettings\n} from './types'\nimport { ESTransporter } from './Transporter'\nimport { getQueryRulesActionsFromRequest, QueryRuleActions } from './queryRules'\nexport * from './types'\n\nclass Client {\n transporter: Transporter\n\n constructor(private config: ClientConfig, private settings: AppSettings = { debug: false }) {\n this.transporter =\n 'msearch' in config.connection ? config.connection : new ESTransporter(config.connection)\n }\n\n private async performSearch(requests: SearchRequest[]) {\n if (this.settings.debug) {\n console.log('Performing search with requests:')\n console.log(JSON.stringify(requests, null, 2))\n }\n const responses = await this.transporter.msearch(requests)\n return responses\n }\n\n async handleRequest(body: any, requestOptions?: RequestOptions) {\n const instantsearchRequests = body as AlgoliaMultipleQueriesQuery[]\n\n const instantsearchResponses = this.handleInstantSearchRequests(\n instantsearchRequests,\n requestOptions\n )\n\n return instantsearchResponses\n }\n\n async handleInstantSearchRequests(\n instantsearchRequests: AlgoliaMultipleQueriesQuery[],\n requestOptions?: RequestOptions\n ) {\n const queryRules = this.config.search_settings.query_rules || []\n\n const requestQueryRuleActions: QueryRuleActions[] = instantsearchRequests.map((request) => {\n return getQueryRulesActionsFromRequest(queryRules, request)\n })\n\n const esRequests: SearchRequest[] = instantsearchRequests.map((request, i) => ({\n body: transformRequest(\n request,\n this.config.search_settings,\n requestQueryRuleActions[i],\n requestOptions\n ),\n indexName: request.indexName\n }))\n\n const esResponses = await this.performSearch(esRequests)\n\n const instantsearchResponses = esResponses.map((response, i) => {\n // @ts-ignore\n if (instantsearchRequests[i].params?.facetName) {\n return transformFacetValuesResponse(response, instantsearchRequests[i])\n }\n return transformResponse(\n response,\n instantsearchRequests[i],\n this.config.search_settings,\n requestQueryRuleActions[i]\n )\n })\n\n return {\n results: instantsearchResponses\n }\n }\n}\n\nconst createClient = (config: ClientConfig, settings?: AppSettings) => new Client(config, settings)\n\nexport default createClient\n"],"mappings":";AAAA,OAAO,eAAe;;;ACoBf,IAAM,WAAW,CACtB,kBACA,kBACmB;AACnB,QAAM,IAAI,iBAAiB,KAAK,CAAC,MAAM;AACrC,QAAI,OAAO,MAAM,UAAU;AACzB,aAAO,MAAM;AAAA,IACf;AACA,WAAO,EAAE,cAAc;AAAA,EACzB,CAAC;AACD,S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AC;AAED,UAAM,aAA8B,sBAAsB,IAAI,CAAC,SAAS,OAAO;AAAA,MAC7E,MAAM;AAAA,QACJ;AAAA,QACA,KAAK,OAAO;AAAA,QACZ,wBAAwB;AAAA,QACxB;AAAA,MACF;AAAA,MACA,WAAW,QAAQ;AAAA,IACrB,EAAE;AAEF,UAAM,cAAc,MAAM,KAAK,cAAc,UAAU;AAEvD,UAAM,yBAAyB,YAAY,IAAI,CAAC,UAAU,MAAM;AAjEpE;AAmEM,WAAI,2BAAsB,GAAG,WAAzB,mBAAiC,WAAW;AAC9C,eAAO,6BAA6B,UAAU,sBAAsB,EAAE;AAAA,MACxE;AACA,aAAO;AAAA,QACL;AAAA,QACA,sBAAsB;AAAA,QACtB,KAAK,OAAO;AAAA,QACZ,wBAAwB;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,SAAS;AAAA,IACX;AAAA,EACF;AACF;AAEA,IAAM,eAAe,CAAC,QAAsB,aAA2B,IAAI,OAAO,QAAQ,QAAQ;AAElG,IAAO,cAAQ;","names":["operator","value","sum","filter","facetAttributes","getHighlightFields","highlightedMatch","getHighlightFields","buckets","sum"]}
{
"name": "@searchkit/api",
"version": "4.0.0-next.5",
"version": "4.0.0-next.6",
"main": "./dist/index.js",

@@ -5,0 +5,0 @@ "description": "",