instantsearch.js 4.75.1 → 4.75.3
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/cjs/components/RefinementList/RefinementList.js +17 -0
- package/cjs/lib/utils/uuid.js +21 -0
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createInsightsMiddleware.js +96 -19
- package/dist/instantsearch.development.js +130 -21
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/RefinementList/RefinementList.d.ts +8 -0
- package/es/components/RefinementList/RefinementList.js +17 -0
- package/es/lib/utils/uuid.d.ts +7 -0
- package/es/lib/utils/uuid.js +15 -0
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createInsightsMiddleware.js +96 -19
- package/es/types/insights.d.ts +1 -1
- package/package.json +5 -5
|
@@ -50,7 +50,9 @@ var RefinementList = /*#__PURE__*/function (_Component) {
|
|
|
50
50
|
args[_key] = arguments[_key];
|
|
51
51
|
}
|
|
52
52
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
53
|
+
_defineProperty(_assertThisInitialized(_this), "listRef", (0, _preact.createRef)());
|
|
53
54
|
_defineProperty(_assertThisInitialized(_this), "searchBox", (0, _preact.createRef)());
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "lastRefinedValue", undefined);
|
|
54
56
|
_defineProperty(_assertThisInitialized(_this), "_generateFacetItem", function (facetValue) {
|
|
55
57
|
var subItems;
|
|
56
58
|
if (isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) {
|
|
@@ -153,6 +155,7 @@ var RefinementList = /*#__PURE__*/function (_Component) {
|
|
|
153
155
|
}, {
|
|
154
156
|
key: "refine",
|
|
155
157
|
value: function refine(facetValueToRefine) {
|
|
158
|
+
this.lastRefinedValue = facetValueToRefine;
|
|
156
159
|
this.props.toggleRefinement(facetValueToRefine);
|
|
157
160
|
}
|
|
158
161
|
}, {
|
|
@@ -162,6 +165,19 @@ var RefinementList = /*#__PURE__*/function (_Component) {
|
|
|
162
165
|
this.searchBox.current.resetInput();
|
|
163
166
|
}
|
|
164
167
|
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* This sets focus on the last refined input element after a render
|
|
171
|
+
* because Preact does not perform it automatically.
|
|
172
|
+
* @see https://github.com/preactjs/preact/issues/3242
|
|
173
|
+
*/
|
|
174
|
+
}, {
|
|
175
|
+
key: "componentDidUpdate",
|
|
176
|
+
value: function componentDidUpdate() {
|
|
177
|
+
var _this$listRef$current, _this$listRef$current2;
|
|
178
|
+
(_this$listRef$current = this.listRef.current) === null || _this$listRef$current === void 0 ? void 0 : (_this$listRef$current2 = _this$listRef$current.querySelector("input[value=\"".concat(this.lastRefinedValue, "\"]"))) === null || _this$listRef$current2 === void 0 ? void 0 : _this$listRef$current2.focus();
|
|
179
|
+
this.lastRefinedValue = undefined;
|
|
180
|
+
}
|
|
165
181
|
}, {
|
|
166
182
|
key: "refineFirstValue",
|
|
167
183
|
value: function refineFirstValue() {
|
|
@@ -213,6 +229,7 @@ var RefinementList = /*#__PURE__*/function (_Component) {
|
|
|
213
229
|
ariaLabel: "Search for filters"
|
|
214
230
|
}));
|
|
215
231
|
var facetValues = this.props.facetValues && this.props.facetValues.length > 0 && (0, _preact.h)("ul", {
|
|
232
|
+
ref: this.listRef,
|
|
216
233
|
className: this.props.cssClasses.list
|
|
217
234
|
}, this.props.facetValues.map(this._generateFacetItem, this));
|
|
218
235
|
var noResults = this.props.searchFacetValues && this.props.isFromSearch && (!this.props.facetValues || this.props.facetValues.length === 0) && (0, _preact.h)(_Template.default, _extends({}, this.props.templateProps, {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createUUID = createUUID;
|
|
7
|
+
/**
|
|
8
|
+
* Create UUID according to
|
|
9
|
+
* https://www.ietf.org/rfc/rfc4122.txt.
|
|
10
|
+
*
|
|
11
|
+
* @returns Generated UUID.
|
|
12
|
+
*/
|
|
13
|
+
function createUUID() {
|
|
14
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
15
|
+
/* eslint-disable no-bitwise */
|
|
16
|
+
var r = Math.random() * 16 | 0;
|
|
17
|
+
var v = c === 'x' ? r : r & 0x3 | 0x8;
|
|
18
|
+
/* eslint-enable */
|
|
19
|
+
return v.toString(16);
|
|
20
|
+
});
|
|
21
|
+
}
|
package/cjs/lib/version.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.createInsightsMiddleware = createInsightsMiddleware;
|
|
8
8
|
var _helpers = require("../helpers");
|
|
9
9
|
var _utils = require("../lib/utils");
|
|
10
|
+
var _uuid = require("../lib/utils/uuid");
|
|
10
11
|
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; }
|
|
11
12
|
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; }
|
|
12
13
|
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; }
|
|
@@ -33,6 +34,7 @@ function createInsightsMiddleware() {
|
|
|
33
34
|
$$internal = _props$$$internal === void 0 ? false : _props$$$internal,
|
|
34
35
|
_props$$$automatic = props.$$automatic,
|
|
35
36
|
$$automatic = _props$$$automatic === void 0 ? false : _props$$$automatic;
|
|
37
|
+
var currentTokenType;
|
|
36
38
|
var potentialInsightsClient = _insightsClient;
|
|
37
39
|
if (!_insightsClient && _insightsClient !== null) {
|
|
38
40
|
(0, _utils.safelyRunOnBrowser)(function (_ref) {
|
|
@@ -79,6 +81,7 @@ function createInsightsMiddleware() {
|
|
|
79
81
|
|
|
80
82
|
// search-insights.js also throws an error so dev-only clarification is sufficient
|
|
81
83
|
process.env.NODE_ENV === 'development' ? (0, _utils.warning)(Boolean(appId && apiKey), 'could not extract Algolia credentials from searchClient in insights middleware.') : void 0;
|
|
84
|
+
var queuedInitParams = undefined;
|
|
82
85
|
var queuedUserToken = undefined;
|
|
83
86
|
var queuedAuthenticatedUserToken = undefined;
|
|
84
87
|
var userTokenBeforeInit = undefined;
|
|
@@ -95,7 +98,7 @@ function createInsightsMiddleware() {
|
|
|
95
98
|
// At this point, even though `search-insights` is not loaded yet,
|
|
96
99
|
// we still want to read the token from the queue.
|
|
97
100
|
// Otherwise, the first search call will be fired without the token.
|
|
98
|
-
var _map = ['setUserToken', 'setAuthenticatedUserToken'].map(function (key) {
|
|
101
|
+
var _map = ['setUserToken', 'setAuthenticatedUserToken', 'init'].map(function (key) {
|
|
99
102
|
var _ref3 = (0, _utils.find)(queue.slice().reverse(), function (_ref5) {
|
|
100
103
|
var _ref6 = _slicedToArray(_ref5, 1),
|
|
101
104
|
method = _ref6[0];
|
|
@@ -105,9 +108,10 @@ function createInsightsMiddleware() {
|
|
|
105
108
|
value = _ref4[1];
|
|
106
109
|
return value;
|
|
107
110
|
});
|
|
108
|
-
var _map2 = _slicedToArray(_map,
|
|
111
|
+
var _map2 = _slicedToArray(_map, 3);
|
|
109
112
|
queuedUserToken = _map2[0];
|
|
110
113
|
queuedAuthenticatedUserToken = _map2[1];
|
|
114
|
+
queuedInitParams = _map2[2];
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
// If user called `aa('setUserToken')` or `aa('setAuthenticatedUserToken')`
|
|
@@ -158,6 +162,23 @@ function createInsightsMiddleware() {
|
|
|
158
162
|
started: function started() {
|
|
159
163
|
insightsClient('addAlgoliaAgent', 'insights-middleware');
|
|
160
164
|
helper = instantSearchInstance.mainHelper;
|
|
165
|
+
var queueAtStart = insightsClient.queue;
|
|
166
|
+
if (Array.isArray(queueAtStart)) {
|
|
167
|
+
var _map3 = ['setUserToken', 'setAuthenticatedUserToken', 'init'].map(function (key) {
|
|
168
|
+
var _ref7 = (0, _utils.find)(queueAtStart.slice().reverse(), function (_ref9) {
|
|
169
|
+
var _ref10 = _slicedToArray(_ref9, 1),
|
|
170
|
+
method = _ref10[0];
|
|
171
|
+
return method === key;
|
|
172
|
+
}) || [],
|
|
173
|
+
_ref8 = _slicedToArray(_ref7, 2),
|
|
174
|
+
value = _ref8[1];
|
|
175
|
+
return value;
|
|
176
|
+
});
|
|
177
|
+
var _map4 = _slicedToArray(_map3, 3);
|
|
178
|
+
queuedUserToken = _map4[0];
|
|
179
|
+
queuedAuthenticatedUserToken = _map4[1];
|
|
180
|
+
queuedInitParams = _map4[2];
|
|
181
|
+
}
|
|
161
182
|
initialParameters = {
|
|
162
183
|
userToken: helper.state.userToken,
|
|
163
184
|
clickAnalytics: helper.state.clickAnalytics
|
|
@@ -173,8 +194,9 @@ function createInsightsMiddleware() {
|
|
|
173
194
|
if (!$$internal) {
|
|
174
195
|
instantSearchInstance.scheduleSearch();
|
|
175
196
|
}
|
|
176
|
-
var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
|
|
177
|
-
var immediate = arguments.length >
|
|
197
|
+
var setUserTokenToSearch = function setUserTokenToSearch(userToken, tokenType) {
|
|
198
|
+
var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
199
|
+
var unsetAuthenticatedUserToken = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
178
200
|
var normalizedUserToken = normalizeUserToken(userToken);
|
|
179
201
|
if (!normalizedUserToken) {
|
|
180
202
|
return;
|
|
@@ -187,6 +209,13 @@ function createInsightsMiddleware() {
|
|
|
187
209
|
if (existingToken && existingToken !== userToken) {
|
|
188
210
|
instantSearchInstance.scheduleSearch();
|
|
189
211
|
}
|
|
212
|
+
currentTokenType = tokenType;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// the authenticated user token cannot be overridden by a user or anonymous token
|
|
216
|
+
// for instant search query requests
|
|
217
|
+
if (currentTokenType && currentTokenType === 'authenticated' && tokenType === 'default' && !unsetAuthenticatedUserToken) {
|
|
218
|
+
return;
|
|
190
219
|
}
|
|
191
220
|
|
|
192
221
|
// Delay the token application to the next render cycle
|
|
@@ -196,14 +225,8 @@ function createInsightsMiddleware() {
|
|
|
196
225
|
applyToken();
|
|
197
226
|
}
|
|
198
227
|
};
|
|
199
|
-
var anonymousUserToken = (0, _helpers.getInsightsAnonymousUserTokenInternal)();
|
|
200
|
-
if (anonymousUserToken) {
|
|
201
|
-
// When `aa('init', { ... })` is called, it creates an anonymous user token in cookie.
|
|
202
|
-
// We can set it as userToken.
|
|
203
|
-
setUserTokenToSearch(anonymousUserToken, true);
|
|
204
|
-
}
|
|
205
228
|
function setUserToken(token, userToken, authenticatedUserToken) {
|
|
206
|
-
setUserTokenToSearch(token, true);
|
|
229
|
+
setUserTokenToSearch(token, authenticatedUserToken ? 'authenticated' : 'default', true);
|
|
207
230
|
if (userToken) {
|
|
208
231
|
insightsClient('setUserToken', userToken);
|
|
209
232
|
}
|
|
@@ -211,19 +234,66 @@ function createInsightsMiddleware() {
|
|
|
211
234
|
insightsClient('setAuthenticatedUserToken', authenticatedUserToken);
|
|
212
235
|
}
|
|
213
236
|
}
|
|
237
|
+
var anonymousUserToken = undefined;
|
|
238
|
+
var anonymousTokenFromInsights = (0, _helpers.getInsightsAnonymousUserTokenInternal)();
|
|
239
|
+
if (anonymousTokenFromInsights) {
|
|
240
|
+
// When `aa('init', { ... })` is called, it creates an anonymous user token in cookie.
|
|
241
|
+
// We can set it as userToken on instantsearch and insights. If it's not set as an insights
|
|
242
|
+
// userToken before a sendEvent, insights automatically generates a new anonymous token,
|
|
243
|
+
// causing a state change and an unnecessary query on instantsearch.
|
|
244
|
+
anonymousUserToken = anonymousTokenFromInsights;
|
|
245
|
+
} else {
|
|
246
|
+
var token = "anonymous-".concat((0, _uuid.createUUID)());
|
|
247
|
+
anonymousUserToken = token;
|
|
248
|
+
}
|
|
249
|
+
var authenticatedUserTokenFromInit;
|
|
250
|
+
var userTokenFromInit;
|
|
251
|
+
|
|
252
|
+
// With SSR, the token could be be set on the state. We make sure
|
|
253
|
+
// that insights is in sync with that token since, there is no
|
|
254
|
+
// insights lib on the server.
|
|
255
|
+
var tokenFromSearchParameters = initialParameters.userToken;
|
|
256
|
+
|
|
257
|
+
// When the first query is sent, the token is possibly not yet be set by
|
|
258
|
+
// the insights onChange callbacks (if insights isn't yet loaded).
|
|
259
|
+
// It is explicitly being set here so that the first query has the
|
|
260
|
+
// initial tokens set and ensure a second query isn't automatically
|
|
261
|
+
// made when the onChange callback actually changes the state.
|
|
262
|
+
if (insightsInitParams) {
|
|
263
|
+
if (insightsInitParams.authenticatedUserToken) {
|
|
264
|
+
authenticatedUserTokenFromInit = insightsInitParams.authenticatedUserToken;
|
|
265
|
+
} else if (insightsInitParams.userToken) {
|
|
266
|
+
userTokenFromInit = insightsInitParams.userToken;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
214
269
|
|
|
215
270
|
// We consider the `userToken` or `authenticatedUserToken` before an
|
|
216
|
-
// `init` call of higher importance than one from the queue
|
|
271
|
+
// `init` call of higher importance than one from the queue and ones set
|
|
272
|
+
// from the init props to be higher than that.
|
|
273
|
+
var tokenFromInit = authenticatedUserTokenFromInit || userTokenFromInit;
|
|
217
274
|
var tokenBeforeInit = authenticatedUserTokenBeforeInit || userTokenBeforeInit;
|
|
218
|
-
var
|
|
219
|
-
if (
|
|
275
|
+
var tokenFromQueue = queuedAuthenticatedUserToken || queuedUserToken;
|
|
276
|
+
if (tokenFromInit) {
|
|
277
|
+
setUserToken(tokenFromInit, userTokenFromInit, authenticatedUserTokenFromInit);
|
|
278
|
+
} else if (tokenFromSearchParameters) {
|
|
279
|
+
setUserToken(tokenFromSearchParameters, tokenFromSearchParameters, undefined);
|
|
280
|
+
} else if (tokenBeforeInit) {
|
|
220
281
|
setUserToken(tokenBeforeInit, userTokenBeforeInit, authenticatedUserTokenBeforeInit);
|
|
221
|
-
} else if (
|
|
222
|
-
setUserToken(
|
|
282
|
+
} else if (tokenFromQueue) {
|
|
283
|
+
setUserToken(tokenFromQueue, queuedUserToken, queuedAuthenticatedUserToken);
|
|
284
|
+
} else if (anonymousUserToken) {
|
|
285
|
+
var _queuedInitParams;
|
|
286
|
+
setUserToken(anonymousUserToken, anonymousUserToken, undefined);
|
|
287
|
+
if (insightsInitParams !== null && insightsInitParams !== void 0 && insightsInitParams.useCookie || (_queuedInitParams = queuedInitParams) !== null && _queuedInitParams !== void 0 && _queuedInitParams.useCookie) {
|
|
288
|
+
var _queuedInitParams2;
|
|
289
|
+
saveTokenAsCookie(anonymousUserToken, (insightsInitParams === null || insightsInitParams === void 0 ? void 0 : insightsInitParams.cookieDuration) || ((_queuedInitParams2 = queuedInitParams) === null || _queuedInitParams2 === void 0 ? void 0 : _queuedInitParams2.cookieDuration));
|
|
290
|
+
}
|
|
223
291
|
}
|
|
224
292
|
|
|
225
293
|
// This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
|
|
226
|
-
insightsClient('onUserTokenChange',
|
|
294
|
+
insightsClient('onUserTokenChange', function (token) {
|
|
295
|
+
return setUserTokenToSearch(token, 'default', true);
|
|
296
|
+
}, {
|
|
227
297
|
immediate: true
|
|
228
298
|
});
|
|
229
299
|
|
|
@@ -232,10 +302,10 @@ function createInsightsMiddleware() {
|
|
|
232
302
|
// If we're unsetting the `authenticatedUserToken`, we revert to the `userToken`
|
|
233
303
|
if (!authenticatedUserToken) {
|
|
234
304
|
insightsClient('getUserToken', null, function (_, userToken) {
|
|
235
|
-
setUserTokenToSearch(userToken);
|
|
305
|
+
setUserTokenToSearch(userToken, 'default', true, true);
|
|
236
306
|
});
|
|
237
307
|
}
|
|
238
|
-
setUserTokenToSearch(authenticatedUserToken);
|
|
308
|
+
setUserTokenToSearch(authenticatedUserToken, 'authenticated', true);
|
|
239
309
|
}, {
|
|
240
310
|
immediate: true
|
|
241
311
|
});
|
|
@@ -284,6 +354,13 @@ function createInsightsMiddleware() {
|
|
|
284
354
|
};
|
|
285
355
|
};
|
|
286
356
|
}
|
|
357
|
+
function saveTokenAsCookie(token, cookieDuration) {
|
|
358
|
+
var MONTH = 30 * 24 * 60 * 60 * 1000;
|
|
359
|
+
var d = new Date();
|
|
360
|
+
d.setTime(d.getTime() + (cookieDuration || MONTH * 6));
|
|
361
|
+
var expires = "expires=".concat(d.toUTCString());
|
|
362
|
+
document.cookie = "_ALGOLIA=".concat(token, ";").concat(expires, ";path=/");
|
|
363
|
+
}
|
|
287
364
|
|
|
288
365
|
/**
|
|
289
366
|
* Determines if a given insights `client` supports the optional call to `init`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! InstantSearch.js 4.75.
|
|
1
|
+
/*! InstantSearch.js 4.75.3 | © 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) :
|
|
@@ -13727,6 +13727,22 @@
|
|
|
13727
13727
|
};
|
|
13728
13728
|
}
|
|
13729
13729
|
|
|
13730
|
+
/**
|
|
13731
|
+
* Create UUID according to
|
|
13732
|
+
* https://www.ietf.org/rfc/rfc4122.txt.
|
|
13733
|
+
*
|
|
13734
|
+
* @returns Generated UUID.
|
|
13735
|
+
*/
|
|
13736
|
+
function createUUID() {
|
|
13737
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
13738
|
+
/* eslint-disable no-bitwise */
|
|
13739
|
+
var r = Math.random() * 16 | 0;
|
|
13740
|
+
var v = c === 'x' ? r : r & 0x3 | 0x8;
|
|
13741
|
+
/* eslint-enable */
|
|
13742
|
+
return v.toString(16);
|
|
13743
|
+
});
|
|
13744
|
+
}
|
|
13745
|
+
|
|
13730
13746
|
var ALGOLIA_INSIGHTS_VERSION = '2.15.0';
|
|
13731
13747
|
var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@".concat(ALGOLIA_INSIGHTS_VERSION, "/dist/search-insights.min.js");
|
|
13732
13748
|
function createInsightsMiddleware() {
|
|
@@ -13738,6 +13754,7 @@
|
|
|
13738
13754
|
$$internal = _props$$$internal === void 0 ? false : _props$$$internal,
|
|
13739
13755
|
_props$$$automatic = props.$$automatic,
|
|
13740
13756
|
$$automatic = _props$$$automatic === void 0 ? false : _props$$$automatic;
|
|
13757
|
+
var currentTokenType;
|
|
13741
13758
|
var potentialInsightsClient = _insightsClient;
|
|
13742
13759
|
if (!_insightsClient && _insightsClient !== null) {
|
|
13743
13760
|
safelyRunOnBrowser(function (_ref) {
|
|
@@ -13784,6 +13801,7 @@
|
|
|
13784
13801
|
|
|
13785
13802
|
// search-insights.js also throws an error so dev-only clarification is sufficient
|
|
13786
13803
|
_warning(Boolean(appId && apiKey), 'could not extract Algolia credentials from searchClient in insights middleware.') ;
|
|
13804
|
+
var queuedInitParams = undefined;
|
|
13787
13805
|
var queuedUserToken = undefined;
|
|
13788
13806
|
var queuedAuthenticatedUserToken = undefined;
|
|
13789
13807
|
var userTokenBeforeInit = undefined;
|
|
@@ -13800,7 +13818,7 @@
|
|
|
13800
13818
|
// At this point, even though `search-insights` is not loaded yet,
|
|
13801
13819
|
// we still want to read the token from the queue.
|
|
13802
13820
|
// Otherwise, the first search call will be fired without the token.
|
|
13803
|
-
var _map = ['setUserToken', 'setAuthenticatedUserToken'].map(function (key) {
|
|
13821
|
+
var _map = ['setUserToken', 'setAuthenticatedUserToken', 'init'].map(function (key) {
|
|
13804
13822
|
var _ref3 = find(queue.slice().reverse(), function (_ref5) {
|
|
13805
13823
|
var _ref6 = _slicedToArray(_ref5, 1),
|
|
13806
13824
|
method = _ref6[0];
|
|
@@ -13810,9 +13828,10 @@
|
|
|
13810
13828
|
value = _ref4[1];
|
|
13811
13829
|
return value;
|
|
13812
13830
|
});
|
|
13813
|
-
var _map2 = _slicedToArray(_map,
|
|
13831
|
+
var _map2 = _slicedToArray(_map, 3);
|
|
13814
13832
|
queuedUserToken = _map2[0];
|
|
13815
13833
|
queuedAuthenticatedUserToken = _map2[1];
|
|
13834
|
+
queuedInitParams = _map2[2];
|
|
13816
13835
|
}
|
|
13817
13836
|
|
|
13818
13837
|
// If user called `aa('setUserToken')` or `aa('setAuthenticatedUserToken')`
|
|
@@ -13863,6 +13882,23 @@
|
|
|
13863
13882
|
started: function started() {
|
|
13864
13883
|
insightsClient('addAlgoliaAgent', 'insights-middleware');
|
|
13865
13884
|
helper = instantSearchInstance.mainHelper;
|
|
13885
|
+
var queueAtStart = insightsClient.queue;
|
|
13886
|
+
if (Array.isArray(queueAtStart)) {
|
|
13887
|
+
var _map3 = ['setUserToken', 'setAuthenticatedUserToken', 'init'].map(function (key) {
|
|
13888
|
+
var _ref7 = find(queueAtStart.slice().reverse(), function (_ref9) {
|
|
13889
|
+
var _ref10 = _slicedToArray(_ref9, 1),
|
|
13890
|
+
method = _ref10[0];
|
|
13891
|
+
return method === key;
|
|
13892
|
+
}) || [],
|
|
13893
|
+
_ref8 = _slicedToArray(_ref7, 2),
|
|
13894
|
+
value = _ref8[1];
|
|
13895
|
+
return value;
|
|
13896
|
+
});
|
|
13897
|
+
var _map4 = _slicedToArray(_map3, 3);
|
|
13898
|
+
queuedUserToken = _map4[0];
|
|
13899
|
+
queuedAuthenticatedUserToken = _map4[1];
|
|
13900
|
+
queuedInitParams = _map4[2];
|
|
13901
|
+
}
|
|
13866
13902
|
initialParameters = {
|
|
13867
13903
|
userToken: helper.state.userToken,
|
|
13868
13904
|
clickAnalytics: helper.state.clickAnalytics
|
|
@@ -13878,8 +13914,9 @@
|
|
|
13878
13914
|
if (!$$internal) {
|
|
13879
13915
|
instantSearchInstance.scheduleSearch();
|
|
13880
13916
|
}
|
|
13881
|
-
var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
|
|
13882
|
-
var immediate = arguments.length >
|
|
13917
|
+
var setUserTokenToSearch = function setUserTokenToSearch(userToken, tokenType) {
|
|
13918
|
+
var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
13919
|
+
var unsetAuthenticatedUserToken = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
13883
13920
|
var normalizedUserToken = normalizeUserToken(userToken);
|
|
13884
13921
|
if (!normalizedUserToken) {
|
|
13885
13922
|
return;
|
|
@@ -13892,6 +13929,13 @@
|
|
|
13892
13929
|
if (existingToken && existingToken !== userToken) {
|
|
13893
13930
|
instantSearchInstance.scheduleSearch();
|
|
13894
13931
|
}
|
|
13932
|
+
currentTokenType = tokenType;
|
|
13933
|
+
}
|
|
13934
|
+
|
|
13935
|
+
// the authenticated user token cannot be overridden by a user or anonymous token
|
|
13936
|
+
// for instant search query requests
|
|
13937
|
+
if (currentTokenType && currentTokenType === 'authenticated' && tokenType === 'default' && !unsetAuthenticatedUserToken) {
|
|
13938
|
+
return;
|
|
13895
13939
|
}
|
|
13896
13940
|
|
|
13897
13941
|
// Delay the token application to the next render cycle
|
|
@@ -13901,14 +13945,8 @@
|
|
|
13901
13945
|
applyToken();
|
|
13902
13946
|
}
|
|
13903
13947
|
};
|
|
13904
|
-
var anonymousUserToken = getInsightsAnonymousUserTokenInternal();
|
|
13905
|
-
if (anonymousUserToken) {
|
|
13906
|
-
// When `aa('init', { ... })` is called, it creates an anonymous user token in cookie.
|
|
13907
|
-
// We can set it as userToken.
|
|
13908
|
-
setUserTokenToSearch(anonymousUserToken, true);
|
|
13909
|
-
}
|
|
13910
13948
|
function setUserToken(token, userToken, authenticatedUserToken) {
|
|
13911
|
-
setUserTokenToSearch(token, true);
|
|
13949
|
+
setUserTokenToSearch(token, authenticatedUserToken ? 'authenticated' : 'default', true);
|
|
13912
13950
|
if (userToken) {
|
|
13913
13951
|
insightsClient('setUserToken', userToken);
|
|
13914
13952
|
}
|
|
@@ -13916,19 +13954,66 @@
|
|
|
13916
13954
|
insightsClient('setAuthenticatedUserToken', authenticatedUserToken);
|
|
13917
13955
|
}
|
|
13918
13956
|
}
|
|
13957
|
+
var anonymousUserToken = undefined;
|
|
13958
|
+
var anonymousTokenFromInsights = getInsightsAnonymousUserTokenInternal();
|
|
13959
|
+
if (anonymousTokenFromInsights) {
|
|
13960
|
+
// When `aa('init', { ... })` is called, it creates an anonymous user token in cookie.
|
|
13961
|
+
// We can set it as userToken on instantsearch and insights. If it's not set as an insights
|
|
13962
|
+
// userToken before a sendEvent, insights automatically generates a new anonymous token,
|
|
13963
|
+
// causing a state change and an unnecessary query on instantsearch.
|
|
13964
|
+
anonymousUserToken = anonymousTokenFromInsights;
|
|
13965
|
+
} else {
|
|
13966
|
+
var token = "anonymous-".concat(createUUID());
|
|
13967
|
+
anonymousUserToken = token;
|
|
13968
|
+
}
|
|
13969
|
+
var authenticatedUserTokenFromInit;
|
|
13970
|
+
var userTokenFromInit;
|
|
13971
|
+
|
|
13972
|
+
// With SSR, the token could be be set on the state. We make sure
|
|
13973
|
+
// that insights is in sync with that token since, there is no
|
|
13974
|
+
// insights lib on the server.
|
|
13975
|
+
var tokenFromSearchParameters = initialParameters.userToken;
|
|
13976
|
+
|
|
13977
|
+
// When the first query is sent, the token is possibly not yet be set by
|
|
13978
|
+
// the insights onChange callbacks (if insights isn't yet loaded).
|
|
13979
|
+
// It is explicitly being set here so that the first query has the
|
|
13980
|
+
// initial tokens set and ensure a second query isn't automatically
|
|
13981
|
+
// made when the onChange callback actually changes the state.
|
|
13982
|
+
if (insightsInitParams) {
|
|
13983
|
+
if (insightsInitParams.authenticatedUserToken) {
|
|
13984
|
+
authenticatedUserTokenFromInit = insightsInitParams.authenticatedUserToken;
|
|
13985
|
+
} else if (insightsInitParams.userToken) {
|
|
13986
|
+
userTokenFromInit = insightsInitParams.userToken;
|
|
13987
|
+
}
|
|
13988
|
+
}
|
|
13919
13989
|
|
|
13920
13990
|
// We consider the `userToken` or `authenticatedUserToken` before an
|
|
13921
|
-
// `init` call of higher importance than one from the queue
|
|
13991
|
+
// `init` call of higher importance than one from the queue and ones set
|
|
13992
|
+
// from the init props to be higher than that.
|
|
13993
|
+
var tokenFromInit = authenticatedUserTokenFromInit || userTokenFromInit;
|
|
13922
13994
|
var tokenBeforeInit = authenticatedUserTokenBeforeInit || userTokenBeforeInit;
|
|
13923
|
-
var
|
|
13924
|
-
if (
|
|
13995
|
+
var tokenFromQueue = queuedAuthenticatedUserToken || queuedUserToken;
|
|
13996
|
+
if (tokenFromInit) {
|
|
13997
|
+
setUserToken(tokenFromInit, userTokenFromInit, authenticatedUserTokenFromInit);
|
|
13998
|
+
} else if (tokenFromSearchParameters) {
|
|
13999
|
+
setUserToken(tokenFromSearchParameters, tokenFromSearchParameters, undefined);
|
|
14000
|
+
} else if (tokenBeforeInit) {
|
|
13925
14001
|
setUserToken(tokenBeforeInit, userTokenBeforeInit, authenticatedUserTokenBeforeInit);
|
|
13926
|
-
} else if (
|
|
13927
|
-
setUserToken(
|
|
14002
|
+
} else if (tokenFromQueue) {
|
|
14003
|
+
setUserToken(tokenFromQueue, queuedUserToken, queuedAuthenticatedUserToken);
|
|
14004
|
+
} else if (anonymousUserToken) {
|
|
14005
|
+
var _queuedInitParams;
|
|
14006
|
+
setUserToken(anonymousUserToken, anonymousUserToken, undefined);
|
|
14007
|
+
if (insightsInitParams !== null && insightsInitParams !== void 0 && insightsInitParams.useCookie || (_queuedInitParams = queuedInitParams) !== null && _queuedInitParams !== void 0 && _queuedInitParams.useCookie) {
|
|
14008
|
+
var _queuedInitParams2;
|
|
14009
|
+
saveTokenAsCookie(anonymousUserToken, (insightsInitParams === null || insightsInitParams === void 0 ? void 0 : insightsInitParams.cookieDuration) || ((_queuedInitParams2 = queuedInitParams) === null || _queuedInitParams2 === void 0 ? void 0 : _queuedInitParams2.cookieDuration));
|
|
14010
|
+
}
|
|
13928
14011
|
}
|
|
13929
14012
|
|
|
13930
14013
|
// This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
|
|
13931
|
-
insightsClient('onUserTokenChange',
|
|
14014
|
+
insightsClient('onUserTokenChange', function (token) {
|
|
14015
|
+
return setUserTokenToSearch(token, 'default', true);
|
|
14016
|
+
}, {
|
|
13932
14017
|
immediate: true
|
|
13933
14018
|
});
|
|
13934
14019
|
|
|
@@ -13937,10 +14022,10 @@
|
|
|
13937
14022
|
// If we're unsetting the `authenticatedUserToken`, we revert to the `userToken`
|
|
13938
14023
|
if (!authenticatedUserToken) {
|
|
13939
14024
|
insightsClient('getUserToken', null, function (_, userToken) {
|
|
13940
|
-
setUserTokenToSearch(userToken);
|
|
14025
|
+
setUserTokenToSearch(userToken, 'default', true, true);
|
|
13941
14026
|
});
|
|
13942
14027
|
}
|
|
13943
|
-
setUserTokenToSearch(authenticatedUserToken);
|
|
14028
|
+
setUserTokenToSearch(authenticatedUserToken, 'authenticated', true);
|
|
13944
14029
|
}, {
|
|
13945
14030
|
immediate: true
|
|
13946
14031
|
});
|
|
@@ -13989,6 +14074,13 @@
|
|
|
13989
14074
|
};
|
|
13990
14075
|
};
|
|
13991
14076
|
}
|
|
14077
|
+
function saveTokenAsCookie(token, cookieDuration) {
|
|
14078
|
+
var MONTH = 30 * 24 * 60 * 60 * 1000;
|
|
14079
|
+
var d = new Date();
|
|
14080
|
+
d.setTime(d.getTime() + (cookieDuration || MONTH * 6));
|
|
14081
|
+
var expires = "expires=".concat(d.toUTCString());
|
|
14082
|
+
document.cookie = "_ALGOLIA=".concat(token, ";").concat(expires, ";path=/");
|
|
14083
|
+
}
|
|
13992
14084
|
|
|
13993
14085
|
/**
|
|
13994
14086
|
* Determines if a given insights `client` supports the optional call to `init`
|
|
@@ -16017,7 +16109,7 @@
|
|
|
16017
16109
|
};
|
|
16018
16110
|
}
|
|
16019
16111
|
|
|
16020
|
-
var version$1 = '4.75.
|
|
16112
|
+
var version$1 = '4.75.3';
|
|
16021
16113
|
|
|
16022
16114
|
var withUsage$v = createDocumentationMessageGenerator({
|
|
16023
16115
|
name: 'instantsearch'
|
|
@@ -20246,7 +20338,9 @@
|
|
|
20246
20338
|
args[_key] = arguments[_key];
|
|
20247
20339
|
}
|
|
20248
20340
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
20341
|
+
_defineProperty(_assertThisInitialized(_this), "listRef", y());
|
|
20249
20342
|
_defineProperty(_assertThisInitialized(_this), "searchBox", y());
|
|
20343
|
+
_defineProperty(_assertThisInitialized(_this), "lastRefinedValue", undefined);
|
|
20250
20344
|
_defineProperty(_assertThisInitialized(_this), "_generateFacetItem", function (facetValue) {
|
|
20251
20345
|
var subItems;
|
|
20252
20346
|
if (isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) {
|
|
@@ -20349,6 +20443,7 @@
|
|
|
20349
20443
|
}, {
|
|
20350
20444
|
key: "refine",
|
|
20351
20445
|
value: function refine(facetValueToRefine) {
|
|
20446
|
+
this.lastRefinedValue = facetValueToRefine;
|
|
20352
20447
|
this.props.toggleRefinement(facetValueToRefine);
|
|
20353
20448
|
}
|
|
20354
20449
|
}, {
|
|
@@ -20358,6 +20453,19 @@
|
|
|
20358
20453
|
this.searchBox.current.resetInput();
|
|
20359
20454
|
}
|
|
20360
20455
|
}
|
|
20456
|
+
|
|
20457
|
+
/**
|
|
20458
|
+
* This sets focus on the last refined input element after a render
|
|
20459
|
+
* because Preact does not perform it automatically.
|
|
20460
|
+
* @see https://github.com/preactjs/preact/issues/3242
|
|
20461
|
+
*/
|
|
20462
|
+
}, {
|
|
20463
|
+
key: "componentDidUpdate",
|
|
20464
|
+
value: function componentDidUpdate() {
|
|
20465
|
+
var _this$listRef$current, _this$listRef$current2;
|
|
20466
|
+
(_this$listRef$current = this.listRef.current) === null || _this$listRef$current === void 0 ? void 0 : (_this$listRef$current2 = _this$listRef$current.querySelector("input[value=\"".concat(this.lastRefinedValue, "\"]"))) === null || _this$listRef$current2 === void 0 ? void 0 : _this$listRef$current2.focus();
|
|
20467
|
+
this.lastRefinedValue = undefined;
|
|
20468
|
+
}
|
|
20361
20469
|
}, {
|
|
20362
20470
|
key: "refineFirstValue",
|
|
20363
20471
|
value: function refineFirstValue() {
|
|
@@ -20409,6 +20517,7 @@
|
|
|
20409
20517
|
ariaLabel: "Search for filters"
|
|
20410
20518
|
}));
|
|
20411
20519
|
var facetValues = this.props.facetValues && this.props.facetValues.length > 0 && h("ul", {
|
|
20520
|
+
ref: this.listRef,
|
|
20412
20521
|
className: this.props.cssClasses.list
|
|
20413
20522
|
}, this.props.facetValues.map(this._generateFacetItem, this));
|
|
20414
20523
|
var noResults = this.props.searchFacetValues && this.props.isFromSearch && (!this.props.facetValues || this.props.facetValues.length === 0) && h(Template, _extends({}, this.props.templateProps, {
|