instantsearch.js 4.31.1 → 4.33.2

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +22 -0
  3. package/cjs/connectors/numeric-menu/connectNumericMenu.js +6 -4
  4. package/cjs/connectors/powered-by/connectPoweredBy.js +13 -4
  5. package/cjs/lib/InstantSearch.js +4 -2
  6. package/cjs/lib/infiniteHitsCache/sessionStorage.js +16 -12
  7. package/cjs/lib/routers/history.js +89 -42
  8. package/cjs/lib/utils/detect-insights-client.js +10 -1
  9. package/cjs/lib/utils/index.js +10 -1
  10. package/cjs/lib/utils/safelyRunOnBrowser.js +30 -0
  11. package/cjs/lib/version.js +1 -1
  12. package/cjs/lib/voiceSearchHelper/index.js +5 -0
  13. package/cjs/middlewares/createMetadataMiddleware.js +12 -3
  14. package/cjs/widgets/index/index.js +1 -1
  15. package/dist/instantsearch.development.d.ts +13 -2
  16. package/dist/instantsearch.development.js +193 -78
  17. package/dist/instantsearch.development.js.map +1 -1
  18. package/dist/instantsearch.development.min.d.ts +13 -2
  19. package/dist/instantsearch.production.d.ts +13 -2
  20. package/dist/instantsearch.production.min.d.ts +13 -2
  21. package/dist/instantsearch.production.min.js +2 -2
  22. package/dist/instantsearch.production.min.js.map +1 -1
  23. package/es/connectors/numeric-menu/connectNumericMenu.js +6 -4
  24. package/es/connectors/powered-by/connectPoweredBy.js +14 -5
  25. package/es/lib/InstantSearch.js +4 -2
  26. package/es/lib/infiniteHitsCache/sessionStorage.js +17 -14
  27. package/es/lib/routers/history.d.ts +13 -2
  28. package/es/lib/routers/history.js +88 -42
  29. package/es/lib/utils/detect-insights-client.js +9 -1
  30. package/es/lib/utils/index.d.ts +1 -0
  31. package/es/lib/utils/index.js +2 -1
  32. package/es/lib/utils/safelyRunOnBrowser.d.ts +14 -0
  33. package/es/lib/utils/safelyRunOnBrowser.js +23 -0
  34. package/es/lib/version.d.ts +1 -1
  35. package/es/lib/version.js +1 -1
  36. package/es/lib/voiceSearchHelper/index.js +5 -0
  37. package/es/middlewares/createMetadataMiddleware.js +12 -3
  38. package/es/widgets/index/index.js +1 -1
  39. package/package.json +6 -6
package/CHANGELOG.md CHANGED
@@ -1,3 +1,45 @@
1
+ ## [4.33.2](https://github.com/algolia/instantsearch.js/compare/v4.33.1...v4.33.2) (2021-11-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **connectNumericMenu:** allow option for same start/end values ([#4951](https://github.com/algolia/instantsearch.js/issues/4951)) ([18da714](https://github.com/algolia/instantsearch.js/commit/18da714574fa98957d29014add3123e9c377551f))
7
+
8
+
9
+
10
+ ## [4.33.1](https://github.com/algolia/instantsearch.js/compare/v4.33.0...v4.33.1) (2021-11-02)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **getUiState:** support `initialUiState` ([#4948](https://github.com/algolia/instantsearch.js/issues/4948)) ([532474d](https://github.com/algolia/instantsearch.js/commit/532474dfaf49446ab59a2a27424ca220947dd5bd))
16
+
17
+
18
+
19
+ # [4.33.0](https://github.com/algolia/instantsearch.js/compare/v4.32.0...v4.33.0) (2021-10-26)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **router:** skip history push on browser back and forward actions ([#4933](https://github.com/algolia/instantsearch.js/issues/4933)) ([7909da4](https://github.com/algolia/instantsearch.js/commit/7909da4903eb1aee885811e280b909a3bda488be))
25
+ * **setUiState:** reset UI state with empty object ([#4944](https://github.com/algolia/instantsearch.js/issues/4944)) ([5faae4a](https://github.com/algolia/instantsearch.js/commit/5faae4ac44ac5ad2f8086ad2a306bcfaa14bc754))
26
+
27
+
28
+ ### Features
29
+
30
+ * **router:** support server environments ([#4940](https://github.com/algolia/instantsearch.js/issues/4940)) ([a002962](https://github.com/algolia/instantsearch.js/commit/a002962df0e7683b29bef8bfaaddb494fa551a14))
31
+
32
+
33
+
34
+ # [4.32.0](https://github.com/algolia/instantsearch.js/compare/v4.31.1...v4.32.0) (2021-10-20)
35
+
36
+
37
+ ### Features
38
+
39
+ * **dependencies:** update algoliasearch-helper ([#4936](https://github.com/algolia/instantsearch.js/issues/4936)) ([014a413](https://github.com/algolia/instantsearch.js/commit/014a413f14dded3861a9c288ea618f1602bcd66d))
40
+
41
+
42
+
1
43
  ## [4.31.1](https://github.com/algolia/instantsearch.js/compare/v4.31.0...v4.31.1) (2021-10-19)
2
44
 
3
45
 
package/README.md CHANGED
@@ -102,6 +102,28 @@ npm install instantsearch.js algoliasearch
102
102
  yarn add instantsearch.js algoliasearch
103
103
  ```
104
104
 
105
+ ### TypeScript users
106
+
107
+ To use InstantSearch.js in a TypeScript environment, depending on your [`algoliasearch`](https://github.com/algolia/algoliasearch-client-javascript) version, you need to import different types.
108
+
109
+ >You still need to import these types even if you don't use InstantSearch.js with [`algoliasearch`](https://github.com/algolia/algoliasearch-client-javascript).
110
+
111
+ #### `algoliasearch` v4.x
112
+
113
+ This version uses types provided by both `algoliasearch` and `@algolia/client-search`.
114
+
115
+ ```bash
116
+ yarn add algoliasearch@4 @algolia/client-search
117
+ ```
118
+
119
+ #### `algoliasearch` v3.x
120
+
121
+ ```bash
122
+ yarn add @types/algoliasearch@3
123
+ ```
124
+
125
+ >v3.x is deprecated and will soon no longer be supported.
126
+
105
127
  ## Documentation
106
128
 
107
129
  The documentation is available on the [Algolia website](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/).
@@ -242,6 +242,8 @@ function isRefined(state, attribute, option) {
242
242
  if (option.start !== undefined && option.end !== undefined) {
243
243
  if (option.start === option.end) {
244
244
  return hasNumericRefinement(currentRefinements, '=', option.start);
245
+ } else {
246
+ return hasNumericRefinement(currentRefinements, '>=', option.start) && hasNumericRefinement(currentRefinements, '<=', option.end);
245
247
  }
246
248
  }
247
249
 
@@ -295,17 +297,17 @@ function getRefinedState(state, attribute, facetValue) {
295
297
  if (refinedOption.start !== undefined) {
296
298
  if (hasNumericRefinement(currentRefinements, '>=', refinedOption.start)) {
297
299
  resolvedState = resolvedState.removeNumericRefinement(attribute, '>=', refinedOption.start);
298
- } else {
299
- resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
300
300
  }
301
+
302
+ resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
301
303
  }
302
304
 
303
305
  if (refinedOption.end !== undefined) {
304
306
  if (hasNumericRefinement(currentRefinements, '<=', refinedOption.end)) {
305
307
  resolvedState = resolvedState.removeNumericRefinement(attribute, '<=', refinedOption.end);
306
- } else {
307
- resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
308
308
  }
309
+
310
+ resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
309
311
  }
310
312
 
311
313
  if (typeof resolvedState.page === 'number') {
@@ -25,11 +25,20 @@ var withUsage = (0, _utils.createDocumentationMessageGenerator)({
25
25
  var connectPoweredBy = function connectPoweredBy(renderFn) {
26
26
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.noop;
27
27
  (0, _utils.checkRendering)(renderFn, withUsage());
28
- var defaultUrl = 'https://www.algolia.com/?' + 'utm_source=instantsearch.js&' + 'utm_medium=website&' + "utm_content=".concat(typeof window !== 'undefined' && window.location ? window.location.hostname : '', "&") + 'utm_campaign=poweredby';
28
+ var defaultUrl = 'https://www.algolia.com/?' + 'utm_source=instantsearch.js&' + 'utm_medium=website&' + "utm_content=".concat((0, _utils.safelyRunOnBrowser)(function (_ref) {
29
+ var _window$location;
30
+
31
+ var window = _ref.window;
32
+ return ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname) || '';
33
+ }, {
34
+ fallback: function fallback() {
35
+ return '';
36
+ }
37
+ }), "&") + 'utm_campaign=poweredby';
29
38
  return function (widgetParams) {
30
- var _ref = widgetParams || {},
31
- _ref$url = _ref.url,
32
- url = _ref$url === void 0 ? defaultUrl : _ref$url;
39
+ var _ref2 = widgetParams || {},
40
+ _ref2$url = _ref2.url,
41
+ url = _ref2$url === void 0 ? defaultUrl : _ref2$url;
33
42
 
34
43
  return {
35
44
  $$type: 'ais.poweredBy',
@@ -522,15 +522,17 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
522
522
  var nextUiState = typeof uiState === 'function' ? uiState(this.mainIndex.getWidgetUiState({})) : uiState;
523
523
 
524
524
  var setIndexHelperState = function setIndexHelperState(indexWidget) {
525
+ var nextIndexUiState = nextUiState[indexWidget.getIndexId()] || {};
526
+
525
527
  if (process.env.NODE_ENV === 'development') {
526
528
  (0, _utils.checkIndexUiState)({
527
529
  index: indexWidget,
528
- indexUiState: nextUiState[indexWidget.getIndexId()]
530
+ indexUiState: nextIndexUiState
529
531
  });
530
532
  }
531
533
 
532
534
  indexWidget.getHelper().setState(indexWidget.getWidgetSearchParameters(indexWidget.getHelper().state, {
533
- uiState: nextUiState[indexWidget.getIndexId()]
535
+ uiState: nextIndexUiState
534
536
  }));
535
537
  indexWidget.getWidgets().filter(_index.isIndexWidget).forEach(setIndexHelperState);
536
538
  };
@@ -21,27 +21,27 @@ function getStateWithoutPage(state) {
21
21
 
22
22
  var KEY = 'ais.infiniteHits';
23
23
 
24
- function hasSessionStorage() {
25
- return typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined';
26
- }
27
-
28
24
  function createInfiniteHitsSessionStorageCache() {
29
25
  return {
30
26
  read: function read(_ref2) {
31
27
  var state = _ref2.state;
28
+ var sessionStorage = (0, _utils.safelyRunOnBrowser)(function (_ref3) {
29
+ var window = _ref3.window;
30
+ return window.sessionStorage;
31
+ });
32
32
 
33
- if (!hasSessionStorage()) {
33
+ if (!sessionStorage) {
34
34
  return null;
35
35
  }
36
36
 
37
37
  try {
38
38
  var cache = JSON.parse( // @ts-expect-error JSON.parse() requires a string, but it actually accepts null, too.
39
- window.sessionStorage.getItem(KEY));
39
+ sessionStorage.getItem(KEY));
40
40
  return cache && (0, _utils.isEqual)(cache.state, getStateWithoutPage(state)) ? cache.hits : null;
41
41
  } catch (error) {
42
42
  if (error instanceof SyntaxError) {
43
43
  try {
44
- window.sessionStorage.removeItem(KEY);
44
+ sessionStorage.removeItem(KEY);
45
45
  } catch (err) {// do nothing
46
46
  }
47
47
  }
@@ -49,16 +49,20 @@ function createInfiniteHitsSessionStorageCache() {
49
49
  return null;
50
50
  }
51
51
  },
52
- write: function write(_ref3) {
53
- var state = _ref3.state,
54
- hits = _ref3.hits;
52
+ write: function write(_ref4) {
53
+ var state = _ref4.state,
54
+ hits = _ref4.hits;
55
+ var sessionStorage = (0, _utils.safelyRunOnBrowser)(function (_ref5) {
56
+ var window = _ref5.window;
57
+ return window.sessionStorage;
58
+ });
55
59
 
56
- if (!hasSessionStorage()) {
60
+ if (!sessionStorage) {
57
61
  return;
58
62
  }
59
63
 
60
64
  try {
61
- window.sessionStorage.setItem(KEY, JSON.stringify({
65
+ sessionStorage.setItem(KEY, JSON.stringify({
62
66
  state: getStateWithoutPage(state),
63
67
  hits: hits
64
68
  }));
@@ -7,6 +7,8 @@ exports.default = historyRouter;
7
7
 
8
8
  var _qs = _interopRequireDefault(require("qs"));
9
9
 
10
+ var _utils = require("../utils");
11
+
10
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
13
 
12
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -19,6 +21,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
19
21
 
20
22
  var setWindowTitle = function setWindowTitle(title) {
21
23
  if (title) {
24
+ // This function is only executed on browsers so we can disable this check.
25
+ // eslint-disable-next-line no-restricted-globals
22
26
  window.document.title = title;
23
27
  }
24
28
  };
@@ -29,11 +33,14 @@ var BrowserHistory = /*#__PURE__*/function () {
29
33
  * using web APIs (`window.location.pushState` and `onpopstate` event).
30
34
  */
31
35
  function BrowserHistory(_ref) {
36
+ var _this = this;
37
+
32
38
  var windowTitle = _ref.windowTitle,
33
39
  _ref$writeDelay = _ref.writeDelay,
34
40
  writeDelay = _ref$writeDelay === void 0 ? 400 : _ref$writeDelay,
35
41
  createURL = _ref.createURL,
36
- parseURL = _ref.parseURL;
42
+ parseURL = _ref.parseURL,
43
+ getLocation = _ref.getLocation;
37
44
 
38
45
  _classCallCheck(this, BrowserHistory);
39
46
 
@@ -45,15 +52,23 @@ var BrowserHistory = /*#__PURE__*/function () {
45
52
 
46
53
  _defineProperty(this, "parseURL", void 0);
47
54
 
55
+ _defineProperty(this, "getLocation", void 0);
56
+
48
57
  _defineProperty(this, "writeTimer", void 0);
49
58
 
59
+ _defineProperty(this, "shouldPushState", true);
60
+
50
61
  this.windowTitle = windowTitle;
51
62
  this.writeTimer = undefined;
52
63
  this.writeDelay = writeDelay;
53
64
  this._createURL = createURL;
54
65
  this.parseURL = parseURL;
55
- var title = this.windowTitle && this.windowTitle(this.read());
56
- setWindowTitle(title);
66
+ this.getLocation = getLocation;
67
+ (0, _utils.safelyRunOnBrowser)(function () {
68
+ var title = _this.windowTitle && _this.windowTitle(_this.read());
69
+
70
+ setWindowTitle(title);
71
+ });
57
72
  }
58
73
  /**
59
74
  * Reads the URL and returns a syncable UI search state.
@@ -65,7 +80,7 @@ var BrowserHistory = /*#__PURE__*/function () {
65
80
  value: function read() {
66
81
  return this.parseURL({
67
82
  qsModule: _qs.default,
68
- location: window.location
83
+ location: this.getLocation()
69
84
  });
70
85
  }
71
86
  /**
@@ -75,20 +90,30 @@ var BrowserHistory = /*#__PURE__*/function () {
75
90
  }, {
76
91
  key: "write",
77
92
  value: function write(routeState) {
78
- var _this = this;
93
+ var _this2 = this;
79
94
 
80
- var url = this.createURL(routeState);
81
- var title = this.windowTitle && this.windowTitle(routeState);
95
+ (0, _utils.safelyRunOnBrowser)(function (_ref2) {
96
+ var window = _ref2.window;
82
97
 
83
- if (this.writeTimer) {
84
- window.clearTimeout(this.writeTimer);
85
- }
98
+ var url = _this2.createURL(routeState);
99
+
100
+ var title = _this2.windowTitle && _this2.windowTitle(routeState);
101
+
102
+ if (_this2.writeTimer) {
103
+ clearTimeout(_this2.writeTimer);
104
+ }
105
+
106
+ _this2.writeTimer = setTimeout(function () {
107
+ setWindowTitle(title);
86
108
 
87
- this.writeTimer = window.setTimeout(function () {
88
- setWindowTitle(title);
89
- window.history.pushState(routeState, title || '', url);
90
- _this.writeTimer = undefined;
91
- }, this.writeDelay);
109
+ if (_this2.shouldPushState) {
110
+ window.history.pushState(routeState, title || '', url);
111
+ }
112
+
113
+ _this2.shouldPushState = true;
114
+ _this2.writeTimer = undefined;
115
+ }, _this2.writeDelay);
116
+ });
92
117
  }
93
118
  /**
94
119
  * Sets a callback on the `onpopstate` event of the history API of the current page.
@@ -98,26 +123,30 @@ var BrowserHistory = /*#__PURE__*/function () {
98
123
  }, {
99
124
  key: "onUpdate",
100
125
  value: function onUpdate(callback) {
101
- var _this2 = this;
126
+ var _this3 = this;
102
127
 
103
128
  this._onPopState = function (event) {
104
- if (_this2.writeTimer) {
105
- window.clearTimeout(_this2.writeTimer);
106
- _this2.writeTimer = undefined;
129
+ if (_this3.writeTimer) {
130
+ clearTimeout(_this3.writeTimer);
131
+ _this3.writeTimer = undefined;
107
132
  }
108
133
 
134
+ _this3.shouldPushState = false;
109
135
  var routeState = event.state; // At initial load, the state is read from the URL without update.
110
136
  // Therefore the state object is not available.
111
137
  // In this case, we fallback and read the URL.
112
138
 
113
139
  if (!routeState) {
114
- callback(_this2.read());
140
+ callback(_this3.read());
115
141
  } else {
116
142
  callback(routeState);
117
143
  }
118
144
  };
119
145
 
120
- window.addEventListener('popstate', this._onPopState);
146
+ (0, _utils.safelyRunOnBrowser)(function (_ref3) {
147
+ var window = _ref3.window;
148
+ window.addEventListener('popstate', _this3._onPopState);
149
+ });
121
150
  }
122
151
  /**
123
152
  * Creates a complete URL from a given syncable UI state.
@@ -133,7 +162,7 @@ var BrowserHistory = /*#__PURE__*/function () {
133
162
  return this._createURL({
134
163
  qsModule: _qs.default,
135
164
  routeState: routeState,
136
- location: window.location
165
+ location: this.getLocation()
137
166
  });
138
167
  }
139
168
  /**
@@ -143,12 +172,18 @@ var BrowserHistory = /*#__PURE__*/function () {
143
172
  }, {
144
173
  key: "dispose",
145
174
  value: function dispose() {
146
- if (this._onPopState) {
147
- window.removeEventListener('popstate', this._onPopState);
148
- }
175
+ var _this4 = this;
176
+
177
+ (0, _utils.safelyRunOnBrowser)(function (_ref4) {
178
+ var window = _ref4.window;
179
+
180
+ if (_this4._onPopState) {
181
+ window.removeEventListener('popstate', _this4._onPopState);
182
+ }
183
+ });
149
184
 
150
185
  if (this.writeTimer) {
151
- window.clearTimeout(this.writeTimer);
186
+ clearTimeout(this.writeTimer);
152
187
  }
153
188
 
154
189
  this.write({});
@@ -159,12 +194,12 @@ var BrowserHistory = /*#__PURE__*/function () {
159
194
  }();
160
195
 
161
196
  function historyRouter() {
162
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
163
- _ref2$createURL = _ref2.createURL,
164
- createURL = _ref2$createURL === void 0 ? function (_ref3) {
165
- var qsModule = _ref3.qsModule,
166
- routeState = _ref3.routeState,
167
- location = _ref3.location;
197
+ var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
198
+ _ref5$createURL = _ref5.createURL,
199
+ createURL = _ref5$createURL === void 0 ? function (_ref6) {
200
+ var qsModule = _ref6.qsModule,
201
+ routeState = _ref6.routeState,
202
+ location = _ref6.location;
168
203
  var protocol = location.protocol,
169
204
  hostname = location.hostname,
170
205
  _location$port = location.port,
@@ -180,11 +215,11 @@ function historyRouter() {
180
215
  }
181
216
 
182
217
  return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
183
- } : _ref2$createURL,
184
- _ref2$parseURL = _ref2.parseURL,
185
- parseURL = _ref2$parseURL === void 0 ? function (_ref4) {
186
- var qsModule = _ref4.qsModule,
187
- location = _ref4.location;
218
+ } : _ref5$createURL,
219
+ _ref5$parseURL = _ref5.parseURL,
220
+ parseURL = _ref5$parseURL === void 0 ? function (_ref7) {
221
+ var qsModule = _ref7.qsModule,
222
+ location = _ref7.location;
188
223
  // `qs` by default converts arrays with more than 20 items to an object.
189
224
  // We want to avoid this because the data structure manipulated can therefore vary.
190
225
  // Setting the limit to `100` seems a good number because the engine's default is 100
@@ -198,15 +233,27 @@ function historyRouter() {
198
233
  return qsModule.parse(location.search.slice(1), {
199
234
  arrayLimit: 99
200
235
  });
201
- } : _ref2$parseURL,
202
- _ref2$writeDelay = _ref2.writeDelay,
203
- writeDelay = _ref2$writeDelay === void 0 ? 400 : _ref2$writeDelay,
204
- windowTitle = _ref2.windowTitle;
236
+ } : _ref5$parseURL,
237
+ _ref5$writeDelay = _ref5.writeDelay,
238
+ writeDelay = _ref5$writeDelay === void 0 ? 400 : _ref5$writeDelay,
239
+ windowTitle = _ref5.windowTitle,
240
+ _ref5$getLocation = _ref5.getLocation,
241
+ getLocation = _ref5$getLocation === void 0 ? function () {
242
+ return (0, _utils.safelyRunOnBrowser)(function (_ref8) {
243
+ var window = _ref8.window;
244
+ return window.location;
245
+ }, {
246
+ fallback: function fallback() {
247
+ throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
248
+ }
249
+ });
250
+ } : _ref5$getLocation;
205
251
 
206
252
  return new BrowserHistory({
207
253
  createURL: createURL,
208
254
  parseURL: parseURL,
209
255
  writeDelay: writeDelay,
210
- windowTitle: windowTitle
256
+ windowTitle: windowTitle,
257
+ getLocation: getLocation
211
258
  });
212
259
  }
@@ -5,6 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = hasDetectedInsightsClient;
7
7
 
8
+ var _safelyRunOnBrowser = require("./safelyRunOnBrowser");
9
+
8
10
  function hasDetectedInsightsClient() {
9
- return typeof window !== 'undefined' && Boolean(window.AlgoliaAnalyticsObject);
11
+ return (0, _safelyRunOnBrowser.safelyRunOnBrowser)(function (_ref) {
12
+ var window = _ref.window;
13
+ return Boolean(window.AlgoliaAnalyticsObject);
14
+ }, {
15
+ fallback: function fallback() {
16
+ return false;
17
+ }
18
+ });
10
19
  }
@@ -55,7 +55,8 @@ var _exportNames = {
55
55
  debounce: true,
56
56
  serializePayload: true,
57
57
  deserializePayload: true,
58
- getWidgetAttribute: true
58
+ getWidgetAttribute: true,
59
+ safelyRunOnBrowser: true
59
60
  };
60
61
  Object.defineProperty(exports, "capitalize", {
61
62
  enumerable: true,
@@ -369,6 +370,12 @@ Object.defineProperty(exports, "getWidgetAttribute", {
369
370
  return _getWidgetAttribute.getWidgetAttribute;
370
371
  }
371
372
  });
373
+ Object.defineProperty(exports, "safelyRunOnBrowser", {
374
+ enumerable: true,
375
+ get: function get() {
376
+ return _safelyRunOnBrowser.safelyRunOnBrowser;
377
+ }
378
+ });
372
379
 
373
380
  var _capitalize = _interopRequireDefault(require("./capitalize"));
374
381
 
@@ -488,4 +495,6 @@ var _serializer = require("./serializer");
488
495
 
489
496
  var _getWidgetAttribute = require("./getWidgetAttribute");
490
497
 
498
+ var _safelyRunOnBrowser = require("./safelyRunOnBrowser");
499
+
491
500
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.safelyRunOnBrowser = safelyRunOnBrowser;
7
+
8
+ // eslint-disable-next-line no-restricted-globals
9
+
10
+ /**
11
+ * Runs code on browser enviromnents safely.
12
+ */
13
+ function safelyRunOnBrowser(callback) {
14
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
15
+ fallback: function fallback() {
16
+ return undefined;
17
+ }
18
+ },
19
+ fallback = _ref.fallback;
20
+
21
+ // eslint-disable-next-line no-restricted-globals
22
+ if (typeof window === 'undefined') {
23
+ return fallback();
24
+ } // eslint-disable-next-line no-restricted-globals
25
+
26
+
27
+ return callback({
28
+ window: window
29
+ });
30
+ }
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.31.1';
7
+ var _default = '4.33.2';
8
8
  exports.default = _default;
@@ -11,6 +11,11 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
11
11
 
12
12
  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; }
13
13
 
14
+ // `SpeechRecognition` is an API used on the browser so we can safely disable
15
+ // the `window` check.
16
+
17
+ /* eslint-disable no-restricted-globals */
18
+
14
19
  /* global SpeechRecognition SpeechRecognitionEvent */
15
20
  var createVoiceSearchHelper = function createVoiceSearchHelper(_ref) {
16
21
  var searchAsYouSpeak = _ref.searchAsYouSpeak,
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.isMetadataEnabled = isMetadataEnabled;
7
7
  exports.createMetadataMiddleware = createMetadataMiddleware;
8
8
 
9
+ var _utils = require("../lib/utils");
10
+
9
11
  function extractPayload(widgets, instantSearchInstance, payload) {
10
12
  var parent = instantSearchInstance.mainIndex;
11
13
  var initOptions = {
@@ -51,7 +53,14 @@ function extractPayload(widgets, instantSearchInstance, payload) {
51
53
  }
52
54
 
53
55
  function isMetadataEnabled() {
54
- return typeof window !== 'undefined' && window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
56
+ return (0, _utils.safelyRunOnBrowser)(function (_ref) {
57
+ var window = _ref.window;
58
+ return window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
59
+ }, {
60
+ fallback: function fallback() {
61
+ return false;
62
+ }
63
+ });
55
64
  }
56
65
  /**
57
66
  * Exposes the metadata of mounted widgets in a custom
@@ -63,8 +72,8 @@ function isMetadataEnabled() {
63
72
 
64
73
 
65
74
  function createMetadataMiddleware() {
66
- return function (_ref) {
67
- var instantSearchInstance = _ref.instantSearchInstance;
75
+ return function (_ref2) {
76
+ var instantSearchInstance = _ref2.instantSearchInstance;
68
77
  var payload = {
69
78
  widgets: []
70
79
  };
@@ -555,7 +555,7 @@ var index = function index(widgetParams) {
555
555
  localUiState = getLocalWidgetsUiState(localWidgets, {
556
556
  searchParameters: this.getHelper().state,
557
557
  helper: this.getHelper()
558
- });
558
+ }, localUiState);
559
559
  }
560
560
  };
561
561
  };
@@ -455,13 +455,23 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
455
455
  * It should be symmetrical to `createURL`.
456
456
  */
457
457
  private readonly parseURL;
458
+ /**
459
+ * Returns the location to store in the history.
460
+ * @default () => window.location
461
+ */
462
+ private readonly getLocation;
458
463
  private writeTimer?;
459
464
  private _onPopState;
465
+ /**
466
+ * Indicates if history.pushState should be executed.
467
+ * It needs to avoid pushing state to history in case of back/forward in browser
468
+ */
469
+ private shouldPushState;
460
470
  /**
461
471
  * Initializes a new storage provider that syncs the search state to the URL
462
472
  * using web APIs (`window.location.pushState` and `onpopstate` event).
463
473
  */
464
- constructor({ windowTitle, writeDelay, createURL, parseURL, }: BrowserHistoryArgs<TRouteState>);
474
+ constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, }: BrowserHistoryArgs<TRouteState>);
465
475
  /**
466
476
  * Reads the URL and returns a syncable UI search state.
467
477
  */
@@ -494,6 +504,7 @@ declare type BrowserHistoryArgs<TRouteState> = {
494
504
  writeDelay: number;
495
505
  createURL: CreateURL_2<TRouteState>;
496
506
  parseURL: ParseURL<TRouteState>;
507
+ getLocation(): Location;
497
508
  };
498
509
 
499
510
  declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hits, eventName?: string) => string;
@@ -1723,7 +1734,7 @@ declare type HighlightOptions = {
1723
1734
  }>;
1724
1735
  };
1725
1736
 
1726
- declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1737
+ declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1727
1738
 
1728
1739
  declare type Hit = {
1729
1740
  __position: number;