Skip to content

@my-swu/simulator-client


@my-swu/simulator-client / MatchesResource

Interface: MatchesResource

Defined in: packages/ts-sdk/src/resources/matches.ts:119

Match resource API methods.

Use this resource for HTTP-only match lifecycle calls. For a stateful socket wrapper, create a MatchSession through client.session.

Example:

ts
import { 
createSimulatorClient
} from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes. const
simulatorClient
=
createSimulatorClient
({
baseUrl
: 'http://127.0.0.1:4000',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Creating a match returns private host seat access. const
hostAccess
= await
simulatorClient
.
matches
.
create
({
hostDeck
:
premierHostDeck
})
const
matchSnapshot
= await
simulatorClient
.
matches
.
get
(
hostAccess
)
console
.
log
(
matchSnapshot
.
phase
)

Example

ts
import { createSimulatorClient } from '@my-swu/simulator-client'

const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})

const premierHostDeck = {
  leader: 46102,
  base: 308,
  cards: Array.from({ length: 50 }, () => 45),
}
const hostAccess = await simulatorClient.matches.create({
  hostDeck: premierHostDeck,
})

console.log(hostAccess.matchId)

See

Methods

applyFormatEvent()

Example:

ts
import { 
createSimulatorClient
} from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes. const
simulatorClient
=
createSimulatorClient
({
baseUrl
: 'http://127.0.0.1:4000',
}) // Format events require private access for the acting seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
nextGameSnapshot
= await
simulatorClient
.
matches
.
applyFormatEvent
(
hostAccess
,
{
type
: 'readyNextGame' },
)

applyFormatEvent(access, command): Promise<GameState>

Defined in: packages/ts-sdk/src/resources/matches.ts:142

Applies one out-of-game format command such as sideboarding or Trilogy selection.

Parameters

access

MatchAccessInput

command

FormatEventCommand

Returns

Promise<GameState>

Example

ts
import { createSimulatorClient } from '@my-swu/simulator-client'

const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})
const hostAccess = { matchId: 'match_123', seatToken: 'seat_token_123' }

const nextGameSnapshot = await simulatorClient.matches.applyFormatEvent(
  hostAccess,
  { type: 'readyNextGame' },
)

console.log(nextGameSnapshot.phase)

See

https://simulator-sdk.my-swu.com/guide/match-lifecycle#format-events


create()

Example:

ts
import { 
createSimulatorClient
} from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes. const
simulatorClient
=
createSimulatorClient
({
baseUrl
: 'http://127.0.0.1:4000',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Host access includes the private seat token for seat one. const
hostAccess
= await
simulatorClient
.
matches
.
create
({
hostDeck
:
premierHostDeck
})

create(request): Promise<MatchAccessResponse>

Defined in: packages/ts-sdk/src/resources/matches.ts:169

Creates one match and returns host access.

Parameters

request

CreateMatchRequest

Returns

Promise<MatchAccessResponse>

Example

ts
import { createSimulatorClient } from '@my-swu/simulator-client'

const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})
const premierHostDeck = {
  leader: 46102,
  base: 308,
  cards: Array.from({ length: 50 }, () => 45),
}

const hostAccess = await simulatorClient.matches.create({
  format: 'premier',
  hostDeck: premierHostDeck,
})

console.log(hostAccess.seat)

See

https://simulator-sdk.my-swu.com/guide/match-lifecycle#creating-matches


get()

Example:

ts
import { 
createSimulatorClient
} from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes. const
simulatorClient
=
createSimulatorClient
({
baseUrl
: 'http://127.0.0.1:4000',
}) // Public fetch returns the current match snapshot projection. const
publicMatchSnapshot
= await
simulatorClient
.
matches
.
get
('match_123')

get(match): Promise<GameState>

Defined in: packages/ts-sdk/src/resources/matches.ts:187

Fetches the public match projection.

Parameters

match

string | MatchReference

Returns

Promise<GameState>

Example

ts
import { createSimulatorClient } from '@my-swu/simulator-client'

const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})

const publicMatchSnapshot = await simulatorClient.matches.get('match_123')
console.log(publicMatchSnapshot.phase)

See

https://simulator-sdk.my-swu.com/guide/http-client


join()

Example:

ts
import { 
createSimulatorClient
} from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes. const
simulatorClient
=
createSimulatorClient
({
baseUrl
: 'http://127.0.0.1:4000',
}) // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Only matchId is needed to join; the response returns seat two access. const
matchReference
= {
matchId
: 'match_123' }
const
guestAccess
= await
simulatorClient
.
matches
.
join
(
matchReference
, {
deck
:
premierGuestDeck
})

join(match, request): Promise<MatchAccessResponse>

Defined in: packages/ts-sdk/src/resources/matches.ts:214

Joins an existing match as the next open seat.

Parameters

match

MatchReference

request

JoinMatchRequest

Returns

Promise<MatchAccessResponse>

Example

ts
import { createSimulatorClient } from '@my-swu/simulator-client'

const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})
const premierGuestDeck = {
  leader: 46107,
  base: 309,
  cards: Array.from({ length: 50 }, () => 35),
}

const guestAccess = await simulatorClient.matches.join(
  { matchId: 'match_123' },
  { deck: premierGuestDeck },
)

console.log(guestAccess.seat)

See

https://simulator-sdk.my-swu.com/guide/match-lifecycle#joining-matches

Released under the MIT License.