@spawnco/server
TypeScript icon, indicating that this package has built-in type declarations

0.0.26 • Public • Published

Spawn Server SDK

Server-side SDK for Spawn game development platform.

Installation

npm install @spawnco/server @spawnco/sdk-types
# or
bun add @spawnco/server @spawnco/sdk-types

Usage

Token Verification

The server SDK provides token verification for authenticating users in your game server:

import { createSDK } from "@spawnco/server";

// Create SDK instance with environment configuration
const sdk = createSDK({
  // For HS256 tokens (default)
  SUPABASE_JWT_SECRET: process.env.SUPABASE_JWT_SECRET,
  // For RS256 tokens (recommended for production)
  RSA_PUBLIC_KEY: process.env.RSA_PUBLIC_KEY,
});

// In your WebSocket handler or API endpoint
async function handleConnection(token: string) {
  const result = await sdk.user.token.verify(token);

  if (!result.valid) {
    throw new Error("Invalid token");
  }

  // Access user information
  const { user, expires, payload } = result;
  console.log(`User ${user.username} connected`);
  console.log(`Token expires at ${expires}`);
  console.log(`Variant ID: ${payload.variantId}`);
}

Token Payload

Verified tokens include the following information:

interface TokenPayload {
  sub: string; // User ID
  variantId: string; // Game variant ID
  email?: string; // User email
  username?: string; // User display name
  isGuest: boolean; // Whether user is anonymous
  iat: number; // Issued at timestamp
  exp: number; // Expiration timestamp
}

Environment Variables

The SDK supports two token signing algorithms:

  • HS256 (Symmetric): Uses SUPABASE_JWT_SECRET
  • RS256 (Asymmetric): Uses RSA_PUBLIC_KEY for verification

The algorithm is automatically detected based on the token header.

Future Features

The v1 SDK will include additional modules:

  • Economy (purchase redemption)
  • Inventory (currency and item management)
  • Storage (room-based persistence)

See the @spawnco/sdk-types package for the full API surface.

Package Sidebar

Install

npm i @spawnco/server

Weekly Downloads

3,545

Version

0.0.26

License

MIT

Unpacked Size

97.9 kB

Total Files

11

Last publish

Collaborators

  • jsnns
  • jaivinspawn
  • bailey99
  • georgeatspawn