-
-
Notifications
You must be signed in to change notification settings - Fork 6
TypeScript Types
The Stake Engine Client provides complete TypeScript type definitions auto-generated from the OpenAPI schema. All types are exported for use in your own code.
All API requests and responses are fully typed, giving you:
- IntelliSense - Autocomplete in your IDE
- Type Safety - Catch errors at compile time
- Documentation - Inline type hints
The types are defined in src/types.ts and exported from the main package.
import type {
components,
paths,
operations
} from 'stake-engine-client';Contains all schema definitions for request/response bodies:
import type { components } from 'stake-engine-client';
type AuthResponse = components['schemas']['res_authenticate'];
type BetResponse = components['schemas']['res_play'];
type Balance = components['schemas']['Balance'];
type Status = components['schemas']['Status'];Maps API endpoints to their operation types:
import type { paths } from 'stake-engine-client';
type AuthenticateEndpoint = paths['/wallet/authenticate'];
type PlayEndpoint = paths['/wallet/play'];Type definitions for each API operation:
import type { operations } from 'stake-engine-client';
type AuthenticateOp = operations['authenticate'];
type PlayOp = operations['play'];
type BalanceOp = operations['balance'];import type { components } from 'stake-engine-client';
// Authentication response
type AuthResponse = components['schemas']['res_authenticate'];
// Contains: balance, config, status, etc.
// Bet/play response
type BetResponse = components['schemas']['res_play'];
// Contains: round, balance, status, bet, etc.
// Balance response
type BalanceResponse = components['schemas']['res_Balance'];
// End round response
type EndRoundResponse = components['schemas']['res_end_round'];
// Replay response
type ReplayResponse = components['schemas']['res_replay'];import type { components } from 'stake-engine-client';
// Authenticate request
type AuthRequest = components['schemas']['req_authenticate'];
// Bet request
type BetRequest = components['schemas']['req_play'];
// Search request
type SearchRequest = components['schemas']['req_search'];import type { components } from 'stake-engine-client';
// Player balance
type Balance = components['schemas']['Balance'];
// Properties: amount, currency
// API status
type Status = components['schemas']['Status'];
// Properties: statusCode, statusMessage
// Round information
type Round = components['schemas']['Round'];
// Properties: roundID, state, payoutMultiplier, etc.
// Game configuration
type Config = components['schemas']['Config'];
// Properties: betLevels, modes, etc.import type { components } from 'stake-engine-client';
function handleBetResponse(response: components['schemas']['res_play']) {
if (response.status?.statusCode === 'SUCCESS') {
console.log('Round ID:', response.round?.roundID);
console.log('Payout:', response.round?.payoutMultiplier);
}
}import { useState } from 'react';
import type { components } from 'stake-engine-client';
function GameComponent() {
const [balance, setBalance] = useState<components['schemas']['Balance'] | null>(null);
const [round, setRound] = useState<components['schemas']['Round'] | null>(null);
// ...
}import type { components } from 'stake-engine-client';
// Extract specific properties
type RoundInfo = {
roundID: string;
payout: number;
state: components['schemas']['Round']['state'];
};
// Extend existing types
interface GameState extends components['schemas']['res_play'] {
localState: {
isAnimating: boolean;
selectedBet: number;
};
}Generic type for game-specific betting logic:
import type { components } from 'stake-engine-client';
// Define your game-specific bet data
interface MyGameBet {
selectedLines: number[];
multiplier: number;
}
type MyGameBetResponse = components['schemas']['res_play'] & {
bet: MyGameBet;
};The Status type includes all possible status codes:
import type { components } from 'stake-engine-client';
type StatusCode = components['schemas']['Status']['statusCode'];
// Common values:
// - 'SUCCESS'
// - 'ERR_IPB' (Insufficient Player Balance)
// - 'ERR_IS' (Invalid Session)
// - 'ERR_IB' (Invalid Bet)
// - 'ERR_PAB' (Player Already has Bet)Usage:
import { play } from 'stake-engine-client';
import type { components } from 'stake-engine-client';
const response = await play({ amount: 1.00, mode: 'base' });
switch (response.status?.statusCode) {
case 'SUCCESS':
console.log('Bet placed successfully');
break;
case 'ERR_IPB':
console.log('Insufficient balance');
break;
case 'ERR_PAB':
console.log('Player already has an active bet');
break;
default:
console.log('Error:', response.status?.statusMessage);
}Use TypeScript's type narrowing for safer code:
import { play } from 'stake-engine-client';
const response = await play({ amount: 1.00, mode: 'base' });
// Check for success
if (response.status?.statusCode === 'SUCCESS') {
// TypeScript knows round should exist here
console.log('Round ID:', response.round?.roundID);
}
// Check for specific fields
if (response.balance && response.balance.amount !== undefined) {
const balance: number = response.balance.amount;
console.log('Balance:', balance / 1000000); // Convert to dollars
}All types are defined in src/types.ts. The file is ~474 lines and includes:
- 8 API endpoints with full request/response types
- 50+ schema definitions for all data structures
- Type helpers for union types and generics
- OpenAPI-compliant types matching the RGS API spec
To explore all available types, check your IDE's autocomplete or view the source file directly.
-
Always import types with
typekeywordimport type { components } from 'stake-engine-client'; // ✅ Good import { components } from 'stake-engine-client'; // ❌ Bad (runtime import)
-
Use optional chaining for nested properties
console.log(response.balance?.amount); // ✅ Safe console.log(response.balance.amount); // ❌ Can throw if undefined
-
Check status codes before accessing data
if (response.status?.statusCode === 'SUCCESS') { // Safe to access round data here }
-
Type your state early in development
const [data, setData] = useState<components['schemas']['res_play'] | null>(null);
- StakeEngineClient Class - Using types with the client
- Error Handling - Working with status types
- Status Codes - Complete status code reference