instantsearch.js 4.41.2 → 4.42.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,17 @@
1
+ # [4.42.0](https://github.com/algolia/instantsearch.js/compare/v4.41.2...v4.42.0) (2022-06-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **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))
7
+
8
+
9
+ ### Features
10
+
11
+ * **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))
12
+
13
+
14
+
1
15
  ## [4.41.2](https://github.com/algolia/instantsearch.js/compare/v4.41.1...v4.41.2) (2022-06-15)
2
16
 
3
17
 
@@ -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.2';
7
+ var _default = '4.42.0';
8
8
  exports.default = _default;
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.41.2 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.42.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) :
@@ -3847,6 +3847,17 @@
3847
3847
 
3848
3848
  var DerivedHelper_1 = DerivedHelper;
3849
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
+
3850
3861
  var requestBuilder = {
3851
3862
  /**
3852
3863
  * Get all the queries to send to the client, those queries can used directly
@@ -3937,7 +3948,7 @@
3937
3948
  additionalParams.numericFilters = numericFilters;
3938
3949
  }
3939
3950
 
3940
- return merge_1({}, state.getQueryParams(), additionalParams);
3951
+ return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
3941
3952
  },
3942
3953
 
3943
3954
  /**
@@ -3982,7 +3993,7 @@
3982
3993
  additionalParams.facetFilters = facetFilters;
3983
3994
  }
3984
3995
 
3985
- return merge_1({}, state.getQueryParams(), additionalParams);
3996
+ return sortObject(merge_1({}, state.getQueryParams(), additionalParams));
3986
3997
  },
3987
3998
 
3988
3999
  /**
@@ -4175,17 +4186,17 @@
4175
4186
  if (typeof maxFacetHits === 'number') {
4176
4187
  searchForFacetSearchParameters.maxFacetHits = maxFacetHits;
4177
4188
  }
4178
- return merge_1(
4189
+ return sortObject(merge_1(
4179
4190
  {},
4180
4191
  requestBuilder._getHitsSearchParams(stateForSearchForFacetValues),
4181
4192
  searchForFacetSearchParameters
4182
- );
4193
+ ));
4183
4194
  }
4184
4195
  };
4185
4196
 
4186
4197
  var requestBuilder_1 = requestBuilder;
4187
4198
 
4188
- var version = '3.8.3';
4199
+ var version = '3.9.0';
4189
4200
 
4190
4201
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
4191
4202
 
@@ -4505,20 +4516,51 @@
4505
4516
  */
4506
4517
  AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxFacetHits, userState) {
4507
4518
  var clientHasSFFV = typeof this.client.searchForFacetValues === 'function';
4519
+ var clientHasInitIndex = typeof this.client.initIndex === 'function';
4508
4520
  if (
4509
4521
  !clientHasSFFV &&
4510
- typeof this.client.initIndex !== 'function'
4522
+ !clientHasInitIndex &&
4523
+ typeof this.client.search !== 'function'
4511
4524
  ) {
4512
4525
  throw new Error(
4513
4526
  'search for facet values (searchable) was called, but this client does not have a function client.searchForFacetValues or client.initIndex(index).searchForFacetValues'
4514
4527
  );
4515
4528
  }
4529
+
4516
4530
  var state = this.state.setQueryParameters(userState || {});
4517
4531
  var isDisjunctive = state.isDisjunctiveFacet(facet);
4518
4532
  var algoliaQuery = requestBuilder_1.getSearchForFacetQuery(facet, query, maxFacetHits, state);
4519
4533
 
4520
4534
  this._currentNbQueries++;
4521
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
+ }
4522
4564
 
4523
4565
  this.emit('searchForFacetValues', {
4524
4566
  state: state,
@@ -4526,10 +4568,6 @@
4526
4568
  query: query
4527
4569
  });
4528
4570
 
4529
- var searchForFacetValuesPromise = clientHasSFFV
4530
- ? this.client.searchForFacetValues([{indexName: state.index, params: algoliaQuery}])
4531
- : this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
4532
-
4533
4571
  return searchForFacetValuesPromise.then(function addIsRefined(content) {
4534
4572
  self._currentNbQueries--;
4535
4573
  if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');
@@ -8565,7 +8603,7 @@
8565
8603
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
8566
8604
  }
8567
8605
 
8568
- var version$1 = '4.41.2';
8606
+ var version$1 = '4.42.0';
8569
8607
 
8570
8608
  var NAMESPACE = 'ais';
8571
8609
  var component = function component(componentName) {