Skip to content
14 changes: 10 additions & 4 deletions .github/scripts/check-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

# Checking if current tag matches the package version
current_tag=$(echo $GITHUB_REF | cut -d '/' -f 3 | tr -d ' ',v)
file_tag=$(grep '"version":' package.json | cut -d ':' -f 2- | tr -d ' ' | tr -d '"' | tr -d ',')
if [ "$current_tag" != "$file_tag" ]; then
echo "Error: the current tag does not match the version in package file(s)."
echo "$current_tag vs $file_tag"

package_file_tag=$(grep '"version":' package.json | cut -d ':' -f 2- | tr -d ' ' | tr -d '"' | tr -d ',')
package_file_name='package.json'
version_file_tag=$(grep "PACKAGE_VERSION =" src/package-version.ts | cut -d "=" -f 2- | tr -d " " | tr -d "'")
version_file_name='src/package-version.ts'

if [ "$current_tag" != "$package_file_tag" ] || [ "$current_tag" != "$version_file_tag" ]; then
echo 'Error: the current tag does not match the version in package file(s).'
echo "$package_file_name: $current_tag vs $package_file_tag"
echo "$version_file_name: $current_tag vs $version_file_tag"
exit 1
fi

Expand Down
10 changes: 8 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,16 @@ _[Read more about this](https://github.com/meilisearch/integration-guides/blob/m

⚠️ 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).

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

[`package.json`](/package.json):
```javascript
"version": "X.X.X"
"version": "X.X.X",
```

[`src/package-version`](/src/package-version.ts)
```javascript
export const PACKAGE_VERSION = 'X.X.X'
```

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`.
Expand Down
9 changes: 9 additions & 0 deletions src/client/agents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PACKAGE_VERSION } from '../package-version'

export const constructClientAgents = (
clientAgents: string[] = []
): string[] => {
const instantMeilisearchAgent = `Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`

return clientAgents.concat(instantMeilisearchAgent)
}
11 changes: 10 additions & 1 deletion src/client/instant-meilisearch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../adapter'
import { createSearchContext } from '../contexts'
import { SearchCache, cacheFirstFacetDistribution } from '../cache/'
import { constructClientAgents } from './agents'

/**
* Instanciate SearchClient required by instantsearch.js.
Expand All @@ -31,7 +32,15 @@ export function instantMeiliSearch(
const searchResolver = SearchResolver(SearchCache())
// paginationTotalHits can be 0 as it is a valid number
let defaultFacetDistribution: any = {}
const meilisearchClient = new MeiliSearch({ host: hostUrl, apiKey: apiKey })
const clientAgents = constructClientAgents(
instantMeiliSearchOptions.clientAgents
)

const meilisearchClient = new MeiliSearch({
host: hostUrl,
apiKey: apiKey,
clientAgents,
})

return {
/**
Expand Down
1 change: 1 addition & 0 deletions src/package-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PACKAGE_VERSION = '0.7.1'
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type InstantMeiliSearchOptions = {
primaryKey?: string
keepZeroFacets?: boolean
finitePagination?: boolean
clientAgents?: string[]
}

export type SearchCacheInterface = {
Expand Down
5 changes: 5 additions & 0 deletions tests/search-resolver.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Movies } from './assets/utils'
import { instantMeiliSearch } from '../src'
import { MeiliSearch } from 'meilisearch'
import { mocked } from 'ts-jest/utils'
import { PACKAGE_VERSION } from '../src/package-version'

jest.mock('meilisearch')

Expand Down Expand Up @@ -48,6 +49,7 @@ describe('Pagination browser test', () => {
expect(mockedMeilisearch).toHaveBeenCalledWith({
host: 'http://localhost:7700',
apiKey: '',
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
})
expect(mockedSearch).toHaveBeenCalledTimes(1)
})
Expand All @@ -73,6 +75,7 @@ describe('Pagination browser test', () => {
expect(mockedMeilisearch).toHaveBeenCalledWith({
host: 'http://localhost:7700',
apiKey: '',
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
})
expect(mockedSearch).toHaveBeenCalledTimes(2)
})
Expand All @@ -99,6 +102,7 @@ describe('Pagination browser test', () => {
expect(mockedMeilisearch).toHaveBeenCalledWith({
host: 'http://localhost:7700',
apiKey: '',
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
})
expect(mockedSearch).toHaveBeenCalledTimes(2)
})
Expand Down Expand Up @@ -126,6 +130,7 @@ describe('Pagination browser test', () => {
expect(mockedMeilisearch).toHaveBeenCalledWith({
host: 'http://localhost:7700',
apiKey: '',
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
})
expect(mockedSearch).toHaveBeenCalledTimes(2)
})
Expand Down