instantsearch.js 4.41.1 → 4.43.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,35 @@
1
+ # [4.43.0](https://github.com/algolia/instantsearch.js/compare/v4.42.0...v4.43.0) (2022-06-28)
2
+
3
+
4
+ ### Features
5
+
6
+ * **types:** support algoliasearch v5 ([#5066](https://github.com/algolia/instantsearch.js/issues/5066)) ([3eb4dc7](https://github.com/algolia/instantsearch.js/commit/3eb4dc75a5935f2ee4fead8787f39af0150b24c4))
7
+
8
+
9
+
10
+ # [4.42.0](https://github.com/algolia/instantsearch.js/compare/v4.41.2...v4.42.0) (2022-06-21)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **es:** update import path for `infiniteHitsCache` in depreciation message ([#5068](https://github.com/algolia/instantsearch.js/issues/5068)) ([545cbaf](https://github.com/algolia/instantsearch.js/commit/545cbafd748bb8be32bff66ac60b5f3f9133a5b4))
16
+
17
+
18
+ ### Features
19
+
20
+ * **core:** sort parameters & support client.search for sffv ([#5069](https://github.com/algolia/instantsearch.js/issues/5069)) ([34e2b00](https://github.com/algolia/instantsearch.js/commit/34e2b00cbc93f1bc86ee0abaec6b6e132bd18354))
21
+
22
+
23
+
24
+ ## [4.41.2](https://github.com/algolia/instantsearch.js/compare/v4.41.1...v4.41.2) (2022-06-15)
25
+
26
+
27
+ ### Bug Fixes
28
+
29
+ * **hierarchicalMenu:** show full hierarchical parent values ([#5063](https://github.com/algolia/instantsearch.js/issues/5063)) ([cd1db34](https://github.com/algolia/instantsearch.js/commit/cd1db34815f92acb3d2d0cec6c1ae7865d14fb13))
30
+
31
+
32
+
1
33
  ## [4.41.1](https://github.com/algolia/instantsearch.js/compare/v4.41.0...v4.41.1) (2022-06-14)
2
34
 
3
35
 
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.41.1';
7
+ var _default = '4.43.0';
8
8
  exports.default = _default;
@@ -1 +1,18 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _algoliasearch = require("algoliasearch-helper/types/algoliasearch.js");
8
+
9
+ Object.keys(_algoliasearch).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _algoliasearch[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _algoliasearch[key];
16
+ }
17
+ });
18
+ });
@@ -1,14 +1,14 @@
1
1
  /// <reference types="google.maps" />
2
2
 
3
- import type algoliasearch from 'algoliasearch/lite';
4
3
  import type { AlgoliaSearchHelper } from 'algoliasearch-helper';
5
- import type * as ClientSearch from '@algolia/client-search';
6
4
  import EventEmitter from '@algolia/events';
5
+ import { FindAnswersOptions } from 'algoliasearch-helper/types/algoliasearch.js';
7
6
  import type { InsightsClient as InsightsClient_2 } from 'search-insights';
8
7
  import type { InsightsMethodMap } from 'search-insights';
9
8
  import type * as Places from 'places.js';
10
9
  import type { PlainSearchParameters } from 'algoliasearch-helper';
11
10
  import { default as qs_2 } from 'qs';
11
+ import { SearchClient } from 'algoliasearch-helper/types/algoliasearch.js';
12
12
  import type { SearchParameters } from 'algoliasearch-helper';
13
13
  import type { SearchResults } from 'algoliasearch-helper';
14
14
 
@@ -1075,18 +1075,12 @@ declare type CustomSendEventForHits = (customPayload: any) => void;
1075
1075
 
1076
1076
  declare type CustomSendEventForToggle = (customPayload: any) => void;
1077
1077
 
1078
- declare type DefaultSearchClient = ReturnType<typeof algoliasearch>;
1079
-
1080
1078
  declare type DisposeOptions = {
1081
1079
  helper: AlgoliaSearchHelper;
1082
1080
  state: SearchParameters;
1083
1081
  parent: IndexWidget;
1084
1082
  };
1085
1083
 
1086
- declare type DummySearchClientV4 = {
1087
- readonly transporter: any;
1088
- };
1089
-
1090
1084
  declare const dynamicWidgets: DynamicWidgetsWidget;
1091
1085
 
1092
1086
  declare type DynamicWidgetsConnector = Connector<DynamicWidgetsWidgetDescription, DynamicWidgetsConnectorParams>;
@@ -1175,8 +1169,6 @@ declare const EXPERIMENTAL_connectDynamicWidgets: DynamicWidgetsConnector;
1175
1169
  /** @deprecated use dynamicWidgets */
1176
1170
  declare const EXPERIMENTAL_dynamicWidgets: DynamicWidgetsWidget;
1177
1171
 
1178
- declare type FindAnswersOptions = DefaultSearchClient extends DummySearchClientV4 ? ClientSearch.FindAnswersOptions : any;
1179
-
1180
1172
  declare type GeoHit = Hit & Required<Pick<Hit, '_geoLoc'>>;
1181
1173
 
1182
1174
  declare type GeoLoc = {
@@ -4582,17 +4574,6 @@ declare type SearchBoxWidgetParams = {
4582
4574
  queryHook?: (query: string, hook: (value: string) => void) => void;
4583
4575
  };
4584
4576
 
4585
- declare type SearchClient = {
4586
- search: DefaultSearchClient['search'];
4587
- searchForFacetValues: DefaultSearchClient['searchForFacetValues'];
4588
- addAlgoliaAgent?: DefaultSearchClient['addAlgoliaAgent'];
4589
- initIndex?: (indexName: string) => SearchIndex extends {
4590
- findAnswers: any;
4591
- } ? Partial<Pick<SearchIndex, 'findAnswers'>> : SearchIndex;
4592
- };
4593
-
4594
- declare type SearchIndex = ReturnType<DefaultSearchClient['initIndex']>;
4595
-
4596
4577
  declare type SendEvent = (...args: [InsightsEvent] | [string, string, string?]) => void;
4597
4578
 
4598
4579
  declare type SendEventForFacet = BuiltInSendEventForFacet & CustomSendEventForFacet;
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.41.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.43.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -2989,7 +2989,7 @@
2989
2989
  nextDisjunctiveResult++;
2990
2990
  });
2991
2991
 
2992
- // if we have some root level values for hierarchical facets, merge them
2992
+ // if we have some parent level values for hierarchical facets, merge them
2993
2993
  state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
2994
2994
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
2995
2995
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
@@ -3001,47 +3001,49 @@
3001
3001
  return;
3002
3002
  }
3003
3003
 
3004
- var result = results[nextDisjunctiveResult];
3005
- var facets = result && result.facets
3006
- ? result.facets
3007
- : {};
3008
- Object.keys(facets).forEach(function(dfacet) {
3009
- var facetResults = facets[dfacet];
3010
- var position = findIndex(state.hierarchicalFacets, function(f) {
3011
- return f.name === hierarchicalFacet.name;
3012
- });
3013
- var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
3014
- return f.attribute === dfacet;
3015
- });
3004
+ results.slice(nextDisjunctiveResult).forEach(function(result) {
3005
+ var facets = result && result.facets
3006
+ ? result.facets
3007
+ : {};
3016
3008
 
3017
- // previous refinements and no results so not able to find it
3018
- if (attributeIndex === -1) {
3019
- return;
3020
- }
3009
+ Object.keys(facets).forEach(function(dfacet) {
3010
+ var facetResults = facets[dfacet];
3011
+ var position = findIndex(state.hierarchicalFacets, function(f) {
3012
+ return f.name === hierarchicalFacet.name;
3013
+ });
3014
+ var attributeIndex = findIndex(self.hierarchicalFacets[position], function(f) {
3015
+ return f.attribute === dfacet;
3016
+ });
3021
3017
 
3022
- // when we always get root levels, if the hits refinement is `beers > IPA` (count: 5),
3023
- // then the disjunctive values will be `beers` (count: 100),
3024
- // but we do not want to display
3025
- // | beers (100)
3026
- // > IPA (5)
3027
- // We want
3028
- // | beers (5)
3029
- // > IPA (5)
3030
- var defaultData = {};
3031
-
3032
- if (currentRefinement.length > 0) {
3033
- var root = currentRefinement[0].split(separator)[0];
3034
- defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
3035
- }
3018
+ // previous refinements and no results so not able to find it
3019
+ if (attributeIndex === -1) {
3020
+ return;
3021
+ }
3036
3022
 
3037
- self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
3038
- defaultData,
3039
- facetResults,
3040
- self.hierarchicalFacets[position][attributeIndex].data
3041
- );
3042
- });
3023
+ // when we always get root levels, if the hits refinement is `beers > IPA` (count: 5),
3024
+ // then the disjunctive values will be `beers` (count: 100),
3025
+ // but we do not want to display
3026
+ // | beers (100)
3027
+ // > IPA (5)
3028
+ // We want
3029
+ // | beers (5)
3030
+ // > IPA (5)
3031
+ var defaultData = {};
3032
+
3033
+ if (currentRefinement.length > 0) {
3034
+ var root = currentRefinement[0].split(separator)[0];
3035
+ defaultData[root] = self.hierarchicalFacets[position][attributeIndex].data[root];
3036
+ }
3043
3037
 
3044
- nextDisjunctiveResult++;
3038
+ self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
3039
+ defaultData,
3040
+ facetResults,
3041
+ self.hierarchicalFacets[position][attributeIndex].data
3042
+ );
3043
+ });
3044
+
3045
+ nextDisjunctiveResult++;
3046
+ });
3045
3047
  });
3046
3048
 
3047
3049
  // add the excludes
@@ -3845,6 +3847,17 @@
3845
3847
 
3846
3848
  var DerivedHelper_1 = DerivedHelper;
3847
3849
 
3850
+ function sortObject(obj) {
3851
+ return Object.keys(obj)
3852
+ .sort(function(a, b) {
3853
+ return a.localeCompare(b);
3854
+ })
3855
+ .reduce(function(acc, curr) {
3856
+ acc[curr] = obj[curr];
3857
+ return acc;
3858
+ }, {});
3859
+ }
3860
+
3848
3861
  var requestBuilder = {
3849
3862
  /**
3850
3863
  * Get all the queries to send to the client, those queries can used directly
@@ -3869,18 +3882,38 @@
3869
3882
  });
3870
3883
  });
3871
3884
 
3872
- // maybe more to get the root level of hierarchical facets when activated
3885
+ // More to get the parent levels of the hierarchical facets when refined
3873
3886
  state.getRefinedHierarchicalFacets().forEach(function(refinedFacet) {
3874
3887
  var hierarchicalFacet = state.getHierarchicalFacetByName(refinedFacet);
3875
-
3876
3888
  var currentRefinement = state.getHierarchicalRefinement(refinedFacet);
3877
- // if we are deeper than level 0 (starting from `beer > IPA`)
3878
- // we want to get the root values
3879
3889
  var separator = state._getHierarchicalFacetSeparator(hierarchicalFacet);
3890
+
3891
+ // If we are deeper than level 0 (starting from `beer > IPA`)
3892
+ // we want to get all parent values
3880
3893
  if (currentRefinement.length > 0 && currentRefinement[0].split(separator).length > 1) {
3881
- queries.push({
3882
- indexName: index,
3883
- params: requestBuilder._getDisjunctiveFacetSearchParams(state, refinedFacet, true)
3894
+ // We generate a map of the filters we will use for our facet values queries
3895
+ var filtersMap = currentRefinement[0].split(separator).slice(0, -1).reduce(
3896
+ function createFiltersMap(map, segment, level) {
3897
+ return map.concat({
3898
+ attribute: hierarchicalFacet.attributes[level],
3899
+ value: level === 0
3900
+ ? segment
3901
+ : [map[map.length - 1].value, segment].join(separator)
3902
+ });
3903
+ }
3904
+ , []);
3905
+
3906
+ filtersMap.forEach(function(filter, level) {
3907
+ var params = requestBuilder._getDisjunctiveFacetSearchParams(
3908
+ state,
3909
+ filter.attribute,
3910
+ level === 0
3911
+ );
3912
+
3913
+ var parent = filtersMap[level - 1];
3914
+ params.facetFilters = level > 0 ? [parent.attribute + ':' + parent.value] : undefined;
3915
+
3916
+ queries.push({indexName: index, params: params});
3884
3917
  });
3885
3918
  }
3886
3919
  });
@@ -3915,7 +3948,7 @@
3915
3948
  additionalParams.numericFilters = numericFilters;
3916
3949
  }
3917
3950
 
3918
- return merge_1({}, state.getQueryParams(), additionalParams);
3951
+ return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
3919
3952
  },
3920
3953
 
3921
3954
  /**
@@ -3930,16 +3963,16 @@
3930
3963
  var numericFilters = requestBuilder._getNumericFilters(state, facet);
3931
3964
  var tagFilters = requestBuilder._getTagFilters(state);
3932
3965
  var additionalParams = {
3933
- hitsPerPage: 1,
3966
+ hitsPerPage: 0,
3934
3967
  page: 0,
3935
- attributesToRetrieve: [],
3936
- attributesToHighlight: [],
3937
- attributesToSnippet: [],
3938
- tagFilters: tagFilters,
3939
3968
  analytics: false,
3940
3969
  clickAnalytics: false
3941
3970
  };
3942
3971
 
3972
+ if (tagFilters.length > 0) {
3973
+ additionalParams.tagFilters = tagFilters;
3974
+ }
3975
+
3943
3976
  var hierarchicalFacet = state.getHierarchicalFacetByName(facet);
3944
3977
 
3945
3978
  if (hierarchicalFacet) {
@@ -3960,7 +3993,7 @@
3960
3993
  additionalParams.facetFilters = facetFilters;
3961
3994
  }
3962
3995
 
3963
- return merge_1({}, state.getQueryParams(), additionalParams);
3996
+ return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
3964
3997
  },
3965
3998
 
3966
3999
  /**
@@ -4153,17 +4186,17 @@
4153
4186
  if (typeof maxFacetHits === 'number') {
4154
4187
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
4155
4188
  }
4156
- return merge_1(
4189
+ return sortObject(merge_1(
4157
4190
  {},
4158
4191
  requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
4159
4192
  searchForFacetSearchParameters
4160
- );
4193
+ ));
4161
4194
  }
4162
4195
  };
4163
4196
 
4164
4197
  var requestBuilder_1 = requestBuilder;
4165
4198
 
4166
- var version = '3.8.2';
4199
+ var version = '3.10.0';
4167
4200
 
4168
4201
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
4169
4202
 
@@ -4483,20 +4516,51 @@
4483
4516
  */
4484
4517
  AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
4485
4518
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
4519
+ var clientHasInitIndex = typeof this.client.initIndex === 'function';
4486
4520
  if (
4487
4521
  !clientHasSFFV &&
4488
- typeof this.client.initIndex !== 'function'
4522
+ !clientHasInitIndex &&
4523
+ typeof this.client.search !== 'function'
4489
4524
  ) {
4490
4525
  throw new Error(
4491
4526
  'search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues'
4492
4527
  );
4493
4528
  }
4529
+
4494
4530
  var state = this.state.setQueryParameters(userState || {});
4495
4531
  var isDisjunctive = state.isDisjunctiveFacet(facet);
4496
4532
  var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
4497
4533
 
4498
4534
  this._currentNbQueries++;
4499
4535
  var self = this;
4536
+ var searchForFacetValuesPromise;
4537
+ // newer algoliasearch ^3.27.1 - ~4.0.0
4538
+ if (clientHasSFFV) {
4539
+ searchForFacetValuesPromise = this.client.searchForFacetValues([
4540
+ {indexName: state.index, params: algoliaQuery}
4541
+ ]);
4542
+ // algoliasearch < 3.27.1
4543
+ } else if (clientHasInitIndex) {
4544
+ searchForFacetValuesPromise = this.client
4545
+ .initIndex(state.index)
4546
+ .searchForFacetValues(algoliaQuery);
4547
+ // algoliasearch ~5.0.0
4548
+ } else {
4549
+ // @MAJOR only use client.search
4550
+ delete algoliaQuery.facetName;
4551
+ searchForFacetValuesPromise = this.client
4552
+ .search([
4553
+ {
4554
+ type: 'facet',
4555
+ facet: facet,
4556
+ indexName: state.index,
4557
+ params: algoliaQuery
4558
+ }
4559
+ ])
4560
+ .then(function processResponse(response) {
4561
+ return response.results[0];
4562
+ });
4563
+ }
4500
4564
 
4501
4565
  this.emit('searchForFacetValues', {
4502
4566
  state: state,
@@ -4504,10 +4568,6 @@
4504
4568
  query: query
4505
4569
  });
4506
4570
 
4507
- var searchForFacetValuesPromise = clientHasSFFV
4508
- ? this.client.searchForFacetValues([{indexName: state.index, params: algoliaQuery}])
4509
- : this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
4510
-
4511
4571
  return searchForFacetValuesPromise.then(function addIsRefined(content) {
4512
4572
  self._currentNbQueries--;
4513
4573
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
@@ -8543,7 +8603,7 @@
8543
8603
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
8544
8604
  }
8545
8605
 
8546
- var version$1 = '4.41.1';
8606
+ var version$1 = '4.43.0';
8547
8607
 
8548
8608
  var NAMESPACE = 'ais';
8549
8609
  var component = function component(componentName) {