strapi-plugin-meilisearch 0.9.2 → 0.10.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
@@ -6,11 +6,12 @@
6
6
 
7
7
  <h4 align="center">
8
8
  <a href="https://github.com/meilisearch/meilisearch">Meilisearch</a> |
9
- <a href="https://docs.meilisearch.com">Documentation</a> |
9
+ <a href="https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=github&utm_medium=strapi-plugin-meilisearch">Meilisearch Cloud</a> |
10
+ <a href="https://www.meilisearch.com/docs">Documentation</a> |
10
11
  <a href="https://discord.meilisearch.com">Discord</a> |
11
12
  <a href="https://roadmap.meilisearch.com/tabs/1-under-consideration">Roadmap</a> |
12
13
  <a href="https://www.meilisearch.com">Website</a> |
13
- <a href="https://docs.meilisearch.com/faq">FAQ</a>
14
+ <a href="https://www.meilisearch.com/docs/faq">FAQ</a>
14
15
  </h4>
15
16
 
16
17
  <p align="center">
@@ -30,6 +31,7 @@ Add your Strapi content-types into a Meilisearch instance. The plugin listens to
30
31
  ## Table of Contents <!-- omit in toc -->
31
32
 
32
33
  - [📖 Documentation](#-documentation)
34
+ - [⚡ Supercharge your Meilisearch experience](#-supercharge-your-meilisearch-experience)
33
35
  - [🔧 Installation](#-installation)
34
36
  - [🎬 Getting Started](#-getting-started)
35
37
  - [💅 Customization](#-customization)
@@ -41,10 +43,14 @@ Add your Strapi content-types into a Meilisearch instance. The plugin listens to
41
43
 
42
44
  ## 📖 Documentation
43
45
 
44
- To understand Meilisearch and how it works, see the [Meilisearch's documentation](https://docs.meilisearch.com/learn/getting_started/quick_start.html).
46
+ To understand Meilisearch and how it works, see the [Meilisearch's documentation](https://www.meilisearch.com/docs/learn/getting_started/installation).
45
47
 
46
48
  To understand Strapi and how to create an app, see [Strapi's documentation](https://strapi.io/documentation/developer-docs/latest/getting-started/introduction.html).
47
49
 
50
+ ## ⚡ Supercharge your Meilisearch experience
51
+
52
+ Say goodbye to server deployment and manual updates with [Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=github&utm_medium=strapi-plugin-meilisearch). Get started with a 14-day free trial! No credit card required.
53
+
48
54
  ## 🔧 Installation
49
55
 
50
56
  This package version works with the [v4 of Strapi](https://docs.strapi.io/developer-docs/latest/getting-started/introduction.html). If you are using [Strapi v3](https://docs-v3.strapi.io/developer-docs/latest/getting-started/introduction.html), please refer to [this README](https://github.com/meilisearch/strapi-plugin-meilisearch/tree/v3_main).
@@ -71,7 +77,7 @@ You will need both a running Strapi app and a running Meilisearch instance. For
71
77
 
72
78
  ### 🏃‍♀️ Run Meilisearch <!-- omit in toc -->
73
79
 
74
- There are many easy ways to [download and run a Meilisearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).
80
+ There are many easy ways to [download and run a Meilisearch instance](https://www.meilisearch.com/docs/reference/features/installation.html#download-and-launch).
75
81
 
76
82
  For example, if you use Docker:
77
83
 
@@ -109,9 +115,9 @@ On the left-navbar, `Meilisearch` appears under the `PLUGINS` category. If it do
109
115
  First, you need to configure credentials via the Strapi config, or on the plugin page.
110
116
  The credentials are composed of:
111
117
  - The `host`: The url to your running Meilisearch instance.
112
- - The `api_key`: The `master` or `private` key as the plugin requires administration permission on Meilisearch.[More about permissions here](https://docs.meilisearch.com/reference/features/authentication.html).
118
+ - The `api_key`: The `master` or `private` key as the plugin requires administration permission on Meilisearch.[More about permissions here](https://www.meilisearch.com/docs/reference/features/authentication.html).
113
119
 
114
- ⚠️ The `master` or `private` key should never be used to `search` on your front end. For searching, use the `public` key available on [the `key` route](https://docs.meilisearch.com/reference/api/keys.html#get-keys).
120
+ ⚠️ The `master` or `private` key should never be used to `search` on your front end. For searching, use the `public` key available on [the `key` route](https://www.meilisearch.com/docs/reference/api/keys.html#get-keys).
115
121
 
116
122
  #### Using the plugin page
117
123
 
@@ -184,7 +190,7 @@ The reload is only possible in develop mode; click on the `Reload Server` button
184
190
 
185
191
  ## 💅 Customization
186
192
 
187
- It is possible to add settings for every collection. Start by creating a sub-object with the name of the collection inside your `plugin.json` file.
193
+ It is possible to add settings for every collection. Start by creating a sub-object with the name of the collection inside your `plugins.js` file.
188
194
 
189
195
  ```js
190
196
  // config/plugins.js
@@ -192,7 +198,9 @@ It is possible to add settings for every collection. Start by creating a sub-obj
192
198
  module.exports = () => ({
193
199
  //...
194
200
  meilisearch: {
195
- restaurant: {}
201
+ config: {
202
+ restaurant: {}
203
+ }
196
204
  }
197
205
  })
198
206
  ```
@@ -202,7 +210,7 @@ Settings:
202
210
  - [🪄 Transform entries](#-transform-entries)
203
211
  - [🤚 Filter entries](#-filter-entries)
204
212
  - [🏗 Add Meilisearch settings](#-add-meilisearch-settings)
205
- - [🔎 Entries query](#🔎-entries-query)
213
+ - [🔎 Entries query](#-entries-query)
206
214
 
207
215
  ### 🏷 Custom index name
208
216
 
@@ -319,7 +327,7 @@ Result:
319
327
  }
320
328
  ```
321
329
 
322
- By transforming the `categories` into an array of names, it is now compatible with the [`filtering` feature](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html#configuring-filters) in Meilisearch.
330
+ By transforming the `categories` into an array of names, it is now compatible with the [`filtering` feature](https://www.meilisearch.com/docs/reference/features/filtering_and_faceted_search.html#configuring-filters) in Meilisearch.
323
331
 
324
332
  **Important**: You should always return the id of the entry without any transformation to [allow sync](https://github.com/meilisearch/strapi-plugin-meilisearch/issues/487) when unpublished or deleting some entries in Strapi.
325
333
 
@@ -349,7 +357,7 @@ module.exports = {
349
357
 
350
358
  ### 🏗 Add Meilisearch settings
351
359
 
352
- Each index in Meilisearch can be customized with specific settings. It is possible to add your [Meilisearch settings](https://docs.meilisearch.com/reference/features/settings.html#settings) configuration to the indexes you create using the `settings` field in the plugin configuration file.
360
+ Each index in Meilisearch can be customized with specific settings. It is possible to add your [Meilisearch settings](https://www.meilisearch.com/docs/reference/api/settings#settings_parameters#settings) configuration to the indexes you create using the `settings` field in the plugin configuration file.
353
361
 
354
362
  The settings are added when either: adding a content-type to Meilisearch or when updating a content-type in Meilisearch. The settings are not updated when documents are added through the [`listeners`](-apply-hooks).
355
363
 
@@ -375,14 +383,18 @@ module.exports = {
375
383
 
376
384
  ### 🔎 Entries query
377
385
 
378
- When indexing a content type to Meilisearch, the plugin has to fetch the documents from your database. With `entriesQuery` it is possible to specify some options that should be applied during the fetching of the entries.
386
+ When indexing a content type to Meilisearch, the plugin has to fetch the documents from your database. With `entriesQuery` it is possible to specify some options are applied during the fetching of the entries.
379
387
  The options you can set are described in the [`findMany` documentation](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/entity-service/crud.html#findmany) of Strapi. However, we do not accept any changes on the `start` parameter.
380
388
 
389
+ **Common use cases**
390
+
381
391
  If you are using the [🌍 Internationalization (i18n)](https://docs.strapi.io/developer-docs/latest/plugins/i18n.html) plugin, an additional field `locale` can also be added in `entriesQuery`.
382
392
 
383
- **For example**
393
+ If you want to add a collection with a relation to the collection being included, you have to configure the `populate` parameter in `entriesQuery`. See [the docs](https://docs.strapi.io/dev-docs/api/entity-service/populate) on how it works, and [an example](./resources/entries-query/populate.js) in our resources.
394
+
395
+ **Example**
384
396
 
385
- For example, if you want your documents to be fetched in batches of `1000` you specify it in the `entriesQuery` option.
397
+ If you want your documents to be fetched in batches of `1000` you specify it in the `entriesQuery` option.
386
398
 
387
399
  ```js
388
400
  module.exports = {
@@ -400,16 +412,15 @@ module.exports = {
400
412
 
401
413
  [See resources](./resources/entries-query) for more entriesQuery examples.
402
414
 
403
-
404
415
  ### 🕵️‍♀️ Start Searching <!-- omit in toc -->
405
416
 
406
- Once you have a content-type indexed in Meilisearch, you can [start searching](https://docs.meilisearch.com/learn/getting_started/quick_start.html#search).
417
+ Once you have a content-type indexed in Meilisearch, you can [start searching](https://www.meilisearch.com/docs/learn/getting_started/quick_start.html#search).
407
418
 
408
- To search in Meilisearch, you can use the [instant-meilisearch](https://github.com/meilisearch/instant-meilisearch) library that integrates a whole search interface, or our [meilisearch-js](https://github.com/meilisearch/meilisearch-js) SDK.
419
+ To search in Meilisearch, you can use the [instant-meilisearch](https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/instant-meilisearch) library that integrates a whole search interface, or our [meilisearch-js](https://github.com/meilisearch/meilisearch-js) SDK.
409
420
 
410
421
  #### ⚡️ Using Instant meiliSearch <!-- omit in toc -->
411
422
 
412
- You can have a front up and running in record time with [instant-meilisearch](https://github.com/meilisearch/instant-meilisearch).
423
+ You can have a front up and running in record time with [instant-meilisearch](https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/instant-meilisearch).
413
424
 
414
425
  <p align="center">
415
426
  <img src="./assets/obrigado.gif" alt="Restaurant demo" width="600"/>
@@ -547,14 +558,14 @@ If you want to know more about the development workflow or want to contribute, p
547
558
 
548
559
  ## 🌎 Community support
549
560
 
550
- - For general help using **Meilisearch**, please refer to [the official Meilisearch documentation](https://docs.meilisearch.com).
551
- - Contact the [Meilisearch support](https://docs.meilisearch.com/learn/what_is_meilisearch/contact.html)
561
+ - For general help using **Meilisearch**, please refer to [the official Meilisearch documentation](https://www.meilisearch.com/docs).
562
+ - Contact the [Meilisearch support](https://www.meilisearch.com/docs/learn/what_is_meilisearch/contact.html)
552
563
  - Strapi [community Slack](https://slack.strapi.io/)
553
564
  - For general help using **Strapi**, please refer to [the official Strapi documentation](https://strapi.io/documentation/).
554
565
 
555
566
  ## 🤩 Just for the pleasure of the eyes
556
567
 
557
- Using the [foodadvisor](https://github.com/strapi/foodadvisor) restaurant demo Strapi provided. We added a searchbar to it using [instant-meilisearch](https://github.com/meilisearch/instant-meilisearch).
568
+ Using the [foodadvisor](https://github.com/strapi/foodadvisor) restaurant demo Strapi provided. We added a searchbar to it using [instant-meilisearch](https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/instant-meilisearch).
558
569
 
559
570
  <p align="center">
560
571
  <img src="./assets/restaurant.gif" alt="Fooradvisor demo" width="600"/>
@@ -45,7 +45,7 @@ const Credentials = () => {
45
45
  <Typography variant="pi" style={{ color: 'red' }}>
46
46
  Do not use this API key on your front-end as it has too much rights.
47
47
  Instead, use the public key available using{' '}
48
- <a href="https://docs.meilisearch.com/reference/api/keys.html#get-keys">
48
+ <a href="https://www.meilisearch.com/docs/reference/api/keys#get-keys">
49
49
  the key route
50
50
  </a>
51
51
  .
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-meilisearch",
3
- "version": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "Synchronise and search in your Strapi content-types with Meilisearch",
5
5
  "scripts": {
6
6
  "playground:dev": "yarn --cwd ./playground && yarn --cwd ./playground dev",
@@ -25,10 +25,12 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@strapi/utils": "^4.5.4",
29
- "meilisearch": "^0.30.0"
28
+ "@strapi/utils": "^4.13.7",
29
+ "meilisearch": "^0.34.2"
30
+ },
31
+ "peerDependencies": {
32
+ "@strapi/strapi": "^4.0.0"
30
33
  },
31
- "peerDependencies": {},
32
34
  "author": {
33
35
  "name": "Charlotte Vermandel <charlotte@meilisearch.com>"
34
36
  },
@@ -4,8 +4,23 @@ const updateSettingsMock = jest.fn(() => 10)
4
4
  const deleteDocuments = jest.fn(() => {
5
5
  return [{ taskUid: 1 }, { taskUid: 2 }]
6
6
  })
7
- const getIndexes = jest.fn(() => {
8
- return { results: [{ uid: 'my_restaurant' }, { uid: 'restaurant' }] }
7
+ const getStats = jest.fn(() => {
8
+ return {
9
+ databaseSize: 447819776,
10
+ lastUpdate: '2019-11-15T11:15:22.092896Z',
11
+ indexes: {
12
+ my_restaurant: {
13
+ numberOfDocuments: 1,
14
+ isIndexing: false,
15
+ fieldDistribution: {},
16
+ },
17
+ restaurant: {
18
+ numberOfDocuments: 1,
19
+ isIndexing: false,
20
+ fieldDistribution: {},
21
+ },
22
+ },
23
+ }
9
24
  })
10
25
 
11
26
  const getTasks = jest.fn(() => {
@@ -18,7 +33,7 @@ const getTasks = jest.fn(() => {
18
33
  }
19
34
  })
20
35
 
21
- const getStats = jest.fn(() => {
36
+ const getIndexStats = jest.fn(() => {
22
37
  return { numberOfDocuments: 1, isIndexing: false, fieldDistribution: {} }
23
38
  })
24
39
 
@@ -27,13 +42,13 @@ const mockIndex = jest.fn(() => ({
27
42
  updateDocuments: updateDocumentsMock,
28
43
  updateSettings: updateSettingsMock,
29
44
  deleteDocuments,
30
- getStats,
45
+ getStats: getIndexStats,
31
46
  }))
32
47
 
33
48
  // @ts-ignore
34
49
  const mock = jest.fn().mockImplementation(() => {
35
50
  return {
36
- getIndexes,
51
+ getStats,
37
52
  index: mockIndex,
38
53
  getTasks,
39
54
  }
@@ -23,9 +23,9 @@ describe('Tests content types', () => {
23
23
  strapi: customStrapi,
24
24
  })
25
25
 
26
- const indexes = await meilisearchService.getIndexes()
26
+ const indexes = await meilisearchService.getIndexUids()
27
27
 
28
- expect(indexes).toEqual([{ uid: 'my_restaurant' }, { uid: 'restaurant' }])
28
+ expect(indexes).toEqual(['my_restaurant', 'restaurant'])
29
29
  })
30
30
 
31
31
  test('Test to delete entries from Meilisearch', async () => {
@@ -31,8 +31,7 @@ async function syncIndexedCollections({
31
31
  contentTypeService,
32
32
  meilisearch,
33
33
  }) {
34
- const indexes = await meilisearch.getIndexes()
35
- const indexUids = indexes.map(index => index.uid)
34
+ const indexUids = await meilisearch.getIndexUids()
36
35
  // All indexed contentTypes
37
36
  const indexedContentTypes = await store.getIndexedContentTypes()
38
37
  const contentTypes = contentTypeService.getContentTypesUid()
@@ -9,7 +9,7 @@ module.exports = ({ strapi }) => {
9
9
  error: {
10
10
  message: e.message,
11
11
  link: {
12
- url: e.link || 'https://docs.meilisearch.com/',
12
+ url: e.link || 'https://www.meilisearch.com/docs',
13
13
  label: {
14
14
  id: 'notification.meilisearch',
15
15
  defaultMessage: 'See more',
@@ -65,16 +65,16 @@ module.exports = ({ strapi, adapter, config }) => {
65
65
 
66
66
  return {
67
67
  /**
68
- * Get indexes with a safe guard in case of error.
68
+ * Get index uids with a safe guard in case of error.
69
69
  *
70
70
  * @returns { Promise<import("meilisearch").Index[]> }
71
71
  */
72
- getIndexes: async function () {
72
+ getIndexUids: async function () {
73
73
  try {
74
74
  const { apiKey, host } = await store.getCredentials()
75
75
  const client = Meilisearch({ apiKey, host })
76
- const { results: indexes } = await client.getIndexes()
77
- return indexes
76
+ const { indexes } = await client.getStats()
77
+ return Object.keys(indexes)
78
78
  } catch (e) {
79
79
  strapi.log.error(`meilisearch: ${e.message}`)
80
80
  return []
@@ -176,8 +176,7 @@ module.exports = ({ strapi, adapter, config }) => {
176
176
  * }>}>} - List of contentTypes reports.
177
177
  */
178
178
  getContentTypesReport: async function () {
179
- const indexes = await this.getIndexes()
180
- const indexUids = indexes.map(index => index.uid)
179
+ const indexUids = await this.getIndexUids()
181
180
 
182
181
  // All listened contentTypes
183
182
  const listenedContentTypes = await store.getListenedContentTypes()