Skip to content

Commit

Permalink
Merge pull request #7 from afosto/Feature/change-proxy-id-to-search-e…
Browse files Browse the repository at this point in the history
…ngine-key

Feature/change-proxy-id-to-search-engine-key
  • Loading branch information
Rapid0o authored Jan 25, 2022
2 parents ca68ae4 + c3175bc commit 3c3af62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ This library supports the **last two** versions of major browsers (Chrome, Edge,

## Getting started

First you initialize the Afosto search client with your **proxy key**. This proxy key can be found in the Afosto app.
First you initialize the Afosto search client with your **search engine key**. This search engine key can be found in the Afosto app.

### ES6

```js
import { afostoInstantSearch } from '@afosto/instant-search-client';

const client = afostoInstantSearch('proxy-key');
const client = afostoInstantSearch('my-search-engine-key');
```

### CJS

```js
const { afostoInstantSearch } = require('@afosto/instant-search-client');

const client = afostoInstantSearch('proxy-key');
const client = afostoInstantSearch('my-search-engine-key');
```

### Browser

```js
const client = afostoInstantSearch('proxy-key');
const client = afostoInstantSearch('my-search-engine-key');
```

## Usage
Expand All @@ -78,7 +78,7 @@ const client = afostoInstantSearch('proxy-key');
### Basic

```js
const client = afostoInstantSearch('proxy-key');
const client = afostoInstantSearch('my-search-engine-key');
const search = instantsearch({
indexName: 'my-index',
searchClient: client,
Expand All @@ -97,7 +97,7 @@ You can use the initialized Afosto client with the [React InstantSearch](https:/
import { afostoInstantSearch } from '@afosto/instant-search-client';
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch-dom';

const searchClient = afostoInstantSearch('proxy-key');
const searchClient = afostoInstantSearch('my-search-engine-key');

const App = () => (
<InstantSearch searchClient={searchClient} indexName="my-index">
Expand Down
10 changes: 5 additions & 5 deletions src/afostoInstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { DEFAULT_OPTIONS } from './constants';

/**
* Afosto instant search client
* @param {String} proxyId
* @param {String} searchEngineKey
* @param {Object} options
* @returns {Object}
* @constructor
*/
const afostoInstantSearch = (proxyId, options) => {
if (!proxyId) {
throw new Error('A proxyId is required to use the Afosto instant search client.')
const afostoInstantSearch = (searchEngineKey, options = {}) => {
if (!searchEngineKey) {
throw new Error('A search engine key is required to use the Afosto instant search client.')
}

const clientOptions = { ...DEFAULT_OPTIONS, ...(options ?? {}) };
const searchRequestAdapter = SearchRequestAdapter();
const searchResponseAdapter = SearchResponseAdapter();

const searchRequest = async context => {
const url = clientOptions.baseUrl?.replace('{proxyId}', proxyId);
const url = clientOptions.baseUrl?.replace('{key}', searchEngineKey);
const requestOptions = clientOptions.requestOptions || {};
const hasContextFormatter = clientOptions.transformContext && typeof clientOptions.transformContext === 'function';
const hasResponseFormatter = clientOptions.transformResponse && typeof clientOptions.transformResponse === 'function';
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const DEFAULT_OPTIONS = {
allowEmptyQuery: true,
baseUrl: 'https://afosto.io/api/instant/search/{proxyId}',
baseUrl: 'https://afosto.io/api/instant/search/{key}',
hitsPerPage: 10,
requestOptions: {},
threshold: 1,
Expand Down

0 comments on commit 3c3af62

Please sign in to comment.