1.9.1 • Published 3 years ago

spacetraders-sdk v1.9.1

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

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>

getAccount

Get your info

spaceTraders.getAccount(): Promise<AccountResponse>

createFlightPlan

Submit a new flight plan

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

createStructure

create a new structure

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

depositToStructure

Deposit goods from a ship to a structure

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

getAvailableStructures

View available structure types to build

spaceTraders.getAvailableStructures(): Promise<AvailableStructuresResponse>

getFlightPlan

Get info on an existing flight plan

spaceTraders.getFlightPlan(): Promise<FlightPlanResponse>

getLocation

Get info on a location

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

getLocationShips

Get info on a location's docked ships

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

getMarketplace

Get info on a locations marketplace

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

getStatus

Use to determine whether the server is alive

spaceTraders.getStatus(): Promise<StatusResponse>

jettisonCargo

Use to jettison goods from a ship's cargo

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

listLocations

Get locations in a system

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

listStructures

Get information about all owned structures

spaceTraders.listStructures(): Promise<ListStructuresResponse>

listSystems

Get systems info

spaceTraders.listSystems(): Promise<SystemsResponse>

payBackLoan

Payback your loan

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

purchaseGood

Place a new purchase order

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

purchaseShip

Buy a new ship

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

sellGood

Place a new sell order

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

takeOutLoan

Request a new loan

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

transferFromShip

Transfers good between two owned ships

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

transferFromStructure

Transfer goods from a structure to a ship

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

viewAvailableLoans

Get available loans

spaceTraders.viewAvailableLoans(): Promise<AvailableLoanResponse>

viewAvailableShips

Get info on available ships

spaceTraders.viewAvailableShips(): Promise<AvailableShipResponse>

viewStructureDetails

Get information about a particular structure

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

warpJump

Attempt a warp jump with a ship

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

3 years ago

1.8.2

3 years ago

1.9.0

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.2

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.1.3

3 years ago

1.3.0

3 years ago

1.1.2

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.1

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.0

3 years ago