typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
393 stars 74 forks source link

Add support for mulltiple API keys per cluster #175

Closed elieobeid7 closed 10 months ago

elieobeid7 commented 10 months ago

I reported this issue https://github.com/typesense/firestore-typesense-search/issues/60 and I thought, it's a Firebase plugin issue, turns out the javascript library accepts only one key for all nodes which makes no sense, is this by design?

All Typesense libraries support one key per cluster, why?

Is it because you only set up a cluster using private IPs and you never thought that someone like me would want to set up servers in multiple data centers? So if a cluster is accessible privately only it's secure by design, this is the main reason, right?

jasonbosco commented 10 months ago

To use multiple API keys, you'd simply instantiate multiple instances of the client each with a separate API key... and use the appropriate client instance to call the methods needed.

Eg:

const typesense1 = new Typesense.Client({
  nodes: [
    {
      host: "hostname",
      port: "443",
      protocol: "https",
    },
  ],
  apiKey: 'APIKEY-ABC',
});

const typesense2 = new Typesense.Client({
  nodes: [
    {
      host: "hostname",
      port: "443",
      protocol: "https",
    },
  ],
  apiKey: 'APIKEY-XYZ,
});

you only set up a cluster using private IPs... a cluster is accessible privately only it's secure by design

No, Typesense can indeed be exposed to the internet using public IPs.

you never thought that someone like me would want to set up servers in multiple data centers

No, Typesense is indeed designed to be run across multiple data centers. We run thousands of nodes this way across 80 data centers in Typesense Cloud.

elieobeid7 commented 10 months ago

We both know this isn't ideal, closing this ticket as it seems to me, this won't be fixed. I added one key for all servers and called it a day since I refuse to write such code.