@rudder/sdk (1.0.1)
Installation
@rudder:registry=https://hub.rudder.build/api/packages/rudder/npm/npm install @rudder/sdk@1.0.1"@rudder/sdk": "1.0.1"About this package
@rudder/sdk
The game client of Rudder for the browser and Node. It signs a device in and calls the functions of the modules of a project through a typed client generated for that project. It has no runtime dependencies.
Install
The package comes from the Rudder registry. Point the scope @rudder at it in the .npmrc of
the game:
@rudder:registry=https://hub.rudder.build/api/packages/rudder/npm/
then install it:
npm install @rudder/sdk
Generate the client
In a repository where rudder project use chose the project:
rudder client generate --lang ts --output src/rudder.ts --game-address https://api.rudder.build \
[--environment staging|prod]
The client follows the newest release of the environment, staging by default: a class per
module with a method per function a game client may call (functions marked server are left
out) and the types of their arguments and results. Generate it again when a release changes
them.
Use
import { Rudder } from './rudder';
const rudder = await Rudder.signInDevice(sdkKey, deviceId);
const stores = await rudder.stores.stores();
await rudder.stores.buy({ offer: 'pumpkin-pack' });
const balances = await rudder.session.wallet();
The third argument of signInDevice takes address (the origin of the page, or the address
given to --game-address, when missing), attempts, fetch and the nickname, avatar,
language and region of the player.
- Errors. A refused call throws
RudderErrorwith thecode,messageand HTTPstatusof the answer: a code the module declares (such aslimit_reached) or one of Rudder (such asplayer_banned,idempotency_key_reusedorrate_limited). - Retries. A request that got no answer or the answer
try_againis sent again after theRetry-Afterit gave or a short backoff, at mostattemptstimes (5). A mutation keeps itsIdempotency-Keyacross them, so it runs once. Pass your own key, such as the id of a purchase, to keep that promise across restarts:buy(input, { idempotencyKey }). - Session. The access token stays in memory; when it expires the device signs in again.
- Cancel. Every method takes the option
signal, anAbortSignal.
Dependencies
Development Dependencies
| ID | Version |
|---|---|
| @types/node | ~24.10.0 |
| typescript | ~5.9.3 |