Skip to content

Commit

Permalink
Merge pull request #91 from meilisearch/add_user_agent_in_client
Browse files Browse the repository at this point in the history
Pass firebase client agent to meilisearch-js
  • Loading branch information
bidoubiwa authored Jul 11, 2022
2 parents c871e05 + 1aea6da commit 8448006
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions functions/__tests__/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { mockConsoleLog, mockConsoleInfo } from './__mocks__/console'
import { MeiliSearch } from 'meilisearch'
import defaultEnvironment from './data/environment'
import defaultDocument from './data/document'
import { version } from '../src/version'

jest.mock('meilisearch')

Expand Down Expand Up @@ -52,6 +53,7 @@ describe('extension', () => {
expect(mockedMeilisearch).toHaveBeenCalledWith({
apiKey: defaultEnvironment.MEILISEARCH_API_KEY,
host: defaultEnvironment.MEILISEARCH_HOST,
clientAgents: [`Meilisearch Firebase (v${version})`],
})
expect(mockConsoleLog).toBeCalledWith(
'Initializing extension with configuration',
Expand Down
9 changes: 9 additions & 0 deletions functions/src/meilisearch/agents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { version } from '../version'

export const constructClientAgents = (
clientAgents: string[] = []
): string[] => {
const firebaseAgent = `Meilisearch Firebase (v${version})`

return clientAgents.concat(firebaseAgent)
}
2 changes: 2 additions & 0 deletions functions/src/meilisearch/create-index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MeiliSearch, Index } from 'meilisearch'
import { MeilisearchConfig } from '../types'
import { constructClientAgents } from './agents'

/**
* initMeilisearchIndex
Expand All @@ -14,6 +15,7 @@ export function initMeilisearchIndex({
const client = new MeiliSearch({
host,
apiKey,
clientAgents: constructClientAgents(),
})

return client.index(indexUid)
Expand Down

0 comments on commit 8448006

Please sign in to comment.