create-instantsearch-app 7.2.0 → 7.3.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.
package/README.md CHANGED
@@ -50,6 +50,10 @@ cd my-app
50
50
  yarn start
51
51
  ```
52
52
 
53
+ > **Important**
54
+ > Selecting 'Y' when being prompted to ‘Enable user events’ activates the [`insights`](https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#widget-param-insights) option for compatible templates, allowing Algolia to process your user Events. Events can unlock powerful features, enhancing your application's effectiveness and we encourage you to consider enabling this valuable functionality. Please review our [API reference](https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#widget-param-insights) for more details about Events collection and settings.
55
+
56
+
53
57
  ## Usage
54
58
 
55
59
  This package comes with the module `createInstantSearchApp(path, options?)` and the command-line tool `create-instantsearch-app`.
@@ -110,7 +114,8 @@ The `config` flag is handy to automate app generations.
110
114
  "indexName": "MY_INDEX_NAME",
111
115
  "searchPlaceholder": "Search",
112
116
  "attributesToDisplay": ["name", "description"],
113
- "attributesForFaceting": ["brand", "location"]
117
+ "attributesForFaceting": ["brand", "location"],
118
+ "enableInsights": true
114
119
  }
115
120
  ```
116
121
 
@@ -132,6 +137,7 @@ const app = createInstantSearchApp('~/lab/my-app', {
132
137
  libraryVersion: '2.0.0',
133
138
  attributesToDisplay: ['name', 'description'],
134
139
  attributesForFaceting: ['keywords'],
140
+ enableInsights: true,
135
141
  });
136
142
 
137
143
  app.create().then(() => console.log('App generated!'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-instantsearch-app",
3
- "version": "7.2.0",
3
+ "version": "7.3.0",
4
4
  "license": "MIT",
5
5
  "description": "⚡️ Build InstantSearch apps at the speed of thought",
6
6
  "keywords": [
@@ -49,9 +49,9 @@
49
49
  "validate-npm-package-name": "3.0.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@instantsearch/testutils": "1.15.0",
52
+ "@instantsearch/testutils": "1.17.0",
53
53
  "jest-image-snapshot": "2.12.0",
54
54
  "walk-sync": "2.0.2"
55
55
  },
56
- "gitHead": "c59c53cab5f6caddf44fca51e32063d737a96bce"
56
+ "gitHead": "1501fae54fbdb280ae4747bf68fbacc915ddc1a3"
57
57
  }
@@ -131,7 +131,7 @@ describe('flags', () => {
131
131
  });
132
132
 
133
133
  describe('insights', () => {
134
- test('with a valid version', async () => {
134
+ test('with a valid version and user consent', async () => {
135
135
  utils.fetchLibraryVersions.mockImplementationOnce(() =>
136
136
  Promise.resolve(['1.2.0'])
137
137
  );
@@ -139,7 +139,7 @@ describe('flags', () => {
139
139
  expect(
140
140
  (
141
141
  await postProcessAnswers({
142
- configuration: {},
142
+ configuration: { enableInsights: true },
143
143
  templateConfig: {
144
144
  libraryName: 'instantsearch.js',
145
145
  flags: {
@@ -152,6 +152,27 @@ describe('flags', () => {
152
152
  ).toEqual(expect.objectContaining({ insights: true }));
153
153
  });
154
154
 
155
+ test('with a valid version and no user consent', async () => {
156
+ utils.fetchLibraryVersions.mockImplementationOnce(() =>
157
+ Promise.resolve(['1.2.0'])
158
+ );
159
+
160
+ expect(
161
+ (
162
+ await postProcessAnswers({
163
+ configuration: { enableInsights: false },
164
+ templateConfig: {
165
+ libraryName: 'instantsearch.js',
166
+ flags: {
167
+ insights: '>= 1',
168
+ },
169
+ },
170
+ optionsFromArguments: {},
171
+ })
172
+ ).flags
173
+ ).toEqual(expect.objectContaining({ insights: false }));
174
+ });
175
+
155
176
  test('with an invalid version', async () => {
156
177
  utils.fetchLibraryVersions.mockImplementationOnce(() =>
157
178
  Promise.resolve(['1.2.0'])
package/src/cli/index.js CHANGED
@@ -286,6 +286,35 @@ const getQuestions = ({ appName }) => ({
286
286
  },
287
287
  when: ({ searchInputType }) => searchInputType === 'autocomplete',
288
288
  },
289
+ {
290
+ type: 'confirm',
291
+ name: 'enableInsights',
292
+ message: 'Enable user events',
293
+ default: true,
294
+ suffix: `${chalk.gray(`
295
+ Selecting 'Y' enables the \`insights\` option.
296
+ By doing this, you instruct Algolia to process your user Events.
297
+ Please review our API reference at ${chalk.bold(
298
+ chalk.underline('https://alg.li/instantsearch-insights')
299
+ )}
300
+ for more details about Events collection and settings.`)}`,
301
+ when: ({ libraryVersion, template }) => {
302
+ const templatePath = getTemplatePath(template);
303
+ const templateConfig = getAppTemplateConfig(templatePath);
304
+
305
+ const selectedLibraryVersion = libraryVersion;
306
+ const requiredLibraryVersion =
307
+ templateConfig.flags && templateConfig.flags.insights;
308
+ const supportsInsights =
309
+ selectedLibraryVersion &&
310
+ requiredLibraryVersion &&
311
+ semver.satisfies(selectedLibraryVersion, requiredLibraryVersion, {
312
+ includePrerelease: true,
313
+ });
314
+
315
+ return supportsInsights;
316
+ },
317
+ },
289
318
  ],
290
319
  widget: [
291
320
  {
@@ -76,7 +76,7 @@ async function postProcessAnswers({
76
76
  combinedAnswers.attributesForFaceting.includes('ais.dynamicWidgets'),
77
77
  insights:
78
78
  Boolean(templateConfig.flags && templateConfig.flags.insights) &&
79
- semver.satisfies(libraryVersion, templateConfig.flags.insights),
79
+ combinedAnswers.enableInsights === true,
80
80
  autocomplete:
81
81
  Boolean(templateConfig.flags && templateConfig.flags.autocomplete) &&
82
82
  combinedAnswers.searchInputType === 'autocomplete',
@@ -14,6 +14,7 @@ const searchClient = algoliasearch('{{appId}}', '{{apiKey}}');
14
14
  const search = instantsearch({
15
15
  indexName: '{{indexName}}',
16
16
  searchClient,
17
+ future: { preserveSharedStateOnUnmount: true },
17
18
  {{#if flags.insights}}insights: true,{{/if}}
18
19
  });
19
20
 
@@ -31,6 +31,8 @@ const searchClient = algoliasearch(
31
31
  '{{apiKey}}'
32
32
  );
33
33
 
34
+ const future = { preserveSharedStateOnUnmount: true };
35
+
34
36
  export function App() {
35
37
  return (
36
38
  <div>
@@ -47,7 +49,7 @@ export function App() {
47
49
  </header>
48
50
 
49
51
  <div className="container">
50
- <InstantSearch searchClient={searchClient} indexName="{{indexName}}" {{#if flags.insights}}insights{{/if}}>
52
+ <InstantSearch searchClient={searchClient} indexName="{{indexName}}" future={future} {{#if flags.insights}}insights{{/if}}>
51
53
  <Configure hitsPerPage={8} />
52
54
  <div className="search-panel">
53
55
  <div className="search-panel__filters">
@@ -16,6 +16,7 @@
16
16
  <ais-instant-search
17
17
  :search-client="searchClient"
18
18
  index-name="{{indexName}}"
19
+ :future="future"
19
20
  {{#if flags.insights}}insights{{/if}}
20
21
  >
21
22
  <ais-configure :hits-per-page.camel="8" />
@@ -85,6 +86,7 @@ export default {
85
86
  data() {
86
87
  return {
87
88
  searchClient: algoliasearch('{{appId}}', '{{apiKey}}'),
89
+ future: { preserveSharedStateOnUnmount: true },
88
90
  };
89
91
  },
90
92
  };