Skip to content

Latest commit

 

History

History
274 lines (176 loc) · 6.62 KB

README.md

File metadata and controls

274 lines (176 loc) · 6.62 KB

Spacetraders.io Javascript/Typescript SDK

Install

yarn add spacetraders-sdk

or

npm i spacetraders-sdk

Usage

The SDK will keep your username + token in memory. It's important that you save the token for a new user otherwise you'll lose access to that user.

The SDK will attempt to retry 429 http status codes up to 3 (default value) times for a request before throwing an error.

import { SpaceTraders } from 'spacetraders-sdk'

const spaceTraders = new SpaceTraders()

// Already existing user
spaceTraders.init('username', 'token')

// Claim a new user
const token = await spaceTraders.init('username')

Options

interface Options {
  /**
   * If all instances of SpaceTraders should use the same limiter. Defaults to false.
   */
  useSharedLimiter?: boolean;
  /**
   * Maximum amount of 429 (Rate-Limited) retries. Defaults to 3.
   */
  maxRetries?: number
}

interface LimiterOptions {
  /**
   * How many jobs can be running at the same time. No default.
   */
  maxConcurrent?: number;
  /**
   * How long to wait after launching a job before launching another one. No default.
   */
  minTime?: number;
}

constructor(options?: Options, limiterOptions?: LimiterOptions)

Basic rate-limiting

import { SpaceTraders } from 'spacetraders-sdk'

const spaceTraders = new SpaceTraders({ useSharedLimiter: true }, { maxConcurrent: 2, minTime: 500 })

Methods

init

Login or create a new account

spaceTraders.init(username: string, token?: string): Promise<string>

Get your info

spaceTraders.getAccount(): Promise<AccountResponse>

Submit a new flight plan

spaceTraders.createFlightPlan(shipId: string, destination: string): Promise<FlightPlanResponse>

create a new structure

spaceTraders.createStructure(type: string, location: string): Promise<CreateStructureResponse>

Deposit goods from a ship to a structure

spaceTraders.depositToOwnedStructure(structureId: string, shipId: string, good: Good, quantity: number): Promise<StructureDepositResponse>

View available structure types to build

spaceTraders.getAvailableStructures(): Promise<AvailableStructuresResponse>

Get info on an existing flight plan

spaceTraders.getFlightPlan(): Promise<FlightPlanResponse>

Get info on a location

spaceTraders.getLocation(location: string): Promise<LocationResponse>;

Get info on a location's docked ships

spaceTraders.getLocation(location: string): Promise<LocationShipResponse>

Get info on a locations marketplace

spaceTraders.getMarketplace(location: string): Promise<MarketplaceResponse>

Use to determine whether the server is alive

spaceTraders.getStatus(): Promise<StatusResponse>

Use to jettison goods from a ship's cargo

spaceTraders.jettisonGoods(shipId: string, good: string, quantity: number): Promise<JettisonResponse>

Get locations in a system

spaceTraders.listLocations(system?: string, type?: string): Promise<LocationsResponse>

Get information about all owned structures

spaceTraders.listStructures(): Promise<ListStructuresResponse>

Get systems info

spaceTraders.listSystems(): Promise<SystemsResponse>

Payback your loan

spaceTraders.payBackLoan(loanId: string): Promise<AccountResponse>

Place a new purchase order

spaceTraders.purchaseGood(shipId: string, good: string, quantity: number): Promise<PurchaseResponse>

Buy a new ship

spaceTraders.purchaseShip(location: string, type: string): Promise<AccountResponse>

Place a new sell order

spaceTraders.sellGood(shipId: string, good: string, quantity: number): Promise<PurchaseResponse>

Request a new loan

spaceTraders.takeOutLoan(type: LoanType): Promise<AccountResponse>

Transfers good between two owned ships

spaceTraders.transferGoodsBetweenShips(fromShip: string, toShip: string, good: Good, quantity: number): Promise<ShipTransferResponse>

Transfer goods from a structure to a ship

spaceTraders.transferFromStructure(structureId: string, shipId: string, good: Good, quantity: number): Promise<StructureTransferResponse>

Get available loans

spaceTraders.viewAvailableLoans(): Promise<AvailableLoanResponse>

Get info on available ships

spaceTraders.viewAvailableShips(): Promise<AvailableShipResponse>

Get information about a particular structure

spaceTraders.viewStructureDetails(structureId: string): Promise<CreateStructureResponse>

Attempt a warp jump with a ship

spaceTraders.warpJump(shipId: string): Promise<FlightPlanResponse>