npm.io
1.20.6 • Published 5 months agoCLI

@moneypot/hub

Licence
UNLICENSED
Version
1.20.6
Deps
15
Size
1.9 MB
Vulns
0
Weekly
0

@moneypot/hub

@moneypot/hub is our official GraphQL game server for building games for MoneyPot.com.

  • Extend it with custom tables and game logic.
  • Give it an api key for each controller you've registered on each casino.
  • It will automatically sync users, their balances, deposits, and withdrawals.

Example implementations:

  1. https://github.com/moneypot/controller-template/: An template hub server that comes with an example of a custom game implementation.

Manual

View our docs: https://docs.moneypot.com

Install

$ pnpm install @moneypot/hub

Usage

import {
  type ServerOptions,
  defaultPlugins,
  startAndListen,
  MakeOutcomeBetPlugin,
} from "@moneypot/hub";
import path from "path";

const options: ServerOptions = {
  // PostgreSQL schemas to expose to the GraphQL API
  // This allows your application-specific tables to be accessible through GraphQL
  extraPgSchemas: ["app"],

  plugins: [
    // These are required for the hub server to function
    ...defaultPlugins,
    // Add your custom plugins here to extend server functionality
    MakeOutcomeBetPlugin({
      houseEdge: 0.01,
    }),
  ],

  // File path where the generated GraphQL schema definition will be saved
  exportSchemaSDLPath: path.join(import.meta.dirname, "../schema.graphql"),

  // Optional: Directory containing migration files for your database
  // When enabled, the server will automatically apply pending migrations on startup
  userDatabaseMigrationsPath: path.join(
    import.meta.dirname,
    "../automigrations",
  ),
};

startAndListen(options)
  .then(({ port }) => {
    console.log(`Listening on ${port}`);
  })
  .catch(console.error);

Dashboard

When the server is running, visit its admin dashboard at the /dashboard route.

You'll need an api key from your hub database:

insert into hub.api_key default values returning key;

Changelog

You should always keep your hub server up to date as soon as possible. Never install an old, intermediate version: it may leave you without an automatic upgrade path.

1.20.x

Adds liability tracking for multistage games (mines, crash, etc.) that lock up bankroll before resolution.

  • (DB migration) New hub.bankroll.liability column
  • (DB migration) New hub.liability table (each row ties to a game row like app.mines_game)
  • dbCreateLiability() to reserve bankroll when a game starts, dbResolveLiability() to release it when it ends
  • Available bankroll = amount - liability
  • Type renames: DbBalanceDbPlayerBalance, DbBankrollDbHouseBankroll
  • dbLockedHouseBankroll() now returns DbLockedHouseBankrollWithAvailable (has available field)
1.19.x
  • All of hub's internal graphql-schema-modifying plugins have been moved to hub's set of required plugins.
  • Added FAILED take request auto-handling.
  • Exposed a @moneypot/hub/test module for end-user server testing.
1.18.x
  • MakeOutcomeBetPlugin replaced by HubGameConfigPlugin({ outcomeBetConfigs, customGameConfigs })
  • Added graphql query hubRiskLimits(gameKinds: [DICE]) to get risk limits for the game kinds configured in HubGameConfigPlugin.
    • This lets experiences display the max payout for each kind of bet.
1.17.x
  • Postgres transactions now default to read committed (postgres default)
  • Added cli script npx db-migrate <userMigrationDirectory> to run hub and user db migrations on SUPERUSER_DATABASE_URL.
    • Note: hub still runs any non-run migrations on server start
1.16.x
  • Added a simple built-in chat system.
  • You can opt-out of the chat system by passing startAndListen({ ..., enableChat: false }).
1.15.x
  • Added a "playground" casino (hub.casino.is_playground = true) that lets skin devs create ephemeral sessions for testing.
  • Added hubCreatePlaygroundSession mutation to create a playground session.
    • It's a drop-in replacement for hubAuthenticate({ userToken, baseCasinoUrl }) when you're testing your experience outside of the MoneyPot.com iframe (thus you don't have a userToken).
  • You can opt-out of allowing playground sessions by passing startAndListen({ ..., enablePlayground: false }), but remember that the objective of this system is to make it easier for developers to build experience frontends that bet against your server.
1.14.x
  • Added preimageHash field to HubHashChain to expose the preimage hash for a hash chain if it's revealed.
1.13.x
  • Added hubRevealHashChain mutation to generate a preimage hash for the chain and mark it as inactive.
1.12.x
1.11.x
  • Migrated database-related "globals" into a ServerContext object.
    • Changed configureApp(app: ExpressServer) to configureApp(args: { app: ExpressServer, superuserPool: pg.Pool })
    • In a postgraphile plugin, you can access the superuser database pool via const $superuserPool = context().get("superuserPool");
1.9.x
  • Added a required risk policy to makeOutcomeBet and a reusable validateRisk function that can be used in custom bet plugins / endpoints to decide how much bankroll you want to risk on a bet.
1.8.x
  • Added pino for logging.
  • Added LOG_LEVEL environment variable to set the logging level. (default: info)
  • Added LOG_PRETTY environment variable to force enable/disable pretty logging (requires npm install pino-pretty).
  • Exposed @moneypot/hub/logger. Example: import { logger } from "@moneypot/hub/logger";
1.7.x

Updated Hub to handle breaking changes in moneypot-server GraphQL transfer API.

1.6.x

Hub now maintains a websocket connection to the casino API so that it can respond immediately to puts and takes.

1.5.x

Migrated to Postgraphile beta.42 which has new plugin and polymorphism systems:

Read more: