kilnfi / sdk-js

Kiln Connect SDK
https://www.npmjs.com/package/@kilnfi/sdk
Other
3 stars 3 forks source link

Multi instance usage #115

Closed DaniSchenk closed 1 month ago

DaniSchenk commented 3 months ago

I try to use a multi Kiln sdk instance approach that looks similar to this:

class KilnService {
  private clientMainnet: Kiln;
  private clientTestnet: Kiln;

  constructor() {
    this.clientMainnet = new Kiln({
      apiToken: "xxx",
      testnet: false,
      baseUrl: "https://api.kiln.fi",
    });

    this.clientTestnet = new Kiln({
      apiToken: "xxx",
      testnet: true,
    });
  }
}

Once I do requests like await this.clientMainnet.accounts.getAll() I see that requests are made to api.testnet.kiln.fi even if mainnet sdk instance was used. Going further, I changed the order of initialization in the constructor (testnet first, mainnet second) all requests - no matter what instance was used - were made to api.kiln.fi.

Can you replicate this behavior? Are both instances sharing the same axios instance, maybe? If that's the root cause, then every Kiln sdk class instance should get its axios instance IMO. IMO, this is more intuitive, and instances must not be recreated before usage.

nooxx commented 2 months ago

Hey thanks for reporting this issue! There is indeed one axios instance. We'll fix asap.

nooxx commented 1 month ago

Hello, this has been fixed in the v3.