@rudder/server (1.0.0)
Installation
@rudder:registry=https://hub.rudder.build/api/packages/rudder/npm/npm install @rudder/server@1.0.0"@rudder/server": "1.0.0"About this package
@rudder/server
The game server of Rudder for Node. It calls the functions of the modules of a project for a player the game server names, and it updates the profile of a player and its ban. 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 server:
@rudder:registry=https://hub.rudder.build/api/packages/rudder/npm/
then install it:
npm install @rudder/server
Generate the client
In a repository where rudder project use chose the project:
rudder server generate --lang ts --output src/rudder-server.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, the functions marked server included, and the types of
their arguments and results. Every method names the player first. Without --game-address the
client uses the address of the CLI. Generate it again when a release changes the functions or
their types.
Use
import { RudderServer } from './rudder-server';
const rudder = new RudderServer({ serverKey: process.env.RUDDER_SERVER_KEY! });
const purchase = await rudder.shop.buy(playerId, { offer: 'pumpkin-pack' });
await rudder.wallet.earn(playerId, 100);
await rudder.setPlayerProfile(playerId, { nickname: 'Ada', avatar: 'https://example.com/ada.png' });
await rudder.banPlayer(playerId, { until: '2026-12-01T00:00:00Z', reason: 'cheating' });
await rudder.unbanPlayer(playerId);
The constructor takes the serverKey of an environment (the secret the game server holds),
address (the address given to --game-address unless missing), attempts and fetch.
- Calls.
query(module, name, playerId, input?, options?)andmutation(module, name, playerId, input?, options?)are the untyped form; the generated methods call them. A banned player is refused to a game client, not to the game server. - Environment.
environment()readsstagingorprodfrom the server key. - Profile and ban.
setPlayerProfilereplaces the nickname and the avatar (an empty one clears it),banPlayerbans until the given moment with the reason the history shows, andunbanPlayerlifts it. A ban of a deleted player answersplayer_not_found. - 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_not_found,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. The key is generated for each call unless you pass one: a retry of the whole request by your game server needs its own key, such as the id of a purchase, or it runs the mutation twice. - Cancel. Every method takes the option
signal, anAbortSignal.
Dependencies
Development Dependencies
| ID | Version |
|---|---|
| @types/node | ~24.10.0 |
| typescript | ~5.9.3 |