1.8.0 • Published 10 months ago

@enterlink/vrchat v1.8.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

vrchat

VRChat API package focused on abstracting session management.

Installation

yarn add @enterlink/vrchat

Usage

Accounts with no totp key must define a ClientOptions#onRequestOtpKey for fetching the relevant otp.

import { Client, CurrentUser, Routes, World } from "@enterlink/vrchat";

const client = new Client({
  email: 'email@example.com',
  password: 'some-secret-password',
  totpKey: 'totp-private-key'
});

;(async () => {
  const user = await client.get<CurrentUser>(Routes.currentUser());
  console.log("Logged in as", user.displayName);

  const world = await client.get<World>(Routes.world("wrld_2851d12c-57d0-4754-84cf-aa494ce7a03a"));
  console.log("Found World:", world.name);

  await client.put(Routes.logout());
  console.log("Logged out!");
})().catch(console.error);

Pooled Usage Example

Our specfic scenario demands us having a pool of accounts. You can achieve this with using the pooler. The pooler expects a constructed implementation of StorageAdapter. In this example we will use the Memory Adapter.

It is highly recommended to use an adapter that will persist session states across restarts. VRChat has a limit to how many active sessions an account can have.

import { CurrentUser, Pooler, Routes } from "@enterlink/vrchat";
import { MemoryStorageAdapter } from '@enterlink/vrchat/adapter/memory';

const adapter = new MemoryStorageAdapter([
  {
    email: 'email@example.com',
    password: 'some-secret-password',
    totpKey: 'totp-private-key'
  },
  {
    email: 'email2@example.com',
    password: 'some-secret-password',
    totpKey: 'totp-private-key'
  },
  {
    email: 'email3@example.com',
    password: 'some-secret-password',
    totpKey: 'totp-private-key'
  }
]);

const pooler = new Pooler(adapter);

;(async () => {
  const users = await pooler.getAll<CurrentUser>(Routes.currentUser());

  for (const user of users) {
    console.log("Logged in as:", user.displayName);
  }

  await pooler.putAll(Routes.logout());
  console.log("Logged out all users");
})().catch(console.error);

Notes

We use otplib internally for generating TOTP codes. I've noticed that on Node.js versions 20 and 21, authentication failures occur because one of otplib's dependencies, thirty-two, uses new Buffer() internally. This results in a Node.js error: TypeError: Cannot read properties of undefined (reading '0'). Since there isn't a straightforward fix for this issue, we are running Node.js v22+ to avoid the problem.

Backlog

  • Implement Prisma adapter for our use case.
  • Prisma adapter optional encryption.
  • Way to select an account to use in pooler.
  • Way to request on all accounts in pooler.
  • Support for accounts all 2fa types (see src/client.ts).
  • Implement all API endpoints (see src/api.ts).
  • Support setting ratelimits.
  • Pooler single account transactions.
1.8.0

10 months ago

1.7.3

11 months ago

1.7.2

11 months ago

1.7.1

11 months ago

1.7.0

11 months ago

1.6.4

11 months ago

1.6.3

11 months ago

1.6.2

11 months ago

1.6.1

11 months ago

1.6.0

11 months ago

1.5.0

11 months ago

1.4.2

11 months ago

1.4.1

11 months ago

1.4.0

11 months ago

1.3.0

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago