instantsearch.js 4.75.5 → 4.75.6
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/Slider/Rheostat.js +4 -4
- package/cjs/connectors/autocomplete/connectAutocomplete.js +9 -5
- package/cjs/connectors/current-refinements/connectCurrentRefinements.js +1 -1
- package/cjs/connectors/hits/connectHitsWithInsights.js +3 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +1 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHitsWithInsights.js +3 -1
- package/cjs/lib/InstantSearch.js +2 -0
- package/cjs/lib/server.js +5 -2
- package/cjs/lib/utils/getRefinements.js +2 -1
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createInsightsMiddleware.js +37 -78
- package/cjs/widgets/analytics/analytics.js +3 -0
- package/cjs/widgets/hits/defaultTemplates.js +1 -0
- package/cjs/widgets/index/index.js +0 -1
- package/cjs/widgets/places/places.js +2 -0
- package/dist/instantsearch.development.d.ts +4 -4
- package/dist/instantsearch.development.js +83 -109
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +4 -4
- package/dist/instantsearch.production.min.d.ts +4 -4
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/autocomplete/connectAutocomplete.js +9 -5
- package/es/connectors/current-refinements/connectCurrentRefinements.js +1 -1
- package/es/connectors/hits/connectHitsWithInsights.js +3 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.d.ts +1 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +1 -1
- package/es/connectors/infinite-hits/connectInfiniteHitsWithInsights.js +3 -1
- package/es/lib/InstantSearch.js +2 -0
- package/es/lib/server.js +5 -2
- package/es/lib/utils/getRefinements.d.ts +1 -1
- package/es/lib/utils/getRefinements.js +2 -1
- package/es/lib/utils/render-args.d.ts +1 -1
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createInsightsMiddleware.js +37 -78
- package/es/types/widget.d.ts +3 -3
- package/es/widgets/analytics/analytics.js +3 -0
- package/es/widgets/hits/defaultTemplates.js +1 -0
- package/es/widgets/index/index.js +0 -1
- package/es/widgets/places/places.js +2 -0
- package/es/widgets/search-box/defaultTemplates.js +0 -1
- package/package.json +6 -6
|
@@ -58,21 +58,25 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
var indices = scopedResults.map(function (scopedResult) {
|
|
61
|
+
var _scopedResult$results2, _scopedResult$results3;
|
|
61
62
|
// We need to escape the hits because highlighting
|
|
62
63
|
// exposes HTML tags to the end-user.
|
|
63
|
-
|
|
64
|
+
if (scopedResult.results) {
|
|
65
|
+
scopedResult.results.hits = escapeHTML ? escapeHits(scopedResult.results.hits) : scopedResult.results.hits;
|
|
66
|
+
}
|
|
64
67
|
var sendEvent = createSendEventForHits({
|
|
65
68
|
instantSearchInstance: instantSearchInstance,
|
|
66
69
|
getIndex: function getIndex() {
|
|
67
|
-
|
|
70
|
+
var _scopedResult$results;
|
|
71
|
+
return ((_scopedResult$results = scopedResult.results) === null || _scopedResult$results === void 0 ? void 0 : _scopedResult$results.index) || '';
|
|
68
72
|
},
|
|
69
73
|
widgetType: _this.$$type
|
|
70
74
|
});
|
|
71
75
|
return {
|
|
72
76
|
indexId: scopedResult.indexId,
|
|
73
|
-
indexName: scopedResult.results.index,
|
|
74
|
-
hits: scopedResult.results.hits,
|
|
75
|
-
results: scopedResult.results,
|
|
77
|
+
indexName: ((_scopedResult$results2 = scopedResult.results) === null || _scopedResult$results2 === void 0 ? void 0 : _scopedResult$results2.index) || '',
|
|
78
|
+
hits: ((_scopedResult$results3 = scopedResult.results) === null || _scopedResult$results3 === void 0 ? void 0 : _scopedResult$results3.hits) || [],
|
|
79
|
+
results: scopedResult.results || {},
|
|
76
80
|
sendEvent: sendEvent
|
|
77
81
|
};
|
|
78
82
|
});
|
|
@@ -60,7 +60,7 @@ var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
|
|
|
60
60
|
function getItems() {
|
|
61
61
|
if (!results) {
|
|
62
62
|
return transformItems(getRefinementsItems({
|
|
63
|
-
results:
|
|
63
|
+
results: null,
|
|
64
64
|
helper: helper,
|
|
65
65
|
indexId: helper.state.index,
|
|
66
66
|
includedAttributes: includedAttributes,
|
|
@@ -5,6 +5,8 @@ import connectHits from "./connectHits.js";
|
|
|
5
5
|
* Due to https://github.com/microsoft/web-build-tools/issues/1050, we need
|
|
6
6
|
* Connector<...> imported in this file, even though it is only used implicitly.
|
|
7
7
|
* This _uses_ Connector<...> so it is not accidentally removed by someone.
|
|
8
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
+
|
|
9
11
|
var connectHitsWithInsights = withInsights(connectHits);
|
|
10
12
|
export default connectHitsWithInsights;
|
|
@@ -81,7 +81,7 @@ export type InfiniteHitsRenderState<THit extends NonNullable<object> = BaseHit>
|
|
|
81
81
|
/**
|
|
82
82
|
* The response from the Algolia API.
|
|
83
83
|
*/
|
|
84
|
-
results?: SearchResults<Hit<THit
|
|
84
|
+
results?: SearchResults<Hit<THit>> | null;
|
|
85
85
|
/**
|
|
86
86
|
* The banner to display above the hits.
|
|
87
87
|
*/
|
|
@@ -216,7 +216,7 @@ export default (function connectInfiniteHits(renderFn) {
|
|
|
216
216
|
sendEvent: sendEvent,
|
|
217
217
|
bindEvent: bindEvent,
|
|
218
218
|
banner: banner,
|
|
219
|
-
results: results,
|
|
219
|
+
results: results || undefined,
|
|
220
220
|
showPrevious: showPrevious,
|
|
221
221
|
showMore: showMore,
|
|
222
222
|
isFirstPage: isFirstPage,
|
|
@@ -5,6 +5,8 @@ import connectInfiniteHits from "./connectInfiniteHits.js";
|
|
|
5
5
|
* Due to https://github.com/microsoft/web-build-tools/issues/1050, we need
|
|
6
6
|
* Connector<...> imported in this file, even though it is only used implicitly.
|
|
7
7
|
* This _uses_ Connector<...> so it is not accidentally removed by someone.
|
|
8
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
+
|
|
9
11
|
var connectInfiniteHitsWithInsights = withInsights(connectInfiniteHits);
|
|
10
12
|
export default connectInfiniteHitsWithInsights;
|
package/es/lib/InstantSearch.js
CHANGED
|
@@ -33,9 +33,11 @@ function defaultCreateURL() {
|
|
|
33
33
|
// this purposely breaks typescript's type inference to ensure it's not used
|
|
34
34
|
// as it's used for a default parameter for example
|
|
35
35
|
// source: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-504042546
|
|
36
|
+
|
|
36
37
|
/**
|
|
37
38
|
* Global options for an InstantSearch instance.
|
|
38
39
|
*/
|
|
40
|
+
|
|
39
41
|
export var INSTANTSEARCH_FUTURE_DEFAULTS = {
|
|
40
42
|
preserveSharedStateOnUnmount: false,
|
|
41
43
|
persistHierarchicalRootCount: false
|
package/es/lib/server.js
CHANGED
|
@@ -78,12 +78,15 @@ requestParamsList) {
|
|
|
78
78
|
var searchResults = widget.getResults();
|
|
79
79
|
var recommendResults = (_widget$getHelper = widget.getHelper()) === null || _widget$getHelper === void 0 ? void 0 : _widget$getHelper.lastRecommendResults;
|
|
80
80
|
if (searchResults || recommendResults) {
|
|
81
|
-
var _searchResults$_rawRe;
|
|
81
|
+
var _searchResults$_rawRe, _requestParams$, _requestParams$2;
|
|
82
82
|
var resultsCount = (searchResults === null || searchResults === void 0 ? void 0 : (_searchResults$_rawRe = searchResults._rawResults) === null || _searchResults$_rawRe === void 0 ? void 0 : _searchResults$_rawRe.length) || 0;
|
|
83
83
|
var requestParams = resultsCount ? requestParamsList === null || requestParamsList === void 0 ? void 0 : requestParamsList.slice(requestParamsIndex, requestParamsIndex + resultsCount) : [];
|
|
84
84
|
requestParamsIndex += resultsCount;
|
|
85
85
|
initialResults[widget.getIndexId()] = _objectSpread(_objectSpread(_objectSpread({}, searchResults && {
|
|
86
|
-
state: _objectSpread({}, searchResults._state),
|
|
86
|
+
state: _objectSpread(_objectSpread({}, searchResults._state), {}, {
|
|
87
|
+
clickAnalytics: requestParams === null || requestParams === void 0 ? void 0 : (_requestParams$ = requestParams[0]) === null || _requestParams$ === void 0 ? void 0 : _requestParams$.clickAnalytics,
|
|
88
|
+
userToken: requestParams === null || requestParams === void 0 ? void 0 : (_requestParams$2 = requestParams[0]) === null || _requestParams$2 === void 0 ? void 0 : _requestParams$2.userToken
|
|
89
|
+
}),
|
|
87
90
|
results: searchResults._rawResults
|
|
88
91
|
}), recommendResults && {
|
|
89
92
|
recommendResults: {
|
|
@@ -36,4 +36,4 @@ export type FacetExcludeRefinement = {
|
|
|
36
36
|
exhaustive?: boolean;
|
|
37
37
|
};
|
|
38
38
|
export type Refinement = FacetRefinement | QueryRefinement | NumericRefinement | FacetExcludeRefinement | TagRefinement;
|
|
39
|
-
export declare function getRefinements(
|
|
39
|
+
export declare function getRefinements(_results: SearchResults | Record<string, never> | null, state: SearchParameters, includesQuery?: boolean): Refinement[];
|
|
@@ -40,8 +40,9 @@ function getRefinement(state, type, attribute, name) {
|
|
|
40
40
|
}
|
|
41
41
|
return res;
|
|
42
42
|
}
|
|
43
|
-
export function getRefinements(
|
|
43
|
+
export function getRefinements(_results, state) {
|
|
44
44
|
var includesQuery = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
45
|
+
var results = _results || {};
|
|
45
46
|
var refinements = [];
|
|
46
47
|
var _state$facetsRefineme = state.facetsRefinements,
|
|
47
48
|
facetsRefinements = _state$facetsRefineme === void 0 ? {} : _state$facetsRefineme,
|
|
@@ -19,7 +19,7 @@ export declare function createRenderArgs(instantSearchInstance: InstantSearch, p
|
|
|
19
19
|
helper: import("algoliasearch-helper").AlgoliaSearchHelper;
|
|
20
20
|
parent: IndexWidget;
|
|
21
21
|
instantSearchInstance: InstantSearch<UiState, UiState>;
|
|
22
|
-
results: import("algoliasearch").RecommendationsResults | import("algoliasearch-helper").SearchResults<any
|
|
22
|
+
results: import("algoliasearch").RecommendationsResults | import("algoliasearch-helper").SearchResults<any> | null;
|
|
23
23
|
scopedResults: import("../../types").ScopedResult[];
|
|
24
24
|
state: any;
|
|
25
25
|
renderState: import("../../types").RenderState;
|
package/es/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.75.
|
|
1
|
+
declare const _default: "4.75.6";
|
|
2
2
|
export default _default;
|
package/es/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.75.
|
|
1
|
+
export default '4.75.6';
|
|
@@ -28,7 +28,6 @@ export function createInsightsMiddleware() {
|
|
|
28
28
|
$$internal = _props$$$internal === void 0 ? false : _props$$$internal,
|
|
29
29
|
_props$$$automatic = props.$$automatic,
|
|
30
30
|
$$automatic = _props$$$automatic === void 0 ? false : _props$$$automatic;
|
|
31
|
-
var currentTokenType;
|
|
32
31
|
var potentialInsightsClient = _insightsClient;
|
|
33
32
|
if (!_insightsClient && _insightsClient !== null) {
|
|
34
33
|
safelyRunOnBrowser(function (_ref) {
|
|
@@ -77,9 +76,7 @@ export function createInsightsMiddleware() {
|
|
|
77
76
|
process.env.NODE_ENV === 'development' ? warning(Boolean(appId && apiKey), 'could not extract Algolia credentials from searchClient in insights middleware.') : void 0;
|
|
78
77
|
var queuedInitParams = undefined;
|
|
79
78
|
var queuedUserToken = undefined;
|
|
80
|
-
var queuedAuthenticatedUserToken = undefined;
|
|
81
79
|
var userTokenBeforeInit = undefined;
|
|
82
|
-
var authenticatedUserTokenBeforeInit = undefined;
|
|
83
80
|
var queue = insightsClient.queue;
|
|
84
81
|
if (Array.isArray(queue)) {
|
|
85
82
|
// Context: The umd build of search-insights is asynchronously loaded by the snippet.
|
|
@@ -92,7 +89,7 @@ export function createInsightsMiddleware() {
|
|
|
92
89
|
// At this point, even though `search-insights` is not loaded yet,
|
|
93
90
|
// we still want to read the token from the queue.
|
|
94
91
|
// Otherwise, the first search call will be fired without the token.
|
|
95
|
-
var _map = ['setUserToken', '
|
|
92
|
+
var _map = ['setUserToken', 'init'].map(function (key) {
|
|
96
93
|
var _ref3 = find(queue.slice().reverse(), function (_ref5) {
|
|
97
94
|
var _ref6 = _slicedToArray(_ref5, 1),
|
|
98
95
|
method = _ref6[0];
|
|
@@ -102,23 +99,18 @@ export function createInsightsMiddleware() {
|
|
|
102
99
|
value = _ref4[1];
|
|
103
100
|
return value;
|
|
104
101
|
});
|
|
105
|
-
var _map2 = _slicedToArray(_map,
|
|
102
|
+
var _map2 = _slicedToArray(_map, 2);
|
|
106
103
|
queuedUserToken = _map2[0];
|
|
107
|
-
|
|
108
|
-
queuedInitParams = _map2[2];
|
|
104
|
+
queuedInitParams = _map2[1];
|
|
109
105
|
}
|
|
110
106
|
|
|
111
|
-
// If user called `aa('setUserToken')`
|
|
112
|
-
//
|
|
113
|
-
// and set it later on.
|
|
107
|
+
// If user called `aa('setUserToken')` before creating the Insights middleware,
|
|
108
|
+
// we temporarily store the token and set it later on.
|
|
114
109
|
//
|
|
115
110
|
// Otherwise, the `init` call might override them with anonymous user token.
|
|
116
111
|
insightsClient('getUserToken', null, function (_error, userToken) {
|
|
117
112
|
userTokenBeforeInit = normalizeUserToken(userToken);
|
|
118
113
|
});
|
|
119
|
-
insightsClient('getAuthenticatedUserToken', null, function (_error, userToken) {
|
|
120
|
-
authenticatedUserTokenBeforeInit = normalizeUserToken(userToken);
|
|
121
|
-
});
|
|
122
114
|
|
|
123
115
|
// Only `init` if the `insightsInitParams` option is passed or
|
|
124
116
|
// if the `insightsClient` version doesn't supports optional `init` calling.
|
|
@@ -158,7 +150,7 @@ export function createInsightsMiddleware() {
|
|
|
158
150
|
helper = instantSearchInstance.mainHelper;
|
|
159
151
|
var queueAtStart = insightsClient.queue;
|
|
160
152
|
if (Array.isArray(queueAtStart)) {
|
|
161
|
-
var _map3 = ['setUserToken', '
|
|
153
|
+
var _map3 = ['setUserToken', 'init'].map(function (key) {
|
|
162
154
|
var _ref7 = find(queueAtStart.slice().reverse(), function (_ref9) {
|
|
163
155
|
var _ref10 = _slicedToArray(_ref9, 1),
|
|
164
156
|
method = _ref10[0];
|
|
@@ -168,15 +160,11 @@ export function createInsightsMiddleware() {
|
|
|
168
160
|
value = _ref8[1];
|
|
169
161
|
return value;
|
|
170
162
|
});
|
|
171
|
-
var _map4 = _slicedToArray(_map3,
|
|
163
|
+
var _map4 = _slicedToArray(_map3, 2);
|
|
172
164
|
queuedUserToken = _map4[0];
|
|
173
|
-
|
|
174
|
-
queuedInitParams = _map4[2];
|
|
165
|
+
queuedInitParams = _map4[1];
|
|
175
166
|
}
|
|
176
|
-
initialParameters =
|
|
177
|
-
userToken: helper.state.userToken,
|
|
178
|
-
clickAnalytics: helper.state.clickAnalytics
|
|
179
|
-
};
|
|
167
|
+
initialParameters = getInitialParameters(instantSearchInstance);
|
|
180
168
|
|
|
181
169
|
// We don't want to force clickAnalytics when the insights is enabled from the search response.
|
|
182
170
|
// This means we don't enable insights for indices that don't opt in
|
|
@@ -188,9 +176,8 @@ export function createInsightsMiddleware() {
|
|
|
188
176
|
if (!$$internal) {
|
|
189
177
|
instantSearchInstance.scheduleSearch();
|
|
190
178
|
}
|
|
191
|
-
var setUserTokenToSearch = function setUserTokenToSearch(userToken
|
|
192
|
-
var immediate = arguments.length >
|
|
193
|
-
var unsetAuthenticatedUserToken = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
179
|
+
var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
|
|
180
|
+
var immediate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
194
181
|
var normalizedUserToken = normalizeUserToken(userToken);
|
|
195
182
|
if (!normalizedUserToken) {
|
|
196
183
|
return;
|
|
@@ -203,13 +190,6 @@ export function createInsightsMiddleware() {
|
|
|
203
190
|
if (existingToken && existingToken !== userToken) {
|
|
204
191
|
instantSearchInstance.scheduleSearch();
|
|
205
192
|
}
|
|
206
|
-
currentTokenType = tokenType;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// the authenticated user token cannot be overridden by a user or anonymous token
|
|
210
|
-
// for instant search query requests
|
|
211
|
-
if (currentTokenType && currentTokenType === 'authenticated' && tokenType === 'default' && !unsetAuthenticatedUserToken) {
|
|
212
|
-
return;
|
|
213
193
|
}
|
|
214
194
|
|
|
215
195
|
// Delay the token application to the next render cycle
|
|
@@ -219,14 +199,9 @@ export function createInsightsMiddleware() {
|
|
|
219
199
|
applyToken();
|
|
220
200
|
}
|
|
221
201
|
};
|
|
222
|
-
function setUserToken(token
|
|
223
|
-
setUserTokenToSearch(token,
|
|
224
|
-
|
|
225
|
-
insightsClient('setUserToken', userToken);
|
|
226
|
-
}
|
|
227
|
-
if (authenticatedUserToken) {
|
|
228
|
-
insightsClient('setAuthenticatedUserToken', authenticatedUserToken);
|
|
229
|
-
}
|
|
202
|
+
function setUserToken(token) {
|
|
203
|
+
setUserTokenToSearch(token, true);
|
|
204
|
+
insightsClient('setUserToken', token);
|
|
230
205
|
}
|
|
231
206
|
var anonymousUserToken = undefined;
|
|
232
207
|
var anonymousTokenFromInsights = getInsightsAnonymousUserTokenInternal();
|
|
@@ -240,7 +215,6 @@ export function createInsightsMiddleware() {
|
|
|
240
215
|
var token = "anonymous-".concat(createUUID());
|
|
241
216
|
anonymousUserToken = token;
|
|
242
217
|
}
|
|
243
|
-
var authenticatedUserTokenFromInit;
|
|
244
218
|
var userTokenFromInit;
|
|
245
219
|
|
|
246
220
|
// With SSR, the token could be be set on the state. We make sure
|
|
@@ -248,36 +222,25 @@ export function createInsightsMiddleware() {
|
|
|
248
222
|
// insights lib on the server.
|
|
249
223
|
var tokenFromSearchParameters = initialParameters.userToken;
|
|
250
224
|
|
|
251
|
-
// When the first query is sent, the token is possibly not yet
|
|
225
|
+
// When the first query is sent, the token is possibly not yet set by
|
|
252
226
|
// the insights onChange callbacks (if insights isn't yet loaded).
|
|
253
227
|
// It is explicitly being set here so that the first query has the
|
|
254
228
|
// initial tokens set and ensure a second query isn't automatically
|
|
255
229
|
// made when the onChange callback actually changes the state.
|
|
256
|
-
if (insightsInitParams) {
|
|
257
|
-
|
|
258
|
-
authenticatedUserTokenFromInit = insightsInitParams.authenticatedUserToken;
|
|
259
|
-
} else if (insightsInitParams.userToken) {
|
|
260
|
-
userTokenFromInit = insightsInitParams.userToken;
|
|
261
|
-
}
|
|
230
|
+
if (insightsInitParams !== null && insightsInitParams !== void 0 && insightsInitParams.userToken) {
|
|
231
|
+
userTokenFromInit = insightsInitParams.userToken;
|
|
262
232
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// `init` call of higher importance than one from the queue and ones set
|
|
266
|
-
// from the init props to be higher than that.
|
|
267
|
-
var tokenFromInit = authenticatedUserTokenFromInit || userTokenFromInit;
|
|
268
|
-
var tokenBeforeInit = authenticatedUserTokenBeforeInit || userTokenBeforeInit;
|
|
269
|
-
var tokenFromQueue = queuedAuthenticatedUserToken || queuedUserToken;
|
|
270
|
-
if (tokenFromInit) {
|
|
271
|
-
setUserToken(tokenFromInit, userTokenFromInit, authenticatedUserTokenFromInit);
|
|
233
|
+
if (userTokenFromInit) {
|
|
234
|
+
setUserToken(userTokenFromInit);
|
|
272
235
|
} else if (tokenFromSearchParameters) {
|
|
273
|
-
setUserToken(tokenFromSearchParameters
|
|
274
|
-
} else if (
|
|
275
|
-
setUserToken(
|
|
276
|
-
} else if (
|
|
277
|
-
setUserToken(
|
|
236
|
+
setUserToken(tokenFromSearchParameters);
|
|
237
|
+
} else if (userTokenBeforeInit) {
|
|
238
|
+
setUserToken(userTokenBeforeInit);
|
|
239
|
+
} else if (queuedUserToken) {
|
|
240
|
+
setUserToken(queuedUserToken);
|
|
278
241
|
} else if (anonymousUserToken) {
|
|
279
242
|
var _queuedInitParams;
|
|
280
|
-
setUserToken(anonymousUserToken
|
|
243
|
+
setUserToken(anonymousUserToken);
|
|
281
244
|
if (insightsInitParams !== null && insightsInitParams !== void 0 && insightsInitParams.useCookie || (_queuedInitParams = queuedInitParams) !== null && _queuedInitParams !== void 0 && _queuedInitParams.useCookie) {
|
|
282
245
|
var _queuedInitParams2;
|
|
283
246
|
saveTokenAsCookie(anonymousUserToken, (insightsInitParams === null || insightsInitParams === void 0 ? void 0 : insightsInitParams.cookieDuration) || ((_queuedInitParams2 = queuedInitParams) === null || _queuedInitParams2 === void 0 ? void 0 : _queuedInitParams2.cookieDuration));
|
|
@@ -286,20 +249,7 @@ export function createInsightsMiddleware() {
|
|
|
286
249
|
|
|
287
250
|
// This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
|
|
288
251
|
insightsClient('onUserTokenChange', function (token) {
|
|
289
|
-
return setUserTokenToSearch(token,
|
|
290
|
-
}, {
|
|
291
|
-
immediate: true
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
// This updates userToken which is set explicitly by `aa('setAuthenticatedtUserToken', authenticatedUserToken)`
|
|
295
|
-
insightsClient('onAuthenticatedUserTokenChange', function (authenticatedUserToken) {
|
|
296
|
-
// If we're unsetting the `authenticatedUserToken`, we revert to the `userToken`
|
|
297
|
-
if (!authenticatedUserToken) {
|
|
298
|
-
insightsClient('getUserToken', null, function (_, userToken) {
|
|
299
|
-
setUserTokenToSearch(userToken, 'default', true, true);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
setUserTokenToSearch(authenticatedUserToken, 'authenticated', true);
|
|
252
|
+
return setUserTokenToSearch(token, true);
|
|
303
253
|
}, {
|
|
304
254
|
immediate: true
|
|
305
255
|
});
|
|
@@ -321,7 +271,7 @@ export function createInsightsMiddleware() {
|
|
|
321
271
|
var lastQueryId;
|
|
322
272
|
instantSearchInstance.mainHelper.derivedHelpers[0].on('result', function (_ref11) {
|
|
323
273
|
var results = _ref11.results;
|
|
324
|
-
if (!results.queryID || results.queryID !== lastQueryId) {
|
|
274
|
+
if (results && (!results.queryID || results.queryID !== lastQueryId)) {
|
|
325
275
|
lastQueryId = results.queryID;
|
|
326
276
|
viewedObjectIDs.clear();
|
|
327
277
|
}
|
|
@@ -361,7 +311,6 @@ export function createInsightsMiddleware() {
|
|
|
361
311
|
},
|
|
362
312
|
unsubscribe: function unsubscribe() {
|
|
363
313
|
insightsClient('onUserTokenChange', undefined);
|
|
364
|
-
insightsClient('onAuthenticatedUserTokenChange', undefined);
|
|
365
314
|
instantSearchInstance.sendEventToInsights = noop;
|
|
366
315
|
if (helper && initialParameters) {
|
|
367
316
|
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread(_objectSpread({}, helper.state), initialParameters));
|
|
@@ -371,6 +320,16 @@ export function createInsightsMiddleware() {
|
|
|
371
320
|
};
|
|
372
321
|
};
|
|
373
322
|
}
|
|
323
|
+
function getInitialParameters(instantSearchInstance) {
|
|
324
|
+
var _instantSearchInstanc, _instantSearchInstanc2;
|
|
325
|
+
// in SSR, the initial state we use in this domain is set on the main index
|
|
326
|
+
var stateFromInitialResults = ((_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : (_instantSearchInstanc2 = _instantSearchInstanc[instantSearchInstance.indexName]) === null || _instantSearchInstanc2 === void 0 ? void 0 : _instantSearchInstanc2.state) || {};
|
|
327
|
+
var stateFromHelper = instantSearchInstance.mainHelper.state;
|
|
328
|
+
return {
|
|
329
|
+
userToken: stateFromInitialResults.userToken || stateFromHelper.userToken,
|
|
330
|
+
clickAnalytics: stateFromInitialResults.clickAnalytics || stateFromHelper.clickAnalytics
|
|
331
|
+
};
|
|
332
|
+
}
|
|
374
333
|
function saveTokenAsCookie(token, cookieDuration) {
|
|
375
334
|
var MONTH = 30 * 24 * 60 * 60 * 1000;
|
|
376
335
|
var d = new Date();
|
package/es/types/widget.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { Expand, RequiredKeys } from './utils';
|
|
|
7
7
|
import type { AlgoliaSearchHelper as Helper, SearchParameters, SearchResults, RecommendParameters } from 'algoliasearch-helper';
|
|
8
8
|
export type ScopedResult = {
|
|
9
9
|
indexId: string;
|
|
10
|
-
results: SearchResults;
|
|
10
|
+
results: SearchResults | null;
|
|
11
11
|
helper: Helper;
|
|
12
12
|
};
|
|
13
13
|
type SharedRenderOptions = {
|
|
@@ -35,7 +35,7 @@ export type ShouldRenderOptions = {
|
|
|
35
35
|
instantSearchInstance: InstantSearch;
|
|
36
36
|
};
|
|
37
37
|
export type RenderOptions = SharedRenderOptions & {
|
|
38
|
-
results: SearchResults;
|
|
38
|
+
results: SearchResults | null;
|
|
39
39
|
};
|
|
40
40
|
export type DisposeOptions = {
|
|
41
41
|
helper: Helper;
|
|
@@ -162,7 +162,7 @@ export type Widget<TWidgetDescription extends WidgetDescription & WidgetParams =
|
|
|
162
162
|
}> = Expand<RequiredWidgetLifeCycle<TWidgetDescription> & WidgetType<TWidgetDescription> & UiStateLifeCycle<TWidgetDescription> & RenderStateLifeCycle<TWidgetDescription>> & (SearchWidget<TWidgetDescription> | RecommendWidget<TWidgetDescription>);
|
|
163
163
|
export type { IndexWidget } from '../widgets';
|
|
164
164
|
export type TransformItemsMetadata = {
|
|
165
|
-
results
|
|
165
|
+
results: SearchResults | undefined | null;
|
|
166
166
|
};
|
|
167
167
|
/**
|
|
168
168
|
* Transforms the given items.
|
|
@@ -118,6 +118,9 @@ var analytics = function analytics(widgetParams) {
|
|
|
118
118
|
render: function render(_ref2) {
|
|
119
119
|
var results = _ref2.results,
|
|
120
120
|
state = _ref2.state;
|
|
121
|
+
if (!results) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
121
124
|
if (isInitialSearch === true) {
|
|
122
125
|
isInitialSearch = false;
|
|
123
126
|
return;
|
|
@@ -46,7 +46,6 @@ function privateHelperSetState(helper, _ref) {
|
|
|
46
46
|
// TODO: emit "change" event when events for Recommend are implemented
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
|
|
50
49
|
function getLocalWidgetsUiState(widgets, widgetStateOptions) {
|
|
51
50
|
var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
52
51
|
return widgets.reduce(function (uiState, widget) {
|
|
@@ -12,7 +12,9 @@ import { deprecate } from "../../lib/utils/index.js";
|
|
|
12
12
|
|
|
13
13
|
/* Places.js is an optional dependency, no error should be reported if the package is missing */
|
|
14
14
|
/** @ts-ignore */
|
|
15
|
+
|
|
15
16
|
// using the type like this requires only one ts-ignore
|
|
17
|
+
|
|
16
18
|
/**
|
|
17
19
|
* This widget sets the geolocation value for the search based on the selected
|
|
18
20
|
* result in the Algolia Places autocomplete.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instantsearch.js",
|
|
3
|
-
"version": "4.75.
|
|
3
|
+
"version": "4.75.6",
|
|
4
4
|
"description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
|
|
5
5
|
"homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@types/google.maps": "^3.55.12",
|
|
32
32
|
"@types/hogan.js": "^3.0.0",
|
|
33
33
|
"@types/qs": "^6.5.3",
|
|
34
|
-
"algoliasearch-helper": "3.22.
|
|
34
|
+
"algoliasearch-helper": "3.22.6",
|
|
35
35
|
"hogan.js": "^3.0.2",
|
|
36
36
|
"htm": "^3.0.0",
|
|
37
37
|
"instantsearch-ui-components": "0.9.0",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"watch:es": "yarn --silent build:es:base --watch"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@instantsearch/mocks": "1.
|
|
60
|
-
"@instantsearch/tests": "1.
|
|
61
|
-
"@instantsearch/testutils": "1.
|
|
59
|
+
"@instantsearch/mocks": "1.64.0",
|
|
60
|
+
"@instantsearch/tests": "1.64.0",
|
|
61
|
+
"@instantsearch/testutils": "1.53.0",
|
|
62
62
|
"@storybook/html": "5.3.9",
|
|
63
63
|
"@types/scriptjs": "0.0.2",
|
|
64
64
|
"algoliasearch": "5.1.1",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"scriptjs": "2.5.9",
|
|
67
67
|
"webpack": "4.47.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "57abee485d8d8f7c0981a3fc9d12bb8537decd74"
|
|
70
70
|
}
|