instantsearch.js 4.63.0 → 4.64.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.
@@ -118,18 +118,18 @@ var RefinementList = /*#__PURE__*/function (_Component) {
118
118
  // if one special key is down
119
119
  return;
120
120
  }
121
- if (!(originalEvent.target instanceof HTMLElement) || !(originalEvent.target.parentNode instanceof HTMLElement)) {
121
+ var parent = originalEvent.target;
122
+ if (parent === null || parent.parentNode === null) {
122
123
  return;
123
124
  }
124
- if (isRefined && originalEvent.target.parentNode.querySelector('input[type="radio"]:checked')) {
125
+ if (isRefined && parent.parentNode.querySelector('input[type="radio"]:checked')) {
125
126
  // Prevent refinement for being reset if the user clicks on an already checked radio button
126
127
  return;
127
128
  }
128
- if (originalEvent.target.tagName === 'INPUT') {
129
+ if (parent.tagName === 'INPUT') {
129
130
  _this.refine(facetValueToRefine);
130
131
  return;
131
132
  }
132
- var parent = originalEvent.target;
133
133
  while (parent !== originalEvent.currentTarget) {
134
134
  if (parent.tagName === 'LABEL' && (parent.querySelector('input[type="checkbox"]') || parent.querySelector('input[type="radio"]'))) {
135
135
  return;
@@ -70,7 +70,7 @@ var connectSearchBox = function connectSearchBox(renderFn) {
70
70
  },
71
71
  getWidgetRenderState: function getWidgetRenderState(_ref3) {
72
72
  var helper = _ref3.helper,
73
- searchMetadata = _ref3.searchMetadata,
73
+ instantSearchInstance = _ref3.instantSearchInstance,
74
74
  state = _ref3.state;
75
75
  if (!_refine) {
76
76
  _refine = function _refine(query) {
@@ -87,7 +87,7 @@ var connectSearchBox = function connectSearchBox(renderFn) {
87
87
  refine: _refine,
88
88
  clear: _clear,
89
89
  widgetParams: widgetParams,
90
- isSearchStalled: searchMetadata.isSearchStalled
90
+ isSearchStalled: instantSearchInstance.status === 'stalled'
91
91
  };
92
92
  },
93
93
  getWidgetUiState: function getWidgetUiState(uiState, _ref4) {
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.63.0';
7
+ var _default = '4.64.0';
8
8
  exports.default = _default;
@@ -80,8 +80,11 @@ function createInsightsMiddleware() {
80
80
  // search-insights.js also throws an error so dev-only clarification is sufficient
81
81
  process.env.NODE_ENV === 'development' ? (0, _utils.warning)(Boolean(appId && apiKey), 'could not extract Algolia credentials from searchClient in insights middleware.') : void 0;
82
82
  var queuedUserToken = undefined;
83
+ var queuedAuthenticatedUserToken = undefined;
83
84
  var userTokenBeforeInit = undefined;
84
- if (Array.isArray(insightsClient.queue)) {
85
+ var authenticatedUserTokenBeforeInit = undefined;
86
+ var queue = insightsClient.queue;
87
+ if (Array.isArray(queue)) {
85
88
  // Context: The umd build of search-insights is asynchronously loaded by the snippet.
86
89
  //
87
90
  // When user calls `aa('setUserToken', 'my-user-token')` before `search-insights` is loaded,
@@ -92,22 +95,32 @@ function createInsightsMiddleware() {
92
95
  // At this point, even though `search-insights` is not loaded yet,
93
96
  // we still want to read the token from the queue.
94
97
  // Otherwise, the first search call will be fired without the token.
95
- var _ref3 = (0, _utils.find)(insightsClient.queue.slice().reverse(), function (_ref5) {
96
- var _ref6 = _slicedToArray(_ref5, 1),
97
- method = _ref6[0];
98
- return method === 'setUserToken';
99
- }) || [];
100
- var _ref4 = _slicedToArray(_ref3, 2);
101
- queuedUserToken = _ref4[1];
98
+ var _map = ['setUserToken', 'setAuthenticatedUserToken'].map(function (key) {
99
+ var _ref3 = (0, _utils.find)(queue.slice().reverse(), function (_ref5) {
100
+ var _ref6 = _slicedToArray(_ref5, 1),
101
+ method = _ref6[0];
102
+ return method === key;
103
+ }) || [],
104
+ _ref4 = _slicedToArray(_ref3, 2),
105
+ value = _ref4[1];
106
+ return value;
107
+ });
108
+ var _map2 = _slicedToArray(_map, 2);
109
+ queuedUserToken = _map2[0];
110
+ queuedAuthenticatedUserToken = _map2[1];
102
111
  }
112
+
113
+ // If user called `aa('setUserToken')` or `aa('setAuthenticatedUserToken')`
114
+ // before creating the Insights middleware, we temporarily store the token
115
+ // and set it later on.
116
+ //
117
+ // Otherwise, the `init` call might override them with anonymous user token.
103
118
  insightsClient('getUserToken', null, function (_error, userToken) {
104
- // If user has called `aa('setUserToken', 'my-user-token')` before creating
105
- // the `insights` middleware, we store them temporarily and
106
- // set it later on.
107
- //
108
- // Otherwise, the `init` call might override it with anonymous user token.
109
119
  userTokenBeforeInit = normalizeUserToken(userToken);
110
120
  });
121
+ insightsClient('getAuthenticatedUserToken', null, function (_error, userToken) {
122
+ authenticatedUserTokenBeforeInit = normalizeUserToken(userToken);
123
+ });
111
124
 
112
125
  // Only `init` if the `insightsInitParams` option is passed or
113
126
  // if the `insightsClient` version doesn't supports optional `init` calling.
@@ -189,21 +202,43 @@ function createInsightsMiddleware() {
189
202
  // We can set it as userToken.
190
203
  setUserTokenToSearch(anonymousUserToken, true);
191
204
  }
205
+ function setUserToken(token, userToken, authenticatedUserToken) {
206
+ setUserTokenToSearch(token, true);
207
+ if (userToken) {
208
+ insightsClient('setUserToken', userToken);
209
+ }
210
+ if (authenticatedUserToken) {
211
+ insightsClient('setAuthenticatedUserToken', authenticatedUserToken);
212
+ }
213
+ }
192
214
 
193
- // We consider the `userToken` coming from a `init` call to have a higher
194
- // importance than the one coming from the queue.
195
- if (userTokenBeforeInit) {
196
- setUserTokenToSearch(userTokenBeforeInit, true);
197
- insightsClient('setUserToken', userTokenBeforeInit);
198
- } else if (queuedUserToken) {
199
- setUserTokenToSearch(queuedUserToken, true);
200
- insightsClient('setUserToken', queuedUserToken);
215
+ // We consider the `userToken` or `authenticatedUserToken` before an
216
+ // `init` call of higher importance than one from the queue.
217
+ var tokenBeforeInit = authenticatedUserTokenBeforeInit || userTokenBeforeInit;
218
+ var queuedToken = queuedAuthenticatedUserToken || queuedUserToken;
219
+ if (tokenBeforeInit) {
220
+ setUserToken(tokenBeforeInit, userTokenBeforeInit, authenticatedUserTokenBeforeInit);
221
+ } else if (queuedToken) {
222
+ setUserToken(queuedToken, queuedUserToken, queuedAuthenticatedUserToken);
201
223
  }
202
224
 
203
225
  // This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
204
226
  insightsClient('onUserTokenChange', setUserTokenToSearch, {
205
227
  immediate: true
206
228
  });
229
+
230
+ // This updates userToken which is set explicitly by `aa('setAuthenticatedtUserToken', authenticatedUserToken)`
231
+ insightsClient('onAuthenticatedUserTokenChange', function (authenticatedUserToken) {
232
+ // If we're unsetting the `authenticatedUserToken`, we revert to the `userToken`
233
+ if (!authenticatedUserToken) {
234
+ insightsClient('getUserToken', null, function (_, userToken) {
235
+ setUserTokenToSearch(userToken);
236
+ });
237
+ }
238
+ setUserTokenToSearch(authenticatedUserToken);
239
+ }, {
240
+ immediate: true
241
+ });
207
242
  var insightsClientWithLocalCredentials = insightsClient;
208
243
  if (isModernInsightsClient(insightsClient)) {
209
244
  insightsClientWithLocalCredentials = function insightsClientWithLocalCredentials(method, payload) {
@@ -239,6 +274,7 @@ function createInsightsMiddleware() {
239
274
  },
240
275
  unsubscribe: function unsubscribe() {
241
276
  insightsClient('onUserTokenChange', undefined);
277
+ insightsClient('onAuthenticatedUserTokenChange', undefined);
242
278
  instantSearchInstance.sendEventToInsights = _utils.noop;
243
279
  if (helper && initialParameters) {
244
280
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread(_objectSpread({}, helper.state), initialParameters));
@@ -5336,9 +5336,7 @@ declare type ToggleRefinementTemplates = Partial<{
5336
5336
  /**
5337
5337
  * the text that describes the toggle action
5338
5338
  */
5339
- labelText: Template<ToggleRefinementValue & {
5340
- name: string;
5341
- }>;
5339
+ labelText: Template<ToggleRefinementRenderState['value']>;
5342
5340
  }>;
5343
5341
 
5344
5342
  declare type ToggleRefinementValue = {
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.63.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! InstantSearch.js 4.64.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
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) :
@@ -4566,7 +4566,7 @@
4566
4566
  },
4567
4567
  getWidgetRenderState: function getWidgetRenderState(_ref3) {
4568
4568
  var helper = _ref3.helper,
4569
- searchMetadata = _ref3.searchMetadata,
4569
+ instantSearchInstance = _ref3.instantSearchInstance,
4570
4570
  state = _ref3.state;
4571
4571
  if (!_refine) {
4572
4572
  _refine = function _refine(query) {
@@ -4583,7 +4583,7 @@
4583
4583
  refine: _refine,
4584
4584
  clear: _clear,
4585
4585
  widgetParams: widgetParams,
4586
- isSearchStalled: searchMetadata.isSearchStalled
4586
+ isSearchStalled: instantSearchInstance.status === 'stalled'
4587
4587
  };
4588
4588
  },
4589
4589
  getWidgetUiState: function getWidgetUiState(uiState, _ref4) {
@@ -12789,8 +12789,11 @@
12789
12789
  // search-insights.js also throws an error so dev-only clarification is sufficient
12790
12790
  _warning(Boolean(appId && apiKey), 'could not extract Algolia credentials from searchClient in insights middleware.') ;
12791
12791
  var queuedUserToken = undefined;
12792
+ var queuedAuthenticatedUserToken = undefined;
12792
12793
  var userTokenBeforeInit = undefined;
12793
- if (Array.isArray(insightsClient.queue)) {
12794
+ var authenticatedUserTokenBeforeInit = undefined;
12795
+ var queue = insightsClient.queue;
12796
+ if (Array.isArray(queue)) {
12794
12797
  // Context: The umd build of search-insights is asynchronously loaded by the snippet.
12795
12798
  //
12796
12799
  // When user calls `aa('setUserToken', 'my-user-token')` before `search-insights` is loaded,
@@ -12801,22 +12804,32 @@
12801
12804
  // At this point, even though `search-insights` is not loaded yet,
12802
12805
  // we still want to read the token from the queue.
12803
12806
  // Otherwise, the first search call will be fired without the token.
12804
- var _ref3 = find(insightsClient.queue.slice().reverse(), function (_ref5) {
12805
- var _ref6 = _slicedToArray(_ref5, 1),
12806
- method = _ref6[0];
12807
- return method === 'setUserToken';
12808
- }) || [];
12809
- var _ref4 = _slicedToArray(_ref3, 2);
12810
- queuedUserToken = _ref4[1];
12807
+ var _map = ['setUserToken', 'setAuthenticatedUserToken'].map(function (key) {
12808
+ var _ref3 = find(queue.slice().reverse(), function (_ref5) {
12809
+ var _ref6 = _slicedToArray(_ref5, 1),
12810
+ method = _ref6[0];
12811
+ return method === key;
12812
+ }) || [],
12813
+ _ref4 = _slicedToArray(_ref3, 2),
12814
+ value = _ref4[1];
12815
+ return value;
12816
+ });
12817
+ var _map2 = _slicedToArray(_map, 2);
12818
+ queuedUserToken = _map2[0];
12819
+ queuedAuthenticatedUserToken = _map2[1];
12811
12820
  }
12821
+
12822
+ // If user called `aa('setUserToken')` or `aa('setAuthenticatedUserToken')`
12823
+ // before creating the Insights middleware, we temporarily store the token
12824
+ // and set it later on.
12825
+ //
12826
+ // Otherwise, the `init` call might override them with anonymous user token.
12812
12827
  insightsClient('getUserToken', null, function (_error, userToken) {
12813
- // If user has called `aa('setUserToken', 'my-user-token')` before creating
12814
- // the `insights` middleware, we store them temporarily and
12815
- // set it later on.
12816
- //
12817
- // Otherwise, the `init` call might override it with anonymous user token.
12818
12828
  userTokenBeforeInit = normalizeUserToken(userToken);
12819
12829
  });
12830
+ insightsClient('getAuthenticatedUserToken', null, function (_error, userToken) {
12831
+ authenticatedUserTokenBeforeInit = normalizeUserToken(userToken);
12832
+ });
12820
12833
 
12821
12834
  // Only `init` if the `insightsInitParams` option is passed or
12822
12835
  // if the `insightsClient` version doesn't supports optional `init` calling.
@@ -12898,21 +12911,43 @@
12898
12911
  // We can set it as userToken.
12899
12912
  setUserTokenToSearch(anonymousUserToken, true);
12900
12913
  }
12914
+ function setUserToken(token, userToken, authenticatedUserToken) {
12915
+ setUserTokenToSearch(token, true);
12916
+ if (userToken) {
12917
+ insightsClient('setUserToken', userToken);
12918
+ }
12919
+ if (authenticatedUserToken) {
12920
+ insightsClient('setAuthenticatedUserToken', authenticatedUserToken);
12921
+ }
12922
+ }
12901
12923
 
12902
- // We consider the `userToken` coming from a `init` call to have a higher
12903
- // importance than the one coming from the queue.
12904
- if (userTokenBeforeInit) {
12905
- setUserTokenToSearch(userTokenBeforeInit, true);
12906
- insightsClient('setUserToken', userTokenBeforeInit);
12907
- } else if (queuedUserToken) {
12908
- setUserTokenToSearch(queuedUserToken, true);
12909
- insightsClient('setUserToken', queuedUserToken);
12924
+ // We consider the `userToken` or `authenticatedUserToken` before an
12925
+ // `init` call of higher importance than one from the queue.
12926
+ var tokenBeforeInit = authenticatedUserTokenBeforeInit || userTokenBeforeInit;
12927
+ var queuedToken = queuedAuthenticatedUserToken || queuedUserToken;
12928
+ if (tokenBeforeInit) {
12929
+ setUserToken(tokenBeforeInit, userTokenBeforeInit, authenticatedUserTokenBeforeInit);
12930
+ } else if (queuedToken) {
12931
+ setUserToken(queuedToken, queuedUserToken, queuedAuthenticatedUserToken);
12910
12932
  }
12911
12933
 
12912
12934
  // This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
12913
12935
  insightsClient('onUserTokenChange', setUserTokenToSearch, {
12914
12936
  immediate: true
12915
12937
  });
12938
+
12939
+ // This updates userToken which is set explicitly by `aa('setAuthenticatedtUserToken', authenticatedUserToken)`
12940
+ insightsClient('onAuthenticatedUserTokenChange', function (authenticatedUserToken) {
12941
+ // If we're unsetting the `authenticatedUserToken`, we revert to the `userToken`
12942
+ if (!authenticatedUserToken) {
12943
+ insightsClient('getUserToken', null, function (_, userToken) {
12944
+ setUserTokenToSearch(userToken);
12945
+ });
12946
+ }
12947
+ setUserTokenToSearch(authenticatedUserToken);
12948
+ }, {
12949
+ immediate: true
12950
+ });
12916
12951
  var insightsClientWithLocalCredentials = insightsClient;
12917
12952
  if (isModernInsightsClient(insightsClient)) {
12918
12953
  insightsClientWithLocalCredentials = function insightsClientWithLocalCredentials(method, payload) {
@@ -12948,6 +12983,7 @@
12948
12983
  },
12949
12984
  unsubscribe: function unsubscribe() {
12950
12985
  insightsClient('onUserTokenChange', undefined);
12986
+ insightsClient('onAuthenticatedUserTokenChange', undefined);
12951
12987
  instantSearchInstance.sendEventToInsights = noop;
12952
12988
  if (helper && initialParameters) {
12953
12989
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), initialParameters));
@@ -14847,7 +14883,7 @@
14847
14883
  };
14848
14884
  }
14849
14885
 
14850
- var version$1 = '4.63.0';
14886
+ var version$1 = '4.64.0';
14851
14887
 
14852
14888
  var withUsage$r = createDocumentationMessageGenerator({
14853
14889
  name: 'instantsearch'
@@ -18312,18 +18348,18 @@
18312
18348
  // if one special key is down
18313
18349
  return;
18314
18350
  }
18315
- if (!(originalEvent.target instanceof HTMLElement) || !(originalEvent.target.parentNode instanceof HTMLElement)) {
18351
+ var parent = originalEvent.target;
18352
+ if (parent === null || parent.parentNode === null) {
18316
18353
  return;
18317
18354
  }
18318
- if (isRefined && originalEvent.target.parentNode.querySelector('input[type="radio"]:checked')) {
18355
+ if (isRefined && parent.parentNode.querySelector('input[type="radio"]:checked')) {
18319
18356
  // Prevent refinement for being reset if the user clicks on an already checked radio button
18320
18357
  return;
18321
18358
  }
18322
- if (originalEvent.target.tagName === 'INPUT') {
18359
+ if (parent.tagName === 'INPUT') {
18323
18360
  _this.refine(facetValueToRefine);
18324
18361
  return;
18325
18362
  }
18326
- var parent = originalEvent.target;
18327
18363
  while (parent !== originalEvent.currentTarget) {
18328
18364
  if (parent.tagName === 'LABEL' && (parent.querySelector('input[type="checkbox"]') || parent.querySelector('input[type="radio"]'))) {
18329
18365
  return;