Spacetraders.io API client built with TypeScript, generated via openapi-generator-cli. See options for generator type typescript-fetch
🌐 Spacetraders Homepage | 📚 Getting Started Guide | 🔧 API Playground
npm install @spacejunk/airlock
- TypeScript support
- Fetch-based HTTP requests
- Generates both ESM and CJS clients
- Autogenerated by openapi-generator-cli
If you're using this in the Browser, you don't need to setup anything!
However, if you're using it serverside with Node.js, this package requires Node.js v18 or higher. Node 18 is the first version to support native fetch. To install Node.js v18, we recommend using Node Version Manager (nvm). Follow the instructions below based on your operating system:
To install nvm on macOS, run the following command in your terminal:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Restart your terminal and run the following command to install Node.js v18:
nvm install 18
# then, set your version to Node 18 via use
nvm use 18
To install nvm on Windows, download and run the installer from the nvm-windows GitHub repository.
Once installed, open a new Command Prompt or PowerShell window and run the following command to install Node.js v18:
nvm install 18
# then, set your version to Node 18 via use
nvm use 18
To use the @spacejunk/airlock
package in your project, follow this example:
import {
Configuration,
FleetApi,
} from '@spacejunk/airlock';
// Set up a configuration with your access token
export const config = new Configuration({
accessToken: 'your agent token'
});
// create and configure an api client
const fleet = new FleetApi(config);
// List your agent's ships
export const getShips = async () => {
try {
const { data } = await fleet.getMyShips();
return data;
} catch (error) {
console.error(error);
}
};
// Navigate to a target destination
export const navigateShip = async ({
shipSymbol,
waypointSymbol,
}: {
shipSymbol: string;
waypointSymbol: string;
}) => {
const { data } = await fleet.navigateShip(shipSymbol, { waypointSymbol });
return data;
};
To build the package and automatically pull the latest OpenAPI schema from https://github.com/SpaceTradersAPI/api-docs, run the following command:
npm run build
This command generates the API client in both ESM and CJS formats.
To watch for changes and rebuild automatically, use:
npm run watch