tanishqmanuja / valorant-api-client

💢 VAPIC is a type safe implementation of an API Client for VALORANT.
MIT License
24 stars 6 forks source link

TypeError: Cannot read properties of undefined (reading 'parseResponseData') #11

Open PeanutDumplings opened 2 months ago

PeanutDumplings commented 2 months ago

For all methods that I have tried under vapic.remote I always get an error that goes along the line of

TypeError: Cannot read properties of undefined (reading 'parseResponseData')
    at RemoteApiClient.getAccountXp (.../valorant-rpc/node_modules/.pnpm/@tqman+valorant-api-client@1.4.0/node_modules/@tqman/valorant-api-client/dist/index.mjs:1354:40)
    at ...//valorant-rpc/src/index.js:42:30
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v22.4.1

That is for the code:

import {
    createValorantApiClient,
    provideAuthViaLocalApi,
    provideClientVersionViaVAPI,
    provideLockFile,
    provideLogFile,
    useProviders,
  } from "@tqman/valorant-api-client";

  const vapic = await createValorantApiClient({
    auth: useProviders(provideClientVersionViaVAPI()),
    local: useProviders(provideLockFile()),
    remote: useProviders([provideLogFile(), provideAuthViaLocalApi()]),
  });

await vapic.local.getChatHistory()

I have Valorant open when running the code, and have tested in games and in the lobby. Other local methods (like getFriends() work just fine).

Also, if I attempt to use a method (for instance vapic.remote.getCurrentGameMatch()) and I'm not in a game, will there be an error message that clearly defines the issue.

Thanks in advance :)

tanishqmanuja commented 2 months ago

Works fine for me

import {
  createValorantApiClient,
  provideAuthViaLocalApi,
  provideClientVersionViaVAPI,
  provideLockFile,
  provideLogFile,
  useProviders,
} from "@tqman/valorant-api-client";

const vapic = await createValorantApiClient({
  auth: useProviders(provideClientVersionViaVAPI()),
  local: useProviders(provideLockFile()),
  remote: useProviders([provideLogFile(), provideAuthViaLocalApi()]),
});

console.log(vapic.remote.puuid);

const { data: chat } = await vapic.local.getChatHistory();

console.log(chat);

const { data: xp } = await vapic.remote.getAccountXp({
  data: { puuid: vapic.remote.puuid },
});

console.log(xp);

OUTPUT: image

PeanutDumplings commented 2 months ago

Those two methods now work :)

One more thing is that I keep getting 404s for the getCurrentGamePlayer() method.

Code:

import {
    createValorantApiClient,
    provideAuthViaLocalApi,
    provideClientVersionViaVAPI,
    provideLockFile,
    provideLogFile,
    useProviders,
  } from "@tqman/valorant-api-client";

  const vapic = await createValorantApiClient({
    auth: useProviders(provideClientVersionViaVAPI()),
    local: useProviders(provideLockFile()),
    remote: useProviders([provideLogFile(), provideAuthViaLocalApi()]),
  });

console.log(vapic.remote.puuid)

await vapic.remote.getCurrentGamePlayer({
  data: { puuid: vapic.remote.puuid },
}).then((data) => {
  console.log(data)
}).catch((err) => {
  throw new Error(err)
})

Error:

335eb7e9-2edb-510f-a897-a478a75e33e5
.../valorant-rpc/src/index.js:47
  throw new Error(err)
        ^

Error: AxiosError: Request failed with status code 404
    at .../valorant-rpc/src/index.js:47:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async .../valorant-rpc/src/index.js:42:1

Node.js v22.4.1
[nodemon] app crashed - waiting for file changes before starting...

If I don't catch I get an even bigger error, the end of which is

data: {
  httpStatus: 404,
  errorCode: 'RESOURCE_NOT_FOUND',
  message: 'resource not found'
}
tanishqmanuja commented 2 months ago

Are you in a game actually?

because it works for me image

tanishqmanuja commented 2 months ago

This is the recommended way to do the calls

import { createValorantApiClient } from "@tqman/valorant-api-client";
import { LOCAL_CONFIG } from "@tqman/valorant-api-client/default-configs";

// Fixes SSL certificate verification issue (UNABLE_TO_VERIFY_LEAF_SIGNATURE)
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";

const vapic = await createValorantApiClient(LOCAL_CONFIG);

const puuid = vapic.remote.puuid;
console.log("PUUID", puuid);

// local call
const { data: chatHistory } = await vapic.local.getChatHistory();
console.log("chatHistory", chatHistory);

// remote call
const { data: xp } = await vapic.remote.getAccountXp({
  data: { puuid },
});
console.log("accountXp", xp);

// current match specific call
const currentMatchId = await vapic.remote
  .getCurrentGamePlayer({
    data: { puuid },
  })
  .then(({ data }) => data.MatchID)
  .catch(() => null);

if (currentMatchId) {
  console.log("currentMatchId", currentMatchId);
} else {
  console.log("player not in a match");
}