diff --git a/.github/scripts/check-release.sh b/.github/scripts/check-release.sh index 22ea2636..f646208c 100644 --- a/.github/scripts/check-release.sh +++ b/.github/scripts/check-release.sh @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ed8b067..7f52b864 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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`. diff --git a/src/client/agents.ts b/src/client/agents.ts new file mode 100644 index 00000000..e15a8900 --- /dev/null +++ b/src/client/agents.ts @@ -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) +} diff --git a/src/client/instant-meilisearch-client.ts b/src/client/instant-meilisearch-client.ts index 6386bfd1..9caf65a3 100644 --- a/src/client/instant-meilisearch-client.ts +++ b/src/client/instant-meilisearch-client.ts @@ -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. @@ -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 { /** diff --git a/src/package-version.ts b/src/package-version.ts new file mode 100644 index 00000000..267c465b --- /dev/null +++ b/src/package-version.ts @@ -0,0 +1 @@ +export const PACKAGE_VERSION = '0.7.1' diff --git a/src/types/types.ts b/src/types/types.ts index 32189ab9..76c9777c 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -33,6 +33,7 @@ export type InstantMeiliSearchOptions = { primaryKey?: string keepZeroFacets?: boolean finitePagination?: boolean + clientAgents?: string[] } export type SearchCacheInterface = { diff --git a/tests/search-resolver.tests.ts b/tests/search-resolver.tests.ts index 956b65fb..28a1ffa0 100644 --- a/tests/search-resolver.tests.ts +++ b/tests/search-resolver.tests.ts @@ -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') @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) })