Skip to content

Commit 903c422

Browse files
bidoubiwaCharlotte Vermandel
andauthored
Pass client agent to meilisearch-js (#780)
* Update search route request and response parameters naming v0.28.x * Pass client agent to meilisearch-js * Improve check release script * Use double quotes on string with no dynamic variable in check releases script * Add missing whitespace in check-release.sh * Add possibility to provide client agents through the parameters of instantMeilisearch * Fix search resolver tests Co-authored-by: Charlotte Vermandel <[email protected]>
1 parent 0fa6e08 commit 903c422

File tree

7 files changed

+44
-7
lines changed

7 files changed

+44
-7
lines changed

.github/scripts/check-release.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
# Checking if current tag matches the package version
44
current_tag=$(echo $GITHUB_REF | cut -d '/' -f 3 | tr -d ' ',v)
5-
file_tag=$(grep '"version":' package.json | cut -d ':' -f 2- | tr -d ' ' | tr -d '"' | tr -d ',')
6-
if [ "$current_tag" != "$file_tag" ]; then
7-
echo "Error: the current tag does not match the version in package file(s)."
8-
echo "$current_tag vs $file_tag"
5+
6+
package_file_tag=$(grep '"version":' package.json | cut -d ':' -f 2- | tr -d ' ' | tr -d '"' | tr -d ',')
7+
package_file_name='package.json'
8+
version_file_tag=$(grep "PACKAGE_VERSION =" src/package-version.ts | cut -d "=" -f 2- | tr -d " " | tr -d "'")
9+
version_file_name='src/package-version.ts'
10+
11+
if [ "$current_tag" != "$package_file_tag" ] || [ "$current_tag" != "$version_file_tag" ]; then
12+
echo 'Error: the current tag does not match the version in package file(s).'
13+
echo "$package_file_name: $current_tag vs $package_file_tag"
14+
echo "$version_file_name: $current_tag vs $version_file_tag"
915
exit 1
1016
fi
1117

CONTRIBUTING.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,16 @@ _[Read more about this](https://github.com/meilisearch/integration-guides/blob/m
131131

132132
⚠️ Before doing anything, make sure you got through the guide about [Releasing an Integration](https://github.com/meilisearch/integration-guides/blob/main/resources/integration-release.md).
133133

134-
Make a PR modifying the file [`package.json`](/package.json) with the right version.
134+
Make a PR modifying the following files with the right version:
135135

136+
[`package.json`](/package.json):
136137
```javascript
137-
"version": "X.X.X"
138+
"version": "X.X.X",
139+
```
140+
141+
[`src/package-version`](/src/package-version.ts)
142+
```javascript
143+
export const PACKAGE_VERSION = 'X.X.X'
138144
```
139145

140146
Once the changes are merged on `main`, you can publish the current draft release via the [GitHub interface](https://github.com/meilisearch/instant-meilisearch/releases): on this page, click on `Edit` (related to the draft release) > update the description (be sure you apply [these recommandations](https://github.com/meilisearch/integration-guides/blob/main/resources/integration-release.md#writting-the-release-description)) > when you are ready, click on `Publish release`.

src/client/agents.ts

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

src/client/instant-meilisearch-client.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../adapter'
1414
import { createSearchContext } from '../contexts'
1515
import { SearchCache, cacheFirstFacetDistribution } from '../cache/'
16+
import { constructClientAgents } from './agents'
1617

1718
/**
1819
* Instanciate SearchClient required by instantsearch.js.
@@ -31,7 +32,15 @@ export function instantMeiliSearch(
3132
const searchResolver = SearchResolver(SearchCache())
3233
// paginationTotalHits can be 0 as it is a valid number
3334
let defaultFacetDistribution: any = {}
34-
const meilisearchClient = new MeiliSearch({ host: hostUrl, apiKey: apiKey })
35+
const clientAgents = constructClientAgents(
36+
instantMeiliSearchOptions.clientAgents
37+
)
38+
39+
const meilisearchClient = new MeiliSearch({
40+
host: hostUrl,
41+
apiKey: apiKey,
42+
clientAgents,
43+
})
3544

3645
return {
3746
/**

src/package-version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const PACKAGE_VERSION = '0.7.1'

src/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type InstantMeiliSearchOptions = {
3333
primaryKey?: string
3434
keepZeroFacets?: boolean
3535
finitePagination?: boolean
36+
clientAgents?: string[]
3637
}
3738

3839
export type SearchCacheInterface = {

tests/search-resolver.tests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Movies } from './assets/utils'
22
import { instantMeiliSearch } from '../src'
33
import { MeiliSearch } from 'meilisearch'
44
import { mocked } from 'ts-jest/utils'
5+
import { PACKAGE_VERSION } from '../src/package-version'
56

67
jest.mock('meilisearch')
78

@@ -48,6 +49,7 @@ describe('Pagination browser test', () => {
4849
expect(mockedMeilisearch).toHaveBeenCalledWith({
4950
host: 'http://localhost:7700',
5051
apiKey: '',
52+
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
5153
})
5254
expect(mockedSearch).toHaveBeenCalledTimes(1)
5355
})
@@ -73,6 +75,7 @@ describe('Pagination browser test', () => {
7375
expect(mockedMeilisearch).toHaveBeenCalledWith({
7476
host: 'http://localhost:7700',
7577
apiKey: '',
78+
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
7679
})
7780
expect(mockedSearch).toHaveBeenCalledTimes(2)
7881
})
@@ -99,6 +102,7 @@ describe('Pagination browser test', () => {
99102
expect(mockedMeilisearch).toHaveBeenCalledWith({
100103
host: 'http://localhost:7700',
101104
apiKey: '',
105+
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
102106
})
103107
expect(mockedSearch).toHaveBeenCalledTimes(2)
104108
})
@@ -126,6 +130,7 @@ describe('Pagination browser test', () => {
126130
expect(mockedMeilisearch).toHaveBeenCalledWith({
127131
host: 'http://localhost:7700',
128132
apiKey: '',
133+
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
129134
})
130135
expect(mockedSearch).toHaveBeenCalledTimes(2)
131136
})

0 commit comments

Comments
 (0)