npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

infinite-games-sdk

v0.0.7

Published

Infinite Games SDK

Readme

Infinite Games SDK

TypeScript SDK for Infinite Games session management and real-time game sync.

Installation

pnpm add infinite-games-sdk

Game Frontend Integration

Initialize Game Session

The initializeGame function handles the complete session flow in one call:

import { initializeGame, AuthError } from 'infinite-games-sdk';
import { createTable, getBalanceFromBackend } from './api';

// Get token from URL
const params = new URLSearchParams(window.location.search);
const token = params.get('token');
const coinType = params.get('coinType');

try {
  const result = await initializeGame({
    token,
    coinType,
    sessionToken: sessionStorage.getItem('session_token'),
    createTable: (session, coin) => createTable(session, coin),
    getTableInfo: (tableId, session) => getBalanceFromBackend(session, tableId),
  });

  // Save session token for future use
  if (result.sessionToken) {
    sessionStorage.setItem('session_token', result.sessionToken);
  }

  // Start the game
  startGame(result.tableId, result.coinType, result.sessionToken);
} catch (error) {
  if (error instanceof AuthError) {
    showError('Launch link expired. Please launch again from the main website.');
  }
}

The function automatically handles:

  • OTT (one-time token): Exchanges for session JWT, creates table, returns result
  • table_id: Fetches table info (spectator/returning player), returns result
  • Expired JWT: Throws AuthError with user-friendly message

Real-time Game Sync (React)

import { useHistoryClient } from 'infinite-games-sdk';

function Game({ tableId, coinType, isSpectator }) {
  const [spectatorBets, setSpectatorBets] = useState({ playerBet: 0, bankerBet: 0 });

  const { isConnected, sendBetUpdate } = useHistoryClient(tableId, coinType, {
    onMessage: (message) => {
      // Game events from history service
      if (message.playerHand) {
        playGameAnimation(message);
      }
      // Bet updates for spectators
      if (message.type === 'bet_update' && isSpectator) {
        setSpectatorBets(message);
      }
    },
  });

  // Owner broadcasts bets to spectators
  const handleBetChange = (bets) => {
    if (!isSpectator) {
      sendBetUpdate(bets);
    }
  };
}

Real-time Game Sync (Vanilla JS)

import { HistoryClient } from 'infinite-games-sdk';

const client = new HistoryClient();

client.onMessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.channel && msg.data) {
    // Game event from history service
    handleGameEvent(msg.data);
  } else if (msg.type === 'bet_update') {
    // Bet update relay
    handleBetUpdate(msg);
  }
};

client.connect(tableId, 'sui/sui');
client.send({ type: 'bet_update', playerBet: 100, bankerBet: 0 });
client.disconnect();

Parent Site Integration (doubleup-io)

Launch a Game

import { SessionClient } from 'infinite-games-sdk';

const session = new SessionClient();

const { launchUrl, origin, token } = await session.getLaunchUrl({
  address: wallet.address,
  signature: await wallet.signMessage('Sign in to Infinite Games'),
  chain: 'sui',
  gameType: 'baccarat',
});

// Load game in iframe
iframe.src = launchUrl;

useGameLauncher Hook

React hook for complete game launch flow with URL management:

import { useGameLauncher } from 'infinite-games-sdk';
import { useSearchParams } from 'react-router-dom';

function BaccaratPage() {
  const { wallet, launch } = useAuth();
  const [searchParams, setSearchParams] = useSearchParams();

  const {
    iframeSrc,
    iframeHeight,
    error,
    isLoading,
    showConnectPrompt,
    retry,
  } = useGameLauncher(
    {
      gameType: 'baccarat',
      defaultOrigin: 'https://baccaratdev.infiniteedgers.com',
    },
    {
      wallet,
      launch,
      getSearchParams: () => searchParams,
      setSearchParams: (params, opts) => setSearchParams(params, opts),
    }
  );

  if (showConnectPrompt) return <ConnectWallet />;
  if (error) return <Error message={error} onRetry={retry} />;
  if (isLoading) return <Loading />;
  
  return <iframe src={iframeSrc} style={{ height: iframeHeight ?? '100vh' }} />;
}

Utilities

Scale Conversion

Backend uses 10^9 scale for precision:

import { toBackendScale, fromBackendScale } from 'infinite-games-sdk';

toBackendScale(1.5);          // 1500000000
fromBackendScale(1500000000); // 1.5

Token Utilities

import { isTableId, isOneTimeToken, getTokenType } from 'infinite-games-sdk';

isTableId('550e8400-e29b-41d4-a716-446655440000');  // true
isOneTimeToken(jwtWithAudLogin);                     // true
getTokenType(token);  // 'ott' | 'table_id' | 'expired_jwt' | 'unknown'

Configuration

// Dev (default)
new SessionClient();
new HistoryClient();

// Production
new SessionClient({ baseUrl: 'https://session.infiniteedgers.com' });
new HistoryClient({ baseUrl: 'history.infiniteedgers.com' });

// initializeGame with custom session URL
initializeGame({
  // ...options
  sessionConfig: { baseUrl: 'https://session.infiniteedgers.com' },
});