spacetraders-sdk
v1.9.1
Published
## Install
Downloads
22
Readme
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>