Resource API
Use client.system, client.cards, client.matches, client.session, and client.limitedEvents for all HTTP and socket workflows.
Namespaced HTTP resources, ergonomic match sessions, generated protocol types, and runtime validation from the Rust server contract.
pnpm add @my-swu/simulator-clientimport { createSimulatorClient } from '@my-swu/simulator-client'
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Use card ids; see /guide/card-ids for what each number means.
const premierHostDeck = {
leader: 46102, // Leia Organa - Someone Who Loves You
base: 308, // Echo Base
cards: Array.from({ length: 50 }, () => 45), // Alliance X-Wing
}
const hostAccess = await simulatorClient.matches.create({
// Fixed seed keeps this quick start reproducible.
seed: 7,
format: 'premier',
hostDeck: premierHostDeck,
})
// Session state keeps private access out of renderable state.
const matchSession = simulatorClient.session.create(hostAccess)
await matchSession.connect()
matchSession.on('snapshot', matchSnapshot => {
// Snapshots are the UI source of truth.
console.log('prompt:', matchSnapshot.prompt)
})
matchSession.ready()Next steps: