@algolia/autocomplete-preset-algolia 1.8.3 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,23 +8,18 @@ var htmlEscapes = {
8
8
  var hasAlphanumeric = new RegExp(/\w/i);
9
9
  var regexEscapedHtml = /&(amp|quot|lt|gt|#39);/g;
10
10
  var regexHasEscapedHtml = RegExp(regexEscapedHtml.source);
11
-
12
11
  function unescape(value) {
13
12
  return value && regexHasEscapedHtml.test(value) ? value.replace(regexEscapedHtml, function (character) {
14
13
  return htmlEscapes[character];
15
14
  }) : value;
16
15
  }
17
-
18
16
  export function isPartHighlighted(parts, i) {
19
17
  var _parts, _parts2;
20
-
21
18
  var current = parts[i];
22
19
  var isNextHighlighted = ((_parts = parts[i + 1]) === null || _parts === void 0 ? void 0 : _parts.isHighlighted) || true;
23
20
  var isPreviousHighlighted = ((_parts2 = parts[i - 1]) === null || _parts2 === void 0 ? void 0 : _parts2.isHighlighted) || true;
24
-
25
21
  if (!hasAlphanumeric.test(unescape(current.value)) && isPreviousHighlighted === isNextHighlighted) {
26
22
  return isPreviousHighlighted;
27
23
  }
28
-
29
24
  return current.isHighlighted;
30
25
  }
@@ -1,28 +1,20 @@
1
1
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
2
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
3
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
4
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
-
9
5
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
7
  import { getAttributeValueByPath, warn } from '@algolia/autocomplete-shared';
14
8
  import { parseAttribute } from './parseAttribute';
15
9
  export function parseAlgoliaHitHighlight(_ref) {
16
10
  var hit = _ref.hit,
17
- attribute = _ref.attribute;
11
+ attribute = _ref.attribute;
18
12
  var path = Array.isArray(attribute) ? attribute : [attribute];
19
13
  var highlightedValue = getAttributeValueByPath(hit, ['_highlightResult'].concat(_toConsumableArray(path), ['value']));
20
-
21
14
  if (typeof highlightedValue !== 'string') {
22
15
  process.env.NODE_ENV !== 'production' ? warn(false, "The attribute \"".concat(path.join('.'), "\" described by the path ").concat(JSON.stringify(path), " does not exist on the hit. Did you set it in `attributesToHighlight`?") + '\nSee https://www.algolia.com/doc/api-reference/api-parameters/attributesToHighlight/') : void 0;
23
16
  highlightedValue = getAttributeValueByPath(hit, path) || '';
24
17
  }
25
-
26
18
  return parseAttribute({
27
19
  highlightedValue: highlightedValue
28
20
  });
@@ -1,28 +1,20 @@
1
1
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
2
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
3
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
4
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
-
9
5
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
7
  import { getAttributeValueByPath, warn } from '@algolia/autocomplete-shared';
14
8
  import { parseAttribute } from './parseAttribute';
15
9
  export function parseAlgoliaHitSnippet(_ref) {
16
10
  var hit = _ref.hit,
17
- attribute = _ref.attribute;
11
+ attribute = _ref.attribute;
18
12
  var path = Array.isArray(attribute) ? attribute : [attribute];
19
13
  var highlightedValue = getAttributeValueByPath(hit, ['_snippetResult'].concat(_toConsumableArray(path), ['value']));
20
-
21
14
  if (typeof highlightedValue !== 'string') {
22
15
  process.env.NODE_ENV !== 'production' ? warn(false, "The attribute \"".concat(path.join('.'), "\" described by the path ").concat(JSON.stringify(path), " does not exist on the hit. Did you set it in `attributesToSnippet`?") + '\nSee https://www.algolia.com/doc/api-reference/api-parameters/attributesToSnippet/') : void 0;
23
16
  highlightedValue = getAttributeValueByPath(hit, path) || '';
24
17
  }
25
-
26
18
  return parseAttribute({
27
19
  highlightedValue: highlightedValue
28
20
  });
@@ -1,5 +1,4 @@
1
1
  import { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG } from '../constants';
2
-
3
2
  /**
4
3
  * Creates a data structure that allows to concatenate similar highlighting
5
4
  * parts in a single value.
@@ -13,7 +12,6 @@ function createAttributeSet() {
13
12
  },
14
13
  add: function add(part) {
15
14
  var lastPart = value[value.length - 1];
16
-
17
15
  if ((lastPart === null || lastPart === void 0 ? void 0 : lastPart.isHighlighted) === part.isHighlighted) {
18
16
  value[value.length - 1] = {
19
17
  value: lastPart.value + part.value,
@@ -25,7 +23,6 @@ function createAttributeSet() {
25
23
  }
26
24
  };
27
25
  }
28
-
29
26
  export function parseAttribute(_ref) {
30
27
  var highlightedValue = _ref.highlightedValue;
31
28
  var preTagParts = highlightedValue.split(HIGHLIGHT_PRE_TAG);
@@ -40,7 +37,6 @@ export function parseAttribute(_ref) {
40
37
  value: postTagParts[0],
41
38
  isHighlighted: true
42
39
  });
43
-
44
40
  if (postTagParts[1] !== '') {
45
41
  parts.add({
46
42
  value: postTagParts[1],
@@ -1,9 +1,9 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
7
  import { isPartHighlighted } from './isPartHighlighted';
8
8
  export function reverseHighlightedParts(parts) {
9
9
  // We don't want to highlight the whole word when no parts match.
@@ -16,7 +16,6 @@ export function reverseHighlightedParts(parts) {
16
16
  });
17
17
  });
18
18
  }
19
-
20
19
  return parts.map(function (part, i) {
21
20
  return _objectSpread(_objectSpread({}, part), {}, {
22
21
  isHighlighted: !isPartHighlighted(parts, i)
@@ -1 +1 @@
1
- export declare const createAlgoliaRequester: (requesterParams: import("./createRequester").RequesterParams<any>) => <TTHit>(requestParams: import("./createRequester").RequestParams<TTHit>) => import("./createRequester").RequesterDescription<TTHit>;
1
+ export declare const createAlgoliaRequester: (requesterParams: import("@algolia/autocomplete-shared/dist/esm/preset-algolia/createRequester").RequesterParams<any>) => <TTHit>(requestParams: import("@algolia/autocomplete-shared/dist/esm/preset-algolia/createRequester").RequestParams<TTHit>) => import("@algolia/autocomplete-shared/dist/esm/preset-algolia/createRequester").RequesterDescription<TTHit>;
@@ -1,74 +1,2 @@
1
- import { fetchAlgoliaResults } from '../search';
2
- import type { MultipleQueriesQuery, SearchForFacetValuesResponse, SearchResponse, SearchClient } from '../types';
3
- declare type Fetcher = typeof fetchAlgoliaResults;
4
- declare type FacetHit = {
5
- label: string;
6
- count: number;
7
- _highlightResult: {
8
- label: {
9
- value: string;
10
- };
11
- };
12
- };
13
- export declare type FetcherParams = Pick<Parameters<Fetcher>[0], 'searchClient' | 'queries'>;
14
- export declare type RequesterParams<THit> = {
15
- transformResponse(response: TransformResponseParams<THit>): TransformedRequesterResponse<THit>;
16
- };
17
- declare type TransformResponseParams<THit> = {
18
- results: Array<SearchResponse<THit> | SearchForFacetValuesResponse>;
19
- hits: Array<SearchResponse<THit>['hits']>;
20
- facetHits: FacetHit[][];
21
- };
22
- export declare type TransformedRequesterResponse<THit> = Array<SearchResponse<THit>['hits']> | SearchResponse<THit>['hits'] | FacetHit[][] | FacetHit[];
23
- export declare type TransformResponse<THit> = (response: TransformResponseParams<THit>) => TransformedRequesterResponse<THit>;
24
- declare type FetcherParamsQuery<THit> = {
25
- query: MultipleQueriesQuery;
26
- sourceId: string;
27
- transformResponse: TransformResponse<THit>;
28
- };
29
- declare type ExecuteParams<THit> = {
30
- searchClient: SearchClient;
31
- requests: Array<FetcherParamsQuery<THit>>;
32
- };
33
- export declare type Execute<THit> = (params: ExecuteParams<THit>) => Promise<ExecuteResponse<THit>>;
34
- export declare type ExecuteResponse<THit> = Array<{
35
- items: SearchResponse<THit> | SearchForFacetValuesResponse;
36
- sourceId: string;
37
- transformResponse: TransformResponse<THit>;
38
- }>;
39
- export declare type RequestParams<THit> = FetcherParams & {
40
- /**
41
- * The function to transform the Algolia response before passing it to the Autocomplete state. You have access to the full Algolia results, as well as the pre-computed hits and facet hits.
42
- *
43
- * This is useful to manipulate the hits, or store data from the results in the [context](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/context/).
44
- */
45
- transformResponse?: TransformResponse<THit>;
46
- };
47
- export declare type RequesterDescription<THit> = {
48
- /**
49
- * The search client used for this request. Multiple queries with the same client are batched (if `requesterId` is also the same).
50
- */
51
- searchClient: SearchClient;
52
- /**
53
- * Identifies requesters to confirm their queries should be batched.
54
- * This ensures that requesters with the same client but different
55
- * post-processing functions don't get batched.
56
- * When falsy, batching is disabled.
57
- * For example, the Algolia requesters use "algolia".
58
- */
59
- requesterId?: string;
60
- /**
61
- * The search parameters used for this query.
62
- */
63
- queries: MultipleQueriesQuery[];
64
- /**
65
- * Transforms the response of this search before returning it to the caller.
66
- */
67
- transformResponse: TransformResponse<THit>;
68
- /**
69
- * Post-processing function for multi-queries.
70
- */
71
- execute: Execute<THit>;
72
- };
1
+ import type { Fetcher, RequesterParams, RequestParams, RequesterDescription } from '../types';
73
2
  export declare function createRequester(fetcher: Fetcher, requesterId?: string): (requesterParams: RequesterParams<any>) => <TTHit>(requestParams: RequestParams<TTHit>) => RequesterDescription<TTHit>;
74
- export {};
@@ -1,9 +1,9 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
7
  export function createRequester(fetcher, requesterId) {
8
8
  function execute(fetcherParams) {
9
9
  return fetcher({
@@ -14,8 +14,8 @@ export function createRequester(fetcher, requesterId) {
14
14
  }).then(function (responses) {
15
15
  return responses.map(function (response, index) {
16
16
  var _fetcherParams$reques = fetcherParams.requests[index],
17
- sourceId = _fetcherParams$reques.sourceId,
18
- transformResponse = _fetcherParams$reques.transformResponse;
17
+ sourceId = _fetcherParams$reques.sourceId,
18
+ transformResponse = _fetcherParams$reques.transformResponse;
19
19
  return {
20
20
  items: response,
21
21
  sourceId: sourceId,
@@ -24,7 +24,6 @@ export function createRequester(fetcher, requesterId) {
24
24
  });
25
25
  });
26
26
  }
27
-
28
27
  return function createSpecifiedRequester(requesterParams) {
29
28
  return function requester(requestParams) {
30
29
  return _objectSpread(_objectSpread({
@@ -1,5 +1,5 @@
1
- import { RequestParams } from './createRequester';
1
+ import { RequestParams } from '../types';
2
2
  /**
3
3
  * Retrieves Algolia facet hits from multiple indices.
4
4
  */
5
- export declare function getAlgoliaFacets<TTHit>(requestParams: RequestParams<TTHit>): import("./createRequester").RequesterDescription<TTHit>;
5
+ export declare function getAlgoliaFacets<TTHit>(requestParams: RequestParams<TTHit>): import("@algolia/autocomplete-shared/dist/esm/preset-algolia/createRequester").RequesterDescription<TTHit>;
@@ -1,15 +1,17 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
5
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
7
+ import { invariant } from '@algolia/autocomplete-shared';
7
8
  import { createAlgoliaRequester } from './createAlgoliaRequester';
8
9
 
9
10
  /**
10
11
  * Retrieves Algolia facet hits from multiple indices.
11
12
  */
12
13
  export function getAlgoliaFacets(requestParams) {
14
+ invariant(_typeof(requestParams.searchClient) === 'object', 'The `searchClient` parameter is required for getAlgoliaFacets({ searchClient }).');
13
15
  var requester = createAlgoliaRequester({
14
16
  transformResponse: function transformResponse(response) {
15
17
  return response.facetHits;
@@ -1,4 +1,5 @@
1
+ import { RequestParams } from '../types';
1
2
  /**
2
3
  * Retrieves Algolia results from multiple indices.
3
4
  */
4
- export declare const getAlgoliaResults: <TTHit>(requestParams: import("./createRequester").RequestParams<TTHit>) => import("./createRequester").RequesterDescription<TTHit>;
5
+ export declare function getAlgoliaResults<TTHit>(requestParams: RequestParams<TTHit>): import("@algolia/autocomplete-shared/dist/esm/preset-algolia/createRequester").RequesterDescription<TTHit>;
@@ -1,10 +1,16 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ import { invariant } from '@algolia/autocomplete-shared';
1
3
  import { createAlgoliaRequester } from './createAlgoliaRequester';
4
+
2
5
  /**
3
6
  * Retrieves Algolia results from multiple indices.
4
7
  */
5
-
6
- export var getAlgoliaResults = createAlgoliaRequester({
7
- transformResponse: function transformResponse(response) {
8
- return response.hits;
9
- }
10
- });
8
+ export function getAlgoliaResults(requestParams) {
9
+ invariant(_typeof(requestParams.searchClient) === 'object', 'The `searchClient` parameter is required for getAlgoliaResults({ searchClient }).');
10
+ var requester = createAlgoliaRequester({
11
+ transformResponse: function transformResponse(response) {
12
+ return response.hits;
13
+ }
14
+ });
15
+ return requester(requestParams);
16
+ }
@@ -1,19 +1,2 @@
1
- import { UserAgent } from '@algolia/autocomplete-shared';
2
- import type { MultipleQueriesQuery, SearchForFacetValuesResponse, SearchResponse, SearchClient } from '../types';
3
- export interface SearchParams {
4
- /**
5
- * The initialized Algolia search client.
6
- */
7
- searchClient: SearchClient;
8
- /**
9
- * A list of queries to execute.
10
- */
11
- queries: MultipleQueriesQuery[];
12
- /**
13
- * A list of user agents to add to the search client.
14
- *
15
- * This is useful to track usage of an integration.
16
- */
17
- userAgents?: UserAgent[];
18
- }
1
+ import type { SearchForFacetValuesResponse, SearchResponse, SearchParams } from '../types';
19
2
  export declare function fetchAlgoliaResults<TRecord>({ searchClient, queries, userAgents, }: SearchParams): Promise<Array<SearchResponse<TRecord> | SearchForFacetValuesResponse>>;
@@ -1,48 +1,40 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  var _excluded = ["params"];
2
-
3
3
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
4
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
-
11
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
12
-
13
10
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
14
-
15
11
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
-
17
12
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
-
19
13
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
20
-
21
14
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
22
-
23
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
24
-
15
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
25
16
  import { userAgents as coreUserAgents } from '@algolia/autocomplete-shared';
26
17
  import { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG } from '../constants';
18
+ import { getAppIdAndApiKey } from '../utils';
27
19
  export function fetchAlgoliaResults(_ref) {
28
20
  var searchClient = _ref.searchClient,
29
- queries = _ref.queries,
30
- _ref$userAgents = _ref.userAgents,
31
- userAgents = _ref$userAgents === void 0 ? [] : _ref$userAgents;
32
-
21
+ queries = _ref.queries,
22
+ _ref$userAgents = _ref.userAgents,
23
+ userAgents = _ref$userAgents === void 0 ? [] : _ref$userAgents;
33
24
  if (typeof searchClient.addAlgoliaAgent === 'function') {
34
25
  var algoliaAgents = [].concat(_toConsumableArray(coreUserAgents), _toConsumableArray(userAgents));
35
26
  algoliaAgents.forEach(function (_ref2) {
36
27
  var segment = _ref2.segment,
37
- version = _ref2.version;
28
+ version = _ref2.version;
38
29
  searchClient.addAlgoliaAgent(segment, version);
39
30
  });
40
31
  }
41
-
32
+ var _getAppIdAndApiKey = getAppIdAndApiKey(searchClient),
33
+ appId = _getAppIdAndApiKey.appId,
34
+ apiKey = _getAppIdAndApiKey.apiKey;
42
35
  return searchClient.search(queries.map(function (searchParameters) {
43
36
  var params = searchParameters.params,
44
- headers = _objectWithoutProperties(searchParameters, _excluded);
45
-
37
+ headers = _objectWithoutProperties(searchParameters, _excluded);
46
38
  return _objectSpread(_objectSpread({}, headers), {}, {
47
39
  params: _objectSpread({
48
40
  hitsPerPage: 5,
@@ -51,6 +43,18 @@ export function fetchAlgoliaResults(_ref) {
51
43
  }, params)
52
44
  });
53
45
  })).then(function (response) {
54
- return response.results;
46
+ return response.results.map(function (result) {
47
+ var _result$hits;
48
+ return _objectSpread(_objectSpread({}, result), {}, {
49
+ hits: (_result$hits = result.hits) === null || _result$hits === void 0 ? void 0 : _result$hits.map(function (hit) {
50
+ return _objectSpread(_objectSpread({}, hit), {}, {
51
+ __autocomplete_algoliaCredentials: {
52
+ appId: appId,
53
+ apiKey: apiKey
54
+ }
55
+ });
56
+ })
57
+ });
58
+ });
55
59
  });
56
60
  }
@@ -1 +1,2 @@
1
- export * from './algoliasearch';
1
+ export * from '@algolia/autocomplete-shared/dist/esm/preset-algolia/algoliasearch';
2
+ export * from '@algolia/autocomplete-shared/dist/esm/preset-algolia/createRequester';
@@ -1 +1,2 @@
1
- export * from './algoliasearch';
1
+ export * from '@algolia/autocomplete-shared/dist/esm/preset-algolia/algoliasearch';
2
+ export * from '@algolia/autocomplete-shared/dist/esm/preset-algolia/createRequester';
@@ -0,0 +1,5 @@
1
+ import type { SearchClient } from '../types';
2
+ export declare function getAppIdAndApiKey(searchClient: SearchClient): {
3
+ appId: string;
4
+ apiKey: string;
5
+ };
@@ -0,0 +1,13 @@
1
+ export function getAppIdAndApiKey(searchClient) {
2
+ var _searchClient$transpo = searchClient.transporter,
3
+ headers = _searchClient$transpo.headers,
4
+ queryParameters = _searchClient$transpo.queryParameters;
5
+ var APP_ID = 'x-algolia-application-id';
6
+ var API_KEY = 'x-algolia-api-key';
7
+ var appId = headers[APP_ID] || queryParameters[APP_ID];
8
+ var apiKey = headers[API_KEY] || queryParameters[API_KEY];
9
+ return {
10
+ appId: appId,
11
+ apiKey: apiKey
12
+ };
13
+ }
@@ -0,0 +1 @@
1
+ export * from './getAppIdAndApiKey';
@@ -0,0 +1 @@
1
+ export * from './getAppIdAndApiKey';