instantsearch.js 4.54.1 → 4.55.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.
Files changed (73) hide show
  1. package/cjs/components/Hits/Hits.js +16 -7
  2. package/cjs/components/InfiniteHits/InfiniteHits.js +13 -2
  3. package/cjs/connectors/autocomplete/connectAutocomplete.js +1 -1
  4. package/cjs/connectors/geo-search/connectGeoSearch.js +1 -1
  5. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
  6. package/cjs/connectors/hits/connectHits.js +1 -1
  7. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +39 -31
  8. package/cjs/connectors/menu/connectMenu.js +1 -1
  9. package/cjs/connectors/numeric-menu/connectNumericMenu.js +1 -1
  10. package/cjs/connectors/rating-menu/connectRatingMenu.js +7 -3
  11. package/cjs/connectors/refinement-list/connectRefinementList.js +1 -1
  12. package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +14 -4
  13. package/cjs/helpers/insights.js +3 -4
  14. package/cjs/lib/InstantSearch.js +18 -2
  15. package/cjs/lib/insights/listener.js +43 -36
  16. package/cjs/lib/routers/history.js +1 -0
  17. package/cjs/lib/stateMappings/simple.js +1 -0
  18. package/cjs/lib/stateMappings/singleIndex.js +1 -0
  19. package/cjs/lib/utils/createSendEventForFacet.js +12 -2
  20. package/cjs/lib/utils/createSendEventForHits.js +34 -11
  21. package/cjs/lib/version.js +1 -1
  22. package/cjs/middlewares/createInsightsMiddleware.js +135 -33
  23. package/cjs/middlewares/createMetadataMiddleware.js +17 -5
  24. package/cjs/middlewares/createRouterMiddleware.js +5 -1
  25. package/cjs/widgets/hits/hits.js +1 -2
  26. package/cjs/widgets/infinite-hits/infinite-hits.js +1 -2
  27. package/dist/instantsearch.development.d.ts +67 -8
  28. package/dist/instantsearch.development.js +433 -251
  29. package/dist/instantsearch.development.js.map +1 -1
  30. package/dist/instantsearch.production.d.ts +67 -8
  31. package/dist/instantsearch.production.min.d.ts +67 -8
  32. package/dist/instantsearch.production.min.js +2 -2
  33. package/dist/instantsearch.production.min.js.map +1 -1
  34. package/es/components/Hits/Hits.d.ts +5 -5
  35. package/es/components/Hits/Hits.js +15 -5
  36. package/es/components/InfiniteHits/InfiniteHits.d.ts +3 -2
  37. package/es/components/InfiniteHits/InfiniteHits.js +13 -2
  38. package/es/connectors/autocomplete/connectAutocomplete.js +1 -1
  39. package/es/connectors/geo-search/connectGeoSearch.js +1 -1
  40. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
  41. package/es/connectors/hits/connectHits.js +1 -1
  42. package/es/connectors/infinite-hits/connectInfiniteHits.js +39 -31
  43. package/es/connectors/menu/connectMenu.js +1 -1
  44. package/es/connectors/numeric-menu/connectNumericMenu.js +1 -1
  45. package/es/connectors/rating-menu/connectRatingMenu.js +7 -3
  46. package/es/connectors/refinement-list/connectRefinementList.js +1 -1
  47. package/es/connectors/toggle-refinement/connectToggleRefinement.js +13 -3
  48. package/es/helpers/insights.d.ts +2 -1
  49. package/es/helpers/insights.js +3 -3
  50. package/es/lib/InstantSearch.d.ts +11 -1
  51. package/es/lib/InstantSearch.js +18 -2
  52. package/es/lib/insights/listener.d.ts +10 -6
  53. package/es/lib/insights/listener.js +42 -36
  54. package/es/lib/routers/history.d.ts +1 -0
  55. package/es/lib/routers/history.js +1 -0
  56. package/es/lib/stateMappings/simple.js +1 -0
  57. package/es/lib/stateMappings/singleIndex.js +1 -0
  58. package/es/lib/utils/createSendEventForFacet.js +12 -2
  59. package/es/lib/utils/createSendEventForHits.d.ts +8 -0
  60. package/es/lib/utils/createSendEventForHits.js +33 -11
  61. package/es/lib/version.d.ts +1 -1
  62. package/es/lib/version.js +1 -1
  63. package/es/middlewares/createInsightsMiddleware.d.ts +12 -12
  64. package/es/middlewares/createInsightsMiddleware.js +136 -34
  65. package/es/middlewares/createMetadataMiddleware.d.ts +3 -1
  66. package/es/middlewares/createMetadataMiddleware.js +17 -5
  67. package/es/middlewares/createRouterMiddleware.js +5 -1
  68. package/es/types/insights.d.ts +19 -1
  69. package/es/types/middleware.d.ts +16 -0
  70. package/es/types/router.d.ts +8 -0
  71. package/es/widgets/hits/hits.js +2 -3
  72. package/es/widgets/infinite-hits/infinite-hits.js +2 -3
  73. package/package.json +6 -6
@@ -1,5 +1,5 @@
1
1
  import { createInitArgs, safelyRunOnBrowser } from "../lib/utils/index.js";
2
- function extractPayload(widgets, instantSearchInstance, payload) {
2
+ function extractWidgetPayload(widgets, instantSearchInstance, payload) {
3
3
  var initOptions = createInitArgs(instantSearchInstance, instantSearchInstance.mainIndex, instantSearchInstance._initialUiState);
4
4
  widgets.forEach(function (widget) {
5
5
  var widgetParams = {};
@@ -21,7 +21,7 @@ function extractPayload(widgets, instantSearchInstance, payload) {
21
21
  params: params
22
22
  });
23
23
  if (widget.$$type === 'ais.index') {
24
- extractPayload(widget.getWidgets(), instantSearchInstance, payload);
24
+ extractWidgetPayload(widget.getWidgets(), instantSearchInstance, payload);
25
25
  }
26
26
  });
27
27
  }
@@ -45,8 +45,11 @@ export function isMetadataEnabled() {
45
45
  * - connector name
46
46
  */
47
47
  export function createMetadataMiddleware() {
48
- return function (_ref2) {
49
- var instantSearchInstance = _ref2.instantSearchInstance;
48
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
49
+ _ref2$$$internal = _ref2.$$internal,
50
+ $$internal = _ref2$$$internal === void 0 ? false : _ref2$$$internal;
51
+ return function (_ref3) {
52
+ var instantSearchInstance = _ref3.instantSearchInstance;
50
53
  var payload = {
51
54
  widgets: []
52
55
  };
@@ -54,13 +57,22 @@ export function createMetadataMiddleware() {
54
57
  var refNode = document.querySelector('head');
55
58
  payloadContainer.name = 'instantsearch:widgets';
56
59
  return {
60
+ $$type: 'ais.metadata',
61
+ $$internal: $$internal,
57
62
  onStateChange: function onStateChange() {},
58
63
  subscribe: function subscribe() {
59
64
  // using setTimeout here to delay extraction until widgets have been added in a tick (e.g. Vue)
60
65
  setTimeout(function () {
61
66
  var client = instantSearchInstance.client;
62
67
  payload.ua = client.transporter && client.transporter.userAgent ? client.transporter.userAgent.value : client._ua;
63
- extractPayload(instantSearchInstance.mainIndex.getWidgets(), instantSearchInstance, payload);
68
+ extractWidgetPayload(instantSearchInstance.mainIndex.getWidgets(), instantSearchInstance, payload);
69
+ instantSearchInstance.middleware.forEach(function (middleware) {
70
+ return payload.widgets.push({
71
+ middleware: true,
72
+ type: middleware.instance.$$type,
73
+ internal: middleware.instance.$$internal
74
+ });
75
+ });
64
76
  payloadContainer.content = JSON.stringify(payload);
65
77
  refNode.appendChild(payloadContainer);
66
78
  }, 0);
@@ -12,7 +12,9 @@ export var createRouterMiddleware = function createRouterMiddleware() {
12
12
  var _props$router = props.router,
13
13
  router = _props$router === void 0 ? historyRouter() : _props$router,
14
14
  _props$stateMapping = props.stateMapping,
15
- stateMapping = _props$stateMapping === void 0 ? simpleStateMapping() : _props$stateMapping;
15
+ stateMapping = _props$stateMapping === void 0 ? simpleStateMapping() : _props$stateMapping,
16
+ _props$$$internal = props.$$internal,
17
+ $$internal = _props$$$internal === void 0 ? false : _props$$$internal;
16
18
  return function (_ref) {
17
19
  var instantSearchInstance = _ref.instantSearchInstance;
18
20
  function topLevelCreateURL(nextState) {
@@ -29,6 +31,8 @@ export var createRouterMiddleware = function createRouterMiddleware() {
29
31
  var lastRouteState = undefined;
30
32
  var initialUiState = instantSearchInstance._initialUiState;
31
33
  return {
34
+ $$type: "ais.router({router:".concat(router.$$type || '__unknown__', ", stateMapping:").concat(stateMapping.$$type || '__unknown__', "})"),
35
+ $$internal: $$internal,
32
36
  onStateChange: function onStateChange(_ref2) {
33
37
  var uiState = _ref2.uiState;
34
38
  var routeState = stateMapping.stateToRoute(uiState);
@@ -1,6 +1,24 @@
1
- import type { InsightsMethodMap, InsightsClient as _InsightsClient } from 'search-insights';
1
+ import type { Hit } from './results';
2
+ import type { InsightsMethodMap as _InsightsMethodMap, InsightsClient as _InsightsClient } from 'search-insights';
2
3
  export type { Init as InsightsInit, AddAlgoliaAgent as InsightsAddAlgoliaAgent, SetUserToken as InsightsSetUserToken, GetUserToken as InsightsGetUserToken, OnUserTokenChange as InsightsOnUserTokenChange, } from 'search-insights';
4
+ export type InsightsMethodMap = _InsightsMethodMap;
3
5
  export type InsightsClientMethod = keyof InsightsMethodMap;
6
+ /**
7
+ * Method allowed by the insights middleware.
8
+ */
9
+ export type InsightsMethod = 'clickedObjectIDsAfterSearch' | 'clickedObjectIDs' | 'clickedFilters' | 'convertedObjectIDsAfterSearch' | 'convertedObjectIDs' | 'convertedFilters' | 'viewedObjectIDs' | 'viewedFilters';
10
+ /**
11
+ * The event sent to the insights middleware.
12
+ */
13
+ export type InsightsEvent<TMethod extends InsightsMethod = InsightsMethod> = {
14
+ insightsMethod?: TMethod;
15
+ payload: InsightsMethodMap[TMethod][0];
16
+ widgetType: string;
17
+ eventType: string;
18
+ eventModifier?: string;
19
+ hits?: Hit[];
20
+ attribute?: string;
21
+ };
4
22
  export type InsightsClientPayload = {
5
23
  eventName: string;
6
24
  queryID: string;
@@ -2,11 +2,27 @@ import type InstantSearch from '../lib/InstantSearch';
2
2
  import type { UiState } from './ui-state';
3
3
  import type { AtLeastOne } from './utils';
4
4
  export type MiddlewareDefinition<TUiState extends UiState = UiState> = {
5
+ /**
6
+ * string to identify the middleware
7
+ */
8
+ $$type: string;
9
+ /**
10
+ * Change handler called on every UiState change
11
+ */
5
12
  onStateChange(options: {
6
13
  uiState: TUiState;
7
14
  }): void;
15
+ /**
16
+ * Called when the middleware is added to InstantSearch
17
+ */
8
18
  subscribe(): void;
19
+ /**
20
+ * Called when InstantSearch is started
21
+ */
9
22
  started(): void;
23
+ /**
24
+ * Called when the middleware is removed from InstantSearch
25
+ */
10
26
  unsubscribe(): void;
11
27
  };
12
28
  export type MiddlewareOptions = {
@@ -34,6 +34,10 @@ export type Router<TRouteState = UiState> = {
34
34
  * Called when InstantSearch is started.
35
35
  */
36
36
  start?: () => void;
37
+ /**
38
+ * Identifier for this router. Used to differentiate between routers.
39
+ */
40
+ $$type?: string;
37
41
  };
38
42
  /**
39
43
  * The state mapping is a way to customize the structure before sending it to the router.
@@ -55,4 +59,8 @@ export type StateMapping<TUiState = UiState, TRouteState = TUiState> = {
55
59
  * The format is the output of `stateToRoute`.
56
60
  */
57
61
  routeToState(routeState: TRouteState): TUiState;
62
+ /**
63
+ * Identifier for this stateMapping. Used to differentiate between stateMappings.
64
+ */
65
+ $$type?: string;
58
66
  };
@@ -8,7 +8,7 @@ import { cx } from '@algolia/ui-components-shared';
8
8
  import { h, render } from 'preact';
9
9
  import Hits from "../../components/Hits/Hits.js";
10
10
  import connectHits from "../../connectors/hits/connectHits.js";
11
- import { withInsights, withInsightsListener } from "../../lib/insights/index.js";
11
+ import { withInsights } from "../../lib/insights/index.js";
12
12
  import { component } from "../../lib/suit.js";
13
13
  import { prepareTemplateProps } from "../../lib/templating/index.js";
14
14
  import { getContainerNode, createDocumentationMessageGenerator } from "../../lib/utils/index.js";
@@ -17,7 +17,6 @@ var withUsage = createDocumentationMessageGenerator({
17
17
  name: 'hits'
18
18
  });
19
19
  var suit = component('Hits');
20
- var HitsWithInsightsListener = withInsightsListener(Hits);
21
20
  var renderer = function renderer(_ref) {
22
21
  var renderState = _ref.renderState,
23
22
  cssClasses = _ref.cssClasses,
@@ -38,7 +37,7 @@ var renderer = function renderer(_ref) {
38
37
  });
39
38
  return;
40
39
  }
41
- render(h(HitsWithInsightsListener, {
40
+ render(h(Hits, {
42
41
  cssClasses: cssClasses,
43
42
  hits: receivedHits,
44
43
  results: results,
@@ -8,7 +8,7 @@ import { cx } from '@algolia/ui-components-shared';
8
8
  import { h, render } from 'preact';
9
9
  import InfiniteHits from "../../components/InfiniteHits/InfiniteHits.js";
10
10
  import connectInfiniteHits from "../../connectors/infinite-hits/connectInfiniteHits.js";
11
- import { withInsights, withInsightsListener } from "../../lib/insights/index.js";
11
+ import { withInsights } from "../../lib/insights/index.js";
12
12
  import { component } from "../../lib/suit.js";
13
13
  import { prepareTemplateProps } from "../../lib/templating/index.js";
14
14
  import { getContainerNode, createDocumentationMessageGenerator } from "../../lib/utils/index.js";
@@ -17,7 +17,6 @@ var withUsage = createDocumentationMessageGenerator({
17
17
  name: 'infinite-hits'
18
18
  });
19
19
  var suit = component('InfiniteHits');
20
- var InfiniteHitsWithInsightsListener = withInsightsListener(InfiniteHits);
21
20
  var renderer = function renderer(_ref) {
22
21
  var containerNode = _ref.containerNode,
23
22
  cssClasses = _ref.cssClasses,
@@ -43,7 +42,7 @@ var renderer = function renderer(_ref) {
43
42
  });
44
43
  return;
45
44
  }
46
- render(h(InfiniteHitsWithInsightsListener, {
45
+ render(h(InfiniteHits, {
47
46
  cssClasses: cssClasses,
48
47
  hits: hits,
49
48
  results: results,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.54.1",
3
+ "version": "4.55.0",
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",
@@ -38,7 +38,7 @@
38
38
  "htm": "^3.0.0",
39
39
  "preact": "^10.10.0",
40
40
  "qs": "^6.5.1 < 6.10",
41
- "search-insights": "^2.1.0"
41
+ "search-insights": "^2.6.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "algoliasearch": ">= 3.1 < 6"
@@ -55,9 +55,9 @@
55
55
  "version": "./scripts/version/update-version.js"
56
56
  },
57
57
  "devDependencies": {
58
- "@instantsearch/mocks": "1.11.0",
59
- "@instantsearch/tests": "1.11.0",
60
- "@instantsearch/testutils": "1.0.14",
58
+ "@instantsearch/mocks": "1.12.0",
59
+ "@instantsearch/tests": "1.12.0",
60
+ "@instantsearch/testutils": "1.1.0",
61
61
  "@storybook/html": "5.3.9",
62
62
  "@types/scriptjs": "0.0.2",
63
63
  "algoliasearch": "4.14.3",
@@ -65,5 +65,5 @@
65
65
  "scriptjs": "2.5.9",
66
66
  "webpack": "4.41.5"
67
67
  },
68
- "gitHead": "1f81b61cf0e78aeb7022d5e9eca0d49de727dc64"
68
+ "gitHead": "c483ae31e1e615be61dffb5d0bc04a4927960a67"
69
69
  }