npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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>