-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(preset-algolia): attach algolia credentials on hits (#1117)
Co-authored-by: Haroen Viaene <[email protected]>
- Loading branch information
Showing
9 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/autocomplete-preset-algolia/src/utils/__tests__/getAppIdAndApiKey.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import algoliasearchV4 from 'algoliasearch'; | ||
|
||
import { getAppIdAndApiKey } from '../getAppIdAndApiKey'; | ||
|
||
const APP_ID = 'myAppId'; | ||
const API_KEY = 'myApiKey'; | ||
|
||
describe('getAppIdAndApiKey', () => { | ||
it('gets appId and apiKey from searchClient', () => { | ||
const searchClient = algoliasearchV4(APP_ID, API_KEY); | ||
const { appId, apiKey } = getAppIdAndApiKey(searchClient); | ||
expect(appId).toEqual(APP_ID); | ||
expect(apiKey).toEqual(API_KEY); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/autocomplete-preset-algolia/src/utils/getAppIdAndApiKey.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { SearchClient } from '../types'; | ||
|
||
export function getAppIdAndApiKey(searchClient: SearchClient): { | ||
appId: string; | ||
apiKey: string; | ||
} { | ||
const { headers, queryParameters } = searchClient.transporter; | ||
const APP_ID = 'x-algolia-application-id'; | ||
const API_KEY = 'x-algolia-api-key'; | ||
const appId = headers[APP_ID] || queryParameters[APP_ID]; | ||
const apiKey = headers[API_KEY] || queryParameters[API_KEY]; | ||
return { appId, apiKey }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './getAppIdAndApiKey'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters