Skip to content

Commit f67cf0b

Browse files
meili-bors[bot]meili-botbidoubiwa
authored
Merge #607
607: Changes related to the next Meilisearch release (v0.28.0) r=bidoubiwa a=meili-bot This PR gathers the changes related to the next Meilisearch release (v0.28.0) so that this package is ready when the official release is out. ⚠️ This PR should NOT be merged until: - the next release of Meilisearch (v0.28.0) is out. - the [`meilisearch-js`](https://github.com/meilisearch/meilisearch-js) dependency has been released to be compatible with Meilisearch v0.28.0. Once the release is out, the upgrade of the `meilisearch-js` dependency might be committed to this branch. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ _Related to this issue: https://github.com/meilisearch/integration-guides/issues/205_ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: cvermand <[email protected]>
2 parents 5c8d50d + b593f8c commit f67cf0b

File tree

10 files changed

+80
-19
lines changed

10 files changed

+80
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ Here is the [CSS customization](https://github.com/meilisearch/vuepress-plugin-m
321321

322322
## 🤖 Compatibility with Meilisearch
323323

324-
This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
324+
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).
325325

326326
## ⚙️ Development Workflow and Contributing
327327

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"dependencies": {
6767
"autocomplete.js": "^0.38.1",
68-
"meilisearch": "^0.26.0",
68+
"meilisearch": "^0.27.0",
6969
"to-factory": "^1.0.0",
7070
"zepto": "^1.2.0"
7171
}

playgrounds/html/setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,6 @@ const { MeiliSearch } = require('meilisearch')
213213

214214
const response = await index.addDocuments(dataset)
215215

216-
const task = await client.waitForTask(response.uid)
216+
const task = await client.waitForTask(response.taskUid)
217217
console.log(task)
218218
})()

src/lib/DocsSearchBar.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import templates from './templates'
33
import utils from './utils'
44
import $ from './zepto'
55
import { MeiliSearch } from 'meilisearch'
6+
import { constructClientAgents } from './agents'
67

78
/**
89
* Adds an autocomplete dropdown to an input field
@@ -56,6 +57,7 @@ class DocsSearchBar {
5657
enhancedSearchInput = false,
5758
layout = 'columns',
5859
enableDarkMode = false,
60+
clientAgents = [],
5961
}) {
6062
DocsSearchBar.checkArguments({
6163
hostUrl,
@@ -72,6 +74,7 @@ class DocsSearchBar {
7274
enhancedSearchInput,
7375
layout,
7476
enableDarkMode,
77+
clientAgents,
7578
})
7679

7780
this.apiKey = apiKey
@@ -115,6 +118,7 @@ class DocsSearchBar {
115118
this.client = new MeiliSearch({
116119
host: hostUrl,
117120
apiKey: this.apiKey,
121+
clientAgents: constructClientAgents(clientAgents),
118122
})
119123

120124
DocsSearchBar.addThemeWrapper(inputSelector, this.enableDarkMode)
@@ -255,6 +259,8 @@ class DocsSearchBar {
255259
false,
256260
)
257261

262+
DocsSearchBar.typeCheck(args, ['clientAgents'], 'array', true)
263+
258264
DocsSearchBar.typeCheck(
259265
args,
260266
['queryDataCallback', 'transformData', 'queryHook', 'handleSelected'],
@@ -268,6 +274,20 @@ class DocsSearchBar {
268274
)
269275
}
270276
}
277+
/**
278+
* Throw a type error.
279+
*
280+
* @param {string} argument - Name of the parameter
281+
* @param {string} type - Type the parameter should have
282+
* @param {string} value - Value the parameter has
283+
*
284+
* @returns {void}
285+
*/
286+
static throwTypeError(argument, type, value) {
287+
throw new Error(
288+
`Error: "${argument}" must be of type: ${type}. Found type: ${typeof value}`,
289+
)
290+
}
271291

272292
/**
273293
* Checks if the arguments defined in the check variable are of the supplied
@@ -283,10 +303,12 @@ class DocsSearchBar {
283303
.filter((argument) => !optional || args[argument])
284304
.forEach((argument) => {
285305
const value = args[argument]
286-
if (typeof args[argument] !== type) {
287-
throw new Error(
288-
`Error: "${argument}" must be of type: ${type}. Found type: ${typeof value}`,
289-
)
306+
if (type === 'array') {
307+
if (!Array.isArray(args[argument])) {
308+
DocsSearchBar.throwTypeError(argument, type, value)
309+
}
310+
} else if (typeof args[argument] !== type) {
311+
DocsSearchBar.throwTypeError(argument, type, value)
290312
}
291313
})
292314
}

src/lib/__tests__/DocsSearchBar-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sinon from 'sinon'
44
import $ from '../zepto'
55
import DocsSearchBar from '../DocsSearchBar'
6+
import PACKAGE_VERSION from '../version'
67
/**
78
* Pitfalls:
89
* Whenever you call new DocsSearchBar(), it will add the a new dropdown markup to
@@ -183,6 +184,7 @@ describe('DocsSearchBar', () => {
183184
MeiliSearch.calledWith({
184185
host: 'https://test.getmeili.com',
185186
apiKey: 'apiKey',
187+
clientAgents: [`Meilisearch docs-searchbar.js (v${PACKAGE_VERSION})`],
186188
}),
187189
).toBe(true)
188190
})
@@ -226,6 +228,27 @@ describe('DocsSearchBar', () => {
226228
expect(autocomplete.on.calledTwice).toBe(true)
227229
expect(autocomplete.on.calledWith('autocomplete:selected')).toBe(true)
228230
})
231+
232+
it('should have spread the user agents', () => {
233+
// Given
234+
const options = { ...defaultOptions, clientAgents: ['test'] }
235+
236+
// When
237+
new DocsSearchBar(options)
238+
239+
// Then
240+
expect(MeiliSearch.calledOnce).toBe(true)
241+
expect(
242+
MeiliSearch.calledWith({
243+
host: 'https://test.getmeili.com',
244+
apiKey: 'apiKey',
245+
clientAgents: [
246+
'test',
247+
`Meilisearch docs-searchbar.js (v${PACKAGE_VERSION})`,
248+
],
249+
}),
250+
).toBe(true)
251+
})
229252
})
230253

231254
describe('checkArguments', () => {
@@ -377,6 +400,15 @@ describe('DocsSearchBar', () => {
377400
// Given
378401
const options = { ...defaultOptions, handleSelected: 'not-a-function' }
379402

403+
// When
404+
expect(() => {
405+
checkArguments(options)
406+
}).toThrow(/^Error:/)
407+
})
408+
it('should throw an error if clientAgents is not an array', () => {
409+
// Given
410+
const options = { ...defaultOptions, clientAgents: 'test' }
411+
380412
// When
381413
expect(() => {
382414
checkArguments(options)

src/lib/agents.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import version from './version'
2+
3+
export const constructClientAgents = (clientAgents = []) => {
4+
const instantMeilisearchAgent = `Meilisearch docs-searchbar.js (v${version})`
5+
6+
return clientAgents.concat(instantMeilisearchAgent)
7+
}

tests/env/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"parcel-bundler": "^1.12.5"
1616
},
1717
"dependencies": {
18-
"meilisearch": "^0.24.0"
18+
"meilisearch": "^0.27.0"
1919
}
2020
}

tests/env/browser/setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,6 @@ const { MeiliSearch } = require('meilisearch')
212212

213213
const response = await index.addDocuments(dataset)
214214

215-
const task = await client.waitForTask(response.uid)
215+
const task = await client.waitForTask(response.taskUid)
216216
console.log(task)
217217
})()

tests/env/browser/yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
17261726
safe-buffer "^5.0.1"
17271727
sha.js "^2.4.8"
17281728

1729-
cross-fetch@^3.1.4:
1729+
cross-fetch@^3.1.5:
17301730
version "3.1.5"
17311731
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
17321732
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
@@ -3270,12 +3270,12 @@ [email protected]:
32703270
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b"
32713271
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==
32723272

3273-
meilisearch@^0.24.0:
3274-
version "0.24.0"
3275-
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.24.0.tgz#a71454baac058f502b931af17069ab676fbaced6"
3276-
integrity sha512-qME1dsHZePBQi8qFdhbilcFzaL+oZJgUuls+FZ23hHpdhJI+iMFSmjjcfsxq5hdg2qczbCXv7yAo3Sh8xgfkgA==
3273+
meilisearch@^0.27.0:
3274+
version "0.27.0"
3275+
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.27.0.tgz#8bd57ddb77b975f93e054cb977b951c488ece297"
3276+
integrity sha512-kZOZFIuSO7c6xRf+Y2/9/h6A9pl0sCl/G44X4KuaSwxGbruOZPhmxbeVEgLHBv4pUFvQ56rNVTA/2d/5GCU1YA==
32773277
dependencies:
3278-
cross-fetch "^3.1.4"
3278+
cross-fetch "^3.1.5"
32793279

32803280
32813281
version "1.0.4"

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5442,10 +5442,10 @@ [email protected]:
54425442
resolved "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz"
54435443
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==
54445444

5445-
meilisearch@^0.26.0:
5446-
version "0.26.0"
5447-
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.26.0.tgz#6bd19118c9841a5ece938da11372d227a75bdbb3"
5448-
integrity sha512-2JAxwqahhv5ToIDLdQAmQJcb3YuoH41m1L4WTtX+zeKeClnkowSxA1CHff+n4K6iEYxF5GiMxpqPsWTt4nQKFA==
5445+
meilisearch@^0.27.0:
5446+
version "0.27.0"
5447+
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.27.0.tgz#8bd57ddb77b975f93e054cb977b951c488ece297"
5448+
integrity sha512-kZOZFIuSO7c6xRf+Y2/9/h6A9pl0sCl/G44X4KuaSwxGbruOZPhmxbeVEgLHBv4pUFvQ56rNVTA/2d/5GCU1YA==
54495449
dependencies:
54505450
cross-fetch "^3.1.5"
54515451

0 commit comments

Comments
 (0)