Socket
Socket
Sign inDemoInstall

gatsby-plugin-meilisearch

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-meilisearch - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

LICENSE

12

gatsby-node.js

@@ -11,3 +11,3 @@ const { MeiliSearch } = require('meilisearch')

/**
* Function triggered after Gatsby's build. Responsible to add the specified data to MeiliSearch.
* Function triggered after Gatsby's build. Responsible to add the specified data to Meilisearch.
*

@@ -42,3 +42,3 @@ * @async

getErrorMsg(
'No indexes provided, nothing has been indexed to MeiliSearch'
'No indexes provided, nothing has been indexed to Meilisearch'
)

@@ -80,3 +80,3 @@ )

// Index data to MeiliSearch
// Index data to Meilisearch
const enqueuedUpdates = await index.addDocumentsInBatches(

@@ -89,3 +89,3 @@ transformedData,

throw getErrorMsg(
'Nothing has been indexed to MeiliSearch. Make sure your documents are transformed into an array of objects'
'Nothing has been indexed to Meilisearch. Make sure your documents are transformed into an array of objects'
)

@@ -105,8 +105,8 @@ }

activity.setStatus('Documents added to MeiliSearch')
activity.setStatus('Documents added to Meilisearch')
} catch (err) {
reporter.error(err.message || err)
activity.setStatus('Failed to index to MeiliSearch')
activity.setStatus('Failed to index to Meilisearch')
}
activity.end()
}
{
"name": "gatsby-plugin-meilisearch",
"version": "0.1.0",
"description": "Gatsby plugin to index your content to MeiliSearch based on queries",
"version": "0.1.1",
"description": "Gatsby plugin to index your content to Meilisearch based on queries",
"main": "gatsby-node.js",

@@ -53,3 +53,3 @@ "scripts": {

"eslint-plugin-react": "^7.24.0",
"gatsby": "^4.6.0",
"gatsby": "^4.9.3",
"jest": "^27.4.7",

@@ -60,4 +60,4 @@ "prettier": "^2.3.2",

"dependencies": {
"meilisearch": "^0.24.0"
"meilisearch": "^0.25.0"
}
}
<p align="center">
<img src="https://res.cloudinary.com/meilisearch/image/upload/v1587402338/SDKs/meilisearch_gatsby.svg" alt="MeiliSearch Gatsby" width="200" height="200" />
<img src="https://raw.githubusercontent.com/meilisearch/integration-guides/main/assets/logos/meilisearch_gatsby.svg" alt="Meilisearch Gatsby" width="200" height="200" />
</p>
<h1 align="center">Gatsby plugin MeiliSearch</h1>
<h1 align="center">Gatsby plugin Meilisearch</h1>
<h4 align="center">
<a href="https://github.com/meilisearch/MeiliSearch">MeiliSearch</a> |
<a href="https://github.com/meilisearch/meilisearch">Meilisearch</a> |
<a href="https://docs.meilisearch.com">Documentation</a> |

@@ -16,9 +16,9 @@ <a href="https://slack.meilisearch.com">Slack</a> |

<p align="center">
<a href="https://app.bors.tech/repositories/34942"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
<a href="https://ms-bors.herokuapp.com/repositories/47"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
<a href="https://github.com/meilisearch/gatsby-plugin-meilisearch/actions"><img src="https://github.com/meilisearch/gatsby-plugin-meilisearch/workflows/Tests/badge.svg" alt="Tests"></a>
<a href="https://github.com/meilisearch/gatsby-plugin-meilisearch/blob/main/LICENCE"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
<a href="https://github.com/meilisearch/gatsby-plugin-meilisearch/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
</p>
<br/>
<p align="center" style="font-weight:bold;" >A plugin to index your Gatsby content to MeiliSearch based on graphQL queries</p>
<p align="center" style="font-weight:bold;" >A plugin to index your Gatsby content to Meilisearch based on graphQL queries</p>

@@ -33,3 +33,3 @@ <br/>

- [🛼 Usage](#-usage)
- [🤖 Compatibility with MeiliSearch and Gatsby](#-compatibility-with-meilisearch-and-gatsby)
- [🤖 Compatibility with Meilisearch and Gatsby](#-compatibility-with-meilisearch-and-gatsby)
- [⚙️ Development Workflow and Contributing](#-development-workflow-and-contributing)

@@ -39,3 +39,3 @@

To understand MeiliSearch and how it works, see the [MeiliSearch's documentation](https://docs.meilisearch.com/learn/what_is_meilisearch/).
To understand Meilisearch and how it works, see the [Meilisearch's documentation](https://docs.meilisearch.com/learn/what_is_meilisearch/).

@@ -60,5 +60,5 @@ To understand Gatsby and how it works, see [Gatsby's documentation](https://www.gatsbyjs.com/docs/tutorial/).

### 🏃‍♀️ Run MeiliSearch
### 🏃‍♀️ Run Meilisearch
There are many easy ways to [download and run a MeiliSearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).
There are many easy ways to [download and run a Meilisearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).

@@ -68,7 +68,7 @@ For example, if you use Docker:

```bash
docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
docker pull getmeili/meilisearch:latest # Fetch the latest version of Meilisearch image from Docker Hub
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey
```
With this command, your MeiliSearch instance `host` is `http://localhost:7700` and your master key is `masterKey`
With this command, your Meilisearch instance `host` is `http://localhost:7700` and your master key is `masterKey`

@@ -92,5 +92,5 @@ ### 🚀 Run Gatsby

Now you should have a running Gatsby app with `gatsby-plugin-meilisearch` installed and a running MeiliSearch instance.
Now you should have a running Gatsby app with `gatsby-plugin-meilisearch` installed and a running Meilisearch instance.
Let's configure our plugin to make it work! In this example, we will fetch every page's URL of our Gatsby website, and index them to MeiliSearch.
Let's configure our plugin to make it work! In this example, we will fetch every page's URL of our Gatsby website, and index them to Meilisearch.

@@ -101,12 +101,13 @@ To make the plugin work, open the `gatsby-config.js` configuration file located at the root of your Gatsby project. All the configuration takes place in that file.

#### 🔑 Add your MeiliSearch credentials
#### 🔑 Add your Meilisearch credentials
First, you need to add your MeiliSearch credentials.
First, you need to add your Meilisearch credentials.
The credentials are composed of:
- The `host`: The url to your running MeiliSearch instance.
- 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).
⚠️ 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).
- The `host`: The url to your running Meilisearch instance.
- The `api_key`: The `master` key or another `key` with the permission to add documents in MeiliSearch. [More about permissions and API keys here](https://docs.meilisearch.com/learn/advanced/security.html).
⚠️ Keys with permissions other than `search` should never be used on your front end. For searching, use the `Default Search Key` key available on [the `key` route](https://docs.meilisearch.com/reference/api/keys.html#get-keys) or [create a custom API key](https://docs.meilisearch.com/learn/advanced/security.html) with only search rights.
Add the credentials the following way in your `gatsby-config.js` file:

@@ -132,3 +133,3 @@

The next step is to define which data we want to add in MeiliSearch and how. This happens in the `indexes` field.
The next step is to define which data we want to add in Meilisearch and how. This happens in the `indexes` field.

@@ -139,3 +140,3 @@ The `indexes` field is an array that can be composed of multiple index objects. Each index object contains the following information:

Let's define the index uid to `pages_url`. On build, the `pages_url` index is created inside MeiliSearch.
Let's define the index uid to `pages_url`. On build, the `pages_url` index is created inside Meilisearch.

@@ -148,3 +149,3 @@ ```bash

**`query`**: GraphQL query fetching the data to add in MeiliSearch
**`query`**: GraphQL query fetching the data to add in Meilisearch

@@ -187,9 +188,9 @@ Let's provide the graphQL query that retrieves the URL's of the pages of our application.

**`transformer`**: Transform the data fetched to a format compatible to MeiliSearch.
**`transformer`**: Transform the data fetched to a format compatible to Meilisearch.
Now that we have fetched the data with the `query` field, it is not yet ready to be sent to MeiliSearch.
Now that we have fetched the data with the `query` field, it is not yet ready to be sent to Meilisearch.
Using a `transformer` function, we can transform the fetched data to a compatible format.
The first problem of the fetched data is that the documents to send to MeiliSearch are nested, while they should be at the root in an array. So the content of `nodes` should be at the root.
The first problem of the fetched data is that the documents to send to Meilisearch are nested, while they should be at the root in an array. So the content of `nodes` should be at the root.

@@ -222,3 +223,3 @@ ```js

The second problem is that each document in MeiliSearch requires an unique indentifier called [primary key](https://docs.meilisearch.com/learn/core_concepts/documents.html#primary-field).
The second problem is that each document in Meilisearch requires an unique indentifier called [primary key](https://docs.meilisearch.com/learn/core_concepts/documents.html#primary-field).

@@ -245,3 +246,3 @@ Thus every document needs a unique field called `id`.

In this function, we map on `data.allSitePage.nodes` in order to return an array of objects that can be indexed by MeiliSearch. We add an `id` field as MeiliSearch needs it for the indexation. As we don't have any field here that can be used as an `id`, we use the index of the current element in the array.
In this function, we map on `data.allSitePage.nodes` in order to return an array of objects that can be indexed by Meilisearch. We add an `id` field as Meilisearch needs it for the indexation. As we don't have any field here that can be used as an `id`, we use the index of the current element in the array.

@@ -252,3 +253,3 @@ If you want to learn more about these options (`indexUid`, `query` and `transformer`) see [indexes options](#-indexes)

After filling in those fields, your MeiliSearch configuration should look like this:
After filling in those fields, your Meilisearch configuration should look like this:

@@ -288,3 +289,3 @@ ```js

The `gatsby-plugin-meilisearch` fetches and adds your data to MeiliSearch on your Gatsby build.
The `gatsby-plugin-meilisearch` fetches and adds your data to Meilisearch on your Gatsby build.

@@ -298,3 +299,3 @@ ```bash

```bash
success gatsby-plugin-meilisearch - x.xxxs - Documents added to MeiliSearch
success gatsby-plugin-meilisearch - x.xxxs - Documents added to Meilisearch
```

@@ -311,15 +312,15 @@

In the gatsby-config.js file, the MeiliSearch plugin accepts the following options:
In the gatsby-config.js file, the Meilisearch plugin accepts the following options:
### `host` (required)
The `host` field is the address where your MeiliSearch instance is running. `gatsby-plugin-meilisearch` needs it in order to communicate with your MeiliSearch instance, and send your data to it.
The `host` field is the address where your Meilisearch instance is running. `gatsby-plugin-meilisearch` needs it in order to communicate with your Meilisearch instance, and send your data to it.
### `apiKey` (optional)
The `apiKey` field contains the API key if the MeiliSearch instance is password protected.
The `apiKey` field contains the API key if the Meilisearch instance is password protected.
### `skipIndexing` (optional)
This option allows you to build your website without indexing to MeiliSearch. Default to false
This option allows you to build your website without indexing to Meilisearch. Default to false

@@ -332,4 +333,4 @@ ### `batchSize` (optional)

If you want to pass settings to your MeiliSearch instance, you can do it here.
[Read more about MeiliSearch settings](https://docs.meilisearch.com/reference/features/settings.html)
If you want to pass settings to your Meilisearch instance, you can do it here.
[Read more about Meilisearch settings](https://docs.meilisearch.com/reference/features/settings.html)

@@ -346,3 +347,3 @@ ### `indexes` (required)

This is the name of your MeiliSearch index. This is a required field as it is where the retrieved data is added inside MeiliSearch. For example if your `indexUid` is `pages_url`, your content will be indexed inside the `pages_url` index in MeiliSearch.
This is the name of your Meilisearch index. This is a required field as it is where the retrieved data is added inside Meilisearch. For example if your `indexUid` is `pages_url`, your content will be indexed inside the `pages_url` index in Meilisearch.
If you provide an index name that already exists, the index will be deleted and recreated.

@@ -381,6 +382,6 @@

This is a function that transforms the fetched data before sending it to MeiliSearch.
This is a function that transforms the fetched data before sending it to Meilisearch.
After executing the graphQL query, a data object is received with a structure that can differ from one project to another, depending on the query you provided.
As MeiliSearch requires a unique identifier at the root of each document and it should avoid nested objects, you will need to transform your data object accordingly. The `transformer` function is the correct place to do so.
As Meilisearch requires a unique identifier at the root of each document and it should avoid nested objects, you will need to transform your data object accordingly. The `transformer` function is the correct place to do so.

@@ -438,3 +439,3 @@ Example:

If you want to learn more about MeiliSearch's documents structure, you can do so in [our documentation](https://docs.meilisearch.com/learn/core_concepts/documents.html#structure).
If you want to learn more about Meilisearch's documents structure, you can do so in [our documentation](https://docs.meilisearch.com/learn/core_concepts/documents.html#structure).

@@ -466,3 +467,3 @@ Full usage example:

## 🤖 Compatibility with MeiliSearch and Gatsby
## 🤖 Compatibility with Meilisearch and Gatsby

@@ -475,5 +476,5 @@ **Supported Gatsby versions**:

**Supported MeiliSearch versions**:
**Supported Meilisearch versions**:
This package only guarantees the compatibility with the [version v0.25.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.25.0).
This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).

@@ -480,0 +481,0 @@ **Node / NPM versions**:

@@ -35,3 +35,3 @@ const PLUGIN_NAME = 'gatsby-plugin-meilisearch'

* @param {string} index.query - GraphQL query used to retrieve the user's data
* @param {function} index.transformer - Function that transforms the data to a format accepted by MeiliSearch
* @param {function} index.transformer - Function that transforms the data to a format accepted by Meilisearch
* @param {number} key - Index position in it's parent array

@@ -60,3 +60,3 @@ */

* @param {Array.<Object>} indexes - List of indexes
* @param {string} host - MeiliSearch's server address
* @param {string} host - Meilisearch's server address
*/

@@ -63,0 +63,0 @@ const validatePluginOptions = (indexes, host) => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc