Skip to content

@my-swu/simulator-client


@my-swu/simulator-client / CardsResource

Interface: CardsResource ​

Defined in: packages/ts-sdk/src/resources/card-resource.ts:35

Card metadata and deck import API methods.

Use this resource to fetch canonical display metadata and convert my-swu JSON deck exports before creating a match.

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',
})

// Resolve card ids from the simulator cache.
const requestedCardMetadata = await simulatorClient.cards.get([
  46102, // Leia Organa - Someone Who Loves You
  308, // Echo Base
])

// Set/card-number lookups return card ids.
const krennicCardId = await simulatorClient.cards.resolveId({
  setCode: 'SOR',
  cardNumber: 1,
  cardTypes: [
    'leader',
  ],
})

// my-swu JSON deck ids use SET_001 form.
const importedDeck = await simulatorClient.cards.convertDeckJson({
  metadata: { name: 'Import Test', author: 'tester' },
  leader: { id: 'SOR_001', count: 1 },
  base: { id: 'SOR_025', count: 1 },
  deck: [{ id: 'SOR_010', count: 3 }],
  sideboard: [{ id: 'SOR_047', count: 2 }],
})

const catalogCards = await simulatorClient.cards.catalog()

console.log(
  requestedCardMetadata.length,
  krennicCardId,
  importedDeck.cards.length,
  catalogCards.length,
)

Example ​

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

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

const requestedCardMetadata = await simulatorClient.cards.get([46102, 308])
console.log(requestedCardMetadata.map(card => card.title))

See ​

Methods ​

catalog() ​

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',
})

// Catalog lists canonical production card metadata.
const catalogCards = await simulatorClient.cards.catalog()

catalog(options?): Promise<CardMetadataView[]>

Defined in: packages/ts-sdk/src/resources/card-resource.ts:74

Lists canonical production card metadata for every card identity.

Parameters ​

options? ​

SimulatorRequestOptions

Returns ​

Promise<CardMetadataView[]>

Example ​

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

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

const catalog = await simulatorClient.cards.catalog()
console.log(catalog.length)

See ​

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


convertDeckJson() ​

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',
})

// my-swu JSON deck ids use SET_001 form.
const importedDeck = await simulatorClient.cards.convertDeckJson({
  metadata: { name: 'Import Test', author: 'tester' },
  leader: { id: 'SOR_001', count: 1 },
  base: { id: 'SOR_025', count: 1 },
  deck: [{ id: 'SOR_010', count: 3 }],
  sideboard: [{ id: 'SOR_047', count: 2 }],
})

convertDeckJson(deckJson, options?): Promise<DeckInput>

Defined in: packages/ts-sdk/src/resources/card-resource.ts:97

Converts a my-swu JSON deck export into simulator deck input.

Parameters ​

deckJson ​

string | DeckJson

options? ​

SimulatorRequestOptions

Returns ​

Promise<DeckInput>

Example ​

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

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

const importedDeck = await simulatorClient.cards.convertDeckJson({
  leader: { id: 'SOR_001', count: 1 },
  base: { id: 'SOR_025', count: 1 },
  deck: [{ id: 'SOR_010', count: 3 }],
})

console.log(importedDeck.cards.length)

See ​

https://simulator-sdk.my-swu.com/guide/card-ids#json-deck-imports


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',
})

// Resolve card ids from the simulator cache.
const requestedCardMetadata = await simulatorClient.cards.get([
  46102, // Leia Organa - Someone Who Loves You
  308, // Echo Base
])

get(ids, options?): Promise<CardMetadataView[]>

Defined in: packages/ts-sdk/src/resources/card-resource.ts:56

Fetches canonical metadata for the requested card ids.

Use this when snapshots or deck lists only contain card ids and your UI needs titles, aspects, traits, cost, rules text, or other display metadata.

Parameters ​

ids ​

number[]

options? ​

SimulatorRequestOptions

Returns ​

Promise<CardMetadataView[]>

Example ​

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

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

const requestedCardMetadata = await simulatorClient.cards.get([46102, 308])
console.log(requestedCardMetadata.map(card => card.title))

See ​

https://simulator-sdk.my-swu.com/guide/card-ids


resolveId() ​

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',
})

// Set/card-number lookups return card ids.
const krennicCardId = await simulatorClient.cards.resolveId({
  setCode: 'SOR',
  cardNumber: 1,
  cardTypes: [
    'leader',
  ],
})

resolveId(reference, options?): Promise<number>

Defined in: packages/ts-sdk/src/resources/card-resource.ts:128

Resolves one set-code/card-number reference into one card id.

This helper throws when the reference is not found or stays ambiguous after applying cardTypes.

Parameters ​

reference ​

CardReferenceInput

options? ​

SimulatorRequestOptions

Returns ​

Promise<number>

Example ​

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

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

const krennicCardId = await simulatorClient.cards.resolveId({
  setCode: 'SOR',
  cardNumber: 1,
  cardTypes: [
    'leader',
  ],
})

console.log(krennicCardId)

See ​

https://simulator-sdk.my-swu.com/guide/card-ids#resolving-card-ids


resolveIds() ​

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',
})

// Batch lookup when importing many set/card-number references.
const cardIdResolutions = await simulatorClient.cards.resolveIds([
  {
    setCode: 'SOR',
    cardNumber: 1,
    cardTypes: [
      'leader',
    ],
  },
  {
    setCode: 'SOR',
    cardNumber: 25,
    cardTypes: [
      'base',
    ],
  },
])

resolveIds(references, options?): Promise<CardIdResolutionView[]>

Defined in: packages/ts-sdk/src/resources/card-resource.ts:165

Resolves set-code/card-number references through the simulator card cache.

Use this for bulk deck imports so you can show all not-found and ambiguous references together instead of failing at the first issue.

Parameters ​

references ​

CardReferenceInput[]

options? ​

SimulatorRequestOptions

Returns ​

Promise<CardIdResolutionView[]>

Example ​

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

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

const cardIdResolutions = await simulatorClient.cards.resolveIds([
  {
    setCode: 'SOR',
    cardNumber: 1,
    cardTypes: [
      'leader',
    ],
  },
  {
    setCode: 'SOR',
    cardNumber: 25,
    cardTypes: [
      'base',
    ],
  },
])

console.log(cardIdResolutions.map(result => result.cardId))

See ​

https://simulator-sdk.my-swu.com/guide/card-ids#resolving-card-ids

Released under the MIT License.