Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass strapi client agent to meilisearch-js #455

Merged
merged 3 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"dependencies": {
"@strapi/utils": "^4.1.9",
"meilisearch": "^0.25.1"
"meilisearch": "^0.27.0-beta.1"
},
"peerDependencies": {},
"author": {
Expand Down
2 changes: 1 addition & 1 deletion server/__tests__/meilisearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const deleteDocuments = jest.fn(() => {
return [{ uid: 1 }, { uid: 2 }]
})
const getIndexes = jest.fn(() => {
return [{ uid: 'my_restaurant' }, { uid: 'restaurant' }]
return { results: [{ uid: 'my_restaurant' }, { uid: 'restaurant' }] }
})

const getTasks = jest.fn(() => {
Expand Down
9 changes: 8 additions & 1 deletion server/services/meilisearch/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
const { MeiliSearch: Meilisearch } = require('meilisearch')
const packageJson = require('../../../package.json')

/**
* Create a Meilisearch client instance.
Expand All @@ -8,4 +9,10 @@ const { MeiliSearch: Meilisearch } = require('meilisearch')
*
* @returns { object } - Meilisearch client instance.
*/
module.exports = config => new Meilisearch(config)
module.exports = config =>
new Meilisearch({
...config,
clientAgents: [
`Meilisearch strapi-plugin-meilisearch ${packageJson.version}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bidoubiwa I suggest you follow: meilisearch/integration-guides#150 (comment) because Guillaume amplitude graphs can be impacted!

],
})
4 changes: 2 additions & 2 deletions server/services/meilisearch/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = ({ strapi, adapter, config }) => {
try {
const { apiKey, host } = await store.getCredentials()
const client = Meilisearch({ apiKey, host })
const indexes = await client.getIndexes()
const { results: indexes } = await client.getIndexes()
return indexes
} catch (e) {
strapi.log.error(`meilisearch: ${e.message}`)
Expand Down Expand Up @@ -280,7 +280,7 @@ module.exports = ({ strapi, adapter, config }) => {
// Add documents in Meilisearch
const task = await client.index(indexUid).addDocuments(documents)

return task.uid
return task.taskUid
}

const tasksUids = await contentTypeService.actionInBatches({
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3140,10 +3140,10 @@ makeerror@1.0.12:
dependencies:
tmpl "1.0.5"

meilisearch@^0.25.1:
version "0.25.1"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.25.1.tgz#0dc25ffad64e6e50eb3da6c0691b0ff54f8578bf"
integrity sha512-20jO0pK9BhghxHSkOLbdoYn58h/Z0PNL3JQcRq7ipNIeqrxkAetCZZ6ttJC3uxcz0jVglmiFoSXu3Z/lEOLOLQ==
meilisearch@^0.27.0-beta.1:
version "0.27.0-beta.1"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.27.0-beta.1.tgz#62e64da55227f405e3f352a43e470947ac50f5ef"
integrity sha512-AnUnYKjpghPVC3zBXbF7QeikADfLyHl37aIcLS5xj+zqzku3ldQlOb9AbyBZ1gDhhWxrbltEgb0btmGyBv2jyQ==
dependencies:
cross-fetch "^3.1.5"

Expand Down