Rudder

Rudder SDK packages

@rudder/server (1.0.0)

Published 2026-11-01 10:01:09 +01:00 by edmand46

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?) and mutation(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() reads staging or prod from the server key.
  • Profile and ban. setPlayerProfile replaces the nickname and the avatar (an empty one clears it), banPlayer bans until the given moment with the reason the history shows, and unbanPlayer lifts it. A ban of a deleted player answers player_not_found.
  • Errors. A refused call throws RudderError with the code, message and HTTP status of the answer: a code the module declares (such as limit_reached) or one of Rudder (such as player_not_found, idempotency_key_reused or rate_limited).
  • Retries. A request that got no answer or the answer try_again is sent again after the Retry-After it gave or a short backoff, at most attempts times (5). A mutation keeps its Idempotency-Key across 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, an AbortSignal.

Dependencies

Development Dependencies

ID Version
@types/node ~24.10.0
typescript ~5.9.3
Details
npm
2026-11-01 10:01:09 +01:00
5
latest
3.5 KiB
Assets (1)
Versions (1) View all
1.0.0 2026-11-01