#community-help

Typesense js client upgrade: API key and SearchClient issues

TLDR Janaka had issues with the API key showing in the query string after upgrading the Typesense js client and noticed a change in the retrieve() method's behavior. Jason explained the change and advised on the API key issue, asking Janaka to create a Github issue for it which was done.

Powered by Struct AI

1

Jan 15, 2022 (24 months ago)
Janaka
Photo of md5-3ecfadbfb82a962691e2d6cb42f876b4
Janaka
02:49 PM
Hey all, long time. It's been a couple of months since I last hacked on top of Typesense. Upgraded the js client to see if it resolved a minor issue I was spotting in js client v0.14.0 (API key was appearing in query string even with the respective config set to false)

My app broke 😅. The cause a breaking change in the client lib API introduced in v1.0.0-3. Seems like this change. I'm unblocked now but thought I'd share some details and check if I'm missing somewhere that tracks the js client API changes? it doesn't seen to mirror what on the docs site.

Since then collection('mycollectionname').retrieve() returns a different type. It used to return as per the docs here. I'm using the SearchClient and accessing the num_documents property. In the PR I see references to a SearchOnlyCollection. I've not managed to find docs for this type. Am I missing something?
02:55
Janaka
02:55 PM
re: api key passed in the query string

on js client v1.1.3-0 it's still doing it. In code I see the default is supposed to be false . Even when the client instantiation config has sendApiKeyAsQueryParam: false,
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:50 PM
Janaka SearchClient does not expose a collection('name').retrieve() method. It is meant to only allow searches on documents.

If you use Client instead, you should see num_documents like this:
04:57
Jason
04:57 PM
re: API Key, looks like in the SearchClient we force sending the API key as a query param and ignore the configuration: https://github.com/typesense/typesense-js/blob/a21d4101bc21fe59e0e85b41e64ba14d6fe88667/src/Typesense/SearchClient.ts#L14-L17

That almost sounds like a bug... Could you open a Github issue for this? I think we should respect the config passed into the config
Janaka
Photo of md5-3ecfadbfb82a962691e2d6cb42f876b4
Janaka
04:59 PM
Can you expand on "only search on documents" pls? In contrast to?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:00 PM
In contrast to allowing all operations on collections like retrieve
05:01
Jason
05:01 PM
SearchClient is intended to only be used for search in say the browser to reduce bundle size.

Client has all the methods that Typesense supports
Janaka
Photo of md5-3ecfadbfb82a962691e2d6cb42f876b4
Janaka
09:55 PM
gotcha. makes sense. sorry, was a slightly silly question to ask.
Jan 16, 2022 (24 months ago)
Janaka
Photo of md5-3ecfadbfb82a962691e2d6cb42f876b4
Janaka
07:20 PM
Created an GH issue for sendApiKeyAsQueryParam 🙏

1

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community