bahrmichael / spacetraders-io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Submit a new flight plan

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

Get your info

spaceTraders.getAccount(): Promise<AccountResponse>

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 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 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>

Get available loans

spaceTraders.viewAvailableLoans(): Promise<AvailableLoanResponse>

Get info on available ships

spaceTraders.viewAvailableShips(): Promise<AvailableShipResponse>

View available structure types to build

spaceTraders.getAvailableStructures(): Promise<AvailableStructuresResponse>

create a new structure

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

Deposit goods from a ship to a structure

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

Transfer goods from a structure to a ship

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

Get information about a particular structure

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

Get information about all owned structures

spaceTraders.listStructures(): Promise<ListStructuresResponse>

About


Languages

Language:TypeScript 100.0%