0.1.0 • Published yesterday
@cwe-dev/casino-sdk
Licence
MIT
Version
0.1.0
Deps
0
Size
510 kB
Vulns
0
Weekly
60
@cwe-dev/casino-sdk
The player / casino frontend SDK for the CasinoWebEngine Runtime Core. It wraps everything a player can do — auth, cashier, wallet, catalog, real game launch, and live realtime updates — and hides the cross-cutting concerns (cookie session, CSRF, tenant header, idempotency keys, reconnect, dedupe) so your frontend never thinks about them.
- Framework-agnostic core + optional React bindings (
/react) and a standalone realtime client (/realtime). - Isomorphic: browser, Node, and Next.js (SSR/RSC-safe — realtime is client-only).
- Fully typed end-to-end, dual ESM + CJS, tree-shakeable, zero secrets.
- Money is integer minor units with
formatMoneydisplay helpers.
The SDK talks to the runtime over the network (
baseUrl/wsUrl). It is not a code dependency of the runtime — it is the player HTTP/WS contract, typed.
Install
pnpm add @cwe-dev/casino-sdk
# React bindings need react as a peer; Node realtime needs ws:
pnpm add react wsQuickstart (login → deposit → lobby → launch → live balance)
import { createCasinoClient, formatMoney } from "@cwe-dev/casino-sdk";
const sdk = createCasinoClient({
baseUrl: "https://api.staging.example",
wsUrl: "wss://api.staging.example/realtime",
tenantId: "grandbet",
realtime: {
// Re-read authoritative state after every (re)connect — the socket accelerates, REST is truth.
resync: async () => {
const b = await sdk.wallet.getBalance();
console.log("balance", formatMoney(b.cash, b.currency));
},
},
});
// 1. Authenticate (cookie session; CSRF + tenant handled for you)
await sdk.auth.login({ email: "player@example.com", password: "secret123" });
// 2. Deposit (amounts in minor units; idempotency key auto-generated)
await sdk.cashier.deposit({ amount: 5_000_0 /* €50.00 */ });
// 3. Lobby (geo/currency-aware)
const { games } = await sdk.catalog.lobby({ country: "DE", limit: 24 });
// 4. Launch a real SlotServ game → render the returned URL in an iframe
const { launchUrl } = await sdk.games.launch(games[0]!.id, { device: "desktop", mode: "real" });
// 5. Live balance over the realtime gateway
await sdk.realtime.connect();
sdk.realtime.on("wallet.balance", (e) => {
console.log("live balance", formatMoney(e.data.balances.cash, e.data.currency));
});React
"use client";
import { CasinoProvider, useAuth, useBalance, useLobby, useGameLaunch } from "@cwe-dev/casino-sdk/react";
import { createCasinoClient, formatMoney } from "@cwe-dev/casino-sdk";
const sdk = createCasinoClient({ baseUrl, wsUrl, tenantId: "grandbet" });
export default function App() {
return (
<CasinoProvider client={sdk}>
<Wallet />
</CasinoProvider>
);
}
function Wallet() {
const { player } = useAuth();
const { data: balance, connection } = useBalance(); // live, realtime-backed
return (
<div>
{player?.email} — {balance && formatMoney(balance.cash, balance.currency)} ({connection})
</div>
);
}Modules
| Module | What |
|---|---|
sdk.auth |
signup, login, logout, refresh, me, social OAuth |
sdk.cashier |
deposit, withdraw (methods/status: roadmap) |
sdk.wallet |
balance buckets (cash/bonus/locked), transaction history |
sdk.catalog |
lobby, search, categories tree, providers, game detail, suggested, trending |
sdk.games |
launch a real SlotServ game → { launchUrl, sessionId } |
sdk.realtime |
ticket handshake → WS; channels wallet.balance/deposit/withdrawal, gaming, bonus, player |
sdk.player |
profile (preferences/limits/KYC: roadmap) |
Documentation
docs/SDK_BIBLE.md— the SDK's source of truth (design, auth/CSRF, realtime, errors, money, versioning, publishing, endpoint map).docs/guides/— per-module guides.- API reference:
pnpm docs(TypeDoc →docs/api). - Local development & linking:
docs/guides/linking.md.
License
MIT