Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration from v4 to v5: Issues with algoliasearch and AlgoliaSearchHelper #1553

Open
paulgrotzke opened this issue Sep 17, 2024 · 1 comment

Comments

@paulgrotzke
Copy link

paulgrotzke commented Sep 17, 2024

We're migrating from v4 to v5, using algoliasearch in combination with AlgoliaSearchHelper

Previously, we used it like this:

import { algoliasearch } from 'algoliasearch'
import algoliasearchHelper from 'algoliasearch-helper'

const client = algoliasearch('id', 'apiKey', {
  headers: { 'X-Algolia-UserToken': 'token' }
})

const helper = algoliasearchHelper(client, 'index', { ...options })

We've encountered two problems:

1) Setting headers during client creation
Previously, we passed the headers directly when creating the client. Now, the TypeScript types indicate this might not be possible:

Object literal may only specify known properties, and 'headers' does not exist in type 'Partial<Omit<CreateClientOptions, "apiKey" | "appId">>'.ts(2353)

Is this correct? If so, what's the recommended way to set headers?
We've only found this article on Request Options which mentions setting headers via searchSingleIndex. However, we're not using that method in our case.

2) Type incompatibility between Algoliasearch client and SearchClient
The client created (typeof Algoliasearch) seems to be incompatible with the type that algoliasearchHelper expects (typeof SearchClient)

const helper = algoliasearchHelper(client, 'index', { ...options })
//                                 ^
// Argument of type 'Algoliasearch' is not assignable to parameter of type 'SearchClient'.
// Types of property 'searchForFacetValues' are incompatible.
// Type '({ indexName, facetName, searchForFacetValuesRequest }: SearchForFacetValuesProps, requestOptions?: RequestOptions | undefined) => Promise<SearchForFacetValuesResponse>' is not assignable to type 'undefined'.
// ts(2345)
@Haroenv
Copy link
Contributor

Haroenv commented Sep 17, 2024

  1. Not sure about this question, @shortcuts, do you know what the new signature is for a static header?

  2. The sffv problem should be solved in the latest version of the helper: algolia/instantsearch@11399e6 (3.22.5), which was caused by an incompatibility of the v4 and v5 signatures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants